patzm / plex-music-rating-sync

Plex Agents do not read music ratings when importing music files. This project aims to provide a sync tool.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

No Rating Found in Plex?

jimcampbell100 opened this issue · comments

Hi,

This tool is exactly what I was looking for! I'm running on a Win10 laptop with the most recent MediaMonkey. My Plex server runs on an Ubuntu box on my local network. I run the script, and it appears to work -- but finds no ratings to sync. According to Plex, I have over 1000 songs rated. I have no songs rated in MM. Here's my output:

G:\plex-music-rating-sync>.\sync_ratings.py --log DEBUG --dry --server [myserver] --user [myusername] --token [mytoken]
[08:26:47] INFO: Connecting to local player MediaMonkey
[08:26:47] INFO: Connecting to the Plex Server [myservername] with username [myusername].
[08:26:49] INFO: Connecting to remote player PlexPlayer on the server [myservername]
[08:26:49] INFO: Successfully connected
[08:26:49] INFO: Looking for music libraries
Found multiple music libraries:
[25]: Comedy
[21]: Music
[22]: Music (Christmas)
[24]: Music (Classical)
Select the library to sync with: 21
[08:26:52] INFO: Starting to sync track ratings from PlexPlayer to MediaMonkey
[08:26:52] DEBUG: Executing query [Rating > 0] against MediaMonkey
[08:26:52] INFO: Reading tracks from the MediaMonkey player
[08:26:52] INFO: Attempting to match 0 tracks
[08:26:52] INFO: Matching source tracks with destination player
[08:26:52] INFO: Matched 0/0 tracks
[08:26:52] INFO: Running a DRY RUN. No changes will be propagated!
[08:26:52] INFO: Synchronizing 0 matching tracks without conflicts
[08:26:52] INFO: 0 pairs have conflicting ratings

It seems like it made a successful connection to Plex - the list of libraries it asks me to choose from is correct.

I have recently (within the past two weeks) completely rebuilt both the Plex and MM libraries.

I suspect I'm doing something wrong with MM...I'm not very familiar with it, and only installed it to use this script to write the rating tags to the mp3 files. Do you have any idea what I may be doing wrong? Or how I can track it down on my own?

Thanks very much for this tool and any help you can provide!

Jim

@jimcampbell100 by default the script runs from MM to Plex. You need to add --reverse to sync from Plex to MM.

Thanks! When I add that option, this happens:

Select the library to sync with: 21
[08:52:46] INFO: Starting to sync track ratings from MediaMonkey to PlexPlayer
Traceback (most recent call last):
  File "G:\Users\jim\Downloads\plex-music-rating-sync\sync_ratings.py", line 180, in <module>
    sync_agent.sync()
  File "G:\Users\jim\Downloads\plex-music-rating-sync\sync_ratings.py", line 109, in sync
    self.sync_tracks()
  File "G:\Users\jim\Downloads\plex-music-rating-sync\sync_ratings.py", line 120, in sync_tracks
    tracks = self.remote_player.search_tracks(rating=True)
  File "G:\Users\jim\Downloads\plex-music-rating-sync\MediaPlayer.py", line 333, in search_tracks
    matches = self.music_library.searchTracks(**{'track.userRating!':'0'})
  File "C:\Users\jim\AppData\Local\Programs\Python\Python39\lib\site-packages\plexapi\library.py", line 1001, in searchTracks
    return self.search(libtype='track', **kwargs)
  File "C:\Users\jim\AppData\Local\Programs\Python\Python39\lib\site-packages\plexapi\library.py", line 668, in search
    args[category] = self._cleanSearchFilter(category, value, libtype)
  File "C:\Users\jim\AppData\Local\Programs\Python\Python39\lib\site-packages\plexapi\library.py", line 715, in _cleanSearchFilter
    raise BadRequest('Unknown filter category: %s' % category[:-1])
plexapi.exceptions.BadRequest: Unknown filter category: track.userRating

@jimcampbell100 what version of plex and the plexapi are you using?

PlexAPI is 4.4.0 (most recent)
Plex is 1.22.0.4136 (which I believe is also the most recent - I have PlexPass)

I think I found the problem - can you pull latest version and try again?

I see the exact same error?

Select the library to sync with: 21
[10:59:23] INFO: Starting to sync track ratings from PlexPlayer to MediaMonkey
Traceback (most recent call last):
File "G:\Users\jim\Downloads\plex-music-rating-sync\sync_ratings.py", line 180, in
sync_agent.sync()
File "G:\Users\jim\Downloads\plex-music-rating-sync\sync_ratings.py", line 109, in sync
self.sync_tracks()
File "G:\Users\jim\Downloads\plex-music-rating-sync\sync_ratings.py", line 120, in sync_tracks
tracks = self.remote_player.search_tracks(rating=True)
File "G:\Users\jim\Downloads\plex-music-rating-sync\MediaPlayer.py", line 333, in search_tracks
matches = self.music_library.searchTracks(**{'track.userRating!':'0'})
File "C:\Users\jim\AppData\Local\Programs\Python\Python39\lib\site-packages\plexapi\library.py", line 1001, in searchTracks
return self.search(libtype='track', **kwargs)
File "C:\Users\jim\AppData\Local\Programs\Python\Python39\lib\site-packages\plexapi\library.py", line 668, in search
args[category] = self._cleanSearchFilter(category, value, libtype)
File "C:\Users\jim\AppData\Local\Programs\Python\Python39\lib\site-packages\plexapi\library.py", line 715, in _cleanSearchFilter
raise BadRequest('Unknown filter category: %s' % category[:-1])
plexapi.exceptions.BadRequest: Unknown filter category: track.userRating

Can you paste the following URL in a browser and let me know if it returns results.
https://[plex-server ip]:[plex-port]/library/sections/21/all?X-Plex-Token=[plex-token]&type=10&userRating!=0

Yes, it returns xml for the files I have rated. Sample below.

image

can you provide the output of
pip freeze

Here you go:

G:\Users\Jim\Downloads\plex-music-rating-sync>pip freeze
certifi==2020.12.5
chardet==4.0.0
ConfigArgParse==1.3
fuzzywuzzy==0.18.0
idna==2.10
numpy==1.20.1
PlexAPI==4.4.0
pypiwin32==223
python-Levenshtein==0.12.2
pywin32==300
requests==2.25.1
urllib3==1.26.3

I did a fresh install from a brand new conda container with all of those versions and the exact command line you provided and can't recreate the error. The only difference I have is I'm running 1 version behind you on Plex.

Maybe @patzm has an idea?

Random info in case it helps:

I had an old version of Python install on Windows. I removed it before I started, and downloaded/installed a recent version from their website when I started.

For my Plex - the Music libraries are the new format (I think it was enhanced vs the old basic format) that they started when they started working with Tidal. All of them were created within the past few weeks.

Also for Plex - I use 2FA, but I don't think that matters when using a token?

I tried it for the other music libraries on Plex, they result in the same error (even the ones with no rated tracks).

Plex was just updated yesterday - I have a script that updates it as soon as the new version is available. I didn't try it with the old version, unfortunately.

I am the admin on the Plex install, and that's the username I used.

For Plex, I have the iTunes plugin turned off. The DLNA server is also off.

For my Plex - the Music libraries are the new format (I think it was enhanced vs the old basic format) that they started when they started working with Tidal. All of them were created within the past few weeks.

I'm pretty sure that my libraries are enhanced - of the things that you outlined this is the only one that seems plausible to me as an issue, unless the latest version somehow broke PlexAPI.

Are you using a virtual python environment like venv or conda? That would be my next direction on troubleshooting in case there is a conflict somewhere somehow.

No, just a typical Windows install. I've never used either of those. I typically use docker for stuff like this on an Ubuntu machine on my network. That obviously won't work for this since it needs to work with MM, so I just did a normal install.

I could try one of those...I'd need some time to figure out how they work. Is there one in particular you recommend? I'll read up on it.

No, just a typical Windows install. I've never used either of those. I typically use docker for stuff like this on an Ubuntu machine on my network. That obviously won't work for this since it needs to work with MM, so I just did a normal install.

I could try one of those...I'd need some time to figure out how they work. Is there one in particular you recommend? I'll read up on it.

conda is super easy and I'm using it on my Windows box.
very high level instructions:

  • install miniconda3
  • create a clean environment by running conda create --name [name] python
  • conda activate [name]
  • pip install -r requirements.txt
  • run the code

At the very least it would rule out something else conflicting

Thanks very much for the detailed instructions...unfortunately, I get the same error.

There is a chance that this is an upstream bug (e.g. in PlexAPI). I would suggest that you try to create a minimal script that does the following:

  1. instantiate a library instance
  2. call library.searchTracks(**{'track.userRating!':'0'}). This is essentially the last line of the stack trace that is in this repo:
     matches = self.music_library.searchTracks(**{'track.userRating!':'0'})
    I am thinking: at that point, hardly no runtime state exists. The argument provided to searchTracks is hard coded if I gathered that correctly. So it should be feasible to reproduce the issue with this stand-alone script.

If that fails as well, you can file a meaningful bug-report upstream.

Oh and sorry for not mentioning maybe something obvious: you could always run the code from an IDE with debugging turned on. Not sure if you are a developer, or even have had exposure to python. But that is tremendously powerful. I would suggest PyCharm here. The free community edition allows you to do this.

I have a software background, but I have not written code in 25+ years...I have limited familiarity with python.

instantiate a library instance
call library.searchTracks({'track.userRating!':'0'}). This is essentially the last line of the stack trace that is in this repo:
matches = self.music_library.searchTracks(
{'track.userRating!':'0'})

If one of you would be willing to give me a little more detail on how to actually do this, I would be happy to try it.

I could try the PyCharm later tonight...but I'm basically starting from scratch with my knowledge on that.

can you also query the API directly for what filters are available:
https://[plex server: port/library/sections/5/filters?X-Plex-Token=[plex-token]&type=10

It's possible that the plex server doesn't have a userRating filter on tracks??

Here you go:
image

I was able to get it running in pycharm.

At the point it fails, it is checking to see if the userRating filter exists. It makes a call to get a list of the categories, and it looks like the list comes back empty. I looked to see what url it was using to get the list, and it is not the url you provided above. The url it is using is:

https://192-168-0-111.[xxxx].plex.direct:32400/library/sections/21/filters?includeMeta=1

That url returns:

image

I'm not sure that helps you...I don't know why it would work for you and not me if that were the case.

My results from that url are very different:
image

So the question is why? I suspect it is a change (bug?) with the Plex API. Someone reported a different problem with the filter API on the PlexAPI here #pkkid/python-plexapi#595 on the exact same release you are using.

@jimcampbell100 you can try manually applying the patch as outlined here. I'm guessing that will fix it until the plexapi is updated.

Yep, that gets it running! Thanks!

I am seeing some occasional failures (although it keeps running) - it looks like some of the characters in the filenames on my Ubuntu box have characters that Windows doesn't like (u2010, for example, which is a dash). I'll need to fix those. In any case, it's totally unrelated to this issue.

that's awesome news!

great to hear that you figured out a solution!