Skip to content

Instantly share code, notes, and snippets.

@avsej
Forked from pavlo/gist:322543
Created March 9, 2010 19:11
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 avsej/326964 to your computer and use it in GitHub Desktop.
Save avsej/326964 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