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

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

Open
pokulo opened this issue Sep 12, 2024 · 0 comments
Open

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

pokulo opened this issue Sep 12, 2024 · 0 comments

Comments

@pokulo
Copy link
Contributor

pokulo commented Sep 12, 2024

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: quodlibet/mutagen#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 added a commit to pokulo/podcats that referenced this issue Sep 12, 2024
…ading podcasts

* this prevents app crash because of single broken/incompatible mp3 files.
jkbrzt pushed a commit that referenced this issue Sep 13, 2024
…ame (#29)

* 🥅 Fix issue #28: catch mutagen.mp3.HeaderNotFoundError while loading podcasts

* this prevents app crash because of single broken/incompatible mp3 files.

* 🥅 Fix "ValueError: year 0 is out of range" error when trying to format date tag as into html

* 🐛 fix UnicodeEncodeError by allowing surrogates in the data while encoding to bytes

* e.g. the following:
     UnicodeEncodeError: 'utf-8' codec can't encode character '\udc84' in position 767364: surrogates not allowed
* ensure request responses are already encoded to bytes to avoid strict encoding by the requests library

* 🔊 add logging for broken file metadata (HeaderNotFoundError)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant