Created
June 18, 2010 22:01
-
-
Save paulclip/444287 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#classify.rb - set id3 tags on mp3 files | |
require 'mp3info' #from http://ruby-mp3info.rubyforge.org/ | |
MUSICDNS = "<path to example.exe from MusicDNS>" | |
MUSICDIR = "<path to your music directory>" | |
def build_filename(fn) | |
"#{MUSICDIR + '/' + fn}" | |
end | |
def analyze_file(fn) | |
system("#{MUSICDNS} \"#{fn}\" > tmpfile.musicdns") | |
lines = IO.readlines("tmpfile.musicdns") | |
File.delete("tmpfile.musicdns") | |
title = lines[1][7..-1].strip | |
artist = lines[2][7..-1].strip | |
return title, artist | |
end | |
def get_id3_info(fn) | |
Mp3Info.open(fn) do |mp3| | |
return mp3.tag.title, mp3.tag.artist | |
end | |
end | |
def set_id3_info(fn, title, artist) | |
Mp3Info.open(fn) do |mp3| | |
mp3.tag.title = title | |
mp3.tag.artist = artist | |
end | |
end | |
puts "filename, id3 artist, mdns artist, id3 title, mdns title" | |
Dir.entries(MUSICDIR).grep(/\.mp3/).each do |f| | |
fullpath = build_filename(f) | |
mtitle, martist = analyze_file(fullpath) | |
id3title, id3artist = get_id3_info(fullpath) | |
if id3title.nil? and id3artist.nil? | |
set_id3_info(fullpath, mtitle, martist) | |
elsif id3title != mtitle or id3artist != martist | |
puts "#{f}, #{id3artist}, #{martist}, #{id3title}, #{mtitle}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment