spl0k / supysonic

Supysonic is a Python implementation of the Subsonic server API.
https://supysonic.readthedocs.io
GNU Affero General Public License v3.0
259 stars 57 forks source link

Cyrillic letters in tags fail the playback / disable lyrics function? #233

Closed ku-dmitry closed 2 years ago

ku-dmitry commented 2 years ago

Playback is impossible for some of the files with Cyrillic letters in names/tags. Looks like it fails while requesting lyrics. Supysonic tries to get lyrics and fails to start playback. Here is the log file contents:

  2022-04-13 17:56:47,479 [ERROR] Exception on /rest/getLyrics.view [GET]
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/dist-packages/mediafile.py", line 137, in mutagen_call
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.9/dist-packages/mutagen/_util.py", line 154, in wrapper
    with _openfile(self, filething, filename, fileobj,
  File "/usr/lib/python3.9/contextlib.py", line 117, in __enter__
    return next(self.gen)
  File "/usr/local/lib/python3.9/dist-packages/mutagen/_util.py", line 251, in _openfile
    fileobj = open(filename, "rb+" if writable else "rb")
UnicodeEncodeError: 'ascii' codec can't encode characters in position 16-21: ordinal not in range(128)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/dist-packages/flask/app.py", line 2073, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.9/dist-packages/flask/app.py", line 1518, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python3.9/dist-packages/flask/app.py", line 1516, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python3.9/dist-packages/flask/app.py", line 1502, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
  File "/usr/local/lib/python3.9/dist-packages/supysonic/api/media.py", line 393, in lyrics
    lyrics = mediafile.MediaFile(track.path).lyrics
  File "/usr/local/lib/python3.9/dist-packages/mediafile.py", line 165, in wrapper
    return mutagen_call('loadfile', '', f, *args, **kwargs)
  File "/usr/local/lib/python3.9/dist-packages/mediafile.py", line 149, in mutagen_call
    raise MutagenError(filename, exc)
mediafile.MutagenError: '': 'ascii' codec can't encode characters in position 16-21: ordinal not in range(128)

Maybe there is a way to disable all the lyrics-related functions?

spl0k commented 2 years ago

Hello, Thank you for the report, I'll take a look into this lyrics issue.

But an error on the lyrics shouldn't prevent you from playing media. If that is the only error you notice in the logs I guess that it is the client you're using that doesn't behave correctly if it receives an error and just prevents playing the file even if the error didn't occur on the request used to fetch the actual media. As a workaround I suggest you take a look in your client settings to see if you can disable the fetching of the lyrics while I work on a fix.

ku-dmitry commented 2 years ago

Thank you for your response. Unfortunately my client (iSub) doesn't allow you to turn off lyrics.

Maybe this stuff from the client side will help you a bit.


2022/04/15 11:13:35:620  [ISMSNSURLSessionStreamHandler] Stream handler request canceled for <ISMSSong: 0x2800339f0>  title: Люди надоели
2022/04/15 11:13:35:620  [SUSCoverArtLoader] art loading failed for: 9191fe6b-9f10-41ba-a1a5-21f178169d5a
2022/04/15 11:13:35:621  [ISMSStreamManager] Removing song from cached songs table: <ISMSSong: 0x2800339f0>  title: Люди надоели
2022/04/15 11:13:35:622  [ISMSSong+DAO] deleting from genres table
2022/04/15 11:13:35:631  [ISMSNSURLSessionStreamHandler] Stream handler didReceiveResponse for <ISMSSong: 0x28003fde0>  title: Крыши
2022/04/15 11:13:35:639  [ISMSSong+DAO] created genres temp, error 0
2022/04/15 11:13:35:671  [ISMSSong+DAO] renamed genrestemp to genres, error 0
2022/04/15 11:13:35:684  [ISMSNSURLSessionStreamHandler] Stream handler didFinishLoadingInternal for <ISMSSong: 0x28003fde0>  title: Крыши
2022/04/15 11:13:35:695  [BassGaplessPlayer] preparing stream for Крыши  file: /var/mobile/Containers/Data/Application/1CB3C107-9CAA-4F8D-8FE1-63E70918B770/Documents/songCache/E25DA2F03107E969B6364F7A00A89C77
2022/04/15 11:13:35:696  [BassGaplessPlayer] checking Крыши length: 18446744073709551615
2022/04/15 11:13:35:729  [ISMSStreamManager] Marking isFullyCached = YES for <ISMSSong: 0x28003fde0>  title: Крыши
2022/04/15 11:13:35:730  [BassGaplessPlayer] seeking to 18446744073709551472  success: NO
2022/04/15 11:13:35:730  [BassGaplessPlayer] seeking to 18446744073709551605  success: NO
2022/04/15 11:13:35:731  [BassGaplessPlayer] seeking to 0  success: YES
2022/04/15 11:13:35:731  [BassGaplessPlayer] seeking to 0  success: YES
2022/04/15 11:13:35:731  [BassGaplessPlayer] seeking to 0  success: YES
2022/04/15 11:13:35:732  [BassGaplessPlayer] Failed to create stream for Крыши with hardware sampling, trying again with software sampling
2022/04/15 11:13:35:739  [BassWrapper] BASS error: 41 - Unsupported file format
2022/04/15 11:13:35:739  [BassGaplessPlayer] failed to create stream for song: Крыши  filename: /var/mobile/Containers/Data/Application/1CB3C107-9CAA-4F8D-8FE1-63E70918B770/Documents/songCache/E25DA2F03107E969B6364F7A00A89C77
2022/04/15 11:13:35:739  [BassWrapper] BASS error: 41 - Unsupported file format
2022/04/15 11:13:35:776  [ISMSSong+DAO] Size for song "Крыши" successfully added to database on cache completion
2022/04/15 11:13:35:905  [ISMSNSURLSessionStreamHandler] Stream handler request canceled for <ISMSSong: 0x28003fde0>  title: Крыши
2022/04/15 11:13:35:907  [ISMSStreamManager] Removing song from cached songs table: <ISMSSong: 0x28003fde0>  title: Крыши
2022/04/15 11:13:35:929  [ISMSSong+DAO] deleting from genres table
2022/04/15 11:13:35:956  [ISMSSong+DAO] created genres temp, error 0
2022/04/15 11:13:36:021  [ISMSSong+DAO] renamed genrestemp to genres, error 0
2022/04/15 11:13:36:043  [ISMSStreamManager] starting handler, handlerStack: (
    "<ISMSNSURLSessionStreamHandler: 0x2807458c0>  title: \U041a\U0440\U044b\U0448\U0438"
)
2022/04/15 11:13:36:043  [ISMSNSURLSessionStreamHandler] Stream handler start:NO for: Крыши
2022/04/15 11:13:36:044  [ISMSNSURLSessionStreamHandler] Stream handler startConnectionInternalSuccess for <ISMSSong: 0x280038360>  title: Крыши
2022/04/15 11:13:36:067  [ISMSSong+DAO] Inserted into cachedSongs with discNumber: 1 and insert was successful? 1
2022/04/15 11:13:36:073  [ISMSStreamManager] fill stream queue, handlerStack: (
    "<ISMSNSURLSessionStreamHandler: 0x2807458c0>  title: \U041a\U0440\U044b\U0448\U0438",
    "<ISMSNSURLSessionStreamHandler: 0x280748a80>  title: \U041b\U044e\U0434\U0438 \U043d\U0430\U0434\U043e\U0435\U043b\U0438"
)

I don't know exactly what's going on here. I've been using Supysonic for almost a year now and it has been working cool. I do not recall whether I had Cyrillic songs before, but maybe I did. Maybe this has something to do with the Mutagen update?

spl0k commented 2 years ago

Well, yet another issue that eludes me. I don't have any error with Cyrillic letters, both in the tags and the filename.

Could you please tell me the versions of mediafile and mutagen you're using? Actually I doubt it comes from these libraries; I'm suspecting your system environment might be the cause here. What is the output of the locale command? What is the type of the file system your media files reside in? Is it set up with a particular encoding?

ku-dmitry commented 2 years ago

Hm, maybe. Never thought of that this way. I have Mutagen 1.45.1 and Mediafile 0.9.0 - both were installed as dependencies for Supysonic and I don't think they are needed elsewhere, so they should be fine.

locale returns following:

LANG=ru_RU.UTF-8
LANGUAGE=
LC_CTYPE=ru_RU.UTF-8
LC_NUMERIC="ru_RU.UTF-8"
LC_TIME="ru_RU.UTF-8"
LC_COLLATE=ru_RU.UTF-8
LC_MONETARY="ru_RU.UTF-8"
LC_MESSAGES="ru_RU.UTF-8"
LC_PAPER="ru_RU.UTF-8"
LC_NAME="ru_RU.UTF-8"
LC_ADDRESS="ru_RU.UTF-8"
LC_TELEPHONE="ru_RU.UTF-8"
LC_MEASUREMENT="ru_RU.UTF-8"
LC_IDENTIFICATION="ru_RU.UTF-8"
LC_ALL=
spl0k commented 2 years ago

I finally managed to reproduce the error, I suppose you are running Supysonic with Apache and modwsgi. This is Apaches's fault, as it is by default run with a locale which is most likely different than the one used by the operating system. Assuming a Debian or Ubuntu distribution, you can change this by editing the /etc/apache2/envvars_ file. Near the middle you'll find these lines:

## The locale used by some modules like mod_dav
export LANG=C
## Uncomment the following line to use the system default locale instead:
#. /etc/default/locale

Here you can either replace the

export LANG=C

by

export LANG=C.UTF-8

or simply uncomment the last line as suggested. Once done restart Apache and you should be good.

Yet another solution would be to avoid any non-ASCII character in the media files name/path 😅.

ku-dmitry commented 2 years ago

Thanks man, it worked like a champ!

I really like Supysonic and added it to awesome-selfhosted list couple of months ago. Hope it will bring more people into community. Folder-view feature rocks!

spl0k commented 2 years ago

Glad I could help you. And thank you for your kind words and promotion :)