summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjörn Stenberg <bjorn@haxx.se>2005-01-17 11:18:44 +0000
committerBjörn Stenberg <bjorn@haxx.se>2005-01-17 11:18:44 +0000
commit025f5c00845a328eb0b8674bc88fd5f9cb8ee76d (patch)
tree72c78036faa62b700cdb5758da898674f9df1b07
parent5bc7e9a952277d58365bd3320daffdf1cfacfe10 (diff)
downloadrockbox-025f5c00845a328eb0b8674bc88fd5f9cb8ee76d.tar.gz
rockbox-025f5c00845a328eb0b8674bc88fd5f9cb8ee76d.zip
Added progress display and summary. Implemented --strip.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@5573 a1c6a512-1295-4272-9138-f99709370657
-rwxr-xr-xtools/songdb.pl108
1 files changed, 73 insertions, 35 deletions
diff --git a/tools/songdb.pl b/tools/songdb.pl
index d4b3989e01..1b1eddee13 100755
--- a/tools/songdb.pl
+++ b/tools/songdb.pl
@@ -10,9 +10,11 @@
10 10
11use MP3::Info; 11use MP3::Info;
12 12
13my $db; 13my $db = "rockbox.id3db";
14my $dir; 14my $dir = ".";
15my $strip; 15my $strip;
16my $verbose;
17my $help;
16 18
17while($ARGV[0]) { 19while($ARGV[0]) {
18 if($ARGV[0] eq "--db") { 20 if($ARGV[0] eq "--db") {
@@ -30,6 +32,14 @@ while($ARGV[0]) {
30 shift @ARGV; 32 shift @ARGV;
31 shift @ARGV; 33 shift @ARGV;
32 } 34 }
35 elsif($ARGV[0] eq "--verbose") {
36 $verbose = 1;
37 shift @ARGV;
38 }
39 elsif($ARGV[0] eq "--help" or ($ARGV[0] eq "-h")) {
40 $help = 1;
41 shift @ARGV;
42 }
33 else { 43 else {
34 shift @ARGV; 44 shift @ARGV;
35 } 45 }
@@ -42,9 +52,9 @@ my %filename;
42 52
43my $dbver = 1; 53my $dbver = 1;
44 54
45if(! -d $dir) { 55if(! -d $dir or $help) {
46 print "songdb [--db <file>] --path <dir> [--strip <path>]\n"; 56 print "'$dir' is not a directory\n" if (! -d $dir);
47 print "given argument is not a directory!\n"; 57 print "songdb [--db <file>] [--path <dir>] [--strip <path>] [--verbose] [--help]\n";
48 exit; 58 exit;
49} 59}
50 60
@@ -100,6 +110,8 @@ my $maxsongperalbum;
100sub dodir { 110sub dodir {
101 my ($dir)=@_; 111 my ($dir)=@_;
102 112
113 print "$dir\n";
114
103 # getdir() returns all entries in the given dir 115 # getdir() returns all entries in the given dir
104 my @a = getdir($dir); 116 my @a = getdir($dir);
105 117
@@ -120,15 +132,26 @@ sub dodir {
120 # TRACKNUM 132 # TRACKNUM
121 # YEAR 133 # YEAR
122 134
135 # don't index songs without tags
136 if (not defined $$id3{'ARTIST'} and
137 not defined $$id3{'ALBUM'} and
138 not defined $$id3{'TITLE'})
139 {
140 next;
141 }
142
123 #printf "Artist: %s\n", $id3->{'ARTIST'}; 143 #printf "Artist: %s\n", $id3->{'ARTIST'};
124 $entries{"$dir/$f"}= $id3; 144 my $path = "$dir/$f";
125 $filename{$id3}="$dir/$f"; 145 if ($strip ne "" and $path =~ /^$strip(.*)/) {
146 $path = $1;
147 }
148
149 $entries{$path}= $id3;
126 $artists{$id3->{'ARTIST'}}++ if($id3->{'ARTIST'}); 150 $artists{$id3->{'ARTIST'}}++ if($id3->{'ARTIST'});
127 $genres{$id3->{'GENRE'}}++ if($id3->{'GENRE'}); 151 $genres{$id3->{'GENRE'}}++ if($id3->{'GENRE'});
128 $years{$id3->{'YEAR'}}++ if($id3->{'YEAR'}); 152 $years{$id3->{'YEAR'}}++ if($id3->{'YEAR'});
129 153
130 $id3->{'FILE'}="$dir/$f"; # store file name 154 # fallback names
131
132 $$id3{'ARTIST'} = "<no artist tag>" if ($$id3{'ARTIST'} eq ""); 155 $$id3{'ARTIST'} = "<no artist tag>" if ($$id3{'ARTIST'} eq "");
133 $$id3{'ALBUM'} = "<no album tag>" if ($$id3{'ALBUM'} eq ""); 156 $$id3{'ALBUM'} = "<no album tag>" if ($$id3{'ALBUM'} eq "");
134 $$id3{'TITLE'} = "<no title tag>" if ($$id3{'TITLE'} eq ""); 157 $$id3{'TITLE'} = "<no title tag>" if ($$id3{'TITLE'} eq "");
@@ -136,10 +159,11 @@ sub dodir {
136 # prepend Artist name to handle duplicate album names from other 159 # prepend Artist name to handle duplicate album names from other
137 # artists 160 # artists
138 my $albumid = $id3->{'ALBUM'}."___".$id3->{'ARTIST'}; 161 my $albumid = $id3->{'ALBUM'}."___".$id3->{'ARTIST'};
139 if($id3->{'ALBUM'}) { 162 if($albumid ne "<no album tag>___<no artist tag>") {
140 my $num = ++$albums{$albumid}; 163 my $num = ++$albums{$albumid};
141 if($num > $maxsongperalbum) { 164 if($num > $maxsongperalbum) {
142 $maxsongperalbum = $num; 165 $maxsongperalbum = $num;
166 $longestalbum = $albumid;
143 } 167 }
144 $album2songs{$albumid}{$$id3{TITLE}} = $id3; 168 $album2songs{$albumid}{$$id3{TITLE}} = $id3;
145 $artist2albums{$$id3{ARTIST}}{$$id3{ALBUM}} = $id3; 169 $artist2albums{$$id3{ARTIST}}{$$id3{ALBUM}} = $id3;
@@ -157,23 +181,25 @@ sub dodir {
157 181
158 182
159dodir($dir); 183dodir($dir);
184print "\n";
160 185
161print "File name table\n"; 186print "File name table\n" if ($verbose);
162my $fc; 187my $fc;
163for(sort keys %entries) { 188for(sort keys %entries) {
164 printf(" %s\n", $_); 189 printf(" %s\n", $_) if ($verbose);
165 $fc += length($_)+1; 190 $fc += length($_)+1;
166} 191}
167 192
168my $maxsonglen; 193my $maxsonglen = 0;
169my $sc; 194my $sc;
170print "\nSong title table\n"; 195print "\nSong title table\n" if ($verbose);
171#for(sort {$entries{$a}->{'TITLE'} cmp $entries{$b}->{'TITLE'}} %entries) { 196
172for(sort {$entries{$a}->{'TITLE'} cmp $entries{$b}->{'TITLE'}} keys %entries) { 197for(sort {$entries{$a}->{'TITLE'} cmp $entries{$b}->{'TITLE'}} keys %entries) {
173 printf(" %s\n", $entries{$_}->{'TITLE'} ); 198 printf(" %s\n", $entries{$_}->{'TITLE'} ) if ($verbose);
174 my $l = length($entries{$_}->{'TITLE'}); 199 my $l = length($entries{$_}->{'TITLE'});
175 if($l > $maxsonglen) { 200 if($l > $maxsonglen) {
176 $maxsonglen = $l; 201 $maxsonglen = $l;
202 $longestsong = $entries{$_}->{'TITLE'};
177 } 203 }
178} 204}
179$maxsonglen++; # include zero termination byte 205$maxsonglen++; # include zero termination byte
@@ -181,16 +207,17 @@ while($maxsonglen&3) {
181 $maxsonglen++; 207 $maxsonglen++;
182} 208}
183 209
184my $maxartistlen; 210my $maxartistlen = 0;
185print "\nArtist table\n"; 211print "\nArtist table\n" if ($verbose);
186my $i=0; 212my $i=0;
187my %artistcount; 213my %artistcount;
188for(sort keys %artists) { 214for(sort keys %artists) {
189 printf(" %s\n", $_); 215 printf(" %s\n", $_) if ($verbose);
190 $artistcount{$_}=$i++; 216 $artistcount{$_}=$i++;
191 my $l = length($_); 217 my $l = length($_);
192 if($l > $maxartistlen) { 218 if($l > $maxartistlen) {
193 $maxartistlen = $l; 219 $maxartistlen = $l;
220 $longestartist = $_;
194 } 221 }
195 222
196 $l = scalar keys %{$artist2albums{$_}}; 223 $l = scalar keys %{$artist2albums{$_}};
@@ -203,27 +230,30 @@ while($maxartistlen&3) {
203 $maxartistlen++; 230 $maxartistlen++;
204} 231}
205 232
206print "\nGenre table\n"; 233if ($verbose) {
207for(sort keys %genres) { 234 print "\nGenre table\n";
208 printf(" %s\n", $_); 235 for(sort keys %genres) {
209} 236 printf(" %s\n", $_);
237 }
210 238
211print "\nYear table\n"; 239 print "\nYear table\n";
212for(sort keys %years) { 240 for(sort keys %years) {
213 printf(" %s\n", $_); 241 printf(" %s\n", $_);
242 }
214} 243}
215 244
216print "\nAlbum table\n"; 245print "\nAlbum table\n" if ($verbose);
217my $maxalbumlen; 246my $maxalbumlen = 0;
218my %albumcount; 247my %albumcount;
219$i=0; 248$i=0;
220for(sort keys %albums) { 249for(sort keys %albums) {
221 my @moo=split(/___/, $_); 250 my @moo=split(/___/, $_);
222 printf(" %s\n", $moo[0]); 251 printf(" %s\n", $moo[0]) if ($verbose);
223 $albumcount{$_} = $i++; 252 $albumcount{$_} = $i++;
224 my $l = length($moo[0]); 253 my $l = length($moo[0]);
225 if($l > $maxalbumlen) { 254 if($l > $maxalbumlen) {
226 $maxalbumlen = $l; 255 $maxalbumlen = $l;
256 $longestalbumname = $moo[0];
227 } 257 }
228} 258}
229$maxalbumlen++; # include zero termination byte 259$maxalbumlen++; # include zero termination byte
@@ -245,17 +275,25 @@ sub dumpint {
245 ($num&0xff)); 275 ($num&0xff));
246} 276}
247 277
248if($db) { 278if (!scalar keys %entries) {
249 print STDERR "\nCreating db $db\n"; 279 print "No songs found. Did you specify the right --path ?\n";
280 print "Use the --help parameter to see all options.\n";
281 exit;
282}
250 283
284if ($db) {
251 my $songentrysize = $maxsonglen + 12; 285 my $songentrysize = $maxsonglen + 12;
252 my $albumentrysize = $maxalbumlen + 4 + $maxsongperalbum*4; 286 my $albumentrysize = $maxalbumlen + 4 + $maxsongperalbum*4;
253 my $artistentrysize = $maxartistlen + $maxalbumsperartist*4; 287 my $artistentrysize = $maxartistlen + $maxalbumsperartist*4;
254 288
255 print STDERR "Max song length: $maxsonglen\n"; 289 printf STDERR "Number of artists : %d\n", scalar keys %artists;
256 print STDERR "Max album length: $maxalbumlen\n"; 290 printf STDERR "Number of albums : %d\n", scalar keys %albums;
257 print STDERR "Max artist length: $maxartistlen\n"; 291 printf STDERR "Number of songs : %d\n", scalar keys %entries;
258 print STDERR "Database version: $dbver\n"; 292 print STDERR "Max artist length : $maxartistlen ($longestartist)\n";
293 print STDERR "Max album length : $maxalbumlen ($longestalbumname)\n";
294 print STDERR "Max song length : $maxsonglen ($longestsong)\n";
295 print STDERR "Max songs per album: $maxsongperalbum ($longestalbum)\n";
296 print STDERR "Database version: $dbver\n" if ($verbose);
259 297
260 open(DB, ">$db") || die "couldn't make $db"; 298 open(DB, ">$db") || die "couldn't make $db";
261 printf DB "RDB%c", $dbver; 299 printf DB "RDB%c", $dbver;