在 Ruby/Rails 中读取远程 MP3 文件的 ID3 标签?
使用 Ruby,如何解析远程 mp3 文件的 ID3 标签而不将整个文件下载到磁盘?
这个问题已在 Java 和 Silverlight,但没有 Ruby。
编辑:查看 Java 答案,似乎可以(HTTP 支持)仅下载文件的尾部,即标签所在的位置。这可以在 Ruby 中完成吗?
Using Ruby, how can one parse the ID3 tags of remote mp3 files without downloading the entire file to disk?
This question has been asked in Java and Silverlight, but no Ruby.
Edit: Looking at the Java answer, it seems as though it's possible (HTTP supports it) to download just the tail end of a file, which is where the tags are. Can this be done in Ruby?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您使用的是哪个 Ruby 版本?
您尝试读取哪个 ID3 标签版本?
ID3v1 标签位于文件末尾,在最后 128 字节。使用 Net::HTTP 似乎不可能向前查找文件末尾并仅读取最后 N 个字节。如果你尝试这样做,使用
headers = {"范围" =>; "bytes=128-"}
,它似乎总是下载完整的文件。resp.body.size =>;文件大小
。但没有什么大的损失,因为ID3版本1在这一点上已经过时了,因为它有局限性,例如固定长度格式,只有ASCII文本,...)。 iTunes 使用 ID3 版本 2.2.0。ID3v2 标签位于文件的开头 - 支持流式传输 - 您可以通过 HTTP 协议下载 MP3 文件的初始部分,其中包含 ID3v2 标头 >= 1.1
简短答案:
例如:
长答案看起来像这样:(您需要 id3 库版本 1.0.0_pre 或更高版本)
请参阅:
http://www.w3.org/Protocols/rfc2616/rfc2616- sec14.html#sec14.35
http://en.wikipedia.org/wiki/Byte_serving
一些如何下载的示例零件文件可以在这里找到:
但请注意,似乎无法“在中间”开始下载
如何通过 HTTP 下载二进制文件?
http://unixgods.org/~tilo/Ruby/ID3/docs/index.html
which Ruby version are you using?
which ID3 Tag version are you trying to read?
ID3v1 tags are at the end of a file, in the last 128 bytes. With Net::HTTP it doesn't seem to be possible to seek forward towards the end of the file and read only the last N bytes. If you try that, using
headers = {"Range" => "bytes=128-"}
, it always seems to download the complete file.resp.body.size => file-size
. But no big loss, because ID3 version 1 is pretty much outdated at this point because of it's limitations, such as fixed length format, only ASCII text, ...). iTunes uses ID3 version 2.2.0.ID3v2 tags are at the beginning of a file - to support streaming - you can download the initial part of the MP3 file, which contains the ID3v2 header, via HTTP protocol >= 1.1
The short answer:
e.g.:
The long answer looks something like this: (you'll need id3 library version 1.0.0_pre or newer)
See:
http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35
http://en.wikipedia.org/wiki/Byte_serving
some examples how to download in parts files can be found here:
but please note that there seems to be no way to start downloading "in the middle"
How do I download a binary file over HTTP?
http://unixgods.org/~tilo/Ruby/ID3/docs/index.html
您至少必须下载文件的最后几个块,其中包含 ID3 标记 - 请参阅 ID3 标记定义...
如果您有权访问远程文件系统上的文件,则可以这样做。远程执行此操作,然后传回 ID3 标签
编辑:
我正在考虑 ID3 v1 标签 - 版本 2 标签位于前面。
you would at least have to download the last blocks of the file, which contain the ID3 tags -- see ID3 tag definitions...
if you have access to the files on the remote file system, you could do. this remotely, and then transfer back the ID3 tags
Edit:
I was thinking of ID3 v1 tags -- version 2 tags are in the front.