更改音频文件的元数据

Changing metadata of audio file

我有一个小程序可以将播放列表中的 YouTube 视频下载为 .mp3 我得到了 .mp3 文件,但有时它们甚至有一个带有下载网站名称的标题 (yt5s.com): Image of file details

我想通过删除标题或更改标题来解决此问题。 我试过了:

from tinytag import TinyTag, TinyTagException

tracks = []
for root, dirs, files, in os.walk(path):
    for name in files:
        if name.endswith((".mp3",".m4a",".flac",".alac")):
            tracks.append(name)
            try:
                temp_track = TinyTag.get(root + "\" + name)
                print(temp_track.artist, "-", temp_track.title)
            except TinyTagException:
                print("Error")

但我只打印出了艺术家和标题。

我终于找到了合适的模块eyed3。 这会更改目录中每首歌曲的标题:

import eyed3
import os

files = os.listdir(path)
for _ ,file in enumerate(files):
    audiofile = eyed3.load(os.path.join(path, file))
    audiofile.tag.title = "Title"
    audiofile.tag.save()

你可能想要这个:

from eyed3.id3.frames import ImageFrame
audiofile.tag.images.set(ImageFrame.FRONT_COVER, open(path2+file,'rb').read(), 'image/jpeg')
audiofile.tag.album = "Album"
audiofile.tag.album_artist = Artist
audiofile.tag.artist = Artist

此外,我遇到了一些错误,导致我看不到歌曲的封面。

  • 当 album_artist 和艺术家不是同一个人时。什么时候有

  • 同一专辑中超过一首不同封面的歌曲。

此外,它会打印出消息“Lame tag CRC check failed”,但它什么也没做。