Skip to content

Instantly share code, notes, and snippets.

@vol4ok
Created December 27, 2011 16:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vol4ok/1524333 to your computer and use it in GitHub Desktop.
Save vol4ok/1524333 to your computer and use it in GitHub Desktop.
Recursive ID3 convert CP1251 to Unicode
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