diff options
Diffstat (limited to 'tools/songdb.pl')
-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 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 | |||
8 | use MP3::Info; | ||
9 | |||
10 | my $dir = $ARGV[0]; | ||
11 | |||
12 | if(! -d $dir) { | ||
13 | print "given argument is not a directory!\n"; | ||
14 | exit; | ||
15 | } | ||
16 | |||
17 | # return ALL directory entries in the given dir | ||
18 | sub 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 | |||
28 | sub 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 | |||
39 | sub 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 | |||
50 | sub 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 | |||
65 | sub 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 | |||
93 | dodir($dir); | ||