jesseward / plex-lastfm-scrobbler

Scrobble played audio items Last.FM from the Plex Media Server application.
MIT License
91 stars 13 forks source link

East Asian characters #47

Closed thxo closed 7 years ago

thxo commented 7 years ago

The scrobbler apparently fails to process metadata containing East Asian characters with the ASCII codec it is using. Consequently the submission to last.fm will not occur at all.

Related scrobbler log:

2017-02-05 21:43:41,065 [16024] [plex_scrobble.plex_monitor parse_line] [INFO] Found played song and extracted library id '538' from plex log 
2017-02-05 21:43:41,065 [16024] [plex_scrobble.plex_monitor fetch_metadata] [INFO] Fetching library metadata from http://localhost:32400/library/metadata/538
2017-02-05 21:43:41,067 [16024] [requests.packages.urllib3.connectionpool _new_conn] [DEBUG] Starting new HTTP connection (1): localhost
2017-02-05 21:43:41,074 [16024] [requests.packages.urllib3.connectionpool _make_request] [DEBUG] http://localhost:32400 "GET /library/metadata/538 HTTP/1.1" 200 825
2017-02-05 21:43:41,076 [16024] [plex_scrobble.plex_monitor monitor_log] [ERROR] unable to scrobble {'album': 'daze / days', 'artist': u'\u3058\u3093 Feat. \u30e1\u30a4\u30ea\u30a2', 'title': 'daze'}, adding to cache. error='ascii' codec can't encode characters in position 0-1: ordinal not in range(128)
2017-02-05 21:43:41,077 [16024] [plex_scrobble.scrobble_cache add] [INFO] adding "じん Feat. メイリア" "daze" (daze / days) to retry cache.

Response of metadata request mentioned in the log (some sensitive information changed):

<?xml version="1.0" encoding="UTF-8"?>
<MediaContainer size="1" allowSync="1" identifier="com.plexapp.plugins.library" librarySectionID="2" librarySectionTitle="Music" librarySectionUUID="aaaaaaaa-1234-aaaa-aaaa-123451234512" mediaTagPrefix="/system/bundle/media/flags/" mediaTagVersion="1486068602">
<Track ratingKey="538" key="/library/metadata/538" parentRatingKey="537" grandparentRatingKey="524" guid="com.plexapp.agents.plexmusic://gracenote/track/431995094-D73A524D5EE92E857CCCDB331E0911D0/444891092-70D20C5F59D82102B7B91FCD4A41E1C6?lang=en" librarySectionID="2" type="track" title="daze" grandparentKey="/library/metadata/524" parentKey="/library/metadata/537" grandparentTitle="&#12376;&#12435;(&#33258;&#28982;&#12398;&#25973;P)" parentTitle="daze / days" originalTitle="&#12376;&#12435; Feat. &#12513;&#12452;&#12522;&#12450;" summary="" index="1" parentIndex="1" viewCount="1" lastViewedAt="1486331020" year="2014" thumb="/library/metadata/537/thumb/1486266973" parentThumb="/library/metadata/537/thumb/1486266973" grandparentThumb="/library/metadata/524/thumb/1486266954" duration="235502" addedAt="1486266669" updatedAt="1486266973">
<Media id="438" duration="235502" bitrate="4621" audioChannels="2" audioCodec="flac" container="flac">
<Part id="438" key="/library/parts/438/1486266413/file.flac" duration="235502" file="/path/to/file/01. daze.flac" size="136024317" container="flac">
<Stream id="766" streamType="2" selected="1" codec="flac" index="0" channels="2" bitrate="4621" audioChannelLayout="stereo" bitDepth="24" samplingRate="96000" />
</Part>
</Media>
</Track>
</MediaContainer>
jesseward commented 7 years ago

@dargasea thanks for reporting.

What OS and Python version are you running?

thxo commented 7 years ago

@jesseward

I managed to get the entire traceback after restarting the program.


  File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
    self.run()
  File "/usr/lib/python2.7/threading.py", line 763, in run
    self.__target(*self.__args, **self.__kwargs)
  File "build/bdist.linux-x86_64/egg/plex_scrobble/__main__.py", line 59, in cache_retry
    cache.retry_queue()
  File "build/bdist.linux-x86_64/egg/plex_scrobble/scrobble_cache.py", line 115, in retry_queue
    age=self.cache[key][2]))
UnicodeEncodeError: 'ascii' codec can't encode characters in position 15-18: ordinal not in range(128)```
jesseward commented 7 years ago

@dargasea thanks for the locale output. Did your copy+paste happen to miss the LANG variable? Or is it not set?

If LANG is missing, would you try setting export LANG="en_US.UTF-8" from your current shell/terminal and re-run the plex-scrobbler application from the shell.

thxo commented 7 years ago

I've run the following commands just to safe:

$ export LANG="en_US.UTF-8"
$ export LC_ALL="en_US.UTF-8"
$ export LANGUAGE="en_US.UTF-8"
$ cat /etc/default/locale 
#  File generated by update-locale
LANG="en_US.UTF-8"
$ locale
LANG=en_US.UTF-8
LANGUAGE=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=en_US.UTF-8

The issue persists, with the same traceback as mentioned above.

jesseward commented 7 years ago

I have committed version 4.0.0, which is a clean-up on the cache retry logic and adds explicit utf-8 encoding in fetch_metadata.

Details in https://github.com/jesseward/plex-lastfm-scrobbler/commit/84c3e6057da66d2996c44c9780f4eb5d14f71e28 .

Please retry to scrobble the track you were previously hanging on.