Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/env perl
- use warnings;
- use strict;
- print "[INFO] CUE file tagger v2\n";
- my $cue_file = shift @ARGV;
- open( my $cue_fh , "<" , $cue_file ) or die ( "Cannot open CUE file: $cue_file $!" );
- my $part = 0;
- my $meta = {};
- my %static_meta;
- my @list;
- if($cue_file =~ /([0-9xX]{4})\.([0-9xX]{2})\.([0-9xX]{2})/)
- {
- print "Found date in filename: $1-$2-$3";
- $static_meta{"date"} = $1;
- }
- while ( <$cue_fh> )
- {
- if( /REM GENRE (.*)/) {
- $static_meta{"genre"} = $1;
- print "Genre: ".$static_meta{"genre"}."\n";
- } elsif (/REM DATE ([0-9x]{4})/) {
- $static_meta{"date"} = $1;
- print "Year: ".$static_meta{"date"}."\n";
- } elsif (/REM DISCID (.*)/) {
- $static_meta{"discid"} = $1;
- print "DiscID: ".$static_meta{"discid"}."\n";
- } elsif (/REM COMMENT "(.*)"/) {
- $static_meta{"comment"} = $1;
- print "Comment: ".$static_meta{"comment"}."\n";
- } elsif (/PERFORMER "(.*)"/) {
- if($part == 0) {
- $static_meta{"albumartist"} = $1;
- print "AlbumArtist: ".$static_meta{"albumartist"}."\n";
- }
- else {
- $meta->{"artist"} = $1;
- print "Artist: ".$meta->{"artist"}."\n";
- }
- } elsif (/TITLE "(.*)"/) {
- if($part == 0) {
- $static_meta{"album"} = $1;
- print "Album: ".$static_meta{"album"}."\n";
- }
- else {
- $meta->{"title"} = $1;
- print "Title: ".$meta->{"title"}."\n";
- }
- } elsif (/FILE "(.*)" (.*)/) {
- print "File ($2): $1\n";
- } elsif (/TRACK (.*) (.*)/) {
- print "Track $1 ($2)\n";
- if($part == 0) {
- while(my($k, $v) = each %static_meta) {
- $meta->{$k} = $v;
- }
- } else {
- push @list, $meta;
- $meta = {};
- while(my($k, $v) = each %static_meta) {
- $meta->{$k} = $v;
- }
- }
- $meta->{"tracknumber"} = $1;
- $meta->{"artist"} = $meta->{"albumartist"};
- $part ++;
- } elsif (/INDEX ([0-9]*) ([0-9]{2}):([0-9]{2}):([0-9]{2})/) {
- print "Index $1 $2-$3-$4\n";
- }
- }
- push @list, $meta;
- close ($cue_fh);
- print " ~~~ ... ~~~ \n";
- foreach my $info (@list)
- {
- my $flac_file = shift @ARGV;
- print "\n";
- print "FLAC: $flac_file\n\n";
- open( my $fh, ">", "/tmp/$$-taginfo.tmp") or die("Could not create tags file");
- while(my($k, $v) = each $info) {
- print $fh "$k=$v\n";
- print "$k=$v\n";
- }
- close $fh;
- system("metaflac", "--remove-all-tags", "--import-tags-from=/tmp/$$-taginfo.tmp","$flac_file");
- unlink "/tmp/$$-taginfo.tmp";
- }
- print " ~~~ ... ~~~ \n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement