public override void Run(IProgress <ICommand> progress = null) { logger.Info("Processing CommandRequest_TraktSyncCollectionSeries"); try { ReportInit(progress); if (!ServerSettings.Instance.TraktTv.Enabled || string.IsNullOrEmpty(ServerSettings.Instance.TraktTv.AuthToken)) { ReportFinish(progress); return; } SVR_AnimeSeries series = Repo.Instance.AnimeSeries.GetByID(AnimeSeriesID); if (series == null) { ReportError(progress, $"Could not find anime series: {AnimeSeriesID}"); return; } ReportUpdate(progress, 50); TraktTVHelper.SyncCollectionToTrakt_Series(series); ReportFinish(progress); } catch (Exception ex) { ReportError(progress, $"Error processing Trakt.TraktSyncCollectionSeries: {AnimeSeriesID} - {ex}", ex); } }
public override void ProcessCommand() { logger.Info("Processing CommandRequest_TraktShowScrobble: {0}", AnimeEpisodeID); try { if (!ServerSettings.WebCache_Trakt_Send || string.IsNullOrEmpty(ServerSettings.Trakt_Username)) { return; } AnimeEpisodeRepository repEpisodes = new AnimeEpisodeRepository(); AnimeEpisode ep = repEpisodes.GetByID(AnimeEpisodeID); if (ep != null) { // before scrobbling try to ensure the episode is in the users collection by sync'ing the series //TraktTVHelper.SyncCollectionToTrakt_Series(ep.AnimeSeries); TraktTVHelper.MarkEpisodeWatched(ep); } } catch (Exception ex) { logger.Error("Error processing CommandRequest_TraktShowScrobble: {0} - {1}", AnimeEpisodeID, ex.ToString()); return; } }
public string RemoveLinkAniDBTrakt(int animeID, int aniEpType, int aniEpNumber, string traktID, int traktSeasonNumber, int traktEpNumber) { try { SVR_AnimeSeries ser = RepoFactory.AnimeSeries.GetByAnimeID(animeID); if (ser == null) { return("Could not find Series for Anime!"); } // check if there are default images used associated List <AniDB_Anime_DefaultImage> images = RepoFactory.AniDB_Anime_DefaultImage.GetByAnimeID(animeID); foreach (AniDB_Anime_DefaultImage image in images) { if (image.ImageParentType == (int)ImageEntityType.Trakt_Fanart || image.ImageParentType == (int)ImageEntityType.Trakt_Poster) { RepoFactory.AniDB_Anime_DefaultImage.Delete(image.AniDB_Anime_DefaultImageID); } } TraktTVHelper.RemoveLinkAniDBTrakt(animeID, (EpisodeType)aniEpType, aniEpNumber, traktID, traktSeasonNumber, traktEpNumber); return(string.Empty); } catch (Exception ex) { logger.Error(ex, ex.ToString()); return(ex.Message); } }
public override void ProcessCommand() { logger.Info("Processing CommandRequest_TraktSyncCollectionSeries"); try { if (!ServerSettings.Trakt_IsEnabled || string.IsNullOrEmpty(ServerSettings.Trakt_AuthToken)) { return; } AnimeSeriesRepository repSeries = new AnimeSeriesRepository(); AnimeSeries series = repSeries.GetByID(AnimeSeriesID); if (series == null) { logger.Error("Could not find anime series: {0}", AnimeSeriesID); return; } TraktTVHelper.SyncCollectionToTrakt_Series(series); } catch (Exception ex) { logger.Error("Error processing CommandRequest_TraktSyncCollectionSeries: {0}", ex.ToString()); return; } }
public List <int> GetSeasonNumbersForTrakt(string traktID) { List <int> seasonNumbers = new List <int>(); try { // refresh show info including season numbers from trakt TraktV2ShowExtended tvshow = TraktTVHelper.GetShowInfoV2(traktID); Trakt_Show show = RepoFactory.Trakt_Show.GetByTraktSlug(traktID); if (show == null) { return(seasonNumbers); } foreach (Trakt_Season season in show.GetSeasons()) { seasonNumbers.Add(season.Season); } return(seasonNumbers); } catch (Exception ex) { logger.Error(ex, ex.ToString()); return(seasonNumbers); } }
public override void Run(IProgress <ICommand> progress = null) { logger.Info("Processing CommandRequest_TraktHistoryEpisode: {0}-{1}", AnimeEpisodeID, Action); try { ReportInit(progress); if (!ServerSettings.Instance.TraktTv.Enabled || string.IsNullOrEmpty(ServerSettings.Instance.TraktTv.AuthToken)) { ReportFinish(progress); return; } SVR_AnimeEpisode ep = Repo.Instance.AnimeEpisode.GetByID(AnimeEpisodeID); ReportUpdate(progress, 50); if (ep != null) { TraktSyncType syncType = TraktSyncType.HistoryAdd; if (ActionEnum == TraktSyncAction.Remove) { syncType = TraktSyncType.HistoryRemove; } TraktTVHelper.SyncEpisodeToTrakt(ep, syncType); } ReportFinish(progress); } catch (Exception ex) { ReportError(progress, $"Error processing CommandRequest_TraktHistoryEpisode: {AnimeEpisodeID} - {Action} - {ex}", ex); } }
public override void ProcessCommand() { logger.Info("Processing CommandRequest_TraktHistoryEpisode: {0}-{1}", AnimeEpisodeID, Action); try { if (!ServerSettings.Trakt_IsEnabled || string.IsNullOrEmpty(ServerSettings.Trakt_AuthToken)) { return; } AnimeEpisodeRepository repEpisodes = new AnimeEpisodeRepository(); AnimeEpisode ep = repEpisodes.GetByID(AnimeEpisodeID); if (ep != null) { TraktSyncType syncType = TraktSyncType.HistoryAdd; if (ActionEnum == TraktSyncAction.Remove) { syncType = TraktSyncType.HistoryRemove; } TraktTVHelper.SyncEpisodeToTrakt(ep, syncType); } } catch (Exception ex) { logger.Error("Error processing CommandRequest_TraktHistoryEpisode: {0} - {1}", AnimeEpisodeID, ex.ToString()); return; } }
public override void ProcessCommand() { logger.Info("Processing CommandRequest_TraktSyncCollectionSeries"); try { if (!ServerSettings.Instance.TraktTv.Enabled || string.IsNullOrEmpty(ServerSettings.Instance.TraktTv.AuthToken)) { return; } SVR_AnimeSeries series = RepoFactory.AnimeSeries.GetByID(AnimeSeriesID); if (series == null) { logger.Error("Could not find anime series: {0}", AnimeSeriesID); return; } TraktTVHelper.SyncCollectionToTrakt_Series(series); } catch (Exception ex) { logger.Error("Error processing CommandRequest_TraktSyncCollectionSeries: {0}", ex); } }
public override void ProcessCommand() { logger.Info("Processing CommandRequest_TraktHistoryEpisode: {0}-{1}", AnimeEpisodeID, Action); try { if (!ServerSettings.Instance.TraktTv.Enabled || string.IsNullOrEmpty(ServerSettings.Instance.TraktTv.AuthToken)) { return; } SVR_AnimeEpisode ep = Repo.Instance.AnimeEpisode.GetByID(AnimeEpisodeID); if (ep != null) { TraktSyncType syncType = TraktSyncType.HistoryAdd; if (ActionEnum == TraktSyncAction.Remove) { syncType = TraktSyncType.HistoryRemove; } TraktTVHelper.SyncEpisodeToTrakt(ep, syncType); } } catch (Exception ex) { logger.Error("Error processing CommandRequest_TraktHistoryEpisode: {0} - {1}", AnimeEpisodeID, ex); } }
public override void ProcessCommand() { logger.Info("Processing CommandRequest_TraktCollectionEpisode: {0}-{1}", AnimeEpisodeID, Action); try { logger.Info("CommandRequest_TraktCollectionEpisode - DEBUG01"); if (!ServerSettings.Trakt_IsEnabled || string.IsNullOrEmpty(ServerSettings.Trakt_AuthToken)) { return; } logger.Info("CommandRequest_TraktCollectionEpisode - DEBUG02"); SVR_AnimeEpisode ep = RepoFactory.AnimeEpisode.GetByID(AnimeEpisodeID); if (ep != null) { logger.Info("CommandRequest_TraktCollectionEpisode - DEBUG03"); TraktSyncType syncType = TraktSyncType.CollectionAdd; if (ActionEnum == TraktSyncAction.Remove) { syncType = TraktSyncType.CollectionRemove; } TraktTVHelper.SyncEpisodeToTrakt(ep, syncType); } } catch (Exception ex) { logger.Error("Error processing CommandRequest_TraktCollectionEpisode: {0} - {1} - {2}", AnimeEpisodeID, Action, ex); } }
private void BtnUpdateTraktInfo_Click(object sender, RoutedEventArgs e) { Cursor = Cursors.Wait; TraktTVHelper.UpdateAllInfo(); Cursor = Cursors.Arrow; MessageBox.Show(Commons.Properties.Resources.Command_UpdateTrakt, Commons.Properties.Resources.Success, MessageBoxButton.OK, MessageBoxImage.Information); }
public ActionResult UpdateTraktInfo() { if (!ServerSettings.Instance.TraktTv.Enabled || string.IsNullOrEmpty(ServerSettings.Instance.TraktTv.AuthToken)) { return(BadRequest()); } TraktTVHelper.UpdateAllInfo(); return(Ok()); }
public bool CheckTraktLinkValidity(string slug, bool removeDBEntries) { try { return(TraktTVHelper.CheckTraktValidity(slug, removeDBEntries)); } catch (Exception ex) { logger.Error(ex, ex.ToString()); } return(false); }
public string UpdateTraktData(string traktID) { try { TraktTVHelper.UpdateAllInfo(traktID); } catch (Exception ex) { logger.Error(ex, ex.ToString()); } return(string.Empty); }
public List <CL_Trakt_CommentUser> GetTraktCommentsForAnime(int animeID) { List <CL_Trakt_CommentUser> comments = new List <CL_Trakt_CommentUser>(); try { List <TraktV2Comment> commentsTemp = TraktTVHelper.GetShowCommentsV2(animeID); if (commentsTemp == null || commentsTemp.Count == 0) { return(comments); } foreach (TraktV2Comment sht in commentsTemp) { CL_Trakt_CommentUser comment = new CL_Trakt_CommentUser(); Trakt_Friend traktFriend = RepoFactory.Trakt_Friend.GetByUsername(sht.user.username); // user details comment.User = new CL_Trakt_User(); if (traktFriend == null) { comment.User.Trakt_FriendID = 0; } else { comment.User.Trakt_FriendID = traktFriend.Trakt_FriendID; } comment.User.Username = sht.user.username; comment.User.Full_name = sht.user.name; // comment details comment.Comment = new CL_Trakt_Comment { CommentType = (int)TraktActivityType.Show, // episode or show Text = sht.comment, Spoiler = sht.spoiler, Inserted = sht.CreatedAtDate, // urls Comment_Url = string.Format(TraktURIs.WebsiteComment, sht.id) }; comments.Add(comment); } } catch (Exception ex) { logger.Error(ex, ex.ToString()); } return(comments); }
public string LinkAniDBTraktEpisode(int aniDBID, int traktEpId) { try { TraktTVHelper.LinkAniDBTraktEpisode(aniDBID, traktEpId); return(string.Empty); } catch (Exception ex) { logger.Error(ex, ex.ToString()); return(ex.Message); } }
private void ScrobbleToTrakt(SVR_VideoLocal file, SVR_AnimeEpisode episode, long position, ScrobblePlayingStatus status) { if (User.IsTraktUser == 0) { return; } float percentage = 100 * (position / file.Duration); ScrobblePlayingType scrobbleType = episode.GetAnimeSeries()?.GetAnime()?.AnimeType == (int)AnimeType.Movie ? ScrobblePlayingType.movie : ScrobblePlayingType.episode; TraktTVHelper.Scrobble(scrobbleType, episode.AnimeEpisodeID.ToString(), status, percentage); }
public override void ProcessCommand() { logger.Info("Processing CommandRequest_TraktUpdateInfoAndImages: {0}", TraktID); try { TraktTVHelper.UpdateAllInfo(TraktID); } catch (Exception ex) { logger.Error("Error processing CommandRequest_TraktUpdateInfoAndImages: {0} - {1}", TraktID, ex); } }
public override void Run(IProgress <ICommand> progress = null) { logger.Info("Processing CommandRequest_TraktUpdateInfo: {0}", TraktID); try { ReportInit(progress); TraktTVHelper.UpdateAllInfo(TraktID); ReportFinish(progress); } catch (Exception ex) { ReportError(progress, $"Error processing CommandRequest_TraktUpdateInfo: {TraktID} - {ex}", ex); } }
public int TraktScrobble(int animeId, int type, int progress, int status) { try { ScrobblePlayingStatus statusTraktV2 = ScrobblePlayingStatus.Start; switch (status) { case (int)ScrobblePlayingStatus.Start: statusTraktV2 = ScrobblePlayingStatus.Start; break; case (int)ScrobblePlayingStatus.Pause: statusTraktV2 = ScrobblePlayingStatus.Pause; break; case (int)ScrobblePlayingStatus.Stop: statusTraktV2 = ScrobblePlayingStatus.Stop; break; } bool isValidProgress = float.TryParse(progress.ToString(), out float progressTrakt); if (isValidProgress) { switch (type) { // Movie case (int)ScrobblePlayingType.movie: return(TraktTVHelper.Scrobble( ScrobblePlayingType.movie, animeId.ToString(), statusTraktV2, progressTrakt)); // TV episode case (int)ScrobblePlayingType.episode: return(TraktTVHelper.Scrobble( ScrobblePlayingType.episode, animeId.ToString(), statusTraktV2, progressTrakt)); } } return(500); } catch (Exception ex) { logger.Error(ex, ex.ToString()); return(500); } }
private bool ProcessSearchResults(ISession session, List <TraktTVShow> results, string searchCriteria) { if (results.Count == 1) { // since we are using this result, lets download the info logger.Trace("Found 1 trakt results for search on {0} --- Linked to {1} ({2})", searchCriteria, results[0].title, results[0].TraktID); TraktTVShow showInfo = TraktTVHelper.GetShowInfo(results[0].TraktID); if (showInfo != null) { TraktTVHelper.LinkAniDBTrakt(session, AnimeID, showInfo.TraktID, 1, false); return(true); } } return(false); }
public override void ProcessCommand() { logger.Info("Processing CommandRequest_TraktSyncCollection"); try { if (!ServerSettings.Trakt_IsEnabled || string.IsNullOrEmpty(ServerSettings.Trakt_AuthToken)) { return; } ScheduledUpdate sched = RepoFactory.ScheduledUpdate.GetByUpdateType((int)ScheduledUpdateType.TraktSync); if (sched == null) { sched = new ScheduledUpdate { UpdateType = (int)ScheduledUpdateType.TraktSync, UpdateDetails = "" }; } else { int freqHours = Utils.GetScheduledHours(ServerSettings.Trakt_SyncFrequency); // if we have run this in the last xxx hours then exit TimeSpan tsLastRun = DateTime.Now - sched.LastUpdate; if (tsLastRun.TotalHours < freqHours) { if (!ForceRefresh) { return; } } } sched.LastUpdate = DateTime.Now; RepoFactory.ScheduledUpdate.Save(sched); TraktTVHelper.SyncCollectionToTrakt(); } catch (Exception ex) { logger.Error("Error processing CommandRequest_TraktSyncCollection: {0}", ex.ToString()); return; } }
public CL_TraktDeviceCode GetTraktDeviceCode() { try { var response = TraktTVHelper.GetTraktDeviceCode(); return(new CL_TraktDeviceCode { VerificationUrl = response.VerificationUrl, UserCode = response.UserCode }); } catch (Exception ex) { logger.Error(ex, "Error in GetTraktDeviceCode: " + ex.ToString()); return(null); } }
public override void Run(IProgress <ICommand> progress = null) { logger.Info("Processing CommandRequest_LinkAniDBTrakt: {0}", AnimeID); try { ReportInit(progress); TraktTVHelper.LinkAniDBTrakt(AnimeID, TraktID, AdditiveLink); ReportUpdate(progress, 50); SVR_AniDB_Anime.UpdateStatsByAnimeID(AnimeID); ReportFinish(progress); } catch (Exception ex) { ReportError(progress, $"Error processing CommandRequest_LinkAniDBTrakt: {AnimeID} - {TraktID} - {ex}", ex); } }
public override void ProcessCommand() { logger.Info("Processing CommandRequest_TraktUpdateAllSeries"); try { ScheduledUpdate sched = RepoFactory.ScheduledUpdate.GetByUpdateType((int)ScheduledUpdateType.TraktUpdate); if (sched == null) { sched = new ScheduledUpdate { UpdateType = (int)ScheduledUpdateType.TraktUpdate, UpdateDetails = string.Empty }; } else { int freqHours = Utils.GetScheduledHours(ServerSettings.Trakt_UpdateFrequency); // if we have run this in the last xxx hours then exit TimeSpan tsLastRun = DateTime.Now - sched.LastUpdate; if (tsLastRun.TotalHours < freqHours) { if (!ForceRefresh) { return; } } } sched.LastUpdate = DateTime.Now; RepoFactory.ScheduledUpdate.Save(sched); // update all info TraktTVHelper.UpdateAllInfo(); // scan for new matches TraktTVHelper.ScanForMatches(); } catch (Exception ex) { logger.Error("Error processing CommandRequest_TraktUpdateAllSeries: {0}", ex.ToString()); return; } }
private static void TraktScrobble(PlexEvent evt, ScrobblePlayingStatus type) { PlexEvent.PlexMetadata metadata = evt.Metadata; (SVR_AnimeEpisode episode, SVR_AnimeSeries anime) = GetEpisode(metadata); if (episode == null) { return; } var vl = Repo.Instance.VideoLocal.GetByAniDBEpisodeID(episode.AniDB_EpisodeID).FirstOrDefault(); float per = 100 * (metadata.ViewOffset / (float)vl.Duration); //this will be nice if plex would ever give me the duration, so I don't have to guess it. ScrobblePlayingType scrobbleType = episode.PlexContract.IsMovie ? ScrobblePlayingType.movie : ScrobblePlayingType.episode; TraktTVHelper.Scrobble(scrobbleType, episode.AnimeEpisodeID.ToString(), type, per); }
public override void Run(IProgress <ICommand> progress = null) { logger.Info("Processing CommandRequest_TraktSyncCollection"); try { ReportInit(progress); if (!ServerSettings.Instance.TraktTv.Enabled || string.IsNullOrEmpty(ServerSettings.Instance.TraktTv.AuthToken)) { ReportFinish(progress); return; } using (var upd = Repo.Instance.ScheduledUpdate.BeginAddOrUpdate( () => Repo.Instance.ScheduledUpdate.GetByUpdateType((int)ScheduledUpdateType.TraktSync), () => new ScheduledUpdate { UpdateType = (int)ScheduledUpdateType.TraktSync, UpdateDetails = string.Empty } )) { if (upd.IsUpdate) { int freqHours = Utils.GetScheduledHours(ServerSettings.Instance.TraktTv.SyncFrequency); // if we have run this in the last xxx hours then exit TimeSpan tsLastRun = DateTime.Now - upd.Entity.LastUpdate; if (tsLastRun.TotalHours < freqHours && !ForceRefresh) { ReportFinish(progress); return; } } upd.Entity.LastUpdate = DateTime.Now; upd.Commit(); } ReportUpdate(progress, 50); TraktTVHelper.SyncCollectionToTrakt(); ReportFinish(progress); } catch (Exception ex) { ReportError(progress, $"Error processing CommandRequest_TraktSyncCollection: {ex}", ex); } }
private bool ProcessSearchResults(ISession session, List <TraktV2SearchShowResult> results, string searchCriteria) { if (results.Count == 1) { if (results[0].show != null) { // since we are using this result, lets download the info logger.Trace("Found 1 trakt results for search on {0} --- Linked to {1} ({2})", searchCriteria, results[0].show.Title, results[0].show.ids.slug); TraktV2ShowExtended showInfo = TraktTVHelper.GetShowInfoV2(results[0].show.ids.slug); if (showInfo != null) { TraktTVHelper.LinkAniDBTrakt(session, AnimeID, AniDBAPI.enEpisodeType.Episode, 1, results[0].show.ids.slug, 1, 1, true); return(true); } } } return(false); }
public string LinkAniDBTrakt(int animeID, int aniEpType, int aniEpNumber, string traktID, int seasonNumber, int traktEpNumber, int?crossRef_AniDB_TraktV2ID) { try { if (crossRef_AniDB_TraktV2ID.HasValue) { CrossRef_AniDB_TraktV2 xrefTemp = RepoFactory.CrossRef_AniDB_TraktV2.GetByID(crossRef_AniDB_TraktV2ID.Value); // delete the existing one if we are updating TraktTVHelper.RemoveLinkAniDBTrakt(xrefTemp.AnimeID, (EpisodeType)xrefTemp.AniDBStartEpisodeType, xrefTemp.AniDBStartEpisodeNumber, xrefTemp.TraktID, xrefTemp.TraktSeasonNumber, xrefTemp.TraktStartEpisodeNumber); } CrossRef_AniDB_TraktV2 xref = RepoFactory.CrossRef_AniDB_TraktV2.GetByTraktID(traktID, seasonNumber, traktEpNumber, animeID, aniEpType, aniEpNumber); if (xref != null) { string msg = string.Format("You have already linked Anime ID {0} to this Trakt show/season/ep", xref.AnimeID); SVR_AniDB_Anime anime = RepoFactory.AniDB_Anime.GetByAnimeID(xref.AnimeID); if (anime != null) { msg = string.Format("You have already linked Anime {0} ({1}) to this Trakt show/season/ep", anime.MainTitle, xref.AnimeID); } return(msg); } return(TraktTVHelper.LinkAniDBTrakt(animeID, (EpisodeType)aniEpType, aniEpNumber, traktID, seasonNumber, traktEpNumber, false)); } catch (Exception ex) { logger.Error(ex, ex.ToString()); return(ex.Message); } }
public override void Run(IProgress <ICommand> progress = null) { logger.Info("Processing CommandRequest_TraktUpdateAllSeries"); try { ReportInit(progress); using (var txn = Repo.Instance.ScheduledUpdate.BeginAddOrUpdate( () => Repo.Instance.ScheduledUpdate.GetByUpdateType((int)ScheduledUpdateType.TraktUpdate), () => new ScheduledUpdate { UpdateType = (int)ScheduledUpdateType.TraktUpdate, UpdateDetails = string.Empty } )) { if (!txn.IsUpdate) { int freqHours = Utils.GetScheduledHours(ServerSettings.Instance.TraktTv.UpdateFrequency); // if we have run this in the last xxx hours then exit TimeSpan tsLastRun = DateTime.Now - txn.Entity.LastUpdate; if (tsLastRun.TotalHours < freqHours && !ForceRefresh) { ReportFinish(progress); return; } } txn.Entity.LastUpdate = DateTime.Now; txn.Commit(); } ReportUpdate(progress, 30); // update all info TraktTVHelper.UpdateAllInfo(); ReportUpdate(progress, 60); // scan for new matches TraktTVHelper.ScanForMatches(); ReportFinish(progress); } catch (Exception ex) { ReportError(progress, $"Error processing CommandRequest_TraktUpdateAllSeries: {ex}", ex); } }