Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support rewatch feature #631

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

Conversation

beschoenen
Copy link

@beschoenen beschoenen commented Dec 29, 2023

This PR adds support for Trakt's rewatch feature. When enabled, the plugin will reset the lastplayed and plays in Kodi's database when the value is lower than the reset_at on the show provided by the Trakt API.

This is achieved by iterating through the episode and settings the last_watched_at to None when the reset_at is greater than the last_watched_at. This allows most logic of the plugin to remain unchanged.

Fixes #292

@beschoenen beschoenen marked this pull request as ready for review December 29, 2023 13:23
@@ -777,3 +777,11 @@ msgstr ""
#~ msgctxt "#32161"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do I generate the correct po files and add the missing translations?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The base translation file is en_gb so you should only be editing that

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm noticing errors in git due to there being a en_US and en_us language folder for example.

warning: the following paths have collided (e.g. case-sensitive paths
on a case-insensitive filesystem) and only one from the same
colliding group is in the working tree:

  'resources/language/resource.language.es_AR/strings.po'
  'resources/language/resource.language.es_ar/strings.po'
  'resources/language/resource.language.es_MX/strings.po'
  'resources/language/resource.language.es_mx/strings.po'
  'resources/language/resource.language.nb_NO/strings.po'
  'resources/language/resource.language.nb_no/strings.po'
  'resources/language/resource.language.pt_BR/strings.po'
  'resources/language/resource.language.pt_br/strings.po'

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's probably a windows thing

@@ -165,11 +165,13 @@ def kodiRpcToTraktMediaObject(type, data, mode='collected'):
data['ids'] = utilities.guessBestTraktId(id, type)[0]

if 'lastplayed' in data:
episode['watched_at'] = utilities.convertDateTimeToUTC(
data['lastplayed'])
episode['last_watched_at'] = utilities.to_iso8601_datetime(
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The key watched_at was inconsistent with Trakt's last_watched_at so I updated it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kodi's timestamps were in a different format from those the Trakt.py library provides so this was updated.

show_dict = show.to_dict()
# reset_at is not included when calling `.to_dict()`
# but needed for watched shows to know whether to reset the watched state
show_dict['reset_at'] = utilities.to_iso8601_datetime(show.reset_at) if hasattr(show, 'reset_at') else None
Copy link
Author

@beschoenen beschoenen Dec 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reset_at is now needed on a show, and while Show extends Media in the trakt.py library, it is not included when calling to_dict() on a show.

@@ -412,6 +422,13 @@ def compareEpisodes(shows_col1, shows_col2, matchByTitleAndYear, watched=False,
if season in season_col2:
b = season_col2[season]
diff = list(set(a).difference(set(b)))
for key in a:
# update lastplayed in KODI if they don't match trakt
if not key in b or a[key]['last_watched_at'] != b[key]['last_watched_at']:
Copy link
Author

@beschoenen beschoenen Dec 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a 100% sure is this is the correct solution. This will update any out of date timestamps not just ones to be removed.

return local.strftime(dateFormat)
else:
return toConvert
def to_datetime(value):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I replaced the existing datetime transformation methods with these 4 new ones, the iso8601 methods come from the trakt.py library.

@beschoenen
Copy link
Author

A current limitation is that if Kodi doesn't properly scrobble a play on a rewatch, the play is removed from Kodi on next sync.

@beschoenen
Copy link
Author

@razzeee Do you have any ideas on how to overcome my mentioned limitation? So we can get this PR merged.
I've been using this branch on my personally KODI for quite a while now and it's working great.
Any help/feedback is greatly appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rewatch support
2 participants