Merge pull request #97 from dulli/rewatch

This commit is contained in:
Cody Robibero 2021-12-23 20:30:20 +00:00 committed by GitHub
commit d46aa80b50
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 0 deletions

View File

@ -10,6 +10,8 @@ namespace Trakt.Api.DataContracts.Users.Watched
public string last_watched_at { get; set; }
public string reset_at { get; set; }
public TraktShow show { get; set; }
public List<Season> seasons { get; set; }

View File

@ -227,6 +227,13 @@ namespace Trakt.ScheduledTasks
? 0
: (episode.ParentIndexNumber ?? 1)));
// keep track of the shows rewatch cycles
DateTime? tLastReset = null;
if (DateTime.TryParse(matchedShow.reset_at, out var resetValue))
{
tLastReset = resetValue;
}
// if it's not a match then it means trakt doesn't know about the season, leave the watched state alone and move on
if (matchedSeason != null)
{
@ -237,6 +244,16 @@ namespace Trakt.ScheduledTasks
var matchedEpisode =
matchedSeason.episodes.FirstOrDefault(x => x.number == (episode.IndexNumber ?? -1));
// prepend a check if the matched episode is on a rewatch cycle and
// discard it if the last play date was before the reset date
if (matchedEpisode != null && tLastReset != null)
{
if (DateTime.TryParse(matchedEpisode.last_watched_at, out var value) && value < tLastReset)
{
matchedEpisode = null;
}
}
if (matchedEpisode != null)
{
_logger.LogDebug("Episode is in Watched list " + GetVerboseEpisodeData(episode));