Ruby mp3 Id3 解析

发布于 2024-07-24 02:47:29 字数 279 浏览 2 评论 0原文

目前我正在从事一个音乐项目,处理用户 mp3 上传。 问题是我找不到适用于所有文件的 id3 库。 我尝试过 id3-ruby 和 Mp3Info 库,但它们都没有给我一致正确的结果。 例如,最常见的问题:

  • 错误的流参数(比特率和采样率,有时是持续时间)
  • 不支持扩展标签

我决定添加一个表单,用户可以在其中提供可选信息,例如艺术家和标题; 这有一点帮助,但并没有完全解决问题。

ruby 中最有用、最强大的 ID3 库是什么?

Currently I'm working on a music project, dealing with user mp3 uploads. The problem is that I can't find an id3 library that will work correctly for all files.
I have tried id3-ruby and Mp3Info libs but none of them gives me consistently correct results.
For example, most common problems:

  • wrong stream parameters (bitrate and sample rate, sometimes duration)
  • doesn't support extended tags

I decided to add a form, where users can supply optional information like Artist and title; that helped a little, but didn't completely solve the problem.

What's the most usable and powerful ID3 library for ruby?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

紫﹏色ふ单纯 2024-07-31 02:47:29

http://www.hakubi.us/ruby-taglib/

我将其用于一个项目而且效果很好。 taglib 的包装,非常便携。

http://www.hakubi.us/ruby-taglib/

I used this for a project and it worked quite well. Wrapper around taglib, which is very portable.

段念尘 2024-07-31 02:47:29

我用过这个:

http://ruby-mp3info.rubyforge.org/

gem install ruby​​-mp3info (为 Mac 或 *nix 添加规则 sudo

有一些 rdoc 文档,很好。 不利的一面是,我不太喜欢使用大写字段名称,这似乎太担心保留规范中的名称。 也许我应该破解一些别名。 不管怎样,这个示例脚本会扫描我的音乐库并计算标题中的单词数:

require 'mp3info'

count = 0
words = Hash.new { |h, k| h[k] = 0 }
Dir.glob("E:/MUSIC/**/*.mp3") do |f|
  count += 1
  Mp3Info.open(f) do |mp3info|
    title = mp3info.tag2.TIT2
    next unless title
    title.split(/\s/).each { |w| words[w.downcase] += 1 }
  end
end
puts "Examined #{count} files"
words.to_a.sort{ |a, b| b[1] <=> a[1] }[0,100].each { |w| puts "#{w[0]}: #{w[1]}" }

I've used this:

http://ruby-mp3info.rubyforge.org/

or

gem install ruby-mp3info (add the regulation sudo for Mac or *nix)

There's some rdoc documentation, which is nice. On the downside, I don't much like the use of upper-case field names, which seems too concerned to preserve the names from the spec. Maybe I should hack in some aliases. Anyway, this sample script scans my music library and counts words in titles:

require 'mp3info'

count = 0
words = Hash.new { |h, k| h[k] = 0 }
Dir.glob("E:/MUSIC/**/*.mp3") do |f|
  count += 1
  Mp3Info.open(f) do |mp3info|
    title = mp3info.tag2.TIT2
    next unless title
    title.split(/\s/).each { |w| words[w.downcase] += 1 }
  end
end
puts "Examined #{count} files"
words.to_a.sort{ |a, b| b[1] <=> a[1] }[0,100].each { |w| puts "#{w[0]}: #{w[1]}" }
远山浅 2024-07-31 02:47:29

截至 2019 年,最佳答案是:

所有其他库都早已无人维护。

Krists Ozols 的 ID3Tag 区分特征

  • 只读
  • 可以读取 v1.x、v2.2.x、v2.3.x、v2.4.x 标签
  • 支持 UTF-8、UTF-16、UTF-16BE 和 ISO8859-1 编码
  • 最后 2018 年 7 月更新
  • 纯 Ruby

Moumar 的 ruby​​-mp3info 区分特征

  • 读写
  • 仅支持 2.3 版本 id3v2 标签
  • id3v2 标签始终以 UTF-16 编码写入
  • 最后更新 2017 年 4 月
  • 纯 Ruby

taglib-ruby 区分特征

  • 读写
  • 许多格式,不仅仅是 Mp3
  • 读取/写入 ID3v1 和 ID3v2,包括 ID3v2.4 和 Unicode,
  • 上次更新时间为 2018 年 5 月
  • 绑定维护良好的 C++ 库

As of 2019, the best answers are:

All other libraries are long-since unmaintained.

Krists Ozols' ID3Tag distinguishing characteristics

  • read only
  • Can read v1.x, v2.2.x, v2.3.x, v2.4.x tags
  • Supports UTF-8, UTF-16, UTF-16BE and ISO8859-1 encoding
  • last updated July 2018
  • Pure Ruby

Moumar's ruby-mp3info distinguishing characteristics

  • read and write
  • Only 2.3 version is supported for writings id3v2 tags
  • id3v2 tags are always written in UTF-16 encoding
  • last updated April 2017
  • Pure Ruby

taglib-ruby distinguishing characteristics

  • read and write
  • Many formats, not just Mp3
  • Reading/writing ID3v1 and ID3v2 including ID3v2.4 and Unicode
  • last updated May 2018
  • Binding of a well-maintained C++ library
一江春梦 2024-07-31 02:47:29

http://id3lib-ruby.rubyforge.org/

我特别喜欢这个,你也可以将标签写入文件。

http://id3lib-ruby.rubyforge.org/

I particularly liked this one, you can also write tags to the file.

一人独醉 2024-07-31 02:47:29

id3tag 是另一种选择。 例子:

require "id3tag"

mp3_file = File.open('/path/to/your/favorite_song.mp3', "rb")
tag = ID3Tag.read(mp3_file)
puts "#{tag.artist} - #{tag.title}"

id3tag is another option. Example:

require "id3tag"

mp3_file = File.open('/path/to/your/favorite_song.mp3', "rb")
tag = ID3Tag.read(mp3_file)
puts "#{tag.artist} - #{tag.title}"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文