Skip to content

Instantly share code, notes, and snippets.

@egze
Created July 18, 2019 11:41
Show Gist options
  • Save egze/065202130d04ab9271fdeba6aa5232df to your computer and use it in GitHub Desktop.
Save egze/065202130d04ab9271fdeba6aa5232df to your computer and use it in GitHub Desktop.
Fixes wrong cp1251 encoding (Ïîñòàðàåìñÿ áîëüøå) in ID3 tags
require 'rubygems'
require 'taglib'
files_names = Dir["*.mp3"].sort
files_names.each do |file_name|
TagLib::MPEG::File.open(file_name) do |mp3_file|
## ID3 tag
tag = mp3_file.id3v2_tag
tag.title = "#{ tag.track } - #{ tag.title.encode(Encoding::CP1252).force_encoding(Encoding::CP1251).encode(Encoding::UTF_8).gsub(/\d\)\s/, "") }"
tag.artist = tag.artist.encode(Encoding::CP1252).force_encoding(Encoding::CP1251).encode(Encoding::UTF_8)
tag.album = tag.album.encode(Encoding::CP1252).force_encoding(Encoding::CP1251).encode(Encoding::UTF_8)
mp3_file.save
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment