podcats icon indicating copy to clipboard operation
podcats copied to clipboard

mutagen.mp3.HeaderNotFoundError: can't sync to MPEG frame

Open pokulo opened this issue 1 year ago • 0 comments

I encounter the following traceback, when podcats tries to load all my podcast files:

192.168.178.29 - - [12/Sep/2024 21:09:17] "GET /web HTTP/1.1" 500 -
[2024-09-12 21:11:25,941] ERROR in app: Exception on /web [GET]
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/flask/app.py", line 1473, in wsgi_app
    response = self.full_dispatch_request()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/flask/app.py", line 882, in full_dispatch_request
    rv = self.handle_user_exception(e)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/flask/app.py", line 880, in full_dispatch_request
    rv = self.dispatch_request()
         ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/flask/app.py", line 865, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)  # type: ignore[no-any-return]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/podcats/__init__.py", line 227, in as_html
    items=u''.join(episode.as_html() for episode in sorted(self)),
                                                    ^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/podcats/__init__.py", line 208, in __iter__
    yield Episode(filepath, relative_dir, self.root_url)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/podcats/__init__.py", line 55, in __init__
    self.tags = mutagen.File(self.filename, easy=True)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/mutagen/_util.py", line 164, in wrapper_func
    return func(h, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/mutagen/_file.py", line 302, in File
    return Kind(fileobj, filename=filething.filename)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/mutagen/_file.py", line 48, in __init__
    self.load(*args, **kwargs)
  File "/usr/local/lib/python3.12/site-packages/mutagen/_util.py", line 156, in wrapper
    return func(self, h, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/mutagen/id3/_file.py", line 420, in load
    self.info = self._Info(fileobj, offset)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/mutagen/_util.py", line 185, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/mutagen/mp3/__init__.py", line 401, in __init__
    raise HeaderNotFoundError("can't sync to MPEG frame")
mutagen.mp3.HeaderNotFoundError: can't sync to MPEG frame

Unfortunately I can't even tell which of the many files in the folder is unreadable/broken.

Background

There is an upstream issue at mutagen to fix this: https://github.com/quodlibet/mutagen/issues/562. But I am not sure, this is supposed to be fixed, because the podcats app depends on the data. But if there is no readable header, the generation of podcast metadata can only rely on the filename/folder name.

Expectation

So I suggest catching and logging this error and try to create metadata only from the filename instead. This way I could load all remaining files as expected and only skip some metadata creation on those view header-broken files, instead of crashing the whole application.

The log of the error should include the path to the broken file.

pokulo avatar Sep 12 '24 21:09 pokulo