如何使用 tkinter、eyed3 和 python 编辑音频元数据以进行更改?

How to edit the audio metadata to change using tkinter, eyed3, and python?

我的目标是制作一个允许您使用 tkinter 编辑音频元数据的程序,但我遇到了困难。无论我尝试什么,程序都不会编辑元数据。我正在使用浏览按钮,以便您可以选择任何文件。这是我的代码:

import tkinter
from tkinter import filedialog
from tkinter.filedialog import askopenfilename
import eyed3

root = tkinter.Tk()
canvas = tkinter.Canvas(root, width=400, height=300)
audio_file = None


def browse_files():
    global audio_file
    audio_file_path = askopenfilename(filetypes=(("Audio Files", "*.mp3"),))
    audio_file = eyed3.load(audio_file_path)
    file_chosen_label = tkinter.Label(root, text=audio_file_path)
    file_chosen_label.pack()
    return audio_file


def change_artist():
    audio_file.tag.album_artist = artist_name.get()
    audio_file.tag.save()
    return


file_choose_label = tkinter.Label(root, text="Song file")
file_choose = tkinter.Button(root, text="Browse...", command=browse_files)
artist_label = tkinter.Label(root, text="Artist")
artist_name = tkinter.StringVar()
artist_entry = tkinter.Entry(root, textvariable=artist_name)
apply_button = tkinter.Button(root, command=change_artist, text="Apply")

file_choose_label.pack()
file_choose.pack()
artist_label.pack()
artist_entry.pack()
apply_button.pack()
canvas.pack()
root.mainloop()

我错过了什么?没有错误或任何错误。

好的,有几件事:

变化:

def change_artist():
    audio_file.tag.genre = artist_name
    audio_file.tag.save()
    return

def change_artist():
    audio_file.tag.album_artist = artist_name.get()
    audio_file.tag.save()
    return

然后,更改:

artist_entry = tkinter.Entry(root, textvariable="artist_name")

收件人:

artist_entry = tkinter.Entry(root, textvariable=artist_name)

告诉我进展如何。


编辑,我想尝试一下。请将您的 change_artist 函数更改为:

def change_artist():
    try:
        audio_file.tag.album_artist = artist_name.get()
        audio_file.tag.save()
    except AttributeError as error:
        print(type(audio_file), audio_file)
        print(type(audio_file.tag))
        raise error
    

让我知道打印了什么。


编辑,再来一次,试试这个:

def change_artist():
    audio_file.initTag().album_artist = artist_name.get()
    audio_file.tag.save()