pannal / plex-for-kodi

Unoffical Plex for Kodi add-on releases.
GNU General Public License v2.0
236 stars 30 forks source link

[BUG] Changes made somewhere around PM4K v0.7.3-rev2 release break TRAKT addon's (script.trakt) ability to scrobble MOVIES when watched using Plex PM4K addon #96

Closed shamanNS closed 2 months ago

shamanNS commented 3 months ago

Description:

It looks like one or more of the changes made since PM4K v0.7.3-rev2 release (= last PM4K version that works correctly with Trakt addon is v0.7.1-rev4 ) has broken the ability of Trakt addon (script.trakt) to correctly detect and "scrobble" (mark as being currently watched on Trakt.tv profile) movies (tv show episodes work just fine) that are being watched using Plex addon.

Movies gets treated as if they were episodes and thus Trakt addon fails to get a match on Trakt's API since it searches using wrong type of media content / uses wrongTrakt API endpoint.

Important notice: this is not a Trakt addon bug and this is not a previosly known bug that was present on v3.5.0 that is still offered as the latest version in Kodi's official rppository. My testing was done with applied patch / code edit on top of script.trakt v3.5.0 to fix the problem of not detecting movies anywhere outside of Kodi's Library. And that patched version of Trakt addon works on every single older PM4K release, with v0.7.1-rev4 as a cutoff point.

Possible solution to the problem:

You could consider implementing this: Providing id's to facilitate scrobbling. If I'm not mistaken Plex's server API returns stuff like TMDB, IMDB.. id for episodes and movies metadata...

That would remove the need to do detection and guessing games currently done by "getInfoLabelDetails()" method.

Details:

Logs:

working with PM4K v0.7.0: kodi_WORKING_log_PM4K_v0.7.0.txt

not working with PM4K v0.7.3-rev2: kodi_BROKEN_log_PM4K_v0.7.3-rev2.txt

Checklist

pannal commented 2 months ago

Yeah, their detection logic for movies is a little weird. I've patched this in 0.7.8-beta3.4: script.plexmod.zip

Please try if it fixes your issue.

As for properly providing IDs: Could be possible, but it's not as straight forward as one might think, due to the different metadata providers one can use in Plex.

shamanNS commented 2 months ago

Please try if it fixes your issue.

@pannal Yes, this 0.7.8-beta3.4 version works (tested on Kodi v20.5 with Trakt addon v3.61) , but only with patched Trakt addon code, With original, unpatched Trakt addon v3.6.1 it doesn't work because of line 540 where if clause contains "season < 0" condition and Plex addon sets the "season" value for movie to be 0 (zero) : this code season = int(xbmc.getInfoLabel("VideoPlayer.Season") or "-1") resolves to zero.

If I patch the Trakt addon (as I've done in the past with previos, older versions of Trakt addon) so line 540 has season <= 0 ( or even replace that check with episode <=0 then movies are correctly scrobbled when watched via Plex Mod addon v0.7.8-beta3.4 (and also any version older than v0.7.1-rev4)

As for properly providing IDs: Could be possible, but it's not as straight forward as one might think, due to the different metadata providers one can use in Plex.

Providing support for libraries using current default Plex Agents ("Plex Movie" and "Plex Series") would be a good (enough) start :)

pannal commented 2 months ago

Hmm, weird. For movies we don't set season/episode to 0, we actually set it to empty string ''. Kodi seems to set that value to 0 in that case. I think we shouldn't set anything at all for those two parameters as that seems to result in -1.

Providing support for libraries using current default Plex Agents ("Plex Movie" and "Plex Series") would be a good (enough) start :)

Please try this 0.7.8-beta3.5: script.plexmod.zip

This should fix episode and season handling, as well as report all known GUIDs to the trakt addon if it's installed, including generating a slug.

shamanNS commented 2 months ago

@pannal Excellent, 0.7.8-beta3.5 works. 🥳

2024-04-29 15:57:04.215 T:5625 debug : [script.trakt] resources.lib.kodiUtilities: getInfoLabelDetails - Started playing a non-library file, checking available data. 2024-04-29 15:57:04.215 T:5625 debug : [script.trakt] resources.lib.kodiUtilities: getInfoLabelDetails info - ids: {"imdb": "tt0353969", "tmdb": 11423, "tvdb": 2586, "slug": "memories-of-murder-2003"}, showtitle: Memories of Murder, Year: 2003, Season: -1, Episode: -1

kodi_trakt_test.log

shamanNS commented 2 months ago

@pannal It works OK for movies but it looks like Trakt scrobble for tv episode doesn't work and causes an Python exception inside Trakt addon code:

Debug log: kodi_Trakt_episode_fail_DEBUG.log

Log except with Python exception:

2024-04-29 16:26:15.226 T:6353 debug : [script.trakt] urllib3.connectionpool: https://api.trakt.tv:443 "POST /scrobble/start HTTP/1.1" 404 None 2024-04-29 16:26:15.229 T:6353 warning : [script.trakt] trakt.interfaces.base: Request failed: "POST /scrobble/start" - 404: "Method exists, but no record found" (Not Found) 2024-04-29 16:26:15.230 T:6353 debug : [script.trakt] resources.lib.scrobbler: [traktPlayer] Setting is enabled to try secondary show title, if necessary. 2024-04-29 16:26:15.257 T:6437 debug : CVideoPlayerVideo::OutputPicture - ttd:313ms pts:2.840 Clock:2.527 Level:5 2024-04-29 16:26:15.258 T:6353 critical : [script.trakt] resources.lib.service: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--

  • NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS! Error Type: <type 'KeyError'> Error Contents: ('title',) Traceback (most recent call last): File "/storage/.kodi/addons/script.trakt/resources/lib/service.py", line 43, in _dispatch self.scrobbler.playbackStarted(data) File "/storage/.kodi/addons/script.trakt/resources/lib/scrobbler.py", line 373, in playbackStarted result = self.scrobble("start") ^^^^^^^^^^^^^^^^^^^^^^^^ File "/storage/.kodi/addons/script.trakt/resources/lib/scrobbler.py", line 561, in scrobble "Searching for show title: %s" % self.traktShowSummary["title"]
    
                                                   KeyError: 'title'
                                                   -->End of Python script error report<--
pannal commented 2 months ago

And that didn't happen before?

Edit: I'm asking because I haven't changed anything with regards to showtitle, originaltitle or title.

pannal commented 2 months ago

We might have entered a different code path with the new guids we provide. Not sure if we can fix this from our end. One possible test would be to only send the guids for movies. If that fixes it, we can go from there.

shamanNS commented 2 months ago

Episode scrobbling works with 0.7.8-beta3.4 (I've reinstalled that older test version over newer, that is the reason why date/time in logs are older / later), The relevant & different log is this:

2024-04-29 17:02:43.416 T:7120 debug : [script.trakt] resources.lib.scrobbler: Episode type, curVideoInfo: {'title': 'Catch Me a Killer', 'season': 1, 'number': 3} 2024-04-29 17:02:43.417 T:7120 debug : [script.trakt] resources.lib.scrobbler: Episode type, traktShowSummary: {'title': 'Catch Me a Killer', 'year': 2024} 2024-04-29 17:02:43.417 T:7120 debug : [script.trakt] resources.lib.scrobbler: scrobble() 2024-04-29 17:02:43.418 T:7120 debug : [script.trakt] resources.lib.scrobbler: scrobble sending show object: {'title': 'Catch Me a Killer', 'year': 2024} 2024-04-29 17:02:43.418 T:7120 debug : [script.trakt] resources.lib.scrobbler: scrobble sending episode object: {'title': 'Catch Me a Killer', 'season': 1, 'number': 3}

Episode scrobblling doesn't work with 0.7.8-beta3.5, the difference in log is this:

2024-04-29 16:38:08.957 T:6565 debug : [script.trakt] resources.lib.scrobbler: Episode type, curVideoInfo: {'season': 1, 'number': 3} 2024-04-29 16:38:08.958 T:6565 debug : [script.trakt] resources.lib.scrobbler: Episode type, traktShowSummary: {'ids': {'imdb': 'tt22176316', 'tmdb': 5137621, 'tvdb': 10306731}} 2024-04-29 16:38:08.958 T:6565 debug : [script.trakt] resources.lib.scrobbler: scrobble() 2024-04-29 16:38:08.960 T:6565 debug : [script.trakt] resources.lib.scrobbler: scrobble sending show object: {'ids': {'imdb': 'tt22176316', 'tmdb': 5137621, 'tvdb': 10306731}} 2024-04-29 16:38:08.961 T:6565 debug : [script.trakt] resources.lib.scrobbler: scrobble sending episode object: {'season': 1, 'number': 3}

So, notice the difference for "curVideoInfo", "traktShowSummary" (it is not only "ids" property's existance)and more importatly what is sends to Trakt API as a payload when it tries to scrobble in "scrobble sending show object" and " scrobble sending episode object". The missing "title" (and that would be TV show title [Catch Me a Killer], not episode title ["Cleveland"]) value is probably the reason it doesn't find a match on Trakt API.

One possible test would be to only send the guids for movies. If that fixes it, we can go from there.

That would probably be the smartest and easiest approach,

shamanNS commented 2 months ago

Look like Trakt API when scrobbling episode expects the ids /guids being sent to be TV show's ids (that would be a "GrandParent" in Plex API terminology?) and not episode's (what Plex Mod 0.7.8-beta3.5+ trakt addon combo end up sending) : as in payload should look like this:

  'show': {
    'title': 'Breaking Bad',
    'year': 2008,
    'ids': {
      'trakt': 1,
      'tvdb': 81189
    }
  },
  'episode': {
    'season': 1,
    'number': 1
  },
  'progress': 10
};
pannal commented 2 months ago

Interesting. I'll fix the imdb ID usage if feasible, otherwise I'll just disable the new handling for TV shows.

This is btw a Trakt codebase bug as well. It shouldn't fail on a bad tvdb ID.

pannal commented 2 months ago

Try this please (no version change, more DEBUG logging, and hopefully the TVDB fix): script.plexmod.zip

shamanNS commented 2 months ago

Now both movies and episodes are correctly matched and scrobbled :) As it now uses TV Show's imdb, tmdb and tvdb ids :) Thanks :)