Skip to content

Instantly share code, notes, and snippets.

@pavlo
Created March 5, 2010 07:58
Show Gist options
  • Save pavlo/322543 to your computer and use it in GitHub Desktop.
Save pavlo/322543 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'id3lib'
$KCODE = 'u'
require 'jcode'
require 'kconv'
FOLDER = '/Users/pa/Tmp/book'
AUTHOR = 'Лем С.'
BOOK_TITLE = 'Возвращение со звезд'
# TODO добавить жанр
# TODO не конвертить константы в UTF16 в каждой итерации цикла
def process
files = Dir.glob("#{FOLDER}/*.mp3").sort
files.each_with_index do |file, ind|
puts "Processing #{file}..."
tag = ID3Lib::Tag.new(file)
tag.strip!
# название трека
tag << {:id => :TIT2, :text => s("#{track(ind)}_#{BOOK_TITLE}"), :textenc => 1}
# исполнитель
tag << {:id => :TPE1, :text => s(AUTHOR), :textenc => 1}
# альбом
tag << {:id => :TALB, :text => s(BOOK_TITLE), :textenc => 1}
tag.track = "#{track(ind)}/#{files.count}"
tag.update!
end
end
def s(str)
Kconv.toutf16(str)
end
def track(index)
"%03\d" % index
end
process
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment