nicfit / eyeD3

eyeD3 is a Python module and command line program for processing ID3 tags. Information about mp3 files (i.e bit rate, sample frequency, play time, etc.) is also provided. The formats supported are ID3v1 (1.0/1.1) and ID3v2 (2.3/2.4).
http://eyed3.nicfit.net/
GNU General Public License v3.0
532 stars 58 forks source link

Unifying (and fixing) removal of specific tags #611

Open TJ-59 opened 9 months ago

TJ-59 commented 9 months ago

So, basically, I noticed that (apparently, didn't test every possibility) whenever the tag itself is a string, entering an empty string removes that tag. Example :

>>> somemp3.tag.album_artist
# None, hence no display, confirmed by
>>> type(somemp3.tag.album_artist)
<class 'NoneType'>
# and by 
>>> somemp3.tag.album_artist is None
True
>>> somemp3.tag.album_artist = "some dudes with instruments"
>>> somemp3.tag.album_artist
'some dudes with instruments'
>>> somemp3.tag.album_artist = ""
>>> somemp3.tag.album_artist
>>> somemp3.tag.album_artist is None
True

Note that trying >>> somemp3.tag.album_artist = None IS working for pure str tags like this one, but does NOT work and cause ERRORS for URL tags like artist_url and the rest of _url tags (typically : AttributeError: 'NoneType' object has no attribute 'encode')

So, this can be "solved" by never using the "None" method, and always using the empty string method instead AFAIK, BUT, some other types of tags do not have this ability, one that I found is the "BPM" tag. Initially, it gives a None, as it is not yet set to any value. Let's say you have a cat jumping on the keyboard, while you have some homemade tag editor using eyeD3, and the cat move the focus to the BPM entry (probably by tippy-tapping on TAB or something) and then sets a weird value (like 69420... which is high even for a hummingbird on coke) and finally press ENTER, which saves the changes (somemp3.tag.save()). You're now having a mp3 with a set bpm tag of 69420, which isn't very fitting for the content, since it is some meditation track for yoga classes or some talk-show podcast with no BPM at all. You can of course always set it to 0 (zero), but unlike the string tags with the empty string method, this does NOT remove that tag, meaning some mediaplayers will spend a few seconds showing you some irrelevant info about the bpm. That bpm tag does not accept None as a value either, and no amount of tinkering from my part managed to get any result in removing that tag. I could of course remove everything by going initTag, but it's sort of a nuclear option and implies setting back everything else.

SO, for a TL;DR and question : Shouldn't tagname = None be some sort of accepted default method of removing ANY specific tag ? Also, if anyone knows how to remove an int typed tag, please let me know, thanks !