抽象id3标签、m4a标签、flac标签之间的转换

发布于 2024-07-16 11:11:00 字数 321 浏览 9 评论 0原文

我正在 python 或 bash 中寻找一种可以轻松获取的资源,例如 mp3 文件 X 和 m4a 文件 Y 并说“将 X 的标签复制到 Y”。

Python 的“mutagen”模块通常非常适合操作标签,但没有跨越不同类型标签的“艺术家领域”的抽象概念; 我想要一个能够处理所有繁琐的部分并知道字段名等效项的库。 对于并非所有标签系统都能表达的事情,我可以接受信息丢失或被最佳猜测。

(用例:我将无损文件编码为 mp3,然后使用 mp3 进行收听。大约每个月,我希望能够使用我对 mp3 所做的任何标签更改来更新“主”无损文件。我我厌倦了在格式之间的实现差异上碰伤我的脚趾。)

I'm looking for a resource in python or bash that will make it easy to take, for example, mp3 file X and m4a file Y and say "copy X's tags to Y".

Python's "mutagen" module is great for manupulating tags in general, but there's no abstract concept of "artist field" that spans different types of tag; I want a library that handles all the fiddly bits and knows fieldname equivalences. For things not all tag systems can express, I'm okay with information being lost or best-guessed.

(Use case: I encode lossless files to mp3, then go use the mp3s for listening. Every month or so, I want to be able to update the 'master' lossless files with whatever tag changes I've made to the mp3s. I'm tired of stubbing my toes on implementation differences among formats.)

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

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

发布评论

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

评论(7

梦归所梦 2024-07-23 11:11:00

我需要这个确切的东西,而且我也很快意识到诱变剂并不是一个遥远到足以做这种事情的抽象概念。 幸运的是,mutagen 的作者需要将其用于他们的媒体播放器 QuodLibet

我必须深入研究 QuodLibet 源代码才能找到如何使用它,但一旦理解了它,我就编写了一个名为 sequitur 的实用程序,它的目的是成为一个相当于 ExFalso< 的命令行。 /strong> (QuodLibet 的标记组件)。 它使用这种抽象机制并提供一些附加的抽象和功能。

如果您想查看源代码,这里有最新 tarball 的链接。 该包实际上是一组三个命令行脚本和一个用于与 QL 交互的模块。 如果你想安装整个东西,你可以使用:

easy_install QLCLI

关于 exfalso/quodlibet (以及因此的 sequitur) 要记住的一件事是它们实际上正确地实现了音频元数据,这意味着所有标签都支持多个值(除非文件类型禁止这样做,但这样做的人并不多)。 因此,执行以下操作:

print qllib.AudioFile('foo.mp3')['artist']

不会输出单个字符串,但会输出如下字符串列表:

[u'The First Artist', u'The Second Artist']

您可以使用它来复制标签的方式类似于:

import os.path
import qllib  # this is the module that comes with QLCLI

def update_tags(mp3_fn, flac_fn):
    mp3 = qllib.AudioFile(mp3_fn)
    flac = qllib.AudioFile(flac_fn)
    # you can iterate over the tag names
    # they will be the same for all file types
    for tag_name in mp3:
        flac[tag_name] = mp3[tag_name]
    flac.write()

mp3_filenames = ['foo.mp3', 'bar.mp3', 'baz.mp3']

for mp3_fn in mp3_filenames:
    flac_fn = os.path.splitext(mp3_fn)[0] + '.flac'
    if os.path.getmtime(mp3_fn) != os.path.getmtime(flac_fn):
        update_tags(mp3_fn, flac_fn)

I needed this exact thing, and I, too, realized quickly that mutagen is not a distant enough abstraction to do this kind of thing. Fortunately, the authors of mutagen needed it for their media player QuodLibet.

I had to dig through the QuodLibet source to find out how to use it, but once I understood it, I wrote a utility called sequitur which is intended to be a command line equivalent to ExFalso (QuodLibet's tagging component). It uses this abstraction mechanism and provides some added abstraction and functionality.

If you want to check out the source, here's a link to the latest tarball. The package is actually a set of three command line scripts and a module for interfacing with QL. If you want to install the whole thing, you can use:

easy_install QLCLI

One thing to keep in mind about exfalso/quodlibet (and consequently sequitur) is that they actually implement audio metadata properly, which means that all tags support multiple values (unless the file type prohibits it, which there aren't many that do). So, doing something like:

print qllib.AudioFile('foo.mp3')['artist']

Will not output a single string, but will output a list of strings like:

[u'The First Artist', u'The Second Artist']

The way you might use it to copy tags would be something like:

import os.path
import qllib  # this is the module that comes with QLCLI

def update_tags(mp3_fn, flac_fn):
    mp3 = qllib.AudioFile(mp3_fn)
    flac = qllib.AudioFile(flac_fn)
    # you can iterate over the tag names
    # they will be the same for all file types
    for tag_name in mp3:
        flac[tag_name] = mp3[tag_name]
    flac.write()

mp3_filenames = ['foo.mp3', 'bar.mp3', 'baz.mp3']

for mp3_fn in mp3_filenames:
    flac_fn = os.path.splitext(mp3_fn)[0] + '.flac'
    if os.path.getmtime(mp3_fn) != os.path.getmtime(flac_fn):
        update_tags(mp3_fn, flac_fn)
思念绕指尖 2024-07-23 11:11:00

我有一个 bash 脚本可以做到这一点,atwat-tagger。 它支持 flac、mp3、ogg 和 mp4 文件。

usage: `atwat-tagger.sh inputfile.mp3 outputfile.ogg`

我知道您的项目已经完成,但是通过搜索引擎找到此页面的人可能会发现它很有用。

I have a bash script that does exactly that, atwat-tagger. It supports flac, mp3, ogg and mp4 files.

usage: `atwat-tagger.sh inputfile.mp3 outputfile.ogg`

I know your project is already finished, but somebody who finds this page through a search engine might find it useful.

苹果你个爱泡泡 2024-07-23 11:11:00

这是一些示例代码,我编写的用于在之间复制标签的脚本
使用 Quod Libet 的音乐格式类(不是诱变剂的!)的文件。 跑步
只需执行copytags.py src1 dest1 src2 dest2 src3 dest3,就可以了
将 sec1 中的标签复制到 dest1 (删除任何现有标签后
在 dest1 上!),等等。 请注意黑名单,您应该对其进行调整
你自己的喜好。 黑名单不仅会阻止某些标签
不被复制,它也会防止它们被破坏
目标文件。

需要明确的是,Quod Libet 的格式不可知标记不是诱变剂的功能; 它是在诱变剂之上实现的。 因此,如果您想要与格式无关的标记,则需要使用 quodlibet.formats.MusicFile 来打开文件,而不是 mutagen.File

现在可以在这里找到代码:https://github.com/DarwinAwardWinner/copytags

如果您也想要要同时进行转码,请使用:https://github.com/DarwinAwardWinner/transfercoder

对我来说一个关键细节是 Quod Libet 的音乐格式课程
期望加载 QL 的配置,因此我的 config.init 行
脚本。 如果没有这个,我在加载或保存时会遇到各种错误
文件。

我已经测试了这个脚本,用于在 flac、ogg 和 mp3 之间进行复制,使用“标准”标签以及任意标签。 到目前为止,它运行得很好。

至于我没有使用 QLLib 的原因,它对我来说不起作用。 我怀疑它遇到了与我相同的配置相关错误,但默默地忽略了它们并且只是无法写入标签。

Here's some example code, a script that I wrote to copy tags between
files using Quod Libet's music format classes (not mutagen's!). To run
it, just do copytags.py src1 dest1 src2 dest2 src3 dest3, and it
will copy the tags in sec1 to dest1 (after deleting any existing tags
on dest1!), and so on. Note the blacklist, which you should tweak to
your own preference. The blacklist will not only prevent certain tags
from being copied, it will also prevent them from being clobbered in
the destination file.

To be clear, Quod Libet's format-agnostic tagging is not a feature of mutagen; it is implemented on top of mutagen. So if you want format-agnostic tagging, you need to use quodlibet.formats.MusicFile to open your files instead of mutagen.File.

Code can now be found here: https://github.com/DarwinAwardWinner/copytags

If you also want to do transcoding at the same time, use this: https://github.com/DarwinAwardWinner/transfercoder

One critical detail for me was that Quod Libet's music format classes
expect QL's configuration to be loaded, hence the config.init line in my
script. Without that, I get all sorts of errors when loading or saving
files.

I have tested this script for copying between flac, ogg, and mp3, with "standard" tags, as well as arbitrary tags. It has worked perfectly so far.

As for the reason that I didn't use QLLib, it didn't work for me. I suspect it was getting the same config-related errors as I was, but was silently ignoring them and simply failing to write tags.

2024-07-23 11:11:00

您只需编写一个简单的应用程序,将每种格式的每个标签名称映射到“抽象标签”类型,然后就可以轻松地从一种类型转换为另一种类型。 您甚至不必了解所有可用的类型 - 只需了解您感兴趣的类型即可。

在我看来,这就像周末项目类型的时间投资,可能更少。 玩得开心,我不介意看一下你的实现,甚至使用它 - 当然,如果你不介意发布它:-)。

You can just write a simple app with a mapping of each tag name in each format to an "abstract tag" type, and then its easy to convert from one to the other. You don't even have to know all available types - just those that you are interested in.

Seems to me like a weekend-project type of time investment, possibly less. Have fun, and I won't mind taking a peek at your implementation and even using it - if you won't mind releasing it of course :-) .

Spring初心 2024-07-23 11:11:00

还有 tagpy,看起来效果不错。

There's also tagpy, which seems to work well.

独﹏钓一江月 2024-07-23 11:11:00

由于其他解决方案大多已从网上消失,因此我基于 python 媒体文件库(Debian GNU/Linux 中的 python3-mediafile)提出了以下解决方案。

#!/usr/bin/python3

import sys
from mediafile import MediaFile

src = MediaFile (sys.argv [1])
dst = MediaFile (sys.argv [2])

for field in src.fields ():
   try:
      setattr (dst, field, getattr (src, field))
   except:
      pass

dst.save ()

用法:mediafile-mergetags srcfile dstfile

它将 srcfile 中的所有标签复制(合并)到 dstfile 中,并且似乎可以与 flac、opus、mp3 等正常工作,包括复制专辑艺术。

Since the other solutions have mostly fallen off the net, here is what I came up, based on the python mediafile library (python3-mediafile in Debian GNU/Linux).

#!/usr/bin/python3

import sys
from mediafile import MediaFile

src = MediaFile (sys.argv [1])
dst = MediaFile (sys.argv [2])

for field in src.fields ():
   try:
      setattr (dst, field, getattr (src, field))
   except:
      pass

dst.save ()

Usage: mediafile-mergetags srcfile dstfile

It copies (merges) all tags from srcfile into dstfile, and seems to work properly with flac, opus, mp3 and so on, including copying album art.

别念他 2024-07-23 11:11:00

自 2013 年以来,Quod Libet 附带了一个名为 operon 可以执行此操作以及更多操作:

operon copy song.flac song.mp3

由于 Quod Libet 是基于 Mutagen 构建的,因此它知道一堆晦涩难懂的信息标签以及如何在各种标签格式之间转换它们,这对于某些工作流程很重要。 我注意到的唯一怪癖是它不会复制具有空值的标签,但这并不困扰我。

Since 2013, Quod Libet has come with a command line tool called operon that does this and more:

operon copy song.flac song.mp3

Since Quod Libet is built on Mutagen, it knows about a bunch of obscure tags and how to translate them among the various tagging formats, which is important for some workflows. The only quirk I noticed is that it doesn't copy tags with empty values, but that doesn't bother me.

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