Skip to main content

MutagenTagWrapper

本模块是 Python 模块 Mutagen 的一个包装器,为各种多媒体标签格式提供了统一的编辑接口,旨在减少批量处理多媒体标签时的时间成本和出错概率。

支持的格式

  • FLAC
  • MP3
  • APE (Monkey's Audio)
  • TTA (True Audio)
  • Ogg Vorbis
  • WAV (Wave)

如何使用

从文件中读取标签

读取 MutagenTagWrapper 支持的标签

>>> import tagwrapper
>>> tag = tagwrapper.openfile('test1.flac')
>>> type(tag)
tagwrapper.flac.FLAC
>>> tag.title
['High jump love']
>>> tag.artist
['綾倉盟', 'Syrufit']
>>> tag.album
['over']
>>> tag.description
["163 key(Don't modify):cEgtqHxwpdRKcBCRPBlPktlHhmrTcizixpMvRszN1/tYwYj5XaTULrYamr8WQPUKDI+bYPvNmaZC9XGraBSuN3t8MRjPn6kvLbU9svyFF8GS1rAtJRkQTztYZu/e16yUYrPIGYS/IakMYWCoXjfTTr72Ew2bfIHYHNyIakhJnkVI0sRdsdhamD8kag/r5Q0nyysl7OXcK83QfHLlO1lVQOVy3WmfAGQzdJhR2dbk1Y2r95oWzUM198YrjS4vP63jq7v0ifagC359t1OPNnqwDBY9znck388gQhGvlT8FTu+H3WKYQthYk6kZSft3z/heFagFbTMnZt2SCfJJPuxNyQxkRhZgYuu1xm8u+f2Lq4JwaiKSMnYzHh3qw75NPQYAY2Ivv6eGeqnahfZyMi5598dOJ52O2u0+TP16N9YDNl2zw7ah//m7LrlQO9JOgRYdnhZyyPHEgiPvSZMmMKL4c/rfZfJ3uIRLVYoJIDJ+TTLDhO/k3fF9VBDRapfmHDy/"]
>>> tag.cover  # 读取封面信息
<Picture 'image/jpeg' (553145 bytes)>
>>> with open('test.flac.cover.jpg', 'wb') as f:  # 将封面数据写入文件
...     f.write(tag.cover.data)
...
>>>

读取 MutagenWrapper 不支持的标签

>>> import tagwrapper
>>> tag = tagwrapper.openfile('test.m4a')  # MutagenTagWrapper 目前不支持 M4A 格式使用的标签,将会返回 None
>>> tag is None
True
>>> tag = tagwrapper.openfile('test.m4a', raw_tag_fallback=True)  # 如果上层 TagWrapper 包装器不支持此格式,返回下层 Mutagen 标签对象;在此例中为 mutagen.mp4.MP4 对象
>>> type(tag)
mutagen.mp4.MP4
>>> tag.get('©nam')
['High jump love']
>>>

修改标签并写入文件

>>> import tagwrapper
>>> tag = tagwrapper.openfile('anothertest.ogg')
>>> tag.description
["163 key(Don't modify):cEgtqHxwpdRKcBCRPBlPktlHhmrTcizixpMvRszN1/tYwYj5XaTULrYamr8WQPUKDI+bYPvNmaZC9XGraBSuN3t8MRjPn6kvLbU9svyFF8GS1rAtJRkQTztYZu/e16yUYrPIGYS/IakMYWCoXjfTTr72Ew2bfIHYHNyIakhJnkVI0sRdsdhamD8kag/r5Q0nyysl7OXcK83QfHLlO1lVQOVy3WmfAGQzdJhR2dbk1Y2r95oWzUM198YrjS4vP63jq7v0ifagC359t1OPNnqwDBY9znck388gQhGvlT8FTu+H3WKYQthYk6kZSft3z/heFagFbTMnZt2SCfJJPuxNyQxkRhZgYuu1xm8u+f2Lq4JwaiKSMnYzHh3qw75NPQYAY2Ivv6eGeqnahfZyMi5598dOJ52O2u0+TP16N9YDNl2zw7ah//m7LrlQO9JOgRYdnhZyyPHEgiPvSZMmMKL4c/rfZfJ3uIRLVYoJIDJ+TTLDhO/k3fF9VBDRapfmHDy/"]
>>> tag.description = '这是一段描述'  # 修改描述信息
>>> tag.description
['这是一段描述']
>>> tag.cover is None  # 读取封面信息,但此文件没有封面,将会为 None
True
>>> # 读取封面图像文件中的数据
>>> with open('anothertest.ogg.cover.png', 'rb') as f:
...     cover_data = f.read()
...
>>> tag.cover = cover_data  # 封面也可修改;向标签中写入封面
>>> tag.cover
<Picture 'image/png' (553145 bytes)>
>>> tag.save()  # 保存对标签的更改
>>>

在两个文件之间复制标签

>>> import tagwrapper
>>> tag1 = tagwrapper.openfile('source.mp3')
>>> tag2 = tagwrapper.openfile('target.ape')
>>> tag1
<MP3, title=['咲かせや咲かせ'], artist=['EGOIST'], album=['咲かせや咲かせ'], date=['2019'], encoder=['Lavf59.16.100']>
>>> tag1.cover
<Picture 'image/png' (466954 bytes)>
>>> tag2  # target.ape 中没有标签信息
<MonkeysAudio>
>>> tag2.cover is None
True
>>> tag2.load_tag(tag1)  # 从 tag1 复制标签信息,写入到 tag2
>>> tag2
<MonkeysAudio, encoder=['Lavf59.16.100'], title=['咲かせや咲かせ'], artist=['EGOIST'], album=['咲かせや咲かせ'], date=['2019']>
>>> tag2.cover
<Picture 'image/png' (466954 bytes)>
>>> tag2.save()  # 保存对 tag2 进行的更改
>>>

Metadata

Release files for MutagenTagWrapper 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for MutagenTagWrapper 0.2.0
File Size Uploaded Provenance Actions
MutagenTagWrapper-0.2.0.tar.gz 12.8 kB Without provenance Details for MutagenTagWrapper-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for MutagenTagWrapper 0.2.0
File Interpreter ABI Platform Actions
MutagenTagWrapper-0.2.0-py3-none-any.whl Python 3 none any Details for MutagenTagWrapper-0.2.0-py3-none-any.whl

Total release size: 30.0 kB

Release files / MutagenTagWrapper-0.2.0.tar.gz

Download URL MutagenTagWrapper-0.2.0.tar.gz
Size 12.8 kB
Tags Source
SHA-256 checksum
How to use checksums
9410c2460b565e13f47c0439b369391cec526a41485d4e6e981740319ec3764b
BLAKE2b-256 checksum
How to use checksums
0c9843468d826c8a5149fb88b07a4886f6c1e0b378bca65dbb47e1fe192a92ea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.6.0 importlib_metadata/4.8.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.64.0 CPython/3.10.4

Release files / MutagenTagWrapper-0.2.0-py3-none-any.whl

Download URL MutagenTagWrapper-0.2.0-py3-none-any.whl
Size 17.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5790a60936ac7e202f03604b3db88e0dda4973fb5950ef586a8a61dc810e668b
BLAKE2b-256 checksum
How to use checksums
761e3645f60a7b3efba01ebdd2a971142375c2b4b961a7b08c6e47eb71e5dd3d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.6.0 importlib_metadata/4.8.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.64.0 CPython/3.10.4

Security for MutagenTagWrapper 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page