我正在尝试从 mp3 或 flac 文件中打印出每个标签,然后使用 python 对其进行编辑,但只有一些标签具有数据显示,例如:艺术家、标题、专辑、日期。但并不是每首歌都会出现相同的标签。
这是我制作的代码。
import os
import mutagen.easyid3
import mutagen.flac ## make reading flac file possible
def main():
print("start")
for root, dirs, files in os.walk("C:\muziek\muziekfiles"): ## where to look for songs
for name in files:
if name.endswith((".mp3", ".flac")):
print()
file_path = os.path.join(root +"\\" + name)
if name.endswith(".flac"):
audio = mutagen.flac.FLAC(file_path)
else:
audio = mutagen.easyid3.EasyID3(file_path)
for key in audio:
if key == "padding": ## if there were to be padding
if audio[key] is None:
print(f"{key}: no_new_padding")
else:
print(f"{key}: {len(audio[key])}")
else:
print(f"{key}: {audio[key]}")
## asks user
choice = input("Do you want to change a tag, y/n: ")
if choice.lower() == "y":
tag_key = input("which one, eg: artist, title: ") ## choose which tag
tag_value = input("new value: ") ## give new value
## stores new values and then saves itn
audio[tag_key] = tag_value
audio.save()
## if there isn't any padding
if "padding" not in audio:
print("padding: None")
if __name__ == "__main__":
main()
我也试图找到填充,但结果是:填充:无,每首歌曲一次。我不知道这是否取决于我从哪里下载歌曲,但我怀疑它没有填充
这就是我得到的:我已经更改了一些标签来测试我的代码
album: ['Paranoid (2009 Remastered Version)']
title: ['random']
artist: ['drake']
tracknumber: ['1']
date: ['2015']
Do you want to change a tag, y/n: n
padding: None
year: ['2022']
artist: ['denzel curry']
album: ['Melt My Eyez See Your Future']
title: ['oei']
date: ['2022-03-25']
Do you want to change a tag, y/n: n
padding: None
album: ['Melt My Eyez See Your Future']
title: ['X-wing']
artist: ['random']
tracknumber: ['1']
date: ['2022']
Do you want to change a tag, y/n: n
padding: None
album: ['Turtle Warnings']
copyright: ['Attribution: http://creativecommons.org/licenses/by/4.0/']
title: ['oei']
artist: ['leopard2A2']
albumartist: ['Drake Stafford']
tracknumber: ['3']
genre: ['Ambient Electronic']
date: ['2018-07-12 20:52:22']
Do you want to change a tag, y/n: n
padding: None
album: ['Turtle Warnings']
copyright: ['Attribution: http://creativecommons.org/licenses/by/4.0/']
title: ['oei']
artist: ['random']
albumartist: ['Drake Stafford']
tracknumber: ['2']
genre: ['Ambient Electronic']
date: ['2018-07-12 20:52:09']
Do you want to change a tag, y/n: n
padding: None
genre: ['goede muziek']
year: ['2007']
artist: ['kung foo panda']
album: ['The Colour And The Shape']
title: ['oei']
date: ['2007-07-02']
Do you want to change a tag, y/n: n
padding: None