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); } }
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 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 EpisodeSyncDetails(TraktSyncType syncType, string slug, int season, int epNumber, DateTime epDate) { SyncType = syncType; Slug = slug; Season = season; EpNumber = epNumber; EpDate = epDate; }
private static DateTime GetEpisodeDateForSync(AnimeEpisode ep, TraktSyncType syncType) { DateTime epDate = DateTime.Now; if (syncType == TraktSyncType.CollectionAdd || syncType == TraktSyncType.CollectionRemove) { epDate = DateTime.Now; // not relevant for a remove if (syncType == TraktSyncType.CollectionAdd) { // get the the first file that was added to this episode DateTime? thisDate = null; foreach (VideoLocal vid in ep.GetVideoLocals()) { if (!thisDate.HasValue) thisDate = vid.DateTimeCreated; if (vid.DateTimeCreated < thisDate) thisDate = vid.DateTimeCreated; } if (thisDate.HasValue) epDate = thisDate.Value; } } else { epDate = DateTime.Now; // not relevant for a remove if (syncType == TraktSyncType.HistoryAdd) { // get the latest user record and find the latest date this episode was watched DateTime? thisDate = null; JMMUserRepository repUsers = new JMMUserRepository(); List<JMMUser> traktUsers = repUsers.GetTraktUsers(); if (traktUsers.Count > 0) { AnimeEpisode_User userRecord = null; foreach (JMMUser juser in traktUsers) { userRecord = ep.GetUserRecord(juser.JMMUserID); if (userRecord != null) { if (!thisDate.HasValue && userRecord.WatchedDate.HasValue) thisDate = userRecord.WatchedDate; if (userRecord.WatchedDate.HasValue && thisDate.HasValue && userRecord.WatchedDate > thisDate) thisDate = userRecord.WatchedDate; } } if (thisDate.HasValue) epDate = thisDate.Value; } } } return epDate; }
/*public static void SyncEpisodeToTrakt(TraktSyncType syncType, int traktEpisodeId, DateTime epDate, bool secondaryAction = true) { try { if (!ServerSettings.Trakt_IsEnabled || string.IsNullOrEmpty(ServerSettings.Trakt_AuthToken)) return; TraktV2SyncCollectionEpisodes sync = new TraktV2SyncCollectionEpisodes(); sync.episodes = new List<TraktV2EpisodePost>(); TraktV2EpisodePost epPost = new TraktV2EpisodePost(); epPost.ids = new TraktV2EpisodeIds(); epPost.ids.trakt = traktEpisodeId.ToString(); sync.episodes.Add(epPost); string json = JSONHelper.Serialize<TraktV2SyncCollectionEpisodes>(sync); Dictionary<string, string> headers = new Dictionary<string, string>(); string url = TraktURIs.SyncCollectionAdd; switch (syncType) { case TraktSyncType.CollectionAdd: url = TraktURIs.SyncCollectionAdd; break; case TraktSyncType.CollectionRemove: url = TraktURIs.SyncCollectionRemove; break; case TraktSyncType.HistoryAdd: url = TraktURIs.SyncHistoryAdd; break; case TraktSyncType.HistoryRemove: url = TraktURIs.SyncHistoryRemove; break; } string retData = string.Empty; int response = SendData(url, json, "POST", BuildRequestHeaders(), ref retData); if (response == TraktStatusCodes.Success || response == TraktStatusCodes.Success_Post || response == TraktStatusCodes.Success_Delete) { // if this was marking an episode as watched, and is successful, let's also add this to the user's collection // this is because you can watch something without adding it to your collection, but in JMM it is always part of your collection if (syncType == TraktSyncType.HistoryAdd && secondaryAction) response = SendData(TraktURIs.SyncCollectionAdd, json, "POST", BuildRequestHeaders(), ref retData); // also if we have removed from our collection, set to un-watched if (syncType == TraktSyncType.CollectionRemove && secondaryAction) response = SendData(TraktURIs.SyncHistoryRemove, json, "POST", BuildRequestHeaders(), ref retData); } } catch (Exception ex) { logger.ErrorException("Error in TraktTVHelper.SyncEpisodeToTrakt: " + ex.ToString(), ex); } }*/ public static void SyncEpisodeToTrakt(TraktSyncType syncType, string slug, int season, int epNumber, DateTime epDate, bool secondaryAction = true) { try { if (!ServerSettings.Trakt_IsEnabled || string.IsNullOrEmpty(ServerSettings.Trakt_AuthToken)) return; string json = string.Empty; if (syncType == TraktSyncType.CollectionAdd || syncType == TraktSyncType.CollectionRemove) { TraktV2SyncCollectionEpisodesByNumber sync = new TraktV2SyncCollectionEpisodesByNumber(slug, season, epNumber, epDate); json = JSONHelper.Serialize<TraktV2SyncCollectionEpisodesByNumber>(sync); } else { TraktV2SyncWatchedEpisodesByNumber sync = new TraktV2SyncWatchedEpisodesByNumber(slug, season, epNumber, epDate); json = JSONHelper.Serialize<TraktV2SyncWatchedEpisodesByNumber>(sync); } string url = TraktURIs.SyncCollectionAdd; switch (syncType) { case TraktSyncType.CollectionAdd: url = TraktURIs.SyncCollectionAdd; break; case TraktSyncType.CollectionRemove: url = TraktURIs.SyncCollectionRemove; break; case TraktSyncType.HistoryAdd: url = TraktURIs.SyncHistoryAdd; break; case TraktSyncType.HistoryRemove: url = TraktURIs.SyncHistoryRemove; break; } string retData = string.Empty; int response = SendData(url, json, "POST", BuildRequestHeaders(), ref retData); /*if (response == TraktStatusCodes.Success || response == TraktStatusCodes.Success_Post || response == TraktStatusCodes.Success_Delete) { // if this was marking an episode as watched, and is successful, let's also add this to the user's collection // this is because you can watch something without adding it to your collection, but in JMM it is always part of your collection if (syncType == TraktSyncType.HistoryAdd && secondaryAction) SyncEpisodeToTrakt(ep, syncType, false); // also if we have removed from our collection, set to un-watched if (syncType == TraktSyncType.CollectionRemove && secondaryAction) response = SendData(TraktURIs.SyncHistoryRemove, json, "POST", BuildRequestHeaders(), ref retData); }*/ } catch (Exception ex) { logger.ErrorException("Error in TraktTVHelper.SyncEpisodeToTrakt: " + ex.ToString(), ex); } }
public static void SyncEpisodeToTrakt(AnimeEpisode ep, TraktSyncType syncType, bool secondaryAction = true) { try { if (!ServerSettings.Trakt_IsEnabled || string.IsNullOrEmpty(ServerSettings.Trakt_AuthToken)) return; string traktShowID = string.Empty; int season = -1; int epNumber = -1; GetTraktEpisodeIdV2(ep, ref traktShowID, ref season, ref epNumber); if (string.IsNullOrEmpty(traktShowID) || season < 0 || epNumber < 0) return; DateTime epDate = GetEpisodeDateForSync(ep, syncType); //SyncEpisodeToTrakt(syncType, traktEpisodeId.Value, secondaryAction); SyncEpisodeToTrakt(syncType, traktShowID, season, epNumber, epDate, secondaryAction); } catch (Exception ex) { logger.ErrorException("Error in TraktTVHelper.MarkEpisodeWatched: " + ex.ToString(), ex); } }
/// <summary> /// Gets the user's saved playback progress of scrobbles that are paused. /// <para>OAuth authorization required.</para> /// <para> /// See <a href="http://docs.trakt.apiary.io/#reference/sync/last-activities/get-playback-progress">"Trakt API Doc - Sync: Playback"</a> for more information. /// </para> /// </summary> /// <param name="objectType">Determines, which type of items should be queried. By default, all types will be returned. See also <seealso cref="TraktSyncType" />.</param> /// <param name="limit">Determines, how many progress items should be queried. By default, all items will be returned</param> /// <param name="cancellationToken"> /// Propagates notification that the request should be canceled.<para/> /// If provided, the exception <see cref="OperationCanceledException" /> should be catched. /// </param> /// <returns>A list of <see cref="ITraktSyncPlaybackProgressItem" /> instances.</returns> /// <exception cref="TraktException">Thrown, if the request fails.</exception> public Task <TraktListResponse <ITraktSyncPlaybackProgressItem> > GetPlaybackProgressAsync(TraktSyncType objectType = null, uint?limit = null, CancellationToken cancellationToken = default) { var requestHandler = new RequestHandler(Client); return(requestHandler.ExecuteListRequestAsync(new SyncPlaybackProgressRequest { Type = objectType, Limit = limit }, cancellationToken)); }
public async Task <IEnumerable <TraktSyncPlaybackProgressItem> > GetPlaybackProgressAsync(TraktSyncType objectType = null, int?limit = null) => await QueryAsync(new TraktSyncPlaybackProgressRequest(Client) { Type = objectType, PaginationOptions = new TraktPaginationOptions(null, limit) });
public void TestTraktSyncTypeIsTraktEnumeration() { var enumeration = new TraktSyncType(); enumeration.Should().BeAssignableTo <TraktEnumeration>(); }
/// <summary> /// Gets the user's saved playback progress of scrobbles that are paused. /// <para>OAuth authorization required.</para> /// <para> /// See <a href="http://docs.trakt.apiary.io/#reference/sync/last-activities/get-playback-progress">"Trakt API Doc - Sync: Playback"</a> for more information. /// </para> /// </summary> /// <param name="objectType">Determines, which type of items should be queried. By default, all types will be returned. See also <seealso cref="TraktSyncType" />.</param> /// <param name="startAt">Determines an optional start date and time for a range of the returned playback progress.</param> /// <param name="endAt">Determines an optional end date and time for a range of the returned playback progress.</param> /// <param name="pagedParameters">Specifies pagination parameters. <see cref="TraktPagedParameters" />.</param> /// <param name="cancellationToken"> /// Propagates notification that the request should be canceled.<para/> /// If provided, the exception <see cref="OperationCanceledException" /> should be catched. /// </param> /// <returns>A list of <see cref="ITraktSyncPlaybackProgressItem" /> instances.</returns> /// <exception cref="TraktException">Thrown, if the request fails.</exception> public Task <TraktPagedResponse <ITraktSyncPlaybackProgressItem> > GetPlaybackProgressAsync(TraktSyncType objectType = null, DateTime?startAt = null, DateTime?endAt = null, TraktPagedParameters pagedParameters = null, CancellationToken cancellationToken = default) { var requestHandler = new RequestHandler(Client); return(requestHandler.ExecutePagedRequestAsync(new SyncPlaybackProgressRequest { Type = objectType, StartAt = startAt, EndAt = endAt, Page = pagedParameters?.Page, Limit = pagedParameters?.Limit }, cancellationToken)); }