mutagen
mutagen copied to clipboard
Having problems figuring out how to write to ID3 tags for MP3's
Hey, pretty new'ish to Python, and I had looked at the documentation to try to figure this out. I couldn't understand how to read the TCOP tag (among other ID3 tags) and write it as blank or remove it. I want to do the same thing to comments and other fields that are unnecessary, but I'm only concerned about doing the copyright (TCOP) tag for the time, because once I figure one out, it'll be easily distributable across other tags I want to change.
Here's the snippet of code I'm having problems with.
def scan_files(): # read the files
for root, subfolders, files, in os.walk(scan_dir):
for name in files:
# if name.endswith((".mp3", ".m4a", ".flac", ".alac")):
if name.endswith((".mp3")): # only handle mp3's
# add track names to a list variable
tracks_import_dir.append(name)
# try:
global track_mp3
global track_id3
track_mp3 = MP3(root + "\\" + name)
track_id3 = ID3(root + "\\" + name)
#tags = ID3(track)
class format_track(): # change various tags
# print("")
# https://mutagen.readthedocs.io/en/latest/api/id3.html#mutagen.id3.ID3
# https://mutagen.readthedocs.io/en/latest/api/mp3.html
def format_copyright():
print("Formatting copyright...")
copyright = (track_mp3['TCOP'].text[0])
print(copyright) # Copyright
# track_id3 = ID3(track)
# print(copyright_tag)
format_copyright()
class save_track: # save track files
track_mp3.save()
track_id3.save()
# tags.save(track)
print(style.color.yellow,
"[INFO] Track saved\n", style.reset)
if config.debug >= 3: # print all the tracks to prove they exist
print(style.color.yellow,
track_mp3.pprint(), style.reset, "\n")
Under def format_copyright
, is a function that when called should set the TCOP tag for my audio files, and class save track:
should write those tags.
I was able to get copyright = (track_mp3['TCOP'].text[0])
which prints the copyright tag, to work, but I was unable to figure out a way to write it. I tried for about 4 hours to figure out a method that would work to write it (I had like 100 comments of failed ways of doing this before...)
Dumbed down for me, how can I take track_id3
and/or track_mp3
and write to the TCOP tag ""
(to be blank) or remove them entirely?
still having problems.
Something like
track_mp3.tags.add(id3.TCOP(encoding=id3.Encoding.LATIN1, text='12345678'))
Should work for setting the tag.
I'm closing this now. If there is still some open question feel free to reopen.