- Timestamp:
- 07/26/12 21:33:59 (12 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MusicBrainz.pm
r3 r4 47 47 my $release_count = $xpath->findvalue('count(//release)'); 48 48 my ($release) = $xpath->findnodes('//release[1]'); 49 $info{RELEASE_MBID} = $xpath->findvalue('@id', $release) ;50 $info{ALBUM} = $xpath->findvalue('title', $release) ;51 $info{ARTIST} = $xpath->findvalue('artist-credit/name-credit/artist/name', $release) ;49 $info{RELEASE_MBID} = $xpath->findvalue('@id', $release)->value; 50 $info{ALBUM} = $xpath->findvalue('title', $release)->value; 51 $info{ARTIST} = $xpath->findvalue('artist-credit/name-credit/artist/name', $release)->value; 52 52 53 53 # TODO: get release date … … 58 58 my $prefix = sprintf('TRACK%02d', $tracknum); 59 59 #$info{"$prefix.MB_TRACKID"} = $xpath->findvalue('@id', $track_node); 60 my $recording_mbid = $info{"$prefix.RECORDING_MBID"} = $xpath->findvalue('recording/@id', $track_node) ;61 $info{"$prefix.TITLE"} = $xpath->findvalue('recording/title', $track_node) ;62 $info{"$prefix.ARTIST"} = $xpath->findvalue('recording/artist-credit/name-credit/artist/name', $track_node) || $info{ARTIST};60 my $recording_mbid = $info{"$prefix.RECORDING_MBID"} = $xpath->findvalue('recording/@id', $track_node)->value; 61 $info{"$prefix.TITLE"} = $xpath->findvalue('recording/title', $track_node)->value; 62 $info{"$prefix.ARTIST"} = $xpath->findvalue('recording/artist-credit/name-credit/artist/name', $track_node)->value || $info{ARTIST}; 63 63 $info{TRACKS}[$tracknum]{TITLE} = $info{"$prefix.TITLE"}; 64 64 $info{TRACKS}[$tracknum]{ARTIST} = $info{"$prefix.ARTIST"}; -
trunk/flactrack
r3 r4 7 7 # TODO: separate sox filter for each track! 8 8 9 use Getopt::Long; 9 use Getopt::Long qw{:config no_ignore_case}; 10 use File::Spec::Functions qw{catfile}; 11 use File::Path; 12 use Audio::FLAC::Header; 10 13 use MusicBrainz; 11 14 … … 14 17 't=s' => \my $TYPE, 15 18 'x=s' => \my $SOX_FILTER, 19 'all|a' => \my $ALL, 20 'dir|d=s' => \my $DIRECTORY, 16 21 ); 17 22 … … 21 26 $TYPE ||= 'mp3'; 22 27 28 # default the directory to be named like the flac file 29 ($DIRECTORY ||= $FLAC_FILE) =~ s/\.flac$//; 30 31 my $flac = Audio::FLAC::Header->new($FLAC_FILE) or die "Can't read FLAC header from $FLAC_FILE\n"; 32 23 33 # for getting track metadata from MusicBrainz 24 34 my $info; 25 if ($TYPE eq 'mp3') { 26 require Audio::FLAC::Header; 27 require LWP; 28 require XML::XPath; 29 require XML::XPath::XMLParser; 30 31 my $flac = Audio::FLAC::Header->new($FLAC_FILE) or warn "Can't read FLAC header from $FLAC_FILE\n"; 35 if ($ALL || $TYPE eq 'mp3') { 32 36 my $discid = $flac->tags('MBZ_DISCID') or warn "No MBZ_DISCID tag in $FLAC_FILE\n" if $flac; 33 37 #TODO: calculate TOC and DISCID from cuesheet if there is no MBZ_DISCID tag present 34 38 39 #TODO: also get the year from MBZ 35 40 $info = get_musicbrainz_info($discid); 41 } 42 43 if ($ALL) { 44 die "Use of --all requires a --directory\n" unless $DIRECTORY; 45 use YAML; 46 my $cuesheet = $flac->cuesheet; 47 my $count = scalar grep { /TRACK \d\d/ } @{ $flac->cuesheet }; 48 print "Found $count tracks\n"; 49 #TODO: default to just 01, 02, etc. if there is no $info 50 %TRACKS = map { 51 $_ => catfile($DIRECTORY, sprintf('%02d.%s', $_, to_filename($info->{TRACKS}[$_]{TITLE}))) 52 } (1 .. $count); 53 print Dump(\%TRACKS); 54 mkpath($DIRECTORY); 36 55 } 37 56 … … 79 98 return qq{"$string"}; 80 99 } 100 101 sub to_filename { 102 my @strings = @_; 103 #TODO: deal with non-ascii characters (unidecode) e.g. ü --> ue 104 return map { 105 s/[^a-z0-9-_ ]+//gi; 106 s/ +/_/g; 107 lc; 108 } @strings; 109 }
Note: See TracChangeset
for help on using the changeset viewer.