Created
December 27, 2011 16:51
-
-
Save vol4ok/1524333 to your computer and use it in GitHub Desktop.
Recursive ID3 convert CP1251 to Unicode
This file contains 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
require 'rubygems' | |
require 'id3lib' | |
require 'iconv' | |
def encode (filename) | |
puts "encode #{filename}" | |
tag = ID3Lib::Tag.new(filename) | |
for f in tag | |
if f[:text] | |
f[:text] = Iconv.conv('UTF-16BE','CP1251',f[:text]) | |
f[:textenc] = 1 | |
end | |
if f[:description] | |
f[:description] = Iconv.conv('UTF-16BE','CP1251',f[:description]) | |
f[:textenc] = 1 | |
end | |
end | |
#puts tag | |
tag.update! | |
end | |
def rename_tree (path) | |
Dir.open(path) do |dir| | |
for file in dir | |
next if file == '.' or file == '..' | |
new_path = path + File::Separator + file | |
if File.directory?(new_path) | |
stats = rename_tree(new_path) | |
else | |
stats = encode(new_path) if file =~ /.*\.mp3/i | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment