music-assistant / hass-music-assistant

Turn your Home Assistant instance into a jukebox, hassle free streaming of your favorite media to Home Assistant media players.
Apache License 2.0
1.32k stars 49 forks source link

'NoneType' object has no attribute 'tag'; causes files to be excluded from library #2793

Closed dmcc closed 1 month ago

dmcc commented 1 month ago

What version of Music Assistant has the issue?

2.2.2

What version of the Home Assistant Integration have you got installed?

N/A

Have you tried everything in the Troubleshooting FAQ and reviewed the Open and Closed Issues and Discussions to resolve this yourself?

The problem

eyed3 returns None when reading some MP3 files. This is related to the fixed issue https://github.com/music-assistant/hass-music-assistant/issues/2656 but with a slightly different error message. We get this stacktrace when running in a development container:

2024-08-23 02:35:43.279 ERROR (MainThread) [music_assistant.filesystem_local] Error processing /path/to/some.mp3 - 'NoneType' object has no attribute 'tag'
Traceback (most recent call last):
  File "/workspaces/music-assistant-server/music_assistant/server/providers/filesystem_local/base.py", line 342, in sync_library
    track = await self._parse_track(item)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspaces/music-assistant-server/music_assistant/server/providers/filesystem_local/base.py", line 761, in _parse_track
    tags = await parse_tags(input_file, file_item.file_size)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspaces/music-assistant-server/music_assistant/server/helpers/tags.py", line 453, in parse_tags
    if audiofile.tag is not None:
       ^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'tag'

How to reproduce

Not sure, but some of my badly tagged files seem to still anger eyed3 (incidentally, I think there are other MP3 tag parsers which might be more robust -- I've had good luck with tinytag in other projects). I haven't dug into why eyed3 rejects the files but it's hopefully moot as I have a workaround.

Music Providers

N/A

Player Providers

N/A

Full log output

No response

Additional information

PR with a workaround coming soon!

What version of Home Assistant Core are your running

2024.8.2

What type of installation are you running?

Home Assistant Container

On what type of hardware are you running?

Linux

OzGav commented 1 month ago

Actually @MelHarbour was already looking into the tagging situation. He should review this.

marcelveldt commented 1 month ago

Good tip about tinytag, I like the fact its pure python

marcelveldt commented 1 month ago

We currently use ffmpeg/ffprobe as our primary tag reader but it has some issues with mp3 files where it simply doesnt read some of the tags, hence eyed3 is only used to fill in the blanks for mp3 files only. We are considering just switching to a different tag library completely, such as taglib or mutagen but the hard thing is that none of them are async friendly (so we still need to run in an executor) and full support for all tags and filetypes is also hard, that is why ffprobe was so great.

I guess we can swap it around. Use a more robust tag scanner for all common file formats and use ffprobe only for the obscure ones. I am definitely going to look into tinytag, maybe we can even make it async friendly

dmcc commented 1 month ago

Thanks for the context! By the way, I just noticed that tinytag has a great library of weird MP3 (and other audio format) samples to test for robustness.

This one in particular is a great example of a file that's not supported by eyed3 but is parseable by tinytag. Happy to add it as a test case if that would be helpful.