jellyfin / jellyfin-plugin-trakt

https://jellyfin.org
MIT License
173 stars 33 forks source link

Use history api for importing episodes from trakt #205

Closed h3llrais3r closed 1 year ago

h3llrais3r commented 1 year ago

The history api includes more details (i.e. indexer id) which can be used to properly match episodes (i.e. when jellyfin is using other indexer than trakt). Matching by indexer id is a lot more accurate than matching by season and number. This is a rework of https://github.com/jellyfin/jellyfin-plugin-trakt/pull/191 where we are now using the history by default for episode sync.

@Shadowghost Maybe we can only use the history api for episode import from trakt? Because I think that the history api will always find a match and there is no need anymore for fallback by season/number lookup. Please provide your feedback. If you agree, I can cleanup the seaons/number logic for episode import and only import based on history api. Or we just keep the legacy code as well, in case in future the trakt api for watched shows/episodes would contain the indexer id's.

Shadowghost commented 1 year ago

If there aren't any specific limits on using the history API I don't see why we should not use it instead of the current implementation.

h3llrais3r commented 1 year ago

There is only 1 call to the history api every time you launch the import from trakt (it was already like that before with my previous PR). Maybe let's leave the old logic still in there as fallback, just in case. If that's ok for you, please review.

h3llrais3r commented 1 year ago

What would be the cases in which the fallback would have any results but the history API won't?

I think it's not possible, but not sure. I don't think that there can be something in the watched api that isn't in the history... just logic thinking... 😉

Shadowghost commented 1 year ago

If it's not possible, we don't need the fallback and you can remove it alltogether.

h3llrais3r commented 1 year ago

Maybe we can leave it in for now, and check if it's not used by adding some different logging? Or I can try on my whole library and see if it's not used... I don't want to break the old logic, in case I missed out a case with the history implementation. Please let me know what you prefer.

Shadowghost commented 1 year ago

I'd prefer more testing. Just keeping it in because we aren't sure fells kinda dirty to me

h3llrais3r commented 1 year ago

I'd prefer more testing. Just keeping it in because we aren't sure fells kinda dirty to me

I can test it, but not sure if my library is sufficient as test case... 😄 @SenorSmartyPants Could you do some testing as well?

h3llrais3r commented 1 year ago

I've changed some logging to see a difference between match by history api or watched api.

h3llrais3r commented 1 year ago

What would be the cases in which the fallback would have any results but the history API won't?

I think it's not possible, but not sure. I don't think that there can be something in the watched api that isn't in the history... just logic thinking... 😉

Actually I think there is still a usecase for the fallback... If the episode in jellyfin doesn't have any providerId assigned to it (do you know if this is possible?), there should still be a fallback to match by season and episode. This because the IsMatch only seems to use the provider ids: image

Or we need to extend this IsMatch to also check on season and number? Something like this (as the history is also containing season and number info): image

Example of history data: image

Sorry for all the questions, but not sure how to reproduce all the cases, as I don't know a lot about jellyfin internals.

SenorSmartyPants commented 1 year ago

I just did my small test case and it didn't behave quite right. I pull from your PR branch and compiled, installed this on my dev setup.

[15:57:34] [DBG] [35] Trakt.ScheduledTasks.SyncFromTraktTask: Episode is in watched history list of user Danzo: Episode: 0x1 'The Cage (Original Pilot)' Series: 'Star Trek' Tvdb id: 248303 Tmdb id: null Imdb id: tt0059753 TvRage id: null
[15:57:34] [DBG] [35] Trakt.ScheduledTasks.SyncFromTraktTask: Marking episode as watched for user Danzo locally: Episode: 0x1 'The Cage (Original Pilot)' Series: 'Star Trek' Tvdb id: 248303 Tmdb id: null Imdb id: tt0059753 TvRage id: null
[15:57:34] [DBG] [35] Trakt.ScheduledTasks.SyncFromTraktTask: Adjusting episode's play count to match a higher remote value (remote: 1 | local: 0) for user Danzo locally: Episode: 0x1 'The Cage (Original Pilot)' Series: 'Star Trek' Tvdb id: 248303 Tmdb id: null Imdb id: tt0059753 TvRage id: null
[15:57:34] [DBG] [35] Trakt.ScheduledTasks.SyncFromTraktTask: Episode is in watched history list of user Danzo: Episode: 1x8 'Balance of Terror' Series: 'Star Trek' Tvdb id: 248317 Tmdb id: null Imdb id: tt0708420 TvRage id: 162321
[15:57:34] [DBG] [35] Trakt.ScheduledTasks.SyncFromTraktTask: Marking episode as watched for user Danzo locally: Episode: 1x8 'Balance of Terror' Series: 'Star Trek' Tvdb id: 248317 Tmdb id: null Imdb id: tt0708420 TvRage id: 162321
[15:57:34] [DBG] [35] Trakt.ScheduledTasks.SyncFromTraktTask: Adjusting episode's play count to match a higher remote value (remote: 1 | local: 0) for user Danzo locally: Episode: 1x8 'Balance of Terror' Series: 'Star Trek' Tvdb id: 248317 Tmdb id: null Imdb id: tt0708420 TvRage id: 162321
[15:57:34] [DBG] [35] Trakt.ScheduledTasks.SyncFromTraktTask: Episode is in watched list of user Danzo: Episode: 1x14 'Court Martial' Series: 'Star Trek' Tvdb id: 248323 Tmdb id: null Imdb id: tt0708425 TvRage id: 162327
[15:57:34] [DBG] [35] Trakt.ScheduledTasks.SyncFromTraktTask: Marking episode as watched for user Danzo locally: Episode: 1x14 'Court Martial' Series: 'Star Trek' Tvdb id: 248323 Tmdb id: null Imdb id: tt0708425 TvRage id: 162327
[15:57:34] [DBG] [35] Trakt.ScheduledTasks.SyncFromTraktTask: Adjusting episode's play count to match a higher remote value (remote: 1 | local: 0) for user Danzo locally: Episode: 1x14 'Court Martial' Series: 'Star Trek' Tvdb id: 248323 Tmdb id: null Imdb id: tt0708425 TvRage id: 162327
[15:57:34] [DBG] [35] Trakt.ScheduledTasks.SyncFromTraktTask: Episode is in watched history list of user Danzo: Episode: 1x28 'The City on the Edge of Forever' Series: 'Star Trek' Tvdb id: 248331 Tmdb id: null Imdb id: tt0708455 TvRage id: 162335
[15:57:34] [DBG] [35] Trakt.ScheduledTasks.SyncFromTraktTask: Marking episode as watched for user Danzo locally: Episode: 1x28 'The City on the Edge of Forever' Series: 'Star Trek' Tvdb id: 248331 Tmdb id: null Imdb id: tt0708455 TvRage id: 162335
[15:57:34] [DBG] [35] Trakt.ScheduledTasks.SyncFromTraktTask: Adjusting episode's play count to match a higher remote value (remote: 1 | local: 0) for user Danzo locally: Episode: 1x28 'The City on the Edge of Forever' Series: 'Star Trek' Tvdb id: 248331 Tmdb id: null Imdb id: tt0708455 TvRage id: 162335

All my episode have multiple IDs(TVDB,IMDB,etc) as you can see. All watched episodes in question have exactly 1 play recorded on Trakt.

Thanks for your work on this.

Shadowghost commented 1 year ago

To answer the question if it's possible that no provider id exists on an item: yes it is, if the metadata source is a NFO without provider ids. Thanks for all the testing, I'd need to setup a whole testing library to check all the cases.

h3llrais3r commented 1 year ago

But 1x14 (local) is also marked as watched. This one is not in my Trakt history.

This is because of the fallback to the season/number. You see this in the logs, as it doesn't mention Episode is in watched history list... [15:57:34] [DBG] [35] Trakt.ScheduledTasks.SyncFromTraktTask: Episode is in watched list of user Danzo: Episode: 1x14 'Court Martial' Series: 'Star Trek' Tvdb id: 248323 Tmdb id: null Imdb id: tt0708425 TvRage id: 162327 The provider id is not found in history, but as fallback, it searches for a match by season/number. Since you have season 1, episode 14 in your watched list on trakt (from watched api), it will mark it as watched.

So it seems it works as expected, the only issue you have is because of the additional fallback.

But since it seems that you can have episodes in jellyfin without a provider Id, I don't think we can remove it.

Maybe if we do the fallback to season/number matching from history api itself, it would solve your problem. Will try to make that change and let you know, so you can retest.

h3llrais3r commented 1 year ago

To answer the question if it's possible that no provider id exists on an item: yes it is, if the metadata source is a NFO without provider ids.

Ok, so we need to keep the fallback by season/number. Since it's also part of history api, I will try to use it from there.

h3llrais3r commented 1 year ago

@SenorSmartyPants Can you rerun your test case on the new version?

h3llrais3r commented 1 year ago

Ok, so we need to keep the fallback by season/number. Since it's also part of history api, I will try to use it from there.

It seems that with adding the check for season/number in IsMatch it also finds it via the history api for episodes that don't have provider id's.

Below some logs: first 2 don't have id's, other have 1 or more id's

[2023-03-03 16:22:28.842 +01:00] [DBG] [32] Trakt.ScheduledTasks.SyncFromTraktTask: Episode is in watched history list of user "ADMIN": "Episode: 1x1 'The Dead Dance' Series: 'Corpse Princess' Tvdb id: null Tmdb id: null Imdb id: null TvRage id: null"
[2023-03-03 16:22:28.849 +01:00] [DBG] [32] Trakt.ScheduledTasks.SyncFromTraktTask: Marking episode as watched for user "ADMIN" locally: "Episode: 1x1 'The Dead Dance' Series: 'Corpse Princess' Tvdb id: null Tmdb id: null Imdb id: null TvRage id: null"
[2023-03-03 16:22:28.849 +01:00] [DBG] [32] Trakt.ScheduledTasks.SyncFromTraktTask: Adjusting episode's last played date to match a more recent remote last played date (remote: 11/28/2022 20:48:07 | local: null) for user "ADMIN" locally: "The Dead Dance"
[2023-03-03 16:22:28.850 +01:00] [DBG] [32] Trakt.ScheduledTasks.SyncFromTraktTask: Adjusting episode's play count to match a higher remote value (remote: 98 | local: 0) for user "ADMIN" locally: "Episode: 1x1 'The Dead Dance' Series: 'Corpse Princess' Tvdb id: null Tmdb id: null Imdb id: null TvRage id: null"
[2023-03-03 16:22:32.094 +01:00] [DBG] [32] Trakt.ScheduledTasks.SyncFromTraktTask: Episode is in watched history list of user "ADMIN": "Episode: 1x2 'The Game Continues' Series: 'Corpse Princess' Tvdb id: null Tmdb id: null Imdb id: null TvRage id: null"
[2023-03-03 16:22:32.157 +01:00] [DBG] [32] Trakt.ScheduledTasks.SyncFromTraktTask: Marking episode as watched for user "ADMIN" locally: "Episode: 1x2 'The Game Continues' Series: 'Corpse Princess' Tvdb id: null Tmdb id: null Imdb id: null TvRage id: null"
[2023-03-03 16:22:32.161 +01:00] [DBG] [32] Trakt.ScheduledTasks.SyncFromTraktTask: Adjusting episode's last played date to match a more recent remote last played date (remote: 11/28/2022 20:48:07 | local: null) for user "ADMIN" locally: "The Game Continues"
[2023-03-03 16:22:32.172 +01:00] [DBG] [32] Trakt.ScheduledTasks.SyncFromTraktTask: Adjusting episode's play count to match a higher remote value (remote: 98 | local: 0) for user "ADMIN" locally: "Episode: 1x2 'The Game Continues' Series: 'Corpse Princess' Tvdb id: null Tmdb id: null Imdb id: null TvRage id: null"
[2023-03-03 16:22:32.242 +01:00] [DBG] [32] Trakt.ScheduledTasks.SyncFromTraktTask: Episode is in watched history list of user "ADMIN": "Episode: 1x3 'Voice of Night' Series: 'Corpse Princess' Tvdb id: 395968 Tmdb id: null Imdb id: null TvRage id: null"
[2023-03-03 16:22:32.272 +01:00] [DBG] [32] Trakt.ScheduledTasks.SyncFromTraktTask: Marking episode as watched for user "ADMIN" locally: "Episode: 1x3 'Voice of Night' Series: 'Corpse Princess' Tvdb id: 395968 Tmdb id: null Imdb id: null TvRage id: null"
[2023-03-03 16:22:32.273 +01:00] [DBG] [32] Trakt.ScheduledTasks.SyncFromTraktTask: Adjusting episode's last played date to match a more recent remote last played date (remote: 11/28/2022 20:48:07 | local: null) for user "ADMIN" locally: "Voice of Night"
[2023-03-03 16:22:32.273 +01:00] [DBG] [32] Trakt.ScheduledTasks.SyncFromTraktTask: Adjusting episode's play count to match a higher remote value (remote: 98 | local: 0) for user "ADMIN" locally: "Episode: 1x3 'Voice of Night' Series: 'Corpse Princess' Tvdb id: 395968 Tmdb id: null Imdb id: null TvRage id: null"
[2023-03-03 16:22:32.333 +01:00] [DBG] [32] Trakt.ScheduledTasks.SyncFromTraktTask: Episode is in watched history list of user "ADMIN": "Episode: 1x4 'Sanbika' Series: 'Corpse Princess' Tvdb id: 401857 Tmdb id: null Imdb id: tt1346488 TvRage id: null"
[2023-03-03 16:22:32.357 +01:00] [DBG] [32] Trakt.ScheduledTasks.SyncFromTraktTask: Marking episode as watched for user "ADMIN" locally: "Episode: 1x4 'Sanbika' Series: 'Corpse Princess' Tvdb id: 401857 Tmdb id: null Imdb id: tt1346488 TvRage id: null"
[2023-03-03 16:22:32.357 +01:00] [DBG] [32] Trakt.ScheduledTasks.SyncFromTraktTask: Adjusting episode's last played date to match a more recent remote last played date (remote: 11/28/2022 20:48:07 | local: null) for user "ADMIN" locally: "Sanbika"
[2023-03-03 16:22:32.358 +01:00] [DBG] [32] Trakt.ScheduledTasks.SyncFromTraktTask: Adjusting episode's play count to match a higher remote value (remote: 98 | local: 0) for user "ADMIN" locally: "Episode: 1x4 'Sanbika' Series: 'Corpse Princess' Tvdb id: 401857 Tmdb id: null Imdb id: tt1346488 TvRage id: null"
[2023-03-03 16:22:32.414 +01:00] [DBG] [32] Trakt.ScheduledTasks.SyncFromTraktTask: Episode is in watched history list of user "ADMIN": "Episode: 1x5 'Haishinsô' Series: 'Corpse Princess' Tvdb id: 403679 Tmdb id: null Imdb id: tt1346183 TvRage id: null"
[2023-03-03 16:22:32.439 +01:00] [DBG] [32] Trakt.ScheduledTasks.SyncFromTraktTask: Marking episode as watched for user "ADMIN" locally: "Episode: 1x5 'Haishinsô' Series: 'Corpse Princess' Tvdb id: 403679 Tmdb id: null Imdb id: tt1346183 TvRage id: null"
[2023-03-03 16:22:32.439 +01:00] [DBG] [32] Trakt.ScheduledTasks.SyncFromTraktTask: Adjusting episode's last played date to match a more recent remote last played date (remote: 11/28/2022 20:48:07 | local: null) for user "ADMIN" locally: "Haishinsô"

EDIT: there seems to be something wrong with the playcount. Please wait for testing until this is fixed.

h3llrais3r commented 1 year ago

Ok, I think this should be it. 😉

[2023-03-03 18:39:41.132 +01:00] [DBG] [21] Trakt.ScheduledTasks.SyncFromTraktTask: Episode is in watched history list of user "ADMIN": "Episode: 1x1 'The Dead Dance' Series: 'Corpse Princess' Tvdb id: null Tmdb id: null Imdb id: null TvRage id: null"
[2023-03-03 18:39:41.132 +01:00] [DBG] [21] Trakt.ScheduledTasks.SyncFromTraktTask: Marking episode as watched for user "ADMIN" locally: "Episode: 1x1 'The Dead Dance' Series: 'Corpse Princess' Tvdb id: null Tmdb id: null Imdb id: null TvRage id: null"
[2023-03-03 18:39:41.133 +01:00] [DBG] [21] Trakt.ScheduledTasks.SyncFromTraktTask: Adjusting episode's last played date to match a more recent remote last played date (remote: 03/13/2018 20:50:44 | local: null) for user "ADMIN" locally: "The Dead Dance"
[2023-03-03 18:39:41.170 +01:00] [DBG] [21] Trakt.ScheduledTasks.SyncFromTraktTask: Adjusting episode's play count to match a higher remote value (remote: 1 | local: 0) for user "ADMIN" locally: "Episode: 1x1 'The Dead Dance' Series: 'Corpse Princess' Tvdb id: null Tmdb id: null Imdb id: null TvRage id: null"
[2023-03-03 18:39:41.247 +01:00] [DBG] [21] Trakt.ScheduledTasks.SyncFromTraktTask: Episode is in watched history list of user "ADMIN": "Episode: 1x2 'The Game Continues' Series: 'Corpse Princess' Tvdb id: null Tmdb id: null Imdb id: null TvRage id: null"
[2023-03-03 18:39:41.247 +01:00] [DBG] [21] Trakt.ScheduledTasks.SyncFromTraktTask: Marking episode as watched for user "ADMIN" locally: "Episode: 1x2 'The Game Continues' Series: 'Corpse Princess' Tvdb id: null Tmdb id: null Imdb id: null TvRage id: null"
[2023-03-03 18:39:41.247 +01:00] [DBG] [21] Trakt.ScheduledTasks.SyncFromTraktTask: Adjusting episode's last played date to match a more recent remote last played date (remote: 03/13/2018 20:50:44 | local: null) for user "ADMIN" locally: "The Game Continues"
[2023-03-03 18:39:41.302 +01:00] [DBG] [21] Trakt.ScheduledTasks.SyncFromTraktTask: Adjusting episode's play count to match a higher remote value (remote: 1 | local: 0) for user "ADMIN" locally: "Episode: 1x2 'The Game Continues' Series: 'Corpse Princess' Tvdb id: null Tmdb id: null Imdb id: null TvRage id: null"
[2023-03-03 18:39:41.367 +01:00] [DBG] [21] Trakt.ScheduledTasks.SyncFromTraktTask: Episode is in watched history list of user "ADMIN": "Episode: 1x3 'Voice of Night' Series: 'Corpse Princess' Tvdb id: 395968 Tmdb id: null Imdb id: null TvRage id: null"
[2023-03-03 18:39:41.368 +01:00] [DBG] [21] Trakt.ScheduledTasks.SyncFromTraktTask: Marking episode as watched for user "ADMIN" locally: "Episode: 1x3 'Voice of Night' Series: 'Corpse Princess' Tvdb id: 395968 Tmdb id: null Imdb id: null TvRage id: null"
[2023-03-03 18:39:41.368 +01:00] [DBG] [21] Trakt.ScheduledTasks.SyncFromTraktTask: Adjusting episode's last played date to match a more recent remote last played date (remote: 03/13/2018 20:50:44 | local: null) for user "ADMIN" locally: "Voice of Night"
[2023-03-03 18:39:41.412 +01:00] [DBG] [21] Trakt.ScheduledTasks.SyncFromTraktTask: Adjusting episode's play count to match a higher remote value (remote: 1 | local: 0) for user "ADMIN" locally: "Episode: 1x3 'Voice of Night' Series: 'Corpse Princess' Tvdb id: 395968 Tmdb id: null Imdb id: null TvRage id: null"
[2023-03-03 18:39:41.476 +01:00] [DBG] [21] Trakt.ScheduledTasks.SyncFromTraktTask: Episode is in watched history list of user "ADMIN": "Episode: 1x4 'Sanbika' Series: 'Corpse Princess' Tvdb id: 401857 Tmdb id: null Imdb id: tt1346488 TvRage id: null"
[2023-03-03 18:39:41.476 +01:00] [DBG] [21] Trakt.ScheduledTasks.SyncFromTraktTask: Marking episode as watched for user "ADMIN" locally: "Episode: 1x4 'Sanbika' Series: 'Corpse Princess' Tvdb id: 401857 Tmdb id: null Imdb id: tt1346488 TvRage id: null"
[2023-03-03 18:39:41.476 +01:00] [DBG] [21] Trakt.ScheduledTasks.SyncFromTraktTask: Adjusting episode's last played date to match a more recent remote last played date (remote: 03/13/2018 20:50:44 | local: null) for user "ADMIN" locally: "Sanbika"
[2023-03-03 18:39:41.494 +01:00] [DBG] [21] Trakt.ScheduledTasks.SyncFromTraktTask: Adjusting episode's play count to match a higher remote value (remote: 1 | local: 0) for user "ADMIN" locally: "Episode: 1x4 'Sanbika' Series: 'Corpse Princess' Tvdb id: 401857 Tmdb id: null Imdb id: tt1346488 TvRage id: null"

Play count is now correct.

SenorSmartyPants commented 1 year ago

@SenorSmartyPants Can you rerun your test case on the new version?

This isn't the fix I'm looking for. ;) Same behavior as before. 1x08, 1x14, and 1x28 marked as watched. 1x14 should not be.

Just from looking at the log file, it seems like you are iterating over the series in JF and matching them to the history. I think this is why it's giving the false positive match. If you iterate over the history from trakt, and match that to episodes in JF then one history item will only match to one episode in JF. As opposed to now, where one history item could match to mulitple episodes in JF.

[13:19:30] [DBG] [4] Trakt.ScheduledTasks.SyncFromTraktTask: Adjusting episode's play count to match a higher remote value (remote: 1 | local: 0) for user Danzo locally: Episode: 1x8 'Balance of Terror' Series: 'Star Trek' Tvdb id: 248317 Tmdb id: null Imdb id: tt0708420 TvRage id: 162321
[13:19:30] [DBG] [4] Trakt.ScheduledTasks.SyncFromTraktTask: No episode history data found for user Danzo for Episode: 1x9 'What Are Little Girls Made Of?' Series: 'Star Trek' Tvdb id: 248310 Tmdb id: null Imdb id: tt0708486 TvRage id: 162314
[13:19:30] [DBG] [4] Trakt.ScheduledTasks.SyncFromTraktTask: No episode history data found for user Danzo for Episode: 1x10 'Dagger of the Mind' Series: 'Star Trek' Tvdb id: 248312 Tmdb id: null Imdb id: tt0708426 TvRage id: 162316
[13:19:30] [DBG] [4] Trakt.ScheduledTasks.SyncFromTraktTask: No episode history data found for user Danzo for Episode: 1x11 'Miri' Series: 'Star Trek' Tvdb id: 248311 Tmdb id: null Imdb id: tt0394905 TvRage id: 162315
[13:19:30] [DBG] [4] Trakt.ScheduledTasks.SyncFromTraktTask: No episode history data found for user Danzo for Episode: 1x12 'The Conscience of the King' Series: 'Star Trek' Tvdb id: 248316 Tmdb id: null Imdb id: tt0394903 TvRage id: 162320
[13:19:30] [DBG] [4] Trakt.ScheduledTasks.SyncFromTraktTask: No episode history data found for user Danzo for Episode: 1x13 'The Galileo Seven' Series: 'Star Trek' Tvdb id: 248319 Tmdb id: null Imdb id: tt0708465 TvRage id: 162323
[13:19:30] [DBG] [4] Trakt.ScheduledTasks.SyncFromTraktTask: Episode is in watched history list of user Danzo: Episode: 1x14 'Court Martial' Series: 'Star Trek' Tvdb id: 248323 Tmdb id: null Imdb id: tt0708425 TvRage id: 162327
[13:19:30] [DBG] [4] Trakt.ScheduledTasks.SyncFromTraktTask: Marking episode as watched for user Danzo locally: Episode: 1x14 'Court Martial' Series: 'Star Trek' Tvdb id: 248323 Tmdb id: null Imdb id: tt0708425 TvRage id: 162327
[13:19:30] [DBG] [4] Trakt.ScheduledTasks.SyncFromTraktTask: Adjusting episode's play count to match a higher remote value (remote: 1 | local: 0) for user Danzo locally: Episode: 1x14 'Court Martial' Series: 'Star Trek' Tvdb id: 248323 Tmdb id: null Imdb id: tt0708425 TvRage id: 162327
[13:19:30] [DBG] [4] Trakt.ScheduledTasks.SyncFromTraktTask: No episode history data found for user Danzo for Episode: 1x15 'The Menagerie (1)' Series: 'Star Trek' Tvdb id: 248314 Tmdb id: null Imdb id: tt0394904 TvRage id: 162322
[13:19:30] [DBG] [4] Trakt.ScheduledTasks.SyncFromTraktTask: No episode history data found for user Danzo for Episode: 1x16 'The Menagerie (2)' Series: 'Star Trek' Tvdb id: 248315 Tmdb id: null Imdb id: tt0708472 TvRage id: 162319
[13:19:30] [DBG] [4] Trakt.ScheduledTasks.SyncFromTraktTask: No episode history data found for user Danzo for Episode: 1x17 'Shore Leave' Series: 'Star Trek' Tvdb id: 248318 Tmdb id: null Imdb id: tt0708446 TvRage id: 162322
[13:19:30] [DBG] [4] Trakt.ScheduledTasks.SyncFromTraktTask: No episode history data found for user Danzo for Episode: 1x18 'The Squire of Gothos' Series: 'Star Trek' Tvdb id: 248320 Tmdb id: null Imdb id: tt0708478 TvRage id: 162324
[13:19:30] [DBG] [4] Trakt.ScheduledTasks.SyncFromTraktTask: No episode history data found for user Danzo for Episode: 1x19 'Arena' Series: 'Star Trek' Tvdb id: 248321 Tmdb id: null Imdb id: tt0708418 TvRage id: 162325
[13:19:30] [DBG] [4] Trakt.ScheduledTasks.SyncFromTraktTask: No episode history data found for user Danzo for Episode: 1x20 'The Alternative Factor' Series: 'Star Trek' Tvdb id: 248330 Tmdb id: null Imdb id: tt0708451 TvRage id: 162334
[13:19:30] [DBG] [4] Trakt.ScheduledTasks.SyncFromTraktTask: No episode history data found for user Danzo for Episode: 1x21 'Tomorrow Is Yesterday' Series: 'Star Trek' Tvdb id: 248322 Tmdb id: null Imdb id: tt0708484 TvRage id: 162326
[13:19:30] [DBG] [4] Trakt.ScheduledTasks.SyncFromTraktTask: No episode history data found for user Danzo for Episode: 1x22 'The Return of the Archons' Series: 'Star Trek' Tvdb id: 248324 Tmdb id: null Imdb id: tt0708476 TvRage id: 162328
[13:19:30] [DBG] [4] Trakt.ScheduledTasks.SyncFromTraktTask: No episode history data found for user Danzo for Episode: 1x23 'A Taste of Armageddon' Series: 'Star Trek' Tvdb id: 248326 Tmdb id: null Imdb id: tt0708414 TvRage id: 162330
[13:19:30] [DBG] [4] Trakt.ScheduledTasks.SyncFromTraktTask: No episode history data found for user Danzo for Episode: 1x24 'Space Seed' Series: 'Star Trek' Tvdb id: 248325 Tmdb id: null Imdb id: tt0708447 TvRage id: 162329
[13:19:30] [DBG] [4] Trakt.ScheduledTasks.SyncFromTraktTask: No episode history data found for user Danzo for Episode: 1x25 'This Side of Paradise' Series: 'Star Trek' Tvdb id: 248327 Tmdb id: null Imdb id: tt0708483 TvRage id: 162331
[13:19:30] [DBG] [4] Trakt.ScheduledTasks.SyncFromTraktTask: No episode history data found for user Danzo for Episode: 1x26 'The Devil in the Dark' Series: 'Star Trek' Tvdb id: 248328 Tmdb id: null Imdb id: tt0708460 TvRage id: 162332
[13:19:30] [DBG] [4] Trakt.ScheduledTasks.SyncFromTraktTask: No episode history data found for user Danzo for Episode: 1x27 'Errand of Mercy' Series: 'Star Trek' Tvdb id: 248329 Tmdb id: null Imdb id: tt0708429 TvRage id: 162333
[13:19:30] [DBG] [4] Trakt.ScheduledTasks.SyncFromTraktTask: Episode is in watched history list of user Danzo: Episode: 1x28 'The City on the Edge of Forever' Series: 'Star Trek' Tvdb id: 248331 Tmdb id: null Imdb id: tt0708455 TvRage id: 162335
[13:19:30] [DBG] [4] Trakt.ScheduledTasks.SyncFromTraktTask: Marking episode as watched for user Danzo locally: Episode: 1x28 'The City on the Edge of Forever' Series: 'Star Trek' Tvdb id: 248331 Tmdb id: null Imdb id: tt0708455 TvRage id: 162335
[13:19:30] [DBG] [4] Trakt.ScheduledTasks.SyncFromTraktTask: Adjusting episode's play count to match a higher remote value (remote: 1 | local: 0) for user Danzo locally: Episode: 1x28 'The City on the Edge of Forever' Series: 'Star Trek' Tvdb id: 248331 Tmdb id: null Imdb id: tt0708455 TvRage id: 162335
[13:19:30] [DBG] [4] Trakt.ScheduledTasks.SyncFromTraktTask: No episode history data found for user Danzo for Episode: 1x29 'Operation: Annihilate!' Series: 'Star Trek' Tvdb id: 248332 Tmdb id: null Imdb id: tt0708441 TvRage id: 162336

BTW, debug lines would be easier for me to read if series name was listed before episode details.

h3llrais3r commented 1 year ago

Not sure if what you want is feasible...

So the sync will look for an item in the history with those id's first. If there is nothing in trakt for those id's, it also check as fallback for match on show/season/name. If it finds a match, it will mark it as watched.

You say that your local files are having ids... So it seems you have a local file for Episode: 1x14 'Court Martial' Series: 'Star Trek' Tvdb id: 248323 This tvdbid is actually linked to 1x14 on tvdb, so you probably have the episode with this id marked as watched in trakt, which is https://trakt.tv/shows/star-trek/seasons/1/episodes/20

If that wouldn't be the case, due to the fallback to show/season/number matching, you probably have the 1x14 episode on trakt marked as watched, which is https://trakt.tv/shows/star-trek/seasons/1/episodes/14 If finds it as marked on trakt and will mark it also locally...

As you can see in the discussion above, we cannot just skip the show/season/number matching, as it's possible to have shows without id's.

Sadly, my fix is mainly for always matching from history, not for matching with different orderings... Maybe we can try to fix the different orderings in a different PR, once this one is concluded.

SenorSmartyPants commented 1 year ago

I think I'm not explaining myself well. Your current approach is to look at an episode in JF and try to match that to an episode in the history list. I propose you start from the episode in the trakt history, and find that episode in JF. This guarantees that one history item will only ever match to at most one JF episode.

This is what should be returned from Trakt in my history that is causing issues. (didn't find it in the logs so hand made it) https://trakt.tv/shows/star-trek/seasons/1/episodes/14

{
    "id": 1982346,
    "watched_at": "2014-03-31T09:28:53.000Z",
    "action": "scrobble",
    "type": "episode",
    "episode": {
      "season": 1,
      "number": 14,
      "title": "Balance of Terror",
      "ids": {
        "tvdb": 248317,
        "imdb": tt0708420
      }
}

If you use the ids Trakt provides to search JF for the episode with the matching id, you will find my local 1x08. This Trakt history episode is now matched and will never do anything to my local 1x14.

[2023-03-03 13:19:30.409 -06:00] [DBG] [4] Trakt.ScheduledTasks.SyncFromTraktTask: Episode is in watched history list of user "Danzo": "Episode: 1x8 'Balance of Terror' Series: 'Star Trek' Tvdb id: 248317 Tmdb id: null Imdb id: tt0708420 TvRage id: 162321"
[2023-03-03 13:19:30.410 -06:00] [DBG] [4] Trakt.ScheduledTasks.SyncFromTraktTask: Marking episode as watched for user "Danzo" locally: "Episode: 1x8 'Balance of Terror' Series: 'Star Trek' Tvdb id: 248317 Tmdb id: null Imdb id: tt0708420 TvRage id: 162321"

Episode: 1x14 'Court Martial' Series: 'Star Trek' Tvdb id: 248323 This tvdbid is actually linked to 1x14 on tvdb

https://thetvdb.com/series/star-trek/episodes/248323 is 1x14 in DVD order. 1x20 Aired order on TVDB.

This episode is not marked as watched on Trakt.

I don't want you to remove the fallback to SxE style matching.

h3llrais3r commented 1 year ago

I understood you well ;) but I don't want to rewrite the complete logic of the plugin, as I'm not the owner. I'm just like you who wants that it works for my own use cases... ;) As far as I see, the plugin works by default from what it finds in jellyfin and then tries to find it on trakt... not the way around.

SenorSmartyPants commented 1 year ago

Ah ok. Understood ;P

As far as I see, the plugin works by default from what it finds in jellyfin and then tries to find it on trakt... not the way around.

And this is the source of my double matching issue.

Maybe when trying to match by SxE, Trakt and JF episodes could be checked or non-null ids and if they exist and don't match on both then don't confirm a match?

h3llrais3r commented 1 year ago

I was just about to say the same thing: I'm going to check if there are provider id's available or not. If yes, use those, if not use season/number for matching.

h3llrais3r commented 1 year ago

Please try again 😉

SenorSmartyPants commented 1 year ago

Tested before the refactoring. Works right in my test case.

One thing that might happen (not sure how often): JF could have ids and Trakt might not. Your test doesn't currently account for that.

Shadowghost commented 1 year ago

You'd need to explicitly check for the id types. It doesn't help that Trakt only guarantees the tmdb ids (and maybe IMDb) to be correct. Afaik tvdb ids aren't updated anymore.

SenorSmartyPants commented 1 year ago

I think if TVDB ids are stored on TMDB Trakt gets them.

But a possibly bigger problem is that JF doesn't store TMDB ids AFAICT

h3llrais3r commented 1 year ago

I now only match by provider id when both trakt and jellyfin have at least 1 provider id. Can you check again?

h3llrais3r commented 1 year ago

You'd need to explicitly check for the id types. It doesn't help that Trakt only guarantees the tmdb ids (and maybe IMDb) to be correct. Afaik tvdb ids aren't updated anymore.

So what you are saying is that we should check if both jellyfin and trakt have the id of the specific type (tvdb, imdb, ...) and only compare when both have it?

h3llrais3r commented 1 year ago

I hope this should be fine now. At least for me it seems to work.

h3llrais3r commented 1 year ago

@Shadowghost Did you already get any change to test this from your side?

h3llrais3r commented 1 year ago

Bump.

h3llrais3r commented 1 year ago

FYI: I've ran the plugin on my whole library and all my missing watched shows are now properly imported. So for me the changes are working fine:

Shadowghost commented 1 year ago

I'm still busy with my thesis, will look at this again once I'm done (~2 weeks).

dabl2 commented 1 year ago

Just a regular user here very interested in seeing this released, hoping it fixes the problem I'm seeing as described in #190

In my case, none of the watched movies or shows in my Trakt.tv account are marked as watched in jellyfin on import using the plugin.

I'm running Jellyfin.Server 10.8.10.0, with Trakt plug-in 23.0.0.0 in a docker on unraid

One thing I don't understand is how to see more information than I do in the below log output, for example any indexer IDs being used and/or what exactly is happening during/after 'ExecuteQueuedTasks' when (presumably) shows are supposed to be getting marked in jellyfin as watched?

I also don't understand why I don't seem to see anything in the log about how the plugin settings are enabled such as 'Skip unwatched import from trakt.tv' etc which seems like it would be helpful if not critical to know when trying to debug?

In my case I'm using the default out of the box settings.

Anyway don't mean to clutter the thread but am appreciative of this work being done to fix the problems and am looking forward to trying it, though as I understand it I wouldn't be able to help test given my docker only environment.


[2023-05-26 11:18:41.967 -04:00] [INF] [59] Emby.Server.Implementations.ScheduledTasks.TaskManager: Executing "Import watched states and playback progress from trakt.tv"
[2023-05-26 11:18:43.159 -04:00] [INF] [51] Trakt.ScheduledTasks.SyncFromTraktTask: Trakt.tv watched movies for user "dabl": 109
[2023-05-26 11:18:43.159 -04:00] [INF] [51] Trakt.ScheduledTasks.SyncFromTraktTask: Trakt.tv watched movies history for user "dabl": 129
[2023-05-26 11:18:43.159 -04:00] [INF] [51] Trakt.ScheduledTasks.SyncFromTraktTask: Trakt.tv paused movies for user "dabl": 1
[2023-05-26 11:18:43.159 -04:00] [INF] [51] Trakt.ScheduledTasks.SyncFromTraktTask: Trakt.tv watched shows for user "dabl": 75
[2023-05-26 11:18:43.159 -04:00] [INF] [51] Trakt.ScheduledTasks.SyncFromTraktTask: Trakt.tv watched episodes history for user "dabl": 937
[2023-05-26 11:18:43.159 -04:00] [INF] [51] Trakt.ScheduledTasks.SyncFromTraktTask: Trakt.tv paused episodes for user "dabl": 37
[2023-05-26 11:18:45.985 -04:00] [INF] [51] Emby.Server.Implementations.ScheduledTasks.TaskManager: "Import watched states and playback progress from trakt.tv" Completed after 0 minute(s) and 4 seconds
[2023-05-26 11:18:45.986 -04:00] [INF] [51] Emby.Server.Implementations.ScheduledTasks.TaskManager: ExecuteQueuedTasks
Shadowghost commented 1 year ago

@h3llrais3r from the limited testing I did and your discussion in this issue I think this is good to go.

h3llrais3r commented 1 year ago

@Shadowghost I ran it on my complete library and I'm also satisfied with it. It has a better import rate from trakt then before. All the ones that were not imported before are now working. 😉

h3llrais3r commented 1 year ago

One thing I don't understand is how to see more information than I do in the below log output, for example any indexer IDs being used and/or what exactly is happening during/after 'ExecuteQueuedTasks' when (presumably) shows are supposed to be getting marked in jellyfin as watched?

I also don't understand why I don't seem to see anything in the log about how the plugin settings are enabled such as 'Skip unwatched import from trakt.tv' etc which seems like it would be helpful if not critical to know when trying to debug?

@dabl2 Enable debug logging: https://jellyfin.org/docs/general/administration/troubleshooting/#debug-logging

dabl2 commented 1 year ago

One thing I don't understand is how to see more information than I do in the below log output, for example any indexer IDs being used and/or what exactly is happening during/after 'ExecuteQueuedTasks' when (presumably) shows are supposed to be getting marked in jellyfin as watched? I also don't understand why I don't seem to see anything in the log about how the plugin settings are enabled such as 'Skip unwatched import from trakt.tv' etc which seems like it would be helpful if not critical to know when trying to debug?

@dabl2 Enable debug logging: https://jellyfin.org/docs/general/administration/troubleshooting/#debug-logging

Ah thanks. RTFM