如何使用 ruby 将 unicode 添加到 ID3 标记?
我正在尝试将 unicode 标题添加到 MP3 的 ID3 标签 (v2.3)。不幸的是,我不知道该怎么做。根据 id3.org 的 id3v2 页面,Unicode 字符串必须以 Unicode BOM 开头。
我目前正在尝试 id3v2,但标签保存为乱码。
我想用 ruby 来做,但 Linux 实用程序也是可以接受的。
更新: 我找到了使用 id3lib-ruby gem 的解决方案。下面列出了。
I'm trying to add a unicode title to an ID3 tag (v2.3) of an MP3. Unfortunately, I can't figure out how to do it. According to id3.org's id3v2 page, Unicode strings have to begin with the Unicode BOM.
I'm currently trying id3v2, but the tag saves as gibberish.
I'd like to do it in ruby, but a linux utility would also be acceptable.
Update:
I figured out a solution using the id3lib-ruby gem. It's listed below.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否尝试
encode()
字符串?Did you try to
encode()
the string?更新:找到了一个稍微优雅的解决方案
我找到了一个使用 id3lib-ruby gem 的解决方案。
utf16 = Iconv.conv('UTF-16', 'UTF-8', str)utf16_no_bom = utf16[2..-1] #删除BOM
标签<< {:id => :TIT2, :textenc => 1、:文本=> utf16_no_bom}
此用法注释在 id3lib.rb(第 105 行)有点误导。如果您设置 :textenc => 1 并包含 UTF-16 BOM (\xFF\xFE),那么你最终会在标签的开头出现一个乱码。
Update: found a slightly more elegant solution
I figured out a solution that works using the id3lib-ruby gem.
utf16 = Iconv.conv('UTF-16', 'UTF-8', str)utf16_no_bom = utf16[2..-1] #removes the BOM
tag << {:id => :TIT2, :textenc => 1, :text => utf16_no_bom}
This usage comments inside id3lib.rb (line 105) are a bit misleading. If you set :textenc => 1 and include the UTF-16 BOM (\xFF\xFE), then you'll end up with a gibberish character at the beginning of your tag.