Journal(2005) | Blog(2006) | RandomLink | WhoAmI | LiveBookmark | HomePage

<<Previous: 如何安装FastCGI  >>Next: PerlTidy

如何设置mp3文件的ID3v1Tag

Category: Script   Keywords: mp3 ID3v1Tag

Task

从网上download了一些歌曲,回来用foobar2000放。发现没有显示其歌曲名和歌手名。
因为迷你歌词/MiniLyrics查找配对歌词要通过mp3的歌曲名和歌手名。一个个修改太麻烦了。就想着用perl写个批量修改。

Code

cpan search了下,install MP3::ID3v1Tag
此模块perldoc说的很清楚,我也就照本宣科写了个代码。
其中获得artist,title,ablum的过程不通用。各位自己去parse
#!/usr/bin/perl
# usage: set one directory mp3's ID3v1Tag, such as artist, title, ablum
use MP3::ID3v1Tag;

my $dir = "E:/Music/Santana_Shaman";
opendir(DIR,"$dir");
my @data = readdir(DIR);
closedir(DIR);
@data = grep(/\.mp3$/, @data);

foreach $mp3 (@data) {
	my $mp3_file = new MP3::ID3v1Tag("$dir/$mp3");
	#if($mp3_file->got_tag()) {
		# it's special,here the file name like "Santana Shaman 11 Feels Like Fire Feat DIDO.mp3"
		# u parse file name and got the artist&album&title&..
		my ($artist, $album, undef, $title) = ($mp3 =~ /^([a-zA-Z]+)\s+([a-zA-Z]+)\s+([0-9]+)\s+(.*?)\.mp3$/);
		print "$artist, $album, $title\n";
		#end
		$mp3_file->set_title("$title");
		$mp3_file->set_artist("$artist");
		$mp3_file->set_album("$album");
		#$mp3_file->set_year(2002);
		#$mp3_file->set_genre("Latin-Rock");
		$mp3_file->save() or warn "failed to save $mp3";
  #}
}

<<Previous: 如何安装FastCGI  >>Next: PerlTidy

Options: +Del.icio.us

Related items Created on 2004-11-17 22:08:34, Last modified on 2004-11-17 22:09:49
Copyright 2004-2005 All Rights Reserved. Powered by Eplanet && Catalyst 5.62.