iluvcapra / wavinfo

Probe WAVE Files for all metadata
https://wavinfo.readthedocs.io/
MIT License
36 stars 7 forks source link

Failed to decode non-ASCII text #10

Closed kakyoism closed 2 years ago

kakyoism commented 2 years ago

Repro

reader = wavinfo.WaveInfoReader('/path/to/my.wav')

Observed

This generates errors

Unhandled exception:
Traceback (most recent call last):
  File "F:\my.py", line 44, in main
    self._extract_rpp_path()
  File "F:\my.py", line 55, in _extract_rpp_path
    reader = wavinfo.WavInfoReader(self.args.path)
  File "F:\.venv\lib\site-packages\wavinfo\wave_reader.py", line 59, in __init__
    self.bext = self._get_bext(f, encoding=bext_encoding)
  File "F:\.venv\lib\site-packages\wavinfo\wave_reader.py", line 117, in _get_bext
    return WavBextReader(bext_data, encoding) if bext_data else None
  File "F:\.venv\lib\site-packages\wavinfo\wave_bext_reader.py", line 26, in __init__
    self.description = sanitize_bytes(unpacked[0])
  File "F:\.venv\lib\site-packages\wavinfo\wave_bext_reader.py", line 22, in sanitize_bytes
    decoded = trimmed.decode(encoding)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe5 in position 35: ordinal not in range(128)

Expected

iluvcapra commented 2 years ago

I'm sortof torn on this one, the EBU spec is pretty clear that the description field has to be ASCII.

iluvcapra commented 2 years ago

Oh sorry, I forgot I actually wrote a way around this: instead of

reader = wavinfo.WaveInfoReader('/path/to/my.wav')

you should do:

reader = wavinfo.WaveInfoReader('/path/to/my.wav', bext_encoding='utf-8')

You can use any encoding here that Python's encoding import recognizes. Let me know if this works!