Skip to content

Instantly share code, notes, and snippets.

@krtx
Created June 3, 2013 17:39
Show Gist options
  • Save krtx/5699843 to your computer and use it in GitHub Desktop.
Save krtx/5699843 to your computer and use it in GitHub Desktop.
mp3のタグを書き換えるスクリプト ruby 1.9.2
require 'mp3info'
dir = '/my/music/library/'
Dir::glob(dir + '*.mp3').each {|f|
Mp3Info.open(f) do |mp3|
t = mp3.tag.title
title = t.slice(t.rindex('/') + 2, t.length)
artist = t.slice(0, t.rindex('/') - 1)
if title.index(' - ')
title = title.slice(0, title.index(' - '))
end
puts "#{artist} // #{title}"
title = title.encode('us-ascii', 'utf-8')
artist = artist.encode('us-ascii', 'utf-8')
aartist = "Various Artists".encode('us-ascii', 'utf-8')
mp3.tag.title = title
mp3.tag.artist = artist
mp3.tag2.TP2 = aartist
end
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment