从 mp3 id3v2 标签中识别歌曲信息

发布于 2024-11-15 22:41:39 字数 1018 浏览 3 评论 0原文

我已经有 mp3 二进制数据,我只想知道如何从中提取信息。 v1 很简单,取最后 128 个字符即可完成。但 v2 的长度可变。文档说标签大小将在标题中,但我无法在我测试的任何歌曲中找到它。

但无论如何我只是想提取专辑和艺术家信息..用javascript将这两个信息组合起来。为了简单起见,让我们假设我在变量中保存了 Taylor Swift 歌曲的前 2000 个字节(下面是歌曲的实际二进制数据):

ID3!vTYER2010TIT2
Last KissMCDI¬E+96+4484+918B+E800+12F4B+1A636+1EC24+23A8E+2905F+2F7DD+33868+3914B+3D931+44555+4A27BTRCK13TCON(2)CountryPRIVPeakValue¡PRIVAverageLevel{ TPE2
Taylor SwiftPRIV)WM/MediaClassSecondaryIDPRIV'WM/MediaClassPrimaryID¼}`Ñ#ãâK¡H¤*(DPRIVWM/ProviderAMGPRIVWM/WMContentIDÇ1t>êDëþëPRIV"WM/WMCollectionID   ¨F}âH"Y#7 ÈPRIV'WM/WMCollectionGroupID  ¨F}âH"Y#7 ÈTPUBBig MachinePRIVWM/UniqueFileIdentifierAMGa_id=R  2026672;AMGp_id=P   816977;AMGt_id=T 22057912TALB
Speak NowTPE1
Taylor SwiftTLEN369120ÿûà@üK

现在我可以轻松找到专辑和艺术家姓名(最后两行)。我还可以很容易地找到数据以 js 开头的位置。只需找到 TALBTPE1。简单的。但我到底怎么知道数据的终点在哪里......?它们在其他歌曲中可能彼此相邻,也可能不相邻。它们可能是也可能不是大写。所有其他库如何确定数据结束的位置?

正如文档所示,一开始也没有“大小”。

编辑有人可以帮我吗?我真的需要这个

i already have mp3 binary data, i just want to know how can i extract info from it. v1 is easy, take last 128 characters and you are done. but v2 has variable length. documentation says that tag size will be in header but i was unable to find it in any song i tested.

but anyways i simply want to extract album and artist info.. jsut these two, with javascript. lets take for simplicity sake that i have first 2000 bytes of a Taylor swift song in a variable (below is the actual binary data of a song):

ID3!vTYER2010TIT2
Last KissMCDI¬E+96+4484+918B+E800+12F4B+1A636+1EC24+23A8E+2905F+2F7DD+33868+3914B+3D931+44555+4A27BTRCK13TCON(2)CountryPRIVPeakValue¡PRIVAverageLevel{ TPE2
Taylor SwiftPRIV)WM/MediaClassSecondaryIDPRIV'WM/MediaClassPrimaryID¼}`Ñ#ãâK¡H¤*(DPRIVWM/ProviderAMGPRIVWM/WMContentIDÇ1t>êDëþëPRIV"WM/WMCollectionID   ¨F}âH"Y#7 ÈPRIV'WM/WMCollectionGroupID  ¨F}âH"Y#7 ÈTPUBBig MachinePRIVWM/UniqueFileIdentifierAMGa_id=R  2026672;AMGp_id=P   816977;AMGt_id=T 22057912TALB
Speak NowTPE1
Taylor SwiftTLEN369120ÿûà@üK

now i can easily locate the album and artist name (last two lines). and i can also find where the data begins with js pretty easily. just locate TALB and TPE1. simple. but how in the world do i know where the data ends..? they may or may not be adjacent to each other in other songs. they may or may not be uppercase. how do all the other libraries figure out where the data ends?

also there is no 'size' in the beginning as the documentation suggests.

EDIT can anyone help me out please? i really need this

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

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

发布评论

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

评论(2

笨笨の傻瓜 2024-11-22 22:41:39

您显示的二进制示例缺少一些数据。 ID3 版本 2.4 标签帧头的长度为 10 字节,由以下字段组成:

  • ID -- 4 字节(例如 TIT2)

  • 大小 -- 4 字节(在版本 >= 2.4 中是同步安全的)

  • 标志 -- 2 字节

大小字段告诉您该特定帧中有多少字节的数据。类似地,实际标签头也是 10 个字节:

  • ID -- 3 字节(始终是 ID3)

  • 版本 -- 2 字节(主要版本和修订版。例如 0x04 0x00 表示 2.4.0 标签版本)

  • 标志 -- 1 字节

  • 大小 -- 4 字节(在版本 >= 2.3 中是同步安全的)

请参阅:http://id3.org/id3v2.4.0-struct

一旦您的脚本获得了二进制数据,您就可以解析这些大小字段以确定完整标记的大小以及每个帧的大小。一旦到达这一点,您将遇到同步安全整数。

请参阅:为什么会有 Synchsafe Integer?

The binary sample you show is missing some data. An ID3 version 2.4 tag frame header is 10 bytes in length and consists of the following fields:

  • ID -- 4 bytes (e.g. TIT2)

  • Size -- 4 bytes (is sync-safe in versions >= 2.4)

  • Flags -- 2 bytes

The size field tells you how many bytes of data are in that particular frame. Similarly the actual tag header is 10 bytes as well:

  • ID -- 3 bytes (always ID3)

  • Version -- 2 bytes (major version and revision. e.g. 0x04 0x00 indicates a 2.4.0 tag version)

  • Flags -- 1 byte

  • Size -- 4 bytes (is sync-safe in versions >= 2.3)

See: http://id3.org/id3v2.4.0-structure

Once your script has the binary data, you can parse these size fields to determine the size of the complete tag as well as the size of each frame. Once you get to this point you're going to run into sync-safe integers.

See: Why are there Synchsafe Integer?

夕色琉璃 2024-11-22 22:41:39

尝试这个库,看起来它做了什么你需要。

Try this library, looks like it does what you need.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文