diff options
| author | Daniel Stenberg <daniel@haxx.se> | 2004-10-13 13:39:15 +0000 |
|---|---|---|
| committer | Daniel Stenberg <daniel@haxx.se> | 2004-10-13 13:39:15 +0000 |
| commit | dd4ce34e003e7fc9c2b11a254f2368904aa40c20 (patch) | |
| tree | 5a7bd4d40999bd0019591481334befab66b4c2fe | |
| parent | 5e54aa956fb9188b78717d88fca72bd11eaa4a6b (diff) | |
| download | rockbox-dd4ce34e003e7fc9c2b11a254f2368904aa40c20.zip rockbox-dd4ce34e003e7fc9c2b11a254f2368904aa40c20.tar.gz rockbox-dd4ce34e003e7fc9c2b11a254f2368904aa40c20.tar.bz2 rockbox-dd4ce34e003e7fc9c2b11a254f2368904aa40c20.tar.xz | |
song db generation tool embryo
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@5269 a1c6a512-1295-4272-9138-f99709370657
| -rwxr-xr-x | tools/songdb.pl | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/tools/songdb.pl b/tools/songdb.pl new file mode 100755 index 0000000..64bce44 --- /dev/null +++ b/tools/songdb.pl @@ -0,0 +1,93 @@ +#!/usr/bin/perl + +# Very sparse docs: +# http://search.cpan.org/~cnandor/MP3-Info-1.02/Info.pm + +# MP3::Info is installed on debian using package 'libmp3-info-perl' + +use MP3::Info; + +my $dir = $ARGV[0]; + +if(! -d $dir) { + print "given argument is not a directory!\n"; + exit; +} + +# return ALL directory entries in the given dir +sub getdir { + my ($dir) = @_; + + opendir(DIR, $dir) || die "can't opendir $dir: $!"; + # my @mp3 = grep { /\.mp3$/ && -f "$dir/$_" } readdir(DIR); + my @all = readdir(DIR); + closedir DIR; + return @all; +} + +sub extractmp3 { + my ($dir, @files) = @_; + my @mp3; + for(@files) { + if( /\.mp3$/ && -f "$dir/$_" ) { + push @mp3, $_; + } + } + return @mp3; +} + +sub extractdirs { + my ($dir, @files) = @_; + my @dirs; + for(@files) { + if( -d "$dir/$_" && ($_ !~ /^\.(|\.)$/)) { + push @dirs, $_; + } + } + return @dirs; +} + +sub singlefile { + my ($file) = @_; + +# print "Check $file\n"; + + my $hash = get_mp3tag($file); + # my $hash = get_mp3info($file); + +# for(keys %$hash) { +# print "Info: $_ ".$hash->{$_}."\n"; +# } + + return $hash; # a hash reference +} + +sub dodir { + my ($dir)=@_; + + # getdir() returns all entries in the given dir + my @a = getdir($dir); + + # extractmp3 filters out only the mp3 files from all given entries + my @m = extractmp3($dir, @a); + + my $f; + + for $f (sort @m) { + + my $id3 = singlefile("$dir/$f"); + + printf "Artist: %s\n", $id3->{'ARTIST'}; + } + + # extractdirs filters out only subdirectories from all given entries + my @d = extractdirs($dir, @a); + + for $d (sort @d) { + print "Subdir: $d\n"; + dodir("$dir/$d"); + } +} + + +dodir($dir); |