-
Notifications
You must be signed in to change notification settings - Fork 148
Support rewatch feature #631
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
Open
beschoenen
wants to merge
9
commits into
trakt:main
Choose a base branch
from
beschoenen:feature/rewatch
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
309f444
Initial version of rewatch support
beschoenen be33a6a
Fixes related to timestamps
beschoenen c058028
Cleanup
beschoenen 50de3cb
Restrict new logic to logic for kodi
beschoenen e35e7fb
Merge remote-tracking branch 'trakt/main' into feature/rewatch
beschoenen 1269a1e
Formatting
beschoenen b96afcd
Merge remote-tracking branch 'trakt/main' into feature/rewatch
beschoenen 695a3e2
Move translation to en_GB
beschoenen dd8d70b
Revert changes to watch_at timestamp
beschoenen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ | |
| import dateutil.parser | ||
| from datetime import datetime | ||
| from dateutil.tz import tzutc, tzlocal | ||
| import arrow | ||
|
|
||
| # make strptime call prior to doing anything, to try and prevent threading | ||
| # errors | ||
|
|
@@ -213,42 +214,49 @@ def findEpisodeMatchInList(id, seasonNumber, episodeNumber, list, idType): | |
| return {} | ||
|
|
||
|
|
||
| def convertDateTimeToUTC(toConvert): | ||
| if toConvert: | ||
| dateFormat = "%Y-%m-%d %H:%M:%S" | ||
| try: | ||
| naive = datetime.strptime(toConvert, dateFormat) | ||
| except TypeError: | ||
| naive = datetime(*(time.strptime(toConvert, dateFormat)[0:6])) | ||
|
|
||
| try: | ||
| local = naive.replace(tzinfo=tzlocal()) | ||
| utc = local.astimezone(tzutc()) | ||
| except ValueError: | ||
| logger.debug( | ||
| "convertDateTimeToUTC() ValueError: movie/show was collected/watched outside of the unix timespan. Fallback to datetime utcnow" | ||
| ) | ||
| utc = datetime.utcnow() | ||
| return str(utc) | ||
| else: | ||
| return toConvert | ||
|
|
||
|
|
||
| def convertUtcToDateTime(toConvert): | ||
| if toConvert: | ||
| dateFormat = "%Y-%m-%d %H:%M:%S" | ||
| try: | ||
| naive = dateutil.parser.parse(toConvert) | ||
| utc = naive.replace(tzinfo=tzutc()) | ||
| local = utc.astimezone(tzlocal()) | ||
| except ValueError: | ||
| logger.debug( | ||
| "convertUtcToDateTime() ValueError: movie/show was collected/watched outside of the unix timespan. Fallback to datetime now" | ||
| ) | ||
| local = datetime.now() | ||
| return local.strftime(dateFormat) | ||
| else: | ||
| return toConvert | ||
| def to_datetime(value): | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| if not value: | ||
| return None | ||
|
|
||
| return value.strftime('%Y-%m-%d %H:%M:%S') | ||
|
|
||
|
|
||
| def from_datetime(value): | ||
| if not value: | ||
| return None | ||
|
|
||
| if arrow is None: | ||
| raise Exception('"arrow" module is not available') | ||
|
|
||
| # Parse datetime | ||
| dt = arrow.get(value, 'YYYY-MM-DD HH:mm:ss') | ||
|
|
||
| # Return datetime object | ||
| return dt.datetime | ||
|
|
||
|
|
||
| def to_iso8601_datetime(value): | ||
| if not value: | ||
| return None | ||
|
|
||
| return value.strftime('%Y-%m-%dT%H:%M:%S') + '.000-00:00' | ||
|
|
||
|
|
||
| def from_iso8601_datetime(value): | ||
| if not value: | ||
| return None | ||
|
|
||
| if arrow is None: | ||
| raise Exception('"arrow" module is not available') | ||
|
|
||
| # Parse ISO8601 datetime | ||
| dt = arrow.get(value, 'YYYY-MM-DDTHH:mm:ss.SZZ') | ||
|
|
||
| # Convert to UTC | ||
| dt = dt.to('UTC') | ||
|
|
||
| # Return datetime object | ||
| return dt.datetime | ||
|
|
||
|
|
||
| def createError(ex): | ||
|
|
@@ -484,6 +492,14 @@ def compareEpisodes( | |
| if season in season_col2: | ||
| b = season_col2[season] | ||
| diff = list(set(a).difference(set(b))) | ||
| # only for removing plays from kodi | ||
| if watched and restrict: | ||
| for key in a: | ||
| # update lastplayed in KODI if they don't match trakt | ||
| if not key in b or a[key]["plays"] != b[key]["plays"]: | ||
| diff.append(key) | ||
| # make unique | ||
| diff = list(set(diff)) | ||
| if playback: | ||
| t = list(set(a).intersection(set(b))) | ||
| if len(t) > 0: | ||
|
|
@@ -700,3 +716,17 @@ def _fuzzyMatch(string1, string2, match_percent=55.0): | |
| return ( | ||
| difflib.SequenceMatcher(None, string1, string2).ratio() * 100 | ||
| ) >= match_percent | ||
|
|
||
|
|
||
| def updateTraktLastWatchedBasedOnResetAt(trakt_shows, update_specials=False): | ||
| for show in trakt_shows["shows"]: | ||
| if show["reset_at"]: | ||
| reset_at = from_iso8601_datetime(show["reset_at"]) | ||
| for season in show["seasons"]: | ||
| if not update_specials and season["number"] == 0: | ||
| continue | ||
| for episode in season["episodes"]: | ||
| last_watched = from_iso8601_datetime(episode["last_watched_at"]) | ||
| if last_watched and last_watched < reset_at: | ||
| episode["last_watched_at"] = None | ||
| episode["plays"] = 0 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.