Exemple #1
0
 public static PlexHelper GetForUser(JMMUser user)
 {
     if (Cache.TryGetValue(user.JMMUserID, out PlexHelper helper))
     {
         return(helper);
     }
     Cache.Add(user.JMMUserID, helper = new PlexHelper(user));
     return(helper);
 }
        public override void ProcessCommand()
        {
            foreach (int section in ServerSettings.Plex_Libraries)
            {
                var allSeries = PlexHelper.GetForUser(_jmmuser).GetPlexSeries(section);
                foreach (PlexSeries series in allSeries)
                {
                    foreach (PlexEpisode episode in series.Episodes)
                    {
                        var animeEpisode = episode.AnimeEpisode;
                        var userRecord   = animeEpisode.GetUserRecord(_jmmuser.JMMUserID);
                        var isWatched    = episode.WatchCount > 0;
                        var lastWatched  = userRecord.WatchedDate;
                        if (userRecord.WatchedCount == 0 && isWatched)
                        {
                            lastWatched = FromUnixTime(episode.LastWatched);
                        }
                        SVR_VideoLocal video = animeEpisode?.GetVideoLocals()?.FirstOrDefault();
                        if (video == null)
                        {
                            continue;
                        }
                        var alreadyWatched = animeEpisode.GetVideoLocals()
                                             .Where(x => x.GetAniDBFile() != null)
                                             .Any(x => x.GetAniDBFile().IsWatched > 0);

                        if (alreadyWatched && !isWatched)
                        {
                            episode.Scrobble();
                        }
                        if (isWatched && !alreadyWatched)
                        {
                            video.ToggleWatchedStatus(true, true, lastWatched, true,
                                                      _jmmuser.JMMUserID, true, true);
                        }
                    }
                }
            }
        }