Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Having problems figuring out how to write to ID3 tags for MP3's #585

Closed
Rycia opened this issue Dec 21, 2022 · 3 comments
Closed

Having problems figuring out how to write to ID3 tags for MP3's #585

Rycia opened this issue Dec 21, 2022 · 3 comments
Labels

Comments

@Rycia
Copy link

Rycia commented Dec 21, 2022

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?

@Rycia
Copy link
Author

Rycia commented Dec 22, 2022

still having problems.

@phw
Copy link
Collaborator

phw commented Feb 14, 2023

Something like

track_mp3.tags.add(id3.TCOP(encoding=id3.Encoding.LATIN1, text='12345678'))

Should work for setting the tag.

@phw phw added the question label Feb 15, 2023
@phw
Copy link
Collaborator

phw commented May 20, 2024

I'm closing this now. If there is still some open question feel free to reopen.

@phw phw closed this as completed May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants