Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Saving MP3 Tags to Songs
#1
Is there a Mp3 module that has the same attributes as TinyTag and can also save the Tags to MP3 Songs?
Reply
#2
Is this what you are after ? https://pypi.org/project/mp3-tagger/ - "This Python package allows to access ID3 tags in MP3 files. There are the usual operations such as set, get, update, delete"
Reply
#3
Thanks for the information. I checked on it but unfortunately at this time the mp3-tagger does not have attributes like tag.disc, tag.disc_total, tag.track_total.
Reply
#4
Tinytag has those attributes - https://pythonawesome.com/a-library-for-...ave-files/
Reply
#5
Thanks for that. How can I save using those mp3 Tags.
Reply
#6
The tags are simply chunks of data, and can be written included with the output song/MP3. Maybe "eyeD3" is the tool for this ??. Some documentation on it at https://eyed3.readthedocs.io/en/latest/ and an example at https://stackoverflow.com/questions/3851...g-python-3
Reply
#7
Thanks. I used eyed3 and the below gettags3 works


  gettags3 = [audiofile.tag.album, audiofile.tag.album_artist, audiofile.tag.title, audiofile.tag.track_num, audiofile.tag.genre]
for some reason tags: artist, track, track-total, disc, disc-num, disc-total, year and comment produce the same error for each tags for instance:
AttributeError: 'Tag' object has no attribute 'disc'
I decided to add mutagen as well and used to add the dates:
from mutagen.easyid3 import EasyID3

audio["date"] = str(yrz.value)
When I tried
print('comment' ,audio["comment"])
I got an error of
raise EasyID3KeyError("%r is not a valid key" % key)
mutagen.easyid3.EasyID3KeyError: "'Comment' is not a valid key"
when I search I found it could be used where can I find the keys/tags/attributes that can be used? Thanks
Reply
#8
Update:
Hello everyone. The following is my add tags to list and save attempt attempt:

from mutagen.easyid3 import EasyID3
from mutagen.mp3 import 
MP3 mtags=[] 

for root, dirs, files, in os.walk('C:\Users\mrdrj\Desktop\SJ\NASB - Copy\'): 
     for name in files: 
          if name.endswith(('.mp3', '.m4a', '.flac', '.alac')): 

tracks.append(name)  # Add Media Files

try: audio = EasyID3(root + '\' + name)

 mtags = audio['album'],    audio['bpm'],  audio['compilation'],  audio['composer'], audio['copyright'],  
            audio['encodedby'],    audio['lyricist'], audio['length'],
            audio['media'],    audio['mood'], audio['title'],    audio['version'],  audio['artist'],   audio['albumartist'],
            audio['conductor'],    audio['arranger'], audio['discnumber'],   audio['organization'], audio['tracknumber'],
            audio['author'],   audio['albumartistsort'],  audio['albumsort'],    audio['composersort'], audio['artistsort'],
            audio['titlesort'],   audio['isrc'], audio['discsubtitle'], audio['language'], audio['genre'],    audio['date'], 
            audio['originaldate'], audio['performer:*']
except TinyTagException:

print('Error')
audio.save()  #Save funtion works.

print(audio['albumartist']) # Test to see if it works and does
When ran I get the following errors: How can this be solved? Thanks

Traceback (most recent call last):
  File "C:\Users\mrdrj\Desktop\Desktop\pythonProject\New MP3 Tags.py", line 211, in <module>
    ain = audio['album'],    audio['bpm'],  audio['compilation'],  audio['composer'], audio['copyright'],    audio['encodedby'],    audio['lyricist'], audio['length'],   audio['media'],    audio['mood'], audio['title'],    audio['version'],  audio['artist'],   audio['albumartist'],  audio['conductor'],    audio['arranger'], audio['discnumber'],   audio['organization'], audio['tracknumber'],  audio['author'],   audio['albumartistsort'],  audio['albumsort'],    audio['composersort'], audio['artistsort'],   audio['titlesort'],    audio['isrc'], audio['discsubtitle'], audio['language'], audio['genre'],    audio['date'], audio['originaldate'], audio['performer:*']
  File "C:\Users\mrdrj\AppData\Local\Programs\Python\Python39\lib\site-packages\mutagen\easyid3.py", line 213, in __getitem__
    return func(self.__id3, key)
  File "C:\Users\mrdrj\AppData\Local\Programs\Python\Python39\lib\site-packages\mutagen\easyid3.py", line 120, in getter
    return list(id3[frameid])
  File "C:\Users\mrdrj\AppData\Local\Programs\Python\Python39\lib\site-packages\mutagen\_util.py", line 537, in __getitem__
    return self.__dict[key]
KeyError: 'TBPM'
Reply
#9
It seems you are trying to access a key that doesn't exist in mutagens dictionary. The following code should show what keys can be accessed

print(EasyID3.valid_keys.keys())
Possibly related, see https://gist.github.com/pschwede/3193087 - "Add bpm tags to your music collection"
Reply
#10
When I used
print(EasyID3.valid_keys.keys())
I get the below keys:
dict_keys(['album', 'bpm', 'compilation', 'composer', 'copyright', 'encodedby', 'lyricist', 'length', 'media', 'mood', 'title', 'version', 'artist', 'albumartist', 'conductor', 'arranger', 'discnumber', 'organization', 'tracknumber', 'author', 'albumartistsort', 'albumsort', 'composersort', 'artistsort', 'titlesort', 'isrc', 'discsubtitle', 'language', 'genre', 'date', 'originaldate', 'performer:*', 'musicbrainz_trackid', 'website', 'replaygain_*_gain', 'replaygain_*_peak', 'musicbrainz_artistid', 'musicbrainz_albumid', 'musicbrainz_albumartistid', 'musicbrainz_trmid', 'musicip_puid', 'musicip_fingerprint', 'musicbrainz_albumstatus', 'musicbrainz_albumtype', 'releasecountry', 'musicbrainz_discid', 'asin', 'performer', 'barcode', 'catalognumber', 'musicbrainz_releasetrackid', 'musicbrainz_releasegroupid', 'musicbrainz_workid', 'acoustid_fingerprint', 'acoustid_id'])


When I ran it multiple times and multiple errors fixed it dwindle down to
mtags:audio['album'],
            audio['length'],
            audio['title'],    audio['artist'],   audio['albumartist'], audio['tracknumber'], audio['genre'],    audio['date']
not sure why it happened?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Loop through tags inside tags in Selenium/Python xpack24 1 5,637 Oct-23-2019, 10:15 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020