summaryrefslogtreecommitdiff
path: root/tools/songdb.pl
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2004-10-13 13:39:15 +0000
committerDaniel Stenberg <daniel@haxx.se>2004-10-13 13:39:15 +0000
commitdd4ce34e003e7fc9c2b11a254f2368904aa40c20 (patch)
tree5a7bd4d40999bd0019591481334befab66b4c2fe /tools/songdb.pl
parent5e54aa956fb9188b78717d88fca72bd11eaa4a6b (diff)
downloadrockbox-dd4ce34e003e7fc9c2b11a254f2368904aa40c20.tar.gz
rockbox-dd4ce34e003e7fc9c2b11a254f2368904aa40c20.zip
song db generation tool embryo
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@5269 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'tools/songdb.pl')
-rwxr-xr-xtools/songdb.pl93
1 files changed, 93 insertions, 0 deletions
diff --git a/tools/songdb.pl b/tools/songdb.pl
new file mode 100755
index 0000000000..64bce440b5
--- /dev/null
+++ b/tools/songdb.pl
@@ -0,0 +1,93 @@
1#!/usr/bin/perl
2
3# Very sparse docs:
4# http://search.cpan.org/~cnandor/MP3-Info-1.02/Info.pm
5
6# MP3::Info is installed on debian using package 'libmp3-info-perl'
7
8use MP3::Info;
9
10my $dir = $ARGV[0];
11
12if(! -d $dir) {
13 print "given argument is not a directory!\n";
14 exit;
15}
16
17# return ALL directory entries in the given dir
18sub getdir {
19 my ($dir) = @_;
20
21 opendir(DIR, $dir) || die "can't opendir $dir: $!";
22 # my @mp3 = grep { /\.mp3$/ && -f "$dir/$_" } readdir(DIR);
23 my @all = readdir(DIR);
24 closedir DIR;
25 return @all;
26}
27
28sub extractmp3 {
29 my ($dir, @files) = @_;
30 my @mp3;
31 for(@files) {
32 if( /\.mp3$/ && -f "$dir/$_" ) {
33 push @mp3, $_;
34 }
35 }
36 return @mp3;
37}
38
39sub extractdirs {
40 my ($dir, @files) = @_;
41 my @dirs;
42 for(@files) {
43 if( -d "$dir/$_" && ($_ !~ /^\.(|\.)$/)) {
44 push @dirs, $_;
45 }
46 }
47 return @dirs;
48}
49
50sub singlefile {
51 my ($file) = @_;
52
53# print "Check $file\n";
54
55 my $hash = get_mp3tag($file);
56 # my $hash = get_mp3info($file);
57
58# for(keys %$hash) {
59# print "Info: $_ ".$hash->{$_}."\n";
60# }
61
62 return $hash; # a hash reference
63}
64
65sub dodir {
66 my ($dir)=@_;
67
68 # getdir() returns all entries in the given dir
69 my @a = getdir($dir);
70
71 # extractmp3 filters out only the mp3 files from all given entries
72 my @m = extractmp3($dir, @a);
73
74 my $f;
75
76 for $f (sort @m) {
77
78 my $id3 = singlefile("$dir/$f");
79
80 printf "Artist: %s\n", $id3->{'ARTIST'};
81 }
82
83 # extractdirs filters out only subdirectories from all given entries
84 my @d = extractdirs($dir, @a);
85
86 for $d (sort @d) {
87 print "Subdir: $d\n";
88 dodir("$dir/$d");
89 }
90}
91
92
93dodir($dir);