Added releasedate information using MusicBrainz
This commit is contained in:
parent
1cb4cace9a
commit
88a95d6bd7
|
@ -19,6 +19,7 @@
|
||||||
#
|
#
|
||||||
# Changelog:
|
# Changelog:
|
||||||
# 0.2.4: added -T option
|
# 0.2.4: added -T option
|
||||||
|
# added releasedate support through MusicBrainz
|
||||||
# 0.2.3: added documentation, -0 command-line option
|
# 0.2.3: added documentation, -0 command-line option
|
||||||
# 0.2.2: added flac support, documentation
|
# 0.2.2: added flac support, documentation
|
||||||
# 0.2.1: fixed version in help message
|
# 0.2.1: fixed version in help message
|
||||||
|
@ -30,6 +31,9 @@
|
||||||
$VERSION = "0.2.4";
|
$VERSION = "0.2.4";
|
||||||
$HELP_MSG = "Vorbiscomment from Filename $VERSION\n\tusage: vcfromfilename [options] <files>\n\nValid options:\n\t-n\tOnly set the track numbers\n\t-0\tPreserve leading 0s in track numbers\n\t-T: Write tag names (not tag content) in all caps\n";
|
$HELP_MSG = "Vorbiscomment from Filename $VERSION\n\tusage: vcfromfilename [options] <files>\n\nValid options:\n\t-n\tOnly set the track numbers\n\t-0\tPreserve leading 0s in track numbers\n\t-T: Write tag names (not tag content) in all caps\n";
|
||||||
|
|
||||||
|
|
||||||
|
use Music::Tag;
|
||||||
|
|
||||||
chomp($COMMENTFILENAME = '/tmp/vcfromfilename-' . `whoami`);
|
chomp($COMMENTFILENAME = '/tmp/vcfromfilename-' . `whoami`);
|
||||||
|
|
||||||
# Look for options
|
# Look for options
|
||||||
|
@ -46,6 +50,11 @@ $album = `pwd`; # We WANT the newline here
|
||||||
$album =~ s/^.*\///; # Remove everything up to the last /
|
$album =~ s/^.*\///; # Remove everything up to the last /
|
||||||
$album = formatName($album, 'album=', $captagnames);
|
$album = formatName($album, 'album=', $captagnames);
|
||||||
|
|
||||||
|
|
||||||
|
# Get the release date, just use the first track
|
||||||
|
my $releasedate = 'releasedate=';
|
||||||
|
|
||||||
|
|
||||||
# Parse the file list, set vorbiscomments
|
# Parse the file list, set vorbiscomments
|
||||||
foreach (@ARGV)
|
foreach (@ARGV)
|
||||||
{
|
{
|
||||||
|
@ -64,8 +73,8 @@ foreach (@ARGV)
|
||||||
system("metaflac --remove-tag=tracknumber $_");
|
system("metaflac --remove-tag=tracknumber $_");
|
||||||
if (!$tracknumonly)
|
if (!$tracknumonly)
|
||||||
{
|
{
|
||||||
system("metaflac --remove-tag=TITLE --remove-tag=ARTIST --remove-tag=ALBUM $_");
|
system("metaflac --remove-tag=TITLE --remove-tag=ARTIST --remove-tag=ALBUM --remove-tag=RELEASEDATE $_");
|
||||||
system("metaflac --remove-tag=title --remove-tag=artist --remove-tag=album $_");
|
system("metaflac --remove-tag=title --remove-tag=artist --remove-tag=album --remove-tag=releasedate $_");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
# Preserve existing comments, except the ones we'll replace
|
# Preserve existing comments, except the ones we'll replace
|
||||||
|
@ -74,7 +83,7 @@ foreach (@ARGV)
|
||||||
foreach (`vorbiscomment -l $_`)
|
foreach (`vorbiscomment -l $_`)
|
||||||
{
|
{
|
||||||
if ($tracknumonly) { print COMMENTFILE $_ unless (/^tracknumber/i); }
|
if ($tracknumonly) { print COMMENTFILE $_ unless (/^tracknumber/i); }
|
||||||
else { print COMMENTFILE $_ unless (/^(title)|(artist)|(tracknumber)|(album)/i); }
|
else { print COMMENTFILE $_ unless (/^(title)|(artist)|(tracknumber)|(album)|(releasedate)/i); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,7 +118,51 @@ foreach (@ARGV)
|
||||||
if ($isflac) { system("metaflac --import-tags-from=$COMMENTFILENAME $_"); }
|
if ($isflac) { system("metaflac --import-tags-from=$COMMENTFILENAME $_"); }
|
||||||
else { system("vorbiscomment -c $COMMENTFILENAME -w $_"); }
|
else { system("vorbiscomment -c $COMMENTFILENAME -w $_"); }
|
||||||
system('rm', $COMMENTFILENAME);
|
system('rm', $COMMENTFILENAME);
|
||||||
|
|
||||||
|
|
||||||
|
# Finally, try to find the release date, if we haven't yet
|
||||||
|
if ($releasedate =~ /^releasedate=\s*$/)
|
||||||
|
{
|
||||||
|
my $mbinfo = Music::Tag->new($_);
|
||||||
|
|
||||||
|
if (/\.ogg$/) { $mbinfo->add_plugin($mbinfo->plugin("OGG")); }
|
||||||
|
elsif (/\.flac$/) { $mbinfo->add_plugin($mbinfo->plugin("FLAC")); }
|
||||||
|
|
||||||
|
$mbinfo->add_plugin("MusicBrainz");
|
||||||
|
$mbinfo->get_tag();
|
||||||
|
$releasedate = formatName($mbinfo->releasedate, 'releasedate=', $captagnames);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if ($tracknumonly || $releasedate =~ /^releasedate=\s*$/) { exit; }
|
||||||
|
|
||||||
|
|
||||||
|
# Loop back through the files again, adding the release date
|
||||||
|
foreach(@ARGV)
|
||||||
|
{
|
||||||
|
my $isflac = true if (/\.flac$/);
|
||||||
|
|
||||||
|
open COMMENTFILE, '>' . $COMMENTFILENAME;
|
||||||
|
|
||||||
|
# Preserve existing comments
|
||||||
|
if (!$isflac)
|
||||||
|
{
|
||||||
|
foreach (`vorbiscomment -l $_`)
|
||||||
|
{
|
||||||
|
print COMMENTFILE $_ unless (/^releasedate/i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
print COMMENTFILE $releasedate;
|
||||||
|
close COMMENTFILE;
|
||||||
|
|
||||||
|
if ($isflac) { system("metaflac --import-tags-from=$COMMENTFILENAME $_"); }
|
||||||
|
else { system("vorbiscomment -c $COMMENTFILENAME -w $_"); }
|
||||||
|
system('rm', $COMMENTFILENAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Formats the first argument, adds the second argument to it
|
# Formats the first argument, adds the second argument to it
|
||||||
# If the third argument is true, the second argument is converted
|
# If the third argument is true, the second argument is converted
|
||||||
|
@ -129,7 +182,7 @@ sub formatName
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Copyright (c) 2005 - 2008 John Wiggins
|
# Copyright (c) 2005 - 2010 John Wiggins
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# This program is free software; you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
|
Reference in New Issue
Block a user