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

251 views Asked by At

My goal is to make a program that lets you edit audio metadata using tkinter, but I've gotten stuck. No matter what I try, the program will not edit the metadata. I am using a browse button so that you can choose any file. Here's my code:

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()

What am I missing? No errors or anything.

1

There are 1 answers

14
Paul M. On BEST ANSWER

OK, a couple of things:

Change:

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

To

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

Then, change:

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

To:

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

Let me know how it goes.


EDIT, I would like to try something. Please change your change_artist function to:

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
    

Let me know what get's printed.


EDIT, One more time, try this:

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