trakt / Plex-Trakt-Scrobbler

Add what you are watching on Plex to trakt.tv
1.45k stars 166 forks source link

tv shows not scrobbling with new scanner/agent #596

Open rnpasinos opened 3 years ago

rnpasinos commented 3 years ago

i have recently created a new movies and tv shows library using the new scanner and agent.

the new movies library, using the PLEX MOVIE scanner and agent are scrobbling properly. i am able to verify that it's able to push and pull watched items and i am able to see the progress of the movie i am watching on trakt.

however, it's not the case for the new tv shows library, using the PLEX TV SERIES scanner and agent. i can confirm that scrobbling on my old library works, using the PLEX SERIES SCANNER.

for now, i'm keeping my old library and continue to watch tv shows from there. hopefully the devs can update the plug-in to support the new scanner/agent.

geaston95 commented 3 years ago

I'm seeing the same issue. Looking at the webhook payload that is sent when playback starts, the formatting of the IDs is a bit different when using the new Plex TV agent.

This the metadata when using old scanner:

Metadata":{ "librarySectionType":"show", "ratingKey":"104560", "key":"/library/metadata/104560", "parentRatingKey":"104558", "grandparentRatingKey":"104557", "guid":"com.plexapp.agents.thetvdb://362829/1/1?lang=en", "parentGuid":"com.plexapp.agents.thetvdb://362829/1?lang=en", "grandparentGuid":"com.plexapp.agents.thetvdb://362829?lang=en", "type":"episode", "title":"Pilot", "grandparentKey":"/library/metadata/104557", "parentKey":"/library/metadata/104558", "librarySectionTitle":"TV Shows", "librarySectionID":2, "librarySectionKey":"/library/sections/2", "grandparentTitle":"Mythic Quest", "parentTitle":"Season 1", "contentRating":"TV-MA", "summary":"As the hit video game Mythic Quest prepares to launch its newest update, creator Ian Grimm obsesses over a seemingly minor detail.", "index":1, "parentIndex":1, "viewCount":1, "lastViewedAt":1605071175, "year":2020, "thumb":"/library/metadata/104560/thumb/1620465313", "art":"/library/metadata/104557/art/1620465313", "parentThumb":"/library/metadata/104558/thumb/1590256581", "grandparentThumb":"/library/metadata/104557/thumb/1620465313", "grandparentArt":"/library/metadata/104557/art/1620465313", "grandparentTheme":"/library/metadata/104557/theme/1620465313", "originallyAvailableAt":"2020-02-07", "addedAt":1581053423, "updatedAt":1620465313, "Writer":[ { "id":11342, "filter":"writer=11342", "tag":"Charlie Day" }, { "id":11378, "filter":"writer=11378", "tag":"Megan Ganz" }, { "id":11343, "filter":"writer=11343", "tag":"Rob McElhenney" } ]

and this is the metadata when using the new Plex TV Scanner

"Metadata":{ "librarySectionType":"show", "ratingKey":"104560", "key":"/library/metadata/104560", "parentRatingKey":"104558", "grandparentRatingKey":"104557", "guid":"plex://episode/5e16137d4e7a9b001ec08b37", "parentGuid":"plex://season/602e76a4de471d002d080f62", "grandparentGuid":"plex://show/5d9c0922170e24001f2af500", "type":"episode", "title":"Pilot", "grandparentKey":"/library/metadata/104557", "parentKey":"/library/metadata/104558", "librarySectionTitle":"TV Shows", "librarySectionID":2, "librarySectionKey":"/library/sections/2", "grandparentTitle":"Mythic Quest", "parentTitle":"Season 1", "contentRating":"TV-MA", "summary":"As the hit video game Mythic Quest prepares to launch its newest update, creator Ian Grimm obsesses over a seemingly minor detail.", "index":1, "parentIndex":1, "audienceRating":8.2, "viewCount":1, "lastViewedAt":1605071175, "parentYear":2020, "thumb":"/library/metadata/104560/thumb/1620367553", "art":"/library/metadata/104558/art/1620367553", "parentThumb":"/library/metadata/104558/thumb/1620367553", "grandparentThumb":"/library/metadata/104557/thumb/1620367553", "grandparentArt":"/library/metadata/104557/art/1620367553", "grandparentTheme":"/library/metadata/104557/theme/1620367553", "originallyAvailableAt":"2020-02-07", "addedAt":1581053423, "updatedAt":1620367553, "audienceRatingImage":"themoviedb://image.rating", "Director":[ { "id":10293, "filter":"director=10293", "tag":"David Gordon Green" } ], "Writer":[ { "id":11343, "filter":"writer=11343", "tag":"Rob McElhenney" }, { "id":11378, "filter":"writer=11378", "tag":"Megan Ganz" }, { "id":11342, "filter":"writer=11342", "tag":"Charlie Day" } ], "Guid":[ { "id":"imdb://tt9719170" }, { "id":"tmdb://1969147" }, { "id":"tvdb://7501639" } ], "Role":[ { "id":45959, "filter":"actor=45959", "tag":"Elisha Henig", "role":"Pootie Shoe", "thumb":"https://metadata-static.plex.tv/people/5d776c657a53e9001e741fe7.jpg" }, { "id":95715, "filter":"actor=95715", "tag":"Naomi Ekperigin", "role":"Carol", "thumb":"https://metadata-static.plex.tv/people/5e164adf61c6140040d80b49.jpg" } ] }

Both are for the same episode file from 2 different servers, one with old scanner and one with the new. I think the plugin needs to be updated to look for the new Guid fields

BeachyHeadCode commented 3 years ago

There is a commit in the main code if you just download the source the issue is fixed. Has been fixed since august 31, 2020. It is not released it is open source so just download the working code man.

rnpasinos commented 3 years ago

you mean download this directly and replace the existing files and folders? https://github.com/trakt/Plex-Trakt-Scrobbler/tree/master/Trakttv.bundle

i already tried that. i also tried using the following forks which has the above-mentioned commit already included in the release.

scrobbling for tv shows only works if you've never watched the show.

if you marked the first few episodes or seasons as watched, any episode you watch after that will be a hit or miss. sometimes, it'll scrobble but most of the time it won't.

if you mark any show, season, or episode as watch on plex, it doesn't sync it to trakt. and any shows, seasons, or episodes already marked as watch on trakt doesn't sync to plex either. the sync function for tv shows doesn't work at all.

i had no issues with movies, as previously mentioned. this one works smoothly.

BeachyHeadCode commented 3 years ago

I would delete the existing package you have installed. The entire folder. And copy the new folder into your plugin folder

rg9400 commented 3 years ago

The plugin is already patched to work with the new TV agent. There are a few important aspects to highlight though

  1. Syncs using this plugin are not properly defined. By default, sync only pushes all the data in Plex, but pulls changes from Trakt into Plex since the last authentication. This means that anything already marked as watched on Trakt will not be synced into Plex with the scheduled sync. To fix this, you need to use a tool like Kitana to access the plugin menu, and from the plugin menu, run the Full Pull task. This will pull the entirety of your Trakt watched status into Plex, even historical data. This is the only way to do this.

  2. Scrobbling does not care about whether you have seen the show or not. Scrobbles and playback progress use the episode GUID of the show. This is not always available, though it should be fairly common for stuff that was not recently aired and not super obscure. For stuff that just aired, these guids are not always populated right away. They get populated during periodic metadata refreshes, but if you watch as soon as you add it, then the scrobble/playback progress will not work.

  3. While the above sounds bad, the scheduled sync task actually uses a different method to push data to Trakt. It uses Season + Episode numbers and the show's GUID. If you run this at regular intervals, it should catch stuff that was missed from above and sync it to Trakt. It is also the only way to sync stuff you manually marked watched.

It is important to use the webpage and Kitana to verify that your settings are correct for this to function properly. But it should have no issues with the new agent. I've been using it since the agent was in beta, and it's been completely accurate (as far as I can tell) with syncing to Trakt...and I watched a ton of TV in that time.

Modifying the behavior for the agent is complicated as it is built like a house of cards. The changes I made to the plugin to get it to work with the new native movie and TV agents were lucky because I was able to make a small change in a precise location that had the desired effect without disturbing anything else. While it can be improved further, those changes are maybe too much for me considering the potential for breaking it as well as the fact that it works perfectly as is for me already.

tonyliangli commented 3 years ago

Thanks for the detailed explanation. I've uploaded the xml files of the episodes that cannot be scrobbled as well as my settings of the TV show library. Two of the episode are the latest that just come out yesterday while the other one has been out for a week.

To test if it's because the show is too new to be available for TrakT or Plex, I purchased the TrakT VIP and tested scrobbling with the Webhook solution. I also tested Infuse with plex media (which has TrakT integrated). All episodes from the xmls.zip can be scrobbled properly (including the playback progress, the time finished watching, etc.) with these solutions.

In that case, I suspect, maybe it's related to how I manage my TV library settings such as the tv agent used or whether include adult content is enabled. Since I'm not familiar with the code of the scrobbler, I was thinking to use a network traffic capture tool to capture the network traffic that of the API request. Since the "404 not found" are returned from the following APIs: https://api.trakt.tv/scrobble/start (pause/stop). I was wondering if there can be something wrong with the request. Maybe the Guid is missing or incorrect? I'm not sure if the TrakT API takes the IMDB schema from the first id of the Guid field as a valid id. The TratT documentation takes the TVDB id as an example for the episode. However, I haven't tried capturing these requests yet.

On the other hand, is it possible to find detailed information of the URL, request body, and response from the log files directly? If that's possible, it would be much easier to locate and fix the issue I'm encountering.

Thanks again!

xmls.zip image image image image image

dylanrjones commented 3 years ago

I would delete the existing package you have installed. The entire folder. And copy the new folder into your plugin folder

Thanks, this worked for me!

rnpasinos commented 3 years ago
  1. Syncs using this plugin are not properly defined. By default, sync only pushes all the data in Plex, but pulls changes from Trakt into Plex since the last authentication. This means that anything already marked as watched on Trakt will not be synced into Plex with the scheduled sync. To fix this, you need to use a tool like Kitana to access the plugin menu, and from the plugin menu, run the Full Pull task. This will pull the entirety of your Trakt watched status into Plex, even historical data. This is the only way to do this.

Running Pull from Trakt.tv worked. Apparently, it seems like Full doesn't perform a 2-way sync.

  1. Scrobbling does not care about whether you have seen the show or not. Scrobbles and playback progress use the episode GUID of the show. This is not always available, though it should be fairly common for stuff that was not recently aired and not super obscure. For stuff that just aired, these guids are not always populated right away. They get populated during periodic metadata refreshes, but if you watch as soon as you add it, then the scrobble/playback progress will not work.

I have since purchased Plex Pass and Trakt VIP and enabled scrobbling using webhooks.

Thank you everyone for your help!

rg9400 commented 3 years ago

Thanks for the detailed explanation. I've uploaded the xml files of the episodes that cannot be scrobbled as well as my settings of the TV show library. Two of the episode are the latest that just come out yesterday while the other one has been out for a week.

Yes, all three XMLs have the proper GUIDs for the episodes. I also tested one of these exact same episodes on my own server, and playback progress worked, as well as scrobble, as well as syncing watched status. To confirm, neither are working for you? Sync nor scrobble? And that it is not working at all, or just for specific episodes?

To test if it's because the show is too new to be available for TrakT or Plex, I purchased the TrakT VIP and tested scrobbling with the Webhook solution. I also tested Infuse with plex media (which has TrakT integrated). All episodes from the xmls.zip can be scrobbled properly (including the playback progress, the time finished watching, etc.) with these solutions.

Yes, these solutions use a different method compared to the plugin. The plugin method is more dated. That said, as I mentioned above, the plugin should work fine for these episodes as well. It is worth trying to pull and replace the very latest version of the plugin to make sure there isn't some local changes or an older version causing issues.

In that case, I suspect, maybe it's related to how I manage my TV library settings such as the tv agent used or whether include adult content is enabled. Since I'm not familiar with the code of the scrobbler, I was thinking to use a network traffic capture tool to capture the network traffic that of the API request. Since the "404 not found" are returned from the following APIs: https://api.trakt.tv/scrobble/start (pause/stop). I was wondering if there can be something wrong with the request. Maybe the Guid is missing or incorrect? I'm not sure if the TrakT API takes the IMDB schema from the first id of the Guid field as a valid id. The TratT documentation takes the TVDB id as an example for the episode. However, I haven't tried capturing these requests yet.

The IMDb ID format is perfectly fine. I'm not sure if you can turn on the debug settings for the plugin to pull this info, but the request itself should be okay as it works for me and others. Your TV settings should bear no connection to the plugin as the episodes already have the relevant guids. I am using TVDB ordering instead of TMDB, but everything else seems the same between our settings anyways. The plugin settings are probably far more relevant. Mine are given below

image image

tonyliangli commented 3 years ago

Yes, all three XMLs have the proper GUIDs for the episodes. I also tested one of these exact same episodes on my own server, and playback progress worked, as well as scrobble, as well as syncing watched status. To confirm, neither are working for you? Sync nor scrobble? And that it is not working at all, or just for specific episodes?

I'm only using the scrobble function so I haven't tested syncing.

Yes, these solutions use a different method compared to the plugin. The plugin method is more dated. That said, as I mentioned above, the plugin should work fine for these episodes as well. It is worth trying to pull and replace the very latest version of the plugin to make sure there isn't some local changes or an older version causing issues.

Yeah. But I'm using this plugin for the first time so I guess there's nothing to replace. By the way I'm using the code from your fork instead of the code from this repo.

The IMDb ID format is perfectly fine. I'm not sure if you can turn on the debug settings for the plugin to pull this info, but the request itself should be okay as it works for me and others. Your TV settings should bear no connection to the plugin as the episodes already have the relevant guids. I am using TVDB ordering instead of TMDB, but everything else seems the same between our settings anyways. The plugin settings are probably far more relevant. Mine are given below

I'll further look into it, thanks!

nserrano10 commented 3 years ago

I deleted all trakt related folders and copied the latest Trakttv.bundle to my synology but i am getting the following error. Any ideas?

2021-06-30 10:24:10,037 - com.plexapp.plugins.trakttv      (7f7a8b1d2808) :  CRITICAL (com.plexapp.plugins.trakttv:615) - Exception starting plug-in (most recent call last):
  File "/volume1/@appstore/Plex Media Server/Resources/Plug-ins-ebb5fe9f3/Framework.bundle/Contents/Resources/Versions/2/Python/Framework/core.py", line 608, in start
    self.sandbox.execute(self.init_code)
  File "/volume1/@appstore/Plex Media Server/Resources/Plug-ins-ebb5fe9f3/Framework.bundle/Contents/Resources/Versions/2/Python/Framework/code/sandbox.py", line 256, in execute
    exec(code) in self.environment
  File "/volume1/Plex/Library/Application Support/Plex Media Server/Plug-ins/Trakttv.bundle/Contents/Code/__init__.py", line 62, in <module>
    import interface
  File "/volume1/@appstore/Plex Media Server/Resources/Plug-ins-ebb5fe9f3/Framework.bundle/Contents/Resources/Versions/2/Python/Framework/code/sandbox.py", line 333, in __import__
    return mod.load_module(_name)
  File "/volume1/@appstore/Plex Media Server/Resources/Plug-ins-ebb5fe9f3/Framework.bundle/Contents/Resources/Versions/2/Python/Framework/code/sandbox.py", line 44, in load_module
    module = RestrictedModule(name, path, sandbox)
  File "/volume1/@appstore/Plex Media Server/Resources/Plug-ins-ebb5fe9f3/Framework.bundle/Contents/Resources/Versions/2/Python/Framework/code/loader.py", line 30, in __init__
    exec(code) in self.__dict__
  File "/volume1/Plex/Library/Application Support/Plex Media Server/Plug-ins/Trakttv.bundle/Contents/Code/interface/__init__.py", line 4, in <module>
    import m_sync
  File "/volume1/@appstore/Plex Media Server/Resources/Plug-ins-ebb5fe9f3/Framework.bundle/Contents/Resources/Versions/2/Python/Framework/code/sandbox.py", line 333, in __import__
    return mod.load_module(_name)
  File "/volume1/@appstore/Plex Media Server/Resources/Plug-ins-ebb5fe9f3/Framework.bundle/Contents/Resources/Versions/2/Python/Framework/code/sandbox.py", line 44, in load_module
    module = RestrictedModule(name, path, sandbox)
  File "/volume1/@appstore/Plex Media Server/Resources/Plug-ins-ebb5fe9f3/Framework.bundle/Contents/Resources/Versions/2/Python/Framework/code/loader.py", line 30, in __init__
    exec(code) in self.__dict__
  File "/volume1/Plex/Library/Application Support/Plex Media Server/Plug-ins/Trakttv.bundle/Contents/Code/interface/m_sync.py", line 8, in <module>
    from plugin.managers.account import AccountManager
  File "/volume1/@appstore/Plex Media Server/Resources/Plug-ins-ebb5fe9f3/Framework.bundle/Contents/Resources/Versions/2/Python/Framework/code/sandbox.py", line 345, in __import__
    raise e
ImportError: No module named core
jeff15110168 commented 3 years ago

I'm having this issue as well where when I mark an episode as watched on trakt app, it doesn't sync to my Plex. Any idea what I need to do to fix this? I believe my movie 2-way sync is working perfectly, as well as when I watch TV show on Plex it gets marked as watched on trakt

SasSam commented 3 years ago

@rg9400 Thank you for your work on this plugin. Unfortunately, it doesn't work for me either. I've recently updated it to the latest Plex server version on Synology and switched to the new Plex Agent (unfortunately)... since then, the original plugin has stopped working. I've tried your fork, but no luck. I've changed my plugin settings to the same as you showed above, but still no luck.

Fun fact: it works with Movies. The scrobbler is failing with TV shows only.

In the logs, I got this:

2021-09-07 20:28:19,344 - plex_activity.activity           (7efd400e8b38) :  INFO (plex_activity.activity:48) - Finished starting 1 method(s): "websocket"
2021-09-07 20:28:23,046 - com.plexapp.plugins.trakttv      (7efd4014bb38) :  INFO (com.plexapp.plugins.trakttv:131) - Saved the dictionary file
2021-09-07 20:28:42,866 - plex.objects.core.base           (7efd3fd04b38) :  WARNING (plex.objects.core.base:156) - [Episode] Omitted attribute: grandparentguid
2021-09-07 20:28:42,867 - plex.objects.core.base           (7efd3fd04b38) :  WARNING (plex.objects.core.base:156) - [Episode] Omitted attribute: parentguid
2021-09-07 20:28:42,867 - plex.objects.core.base           (7efd3fd04b38) :  WARNING (plex.objects.core.base:156) - [Episode] Omitted attribute: parentyear
2021-09-07 20:28:42,886 - plex.objects.core.base           (7efd3fd04b38) :  WARNING (plex.objects.core.base:156) - [Episode] Omitted attribute: grandparentguid
2021-09-07 20:28:42,887 - plex.objects.core.base           (7efd3fd04b38) :  WARNING (plex.objects.core.base:156) - [Episode] Omitted attribute: parentguid
2021-09-07 20:28:42,887 - plex.objects.core.base           (7efd3fd04b38) :  WARNING (plex.objects.core.base:156) - [Episode] Omitted attribute: parentyear
2021-09-07 20:28:42,980 - plex.objects.core.base           (7efd3fd04b38) :  WARNING (plex.objects.core.base:156) - [Episode] Omitted attribute: grandparentguid
2021-09-07 20:28:42,981 - plex.objects.core.base           (7efd3fd04b38) :  WARNING (plex.objects.core.base:156) - [Episode] Omitted attribute: parentguid
2021-09-07 20:28:42,981 - plex.objects.core.base           (7efd3fd04b38) :  WARNING (plex.objects.core.base:156) - [Episode] Omitted attribute: parentyear
2021-09-07 20:28:44,502 - trakt.interfaces.base            (7efd3ff1ab38) :  WARNING (trakt.interfaces.base:48) - Request failed: "POST /scrobble/start" - 404: "Method exists, but no record found" (Not Found)
2021-09-07 20:29:26,927 - plex.objects.core.base           (7efd3fd04b38) :  WARNING (plex.objects.core.base:156) - [Episode] Omitted attribute: grandparentguid
2021-09-07 20:29:26,927 - plex.objects.core.base           (7efd3fd04b38) :  WARNING (plex.objects.core.base:156) - [Episode] Omitted attribute: parentguid
2021-09-07 20:29:26,928 - plex.objects.core.base           (7efd3fd04b38) :  WARNING (plex.objects.core.base:156) - [Episode] Omitted attribute: parentyear
2021-09-07 20:29:30,143 - trakt.interfaces.base            (7efd3ff1ab38) :  WARNING (trakt.interfaces.base:48) - Request failed: "POST /scrobble/pause" - 404: "Method exists, but no record found" (Not Found)
2021-09-07 20:38:33,392 - plex.objects.core.base           (7efd3fd04b38) :  WARNING (plex.objects.core.base:156) - [Episode] Omitted attribute: grandparentguid
2021-09-07 20:38:33,392 - plex.objects.core.base           (7efd3fd04b38) :  WARNING (plex.objects.core.base:156) - [Episode] Omitted attribute: parentguid
2021-09-07 20:38:33,392 - plex.objects.core.base           (7efd3fd04b38) :  WARNING (plex.objects.core.base:156) - [Episode] Omitted attribute: parentyear
2021-09-07 20:38:36,519 - trakt.interfaces.base            (7efd3ff1ab38) :  WARNING (trakt.interfaces.base:48) - Request failed: "POST /scrobble/stop" - 404: "Method exists, but no record found" (Not Found)

Do you have any ideas/advice? Thanks in advance!

jeff15110168 commented 3 years ago

I'm still having issues specifically with TV Shows scribbling using rg9400's branch of the trakt plugin.

It basically is hit or miss with TV shows. I added cobra Kai S3 to my library (already had S1/S2 in Plex and both marked as played), which I had marked S3 as fully watched on Trakt manually. S3 is showing up as unwatched in Plex. I manually marked Queen's Gambit (brand new show not in Plex) as played in Trakt web, but then when I added it to Plex it is currently marked as Unplayed.

Any idea what could be causing this?

SasSam commented 3 years ago

@rg9400 just another update on the issue... I've changed the agent back on TV shows to use the legacy scanner like this: image

But still no luck. It doesn't work. I got the same error that I mentioned above. The movies are fine.

Before the plugin update, I stopped the server and then restarted it. After I changed the agent and scanner on TV shows library, I re-ran the scanner on the whole library.

I'm using the latest master branch from this repo and my plex server version is the latest as well: 1.24.1.4931

I hope you will be able to do some magic here again... šŸ˜…

jeff15110168 commented 3 years ago

I'm still having issues specifically with TV Shows scribbling using rg9400's branch of the trakt plugin.

It basically is hit or miss with TV shows. I added cobra Kai S3 to my library (already had S1/S2 in Plex and both marked as played), which I had marked S3 as fully watched on Trakt manually. S3 is showing up as unwatched in Plex. I manually marked Queen's Gambit (brand new show not in Plex) as played in Trakt web, but then when I added it to Plex it is currently marked as Unplayed.

Any idea what could be causing this?

what is the latest branch of plex trakt plugin that works for the newest movies/tv show agent? I believe i have rg9400 and still having the issue where if i manually mark episodes/whole season as watched on trakt, it's not syncing down the the plex level. maybe i just need to refresh reinstall the plugin again but want to make sure i grab the latest / greatest.

eskwire commented 3 years ago

I have to servers two server but the plug is not working in current version of the server. new version that dont work in Version 1.24.2.4973, but works on old version of the server Version 1.24.3.5033

krugster commented 3 years ago

I seem to be getting the same 404 error: 2021-09-28 16:39:45,197 - trakt.interfaces.base (7f4e4cfd6b38) : WARNING (trakt.interfaces.base:48) - Request failed: "POST /scrobble/pause" - 404: "Method exists, but no record found" (Not Found)

the-jeffski commented 3 years ago

@krugster I was getting that, deleted and replaced the whole plugin folder again and all is working for me.

krugster commented 3 years ago

Yes, I did as well and it is working again. Thanks!

jeff15110168 commented 3 years ago

@krugster I was getting that, deleted and replaced the whole plugin folder again and all is working for me.

Which version did you reinstall? Can you link?

krugster commented 3 years ago

To be honest Iā€™m not %100 sure. I downloaded develop, master and 1.3.3 and things didnā€™t work right away so I swapped between a couple different ones until it did.

p3lim commented 2 years ago

Been annoyed by this one for a while, finally figured it out (for me): this only happens when the new Plex agent adds the year to the title of the show. If I manually remove it (e.g. "Hawkeye" instead of "Hawkeye (2021)") it works.

According to the debug logs, the imdb id for the specific episode is also used here, so the plugin should completely ignore the title of the show, and only consider the imdb id.

Before renaming the show (as in Plex used the agent and fetched the metadata for me):

plugin.managers.action           (7f788c41eb38) :  DEBUG (plugin.managers.action:126) - Retrieved u'scrobble/start' action from queue
plugin.managers.action           (7f788c41eb38) :  DEBUG (plugin.managers.action:156) - Sending action u'scrobble/start' (account: <Account name: u'XXXXX'>, interface: u'scrobble', method: u'start')
plugin.managers.action           (7f788c41eb38) :  DEBUG (plugin.managers.action:212) - request: {u'progress': 0.0, u'episode': {u'season': 1, u'number': 2, u'title': u'Hide and Seek'}, u'show': {u'title': u'Hawkeye (2021)', u'ids': {u'imdb': u'tt10166576'}, u'year': None}}
plugin.models.m_trakt.account    (7f788c41eb38) :  DEBUG (plugin.models.m_trakt.account:88) - Using oauth authorization for <TraktAccount username: u'XXXXX'>
trakt.interfaces.base            (7f788c41eb38) :  WARNING (trakt.interfaces.base:48) - Request failed: "POST /scrobble/start" - 404: "Method exists, but no record found" (Not Found)
plugin.managers.action           (7f788c41eb38) :  DEBUG (plugin.managers.action:133) - Action u'scrobble/start' sent, moved action to history

After manually removing the year from the title of the show:

plugin.managers.action           (7f788c41eb38) :  DEBUG (plugin.managers.action:126) - Retrieved u'scrobble/start' action from queue
plugin.managers.action           (7f788c41eb38) :  DEBUG (plugin.managers.action:156) - Sending action u'scrobble/start' (account: <Account name: u'XXXXX'>, interface: u'scrobble', method: u'start')
plugin.managers.action           (7f788c41eb38) :  DEBUG (plugin.managers.action:212) - request: {u'progress': 0.0, u'episode': {u'season': 1, u'number': 2, u'title': u'Hide and Seek'}, u'show': {u'title': u'Hawkeye', u'ids': {u'imdb': u'tt10166576'}, u'year': None}}
plugin.models.m_trakt.account    (7f788c41eb38) :  DEBUG (plugin.models.m_trakt.account:88) - Using oauth authorization for <TraktAccount username: u'XXXXX'>
plugin.managers.action           (7f788c41eb38) :  DEBUG (plugin.managers.action:133) - Action u'scrobble/start' sent, moved action to history

Issue might also be because it's not using the imdb id at all, since it's the episode id and not the show id, and it's used for the show data. Also bothers me that the year field is None. The information this plugin gets from Plex is obviously broken.

The Trakt API can take an imdb id for both the show and the episode, I'd wager it's enough to move the imdb id supplied for the show and move it to the episode in the POST query, and that'd fix this issue, unless the scrobble API also requires the correct show imdb id.

Edit: same issue if the title contains something like "(US)" at the end.

jeff15110168 commented 2 years ago

Been annoyed by this one for a while, finally figured it out (for me): this only happens when the new Plex agent adds the year to the title of the show. If I manually remove it (e.g. "Hawkeye" instead of "Hawkeye (2021)") it works.

According to the debug logs, the imdb id for the specific episode is also used here, so the plugin should completely ignore the title of the show, and only consider the imdb id.

Before renaming the show (as in Plex used the agent and fetched the metadata for me):

plugin.managers.action           (7f788c41eb38) :  DEBUG (plugin.managers.action:126) - Retrieved u'scrobble/start' action from queue
plugin.managers.action           (7f788c41eb38) :  DEBUG (plugin.managers.action:156) - Sending action u'scrobble/start' (account: <Account name: u'XXXXX'>, interface: u'scrobble', method: u'start')
plugin.managers.action           (7f788c41eb38) :  DEBUG (plugin.managers.action:212) - request: {u'progress': 0.0, u'episode': {u'season': 1, u'number': 2, u'title': u'Hide and Seek'}, u'show': {u'title': u'Hawkeye (2021)', u'ids': {u'imdb': u'tt10166576'}, u'year': None}}
plugin.models.m_trakt.account    (7f788c41eb38) :  DEBUG (plugin.models.m_trakt.account:88) - Using oauth authorization for <TraktAccount username: u'XXXXX'>
trakt.interfaces.base            (7f788c41eb38) :  WARNING (trakt.interfaces.base:48) - Request failed: "POST /scrobble/start" - 404: "Method exists, but no record found" (Not Found)
plugin.managers.action           (7f788c41eb38) :  DEBUG (plugin.managers.action:133) - Action u'scrobble/start' sent, moved action to history

After manually removing the year from the title of the show:

plugin.managers.action           (7f788c41eb38) :  DEBUG (plugin.managers.action:126) - Retrieved u'scrobble/start' action from queue
plugin.managers.action           (7f788c41eb38) :  DEBUG (plugin.managers.action:156) - Sending action u'scrobble/start' (account: <Account name: u'XXXXX'>, interface: u'scrobble', method: u'start')
plugin.managers.action           (7f788c41eb38) :  DEBUG (plugin.managers.action:212) - request: {u'progress': 0.0, u'episode': {u'season': 1, u'number': 2, u'title': u'Hide and Seek'}, u'show': {u'title': u'Hawkeye', u'ids': {u'imdb': u'tt10166576'}, u'year': None}}
plugin.models.m_trakt.account    (7f788c41eb38) :  DEBUG (plugin.models.m_trakt.account:88) - Using oauth authorization for <TraktAccount username: u'XXXXX'>
plugin.managers.action           (7f788c41eb38) :  DEBUG (plugin.managers.action:133) - Action u'scrobble/start' sent, moved action to history

Issue might also be because it's not using the imdb id at all, since it's the episode id and not the show id, and it's used for the show data. Also bothers me that the year field is None. The information this plugin gets from Plex is obviously broken.

Edit: same issue if the title contains something like "(US)" at the end.

Do you mean changing the name of the folder that the show resides in (like the automatic folder naming sonarr adds)? Or what are you referencing that includes the year

p3lim commented 2 years ago

Do you mean changing the name of the folder that the show resides in (like the automatic folder naming sonarr adds)? Or what are you referencing that includes the year

In Plex, e.g: image

anonyme123 commented 2 years ago

Same situation here, works as soon as I remove the "(US)" from "The Office (US)" title in Plex.

jeff15110168 commented 2 years ago

Same situation here, works as soon as I remove the "(US)" from "The Office (US)" title in Plex.

are you guys both saying that if you change the name of the actual show in Plex itself to remove the suffixes (year or country), then the plugin starts working again for scrobbling?

p3lim commented 2 years ago

Consider the data I found from the debug logs:

{
    'progress': 0.0,
    'episode': {
        'season': 1,
        'number': 2,
        'title': 'Hide and Seek'
    },
    'show': {
        'title': 'Hawkeye (2021)',
        'ids': {
            'imdb': 'tt10166576'
        },
        'year': None
    }
}

and compare that to the Trakt scrobble API: https://trakt.docs.apiary.io/#reference/scrobble

There are a few problems with this request:

  1. .show.title contains extra information about the show that Trakt doesn't have in their own metadata (in this case it's "(2021)"), so it can't use the title to match the show
  2. .show.ids.imdb is the ID for the episode, not the show, so it's unable to match the show using that
  3. .show.year is None (null), so it's useless for matching the show

It should be clear why the plugin is failing based on that.

Now onto how to fix this:

The bare minimum the Trakt API needs to know is the following:

So the fix is simply to rewrite the code in this plugin to use this format for shows:

{
    "progress": 0.0,
    "episode": {
        "ids": {
            "imdb": "tt10166576"
        }
    }
}

I tested this with manual API calls, and this is the response from Trakt API:

{
  "id": 0,
  "action": "start",
  "progress": 2,
  "sharing": {
    "facebook": false,
    "twitter": false,
    "tumblr": false
  },
  "episode": {
    "season": 1,
    "number": 2,
    "title": "Hide and Seek",
    "ids": {
      "trakt": 5612882,
      "tvdb": 8585109,
      "imdb": "tt10166576",
      "tmdb": 3273258,
      "tvrage": null
    }
  },
  "show": {
    "title": "Hawkeye",
    "year": 2021,
    "ids": {
      "trakt": 146415,
      "slug": "hawkeye-2021",
      "tvdb": 367146,
      "imdb": "tt10160804",
      "tmdb": 88329,
      "tvrage": null
    }
  }
}

So it's clear that Trakt is fully able to fill in the blanks when only given the episode imdb id.

Here's an ugly and untested patch:

diff --git a/Trakttv.bundle/Contents/Libraries/Shared/trakt/interfaces/scrobble.py b/Trakttv.bundle/Contents/Libraries/Shared/trakt/interfaces/scrobble.py
index b97e9269..069ca363 100644
--- a/Trakttv.bundle/Contents/Libraries/Shared/trakt/interfaces/scrobble.py
+++ b/Trakttv.bundle/Contents/Libraries/Shared/trakt/interfaces/scrobble.py
@@ -114,11 +114,14 @@ class ScrobbleInterface(Interface):
             # TODO validate
             data['movie'] = movie
         elif episode:
-            if show:
-                data['show'] = show
-
-            # TODO validate
-            data['episode'] = episode
+            if show and 'ids' in show and 'imdb' in show['ids']:
+                data['episode'] = {
+                    'ids': {
+                        'imdb': show['ids']['imdb']
+                    }
+                }
+            else:
+                raise ValueError('Missing episode metadata')

         response = self.http.post(
             action,
thebatfink commented 2 years ago

So it's clear that Trakt is fully able to fill in the blanks when only given the episode imdb id.

Here's an ugly and untested patch:

diff --git a/Trakttv.bundle/Contents/Libraries/Shared/trakt/interfaces/scrobble.py b/Trakttv.bundle/Contents/Libraries/Shared/trakt/interfaces/scrobble.py
index b97e9269..069ca363 100644
--- a/Trakttv.bundle/Contents/Libraries/Shared/trakt/interfaces/scrobble.py
+++ b/Trakttv.bundle/Contents/Libraries/Shared/trakt/interfaces/scrobble.py
@@ -114,11 +114,14 @@ class ScrobbleInterface(Interface):
             # TODO validate
             data['movie'] = movie
         elif episode:
-            if show:
-                data['show'] = show
-
-            # TODO validate
-            data['episode'] = episode
+            if show and 'ids' in show and 'imdb' in show['ids']:
+                data['episode'] = {
+                    'ids': {
+                        'imdb': show['ids']['imdb']
+                    }
+                }
+            else:
+                raise ValueError('Missing episode metadata')

         response = self.http.post(
             action,

Seems to work for me at least initially, thanks šŸ‘

jeff15110168 commented 2 years ago

As another person with datapoint. Iā€™m watching the new Apple TV show ā€œFoundationā€, and it wonā€™t scrobble to Trakt. It also has prefix issue, named ā€œFoundation (2021)ā€ in Plex. When i change the name of the show in Plex title to just ā€œFoundationā€, then scrobble works.

jeff15110168 commented 2 years ago

So it's clear that Trakt is fully able to fill in the blanks when only given the episode imdb id. Here's an ugly and untested patch:

diff --git a/Trakttv.bundle/Contents/Libraries/Shared/trakt/interfaces/scrobble.py b/Trakttv.bundle/Contents/Libraries/Shared/trakt/interfaces/scrobble.py
index b97e9269..069ca363 100644
--- a/Trakttv.bundle/Contents/Libraries/Shared/trakt/interfaces/scrobble.py
+++ b/Trakttv.bundle/Contents/Libraries/Shared/trakt/interfaces/scrobble.py
@@ -114,11 +114,14 @@ class ScrobbleInterface(Interface):
             # TODO validate
             data['movie'] = movie
         elif episode:
-            if show:
-                data['show'] = show
-
-            # TODO validate
-            data['episode'] = episode
+            if show and 'ids' in show and 'imdb' in show['ids']:
+                data['episode'] = {
+                    'ids': {
+                        'imdb': show['ids']['imdb']
+                    }
+                }
+            else:
+                raise ValueError('Missing episode metadata')

         response = self.http.post(
             action,

Seems to work for me at least initially, thanks šŸ‘

How do i go about making this change? I am using Plex on Unraid and have the add-in installed in the appdata folder (mnt/user/appdata/Plex/Library/Application Support/Plex Media Server/Plug-ins/Trakttv.bundle)

thebatfink commented 2 years ago

The file is referenced at the top of what you have quoted along with path? did you even look at it before replying? Edit scrobble.py with some text editor remove the red lines after ā€œelif episode:ā€ and replace with the green.

nehalvpatel commented 2 years ago

I have iterated on @p3lim's excellent patch. Their version will work if and only if the episode has been matched with an IMDB ID.

This version should work on episodes that have been matched with TMDB, TheTVDB, etc.

if show and 'ids' in show:
    data['episode'] = {
        'ids': show['ids']
    }
else:
    raise ValueError('Missing episode metadata')
p3lim commented 2 years ago

My patch was "ugly" because it's not the correct place to fix the issue, I just don't know the code well enough to fix it proper. It was just a PoC that this plugin is broken and giving a reason why.

nehalvpatel commented 2 years ago

Sorry if I gave the impression that I was dissing your patch. I'm really thankful for it! It's great that we finally have the reason behind scrobbling being flaky, and we wouldn't know the cause without your time investment.

p3lim commented 2 years ago

It was not the impression I got, I just don't want people to think this is the correct way to fix the issue.

jeff15110168 commented 2 years ago

Sorry if I gave the impression that I was dissing your patch. I'm really thankful for it! It's great that we finally have the reason behind scrobbling being flaky, and we wouldn't know the cause without your time investment.

Apologies for asking, but could you upload the correct scrobble.py ? I'm not very familiar with editing python files so it would be very helpful :)

p3lim commented 2 years ago

Apologies for asking, but could you upload the correct scrobble.py ? I'm not very familiar with editing python files so it would be very helpful :)

Copy the entire patch, save it as "scrobble.patch" in your plugins directory (e.g. next to Trakt.bundle), then run patch < scrobble.patch.

Cornishman commented 2 years ago

So I applied the patch suggested above and although it did resolve most of my scrobbling issues, it's not completly fool proof, I still encountered some issues with some shows where trakt wasn't acknowledging the scrobble request with just the imdb id being sent, no idea why.

After lots of trial and error I think I found the cause. This plugin currently only takes the First external identifier for an episode from the plex metadata instead of using them all. This I suspect is due to various plex changes over the years.

So the plex metadata looks something like this

<MediaContainer>
    <Video>
        <Guid id="imdb://XXXXX"/>
        <Guid id="tmdb://XXXX"/>
        <Guid id="tvdb://XXXX"/>
    </Video>
</MediaContainer>

Which this plugin only reads the first Guid (imdb) and eventually ends up as per the detailed description that @p3lim provided further up #https://github.com/trakt/Plex-Trakt-Scrobbler/issues/596#issuecomment-983393949

I have very little experience in python, but I made some educated guesses and changes to try and support multiple Guid's being parsed from the plex metadata and then passing them along correctly to trakt scrobbling as episode id's and not as the show id's. With my limited localised testing these changes now work for me, where all my shows that weren't tracking before now appear to scrobble correctly in trakt. As an example, this is now what gets sent to trakt scrobble:

{
    "app_date": None,
    "progress": 0.21,
    "app_version": "1.3.3",
    "episode": {
        "ids": {
            "tvdb": 8287132,
            "tmdb": 2670881,
            "imdb": "tt10166574"
        }
    }
}

Please note: I have not tested these changes and there may be unforseen issues

The changes can be obtained here

thebatfink commented 2 years ago

The changes can be seen here:

Is that not what was done here? Or is this addressing some other issue?

nehalvpatel commented 2 years ago

I believe @Cornishman is trying to fix the underlying issue with their version.

p3lim commented 2 years ago

Still hacking it with the scrobble part though, the data passed to scrobble.py should be correct before it reaches that far.

Cornishman commented 2 years ago

The changes can be seen here:

Is that not what was done here? Or is this addressing some other issue?

I believe @Cornishman is trying to fix the underlying issue with their version.

Correct, the patch suggested further up did work for me for most of my problem shows, but some still wouldn't scrobble to trakt even with the patch, as it was only sending the imdb id, or whatever id came first, and trakt still couldn't match with just that one id - I have no idea why that is the case. Even with the later patch that attempts to send all id's #https://github.com/trakt/Plex-Trakt-Scrobbler/issues/596#issuecomment-987334587) it doesn't actually send anymore than the first one parsed due to how the plugin parses the Plex metadata and only reads the first one it encounters.

With my changes it now sends all the episode external id's that are returned in the Plex metadata, so imdb, tmdb, tvdb... etc are all sent across. Which for me, fixed all my shows (so far!)

Cornishman commented 2 years ago

Still hacking it with the scrobble part though, the data passed to scrobble.py should be correct before it reaches that far.

That's true, I probably could have just changed the build_episode bit .. which looking I failed to commit ... let me correct that on my end and update

the-jeffski commented 2 years ago

I was testing out the previous patch and found I still had odd episodes not scrobbling. The more I investigated I could see they were generally those where a corresponding ID wasn't in Trakt e.g. Plex only had a tvdb and trakt only had the the tmdb. SO think this could be the cause of the odd ones never matching on scrobble.

Cornishman commented 2 years ago

Ok, I redid my change as per suggested. The patch isn't needed, instead I've updated the build_episode routine for the scrobbling request so that if the episode being played is a single episode it'll just use all of the ID's that the plex metadata returned.

For shows that are multipart it'll revert back to the current process so that the multiple episodes are scrobbled instead of just the one linked to the ID's. Becuase of this it's not 100% fool proof and if those shows fail to match on show name and episode number/name then it'll not scrobble those.

The main problems overall are as @p3lim pointed out, when playing an episode the plex metadata only contains most of the information about the episode, such as the episodes air date / year, instead of also providing enough details about the show itself. Which means trying to scrobble with trakt using show name / episode numbers isn't 100% reliable. The main issue is that the external id's being returned when playing an episode only relate to the episode (or first episode in a multipart episode) and not the show. So with the current plex metadata that I'm seeing on my own plex server, means we never have the show id's without additional calls to get metadata. - I'm not sure I have the python knowledge to adjust that to make additional calls to get show metadata alongside the episode metadata to fill it out more

thebatfink commented 2 years ago

Ok, I redid my change as per suggested. The patch isn't needed, instead I've updated the build_episode routine for the scrobbling request so that if the episode being played is a single episode it'll just use all of the ID's that the plex metadata returned.

So how to apply this now?

Cornishman commented 2 years ago

Ok, I redid my change as per suggested. The patch isn't needed, instead I've updated the build_episode routine for the scrobbling request so that if the episode being played is a single episode it'll just use all of the ID's that the plex metadata returned.

So how to apply this now?

Quickest way, just download the zip from my fork and replace your Trakttv.bundle plugin folder with the one you just downloaded.

\ \ After going away and spending a bit more time on it, I've improved my version so that it now pulls back the show metadata to get the external ids and year for the show, and passes it all along to Trakt as part of the scrobbling message.

So the scrobble message to trakt now looks something like:

{
    "app_date": None,
    "progress": 14.24,
    "app_version": "1.3.3",
    "show": {
        "title": "Hawkeye (2021)",
        "ids": {
            "imdb": "tt10160804",
            "tmdb": 88329,
            "tvdb": 367146
        },
        "year": 2021
    },
    "episode": {
        "season": 1,
        "number": 1,
        "title": "Never Meet Your Heroes"
    }
}

This should now mean that, 1) the correct show is matched in trakt as I belive the ids take precendence over the show title when trakt is matching the show and now it's grabbing all the show ids and ignoring the episode ids. 2) multipart episodes should now scrobble correctly again, there is already logic to figure out multipart episodes and which one to currently scrobble, so I've made sure it's still used as were now grabbing the correct show ids to send to trakt.

ricky commented 2 years ago

I installed the version from master in this repo, which contains the changes from https://github.com/trakt/Plex-Trakt-Scrobbler/pull/571, and it resolved the sync issues for me. Putting out a new release would probably help most people.

jeff15110168 commented 2 years ago

I installed the version from master in this repo, which contains the changes from #571, and it resolved the sync issues for me. Putting out a new release would probably help most people.

the new release is cornishman's fork i believe, i just downloaded the zip from the below link https://github.com/Cornishman/Plex-Trakt-Scrobbler