public override void ProcessCommand() { logger.Info("Processing CommandRequest_AddFileToMyList: {0}", Hash); try { vid = RepoFactory.VideoLocal.GetByHash(this.Hash); List<AnimeEpisode> animeEpisodes = new List<AnimeEpisode>(); if (vid != null) animeEpisodes = vid.GetAnimeEpisodes(); if (vid != null) { // when adding a file via the API, newWatchedStatus will return with current watched status on AniDB // if the file is already on the user's list bool isManualLink = false; List<CrossRef_File_Episode> xrefs = vid.EpisodeCrossRefs; if (xrefs.Count > 0) isManualLink = xrefs[0].CrossRefSource != (int) CrossRefSource.AniDB; // mark the video file as watched DateTime? watchedDate = null; bool newWatchedStatus = false; if (isManualLink) newWatchedStatus = JMMService.AnidbProcessor.AddFileToMyList(xrefs[0].AnimeID, xrefs[0].Episode.EpisodeNumber, ref watchedDate); else newWatchedStatus = JMMService.AnidbProcessor.AddFileToMyList(vid, ref watchedDate); // do for all AniDB users List<JMMUser> aniDBUsers = RepoFactory.JMMUser.GetAniDBUsers(); if (aniDBUsers.Count > 0) { JMMUser juser = aniDBUsers[0]; vid.ToggleWatchedStatus(newWatchedStatus, false, watchedDate, false, false, juser.JMMUserID, false, true); logger.Info("Adding file to list: {0} - {1}", vid.ToString(), watchedDate); // if the the episode is watched we may want to set the file to watched as well if (ServerSettings.Import_UseExistingFileWatchedStatus && !newWatchedStatus) { if (animeEpisodes.Count > 0) { AnimeEpisode ep = animeEpisodes[0]; AnimeEpisode_User epUser = null; foreach (JMMUser tempuser in aniDBUsers) { // only find the first user who watched this if (epUser == null) epUser = ep.GetUserRecord(tempuser.JMMUserID); } if (epUser != null) { logger.Info( "Setting file as watched, because episode was already watched: {0} - user: {1}", vid.ToString(), juser.Username); vid.ToggleWatchedStatus(true, true, epUser.WatchedDate, false, false, epUser.JMMUserID, false, true); } } } } AnimeSeries ser = animeEpisodes[0].GetAnimeSeries(); // all the eps should belong to the same anime ser.QueueUpdateStats(); //StatsCache.Instance.UpdateUsingSeries(ser.AnimeSeriesID); // lets also try adding to the users trakt collecion if (ser != null && ServerSettings.Trakt_IsEnabled && !string.IsNullOrEmpty(ServerSettings.Trakt_AuthToken)) { foreach (AnimeEpisode aep in animeEpisodes) { CommandRequest_TraktCollectionEpisode cmdSyncTrakt = new CommandRequest_TraktCollectionEpisode ( aep.AnimeEpisodeID, TraktSyncAction.Add); cmdSyncTrakt.Save(); } } // sync the series on MAL if (ser != null && !string.IsNullOrEmpty(ServerSettings.MAL_Username) && !string.IsNullOrEmpty(ServerSettings.MAL_Password)) { CommandRequest_MALUpdatedWatchedStatus cmdMAL = new CommandRequest_MALUpdatedWatchedStatus(ser.AniDB_ID); cmdMAL.Save(); } } } catch (Exception ex) { logger.Error("Error processing CommandRequest_AddFileToMyList: {0} - {1}", Hash, ex.ToString()); return; } }
public override void ProcessCommand() { logger.Info("Processing CommandRequest_AddFileToMyList: {0}", Hash); try { VideoLocalRepository repVids = new VideoLocalRepository(); AnimeEpisodeRepository repEpisodes = new AnimeEpisodeRepository(); vid = repVids.GetByHash(this.Hash); if (vid != null) { // when adding a file via the API, newWatchedStatus will return with current watched status on AniDB // if the file is already on the user's list bool isManualLink = false; List<CrossRef_File_Episode> xrefs = vid.EpisodeCrossRefs; if (xrefs.Count > 0) isManualLink = xrefs[0].CrossRefSource != (int)CrossRefSource.AniDB; // mark the video file as watched DateTime? watchedDate = null; bool newWatchedStatus = false; if (isManualLink) newWatchedStatus = JMMService.AnidbProcessor.AddFileToMyList(xrefs[0].AnimeID, xrefs[0].Episode.EpisodeNumber, ref watchedDate); else newWatchedStatus = JMMService.AnidbProcessor.AddFileToMyList(vid, ref watchedDate); // do for all AniDB users JMMUserRepository repUsers = new JMMUserRepository(); List<JMMUser> aniDBUsers = repUsers.GetAniDBUsers(); List<AnimeEpisode> animeEpisodes = vid.GetAnimeEpisodes(); if (aniDBUsers.Count > 0) { JMMUser juser = aniDBUsers[0]; vid.ToggleWatchedStatus(newWatchedStatus, false, watchedDate, false, false, juser.JMMUserID, false, true); logger.Info("Adding file to list: {0} - {1}", vid.ToString(), watchedDate); // if the the episode is watched we may want to set the file to watched as well if (ServerSettings.Import_UseExistingFileWatchedStatus && !newWatchedStatus) { if (animeEpisodes.Count > 0) { AnimeEpisode ep = animeEpisodes[0]; AnimeEpisode_User epUser = null; foreach (JMMUser tempuser in aniDBUsers) { // only find the first user who watched this if (epUser == null) epUser = ep.GetUserRecord(tempuser.JMMUserID); } if (epUser != null) { logger.Info("Setting file as watched, because episode was already watched: {0} - user: {1}", vid.ToString(), juser.Username); vid.ToggleWatchedStatus(true, true, epUser.WatchedDate, false, false, epUser.JMMUserID, false, true); } } } } AnimeSeries ser = animeEpisodes[0].GetAnimeSeries(); // all the eps should belong to the same anime ser.UpdateStats(true, true, true); StatsCache.Instance.UpdateUsingSeries(ser.AnimeSeriesID); } } catch (Exception ex) { logger.Error("Error processing CommandRequest_AddFileToMyList: {0} - {1}", Hash, ex.ToString()); return; } }