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

cannot tag .wav file with mutagen.id3.WAVE #545

Closed
maphouse opened this issue Oct 29, 2021 · 1 comment
Closed

cannot tag .wav file with mutagen.id3.WAVE #545

maphouse opened this issue Oct 29, 2021 · 1 comment
Labels

Comments

@maphouse
Copy link

I have a WAV file in which I already added a few dummy tags using foobar2000
Trying to add tags using mutagen now I'm having difficulty

>>> wlist = glob('*.wav')
>>> w = wlist[0]
>>> WAVE(w)
{'TIT2': TIT2(encoding=<Encoding.UTF16: 1>, text=['Little By Little (Waste Wisely Edit)']), 'TPE1': TPE1(encoding=<Encoding.UTF16: 1>, text=['The Marias']), 'TXXX:initialkey': TXXX(encoding=<Encoding.UTF16: 1>, desc='initialkey', text=['HI'])}
>>> WAVE(w).tags.add(TKEY(encoding=3, text=['Abm']))
>>> WAVE(w).save()
>>> WAVE(w)
{'TIT2': TIT2(encoding=<Encoding.UTF16: 1>, text=['Little By Little (Waste Wisely Edit)']), 'TPE1': TPE1(encoding=<Encoding.UTF16: 1>, text=['The Marias']), 'TXXX:initialkey': TXXX(encoding=<Encoding.UTF16: 1>, desc='initialkey', text=['HI'])}

I tried another technique which seemed to be suggested in #392 where I deleted all the tags, and then try to add new ones using only mutagen, but I get an error

>>> mutagen.wave.delete(w)
>>> WAVE(w)
{}
>>> WAVE(w).add_tags()
>>> WAVE(w).tags.add(TKEY(encoding=3, text=['Abm']))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'add'

Any assistance would be much appreciated!

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

phw commented Feb 15, 2023

The issue here was that there was always a new WAVE object created in the code. So there is a call to WAVE(w).add_tags(), that creates a WAVE object and adds tags to it. But as the object is not assigned it gets discarded again. Then the next call WAVE(w).tags.add(...) creates a new object and tries to access it tags, but if the loaded file does not have tags this of course fails again.

Something like this would work:

wave = WAVE(w)
if not wave.tags:
    wave.add_tags()
wave.tags.add(TKEY(encoding=3, text=['Abm']))
wave.save(w)

@phw phw closed this as completed Feb 15, 2023
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