/// <summary> /// Syncronize our collection on trakt /// </summary> /// <param name="episodes">local tvseries dbepisode list</param> /// <param name="mode">trakt sync mode</param> private void SyncLibrary(List <FileLocal> episodes, TraktSyncModes mode) { if (episodes.Count == 0) { return; } // get unique series ids var uniqueSeries = (from s in episodes where (s.AniDB_File != null && s.AniDB_File.AnimeSeries.TvDB_ID > 0) select s.AniDB_File.AnimeSeries.TvDB_ID).Distinct().ToList(); if (uniqueSeries.Count == 0) { TraktLogger.Info("TVDb info not available for series, can not sync '{0}' with trakt.", mode.ToString()); } // go over each series, can only send one series at a time foreach (int seriesid in uniqueSeries) { // There should only be one series List <AnimeSeries> series = AnimeSeries.GetSeriesWithSpecificTvDB(seriesid); if (series == null) { continue; } TraktLogger.Info("Synchronizing '{0}' episodes for series '{1}'.", mode.ToString(), series[0].ToString()); // upload to trakt TraktEpisodeSync episodeSync = CreateSyncData(series[0], episodes); if (episodeSync != null) { TraktResponse response = TraktAPI.TraktAPI.SyncEpisodeLibrary(episodeSync, mode); // check for any error and log result TraktAPI.TraktAPI.LogTraktResponse(response); // wait a short period before uploading another series Thread.Sleep(2000); } } }
/// <summary> /// Syncronize our collection on trakt /// </summary> /// <param name="episodes">local tvseries dbepisode list</param> /// <param name="mode">trakt sync mode</param> private void SyncLibrary(List<DBEpisode> episodes, TraktSyncModes mode) { // get unique series ids var uniqueSeries = (from s in episodes select s[DBEpisode.cSeriesID].ToString()).Distinct().ToList(); // go over each series, can only send one series at a time foreach (string seriesid in uniqueSeries) { // get series and check if we should ignore it DBSeries series = Helper.getCorrespondingSeries(int.Parse(seriesid)); if (series == null || series[DBOnlineSeries.cTraktIgnore]) continue; TraktLogger.Info("Synchronizing '{0}' episodes for series '{1}'.", mode.ToString(), series.ToString()); // upload to trakt TraktResponse response = TraktAPI.TraktAPI.SyncEpisodeLibrary(CreateSyncData(series, episodes), mode); // check for any error and log result TraktAPI.TraktAPI.LogTraktResponse(response); // wait a short period before uploading another series Thread.Sleep(2000); } }
/// <summary> /// Sends movie sync data to Trakt /// </summary> /// <param name="syncData">The sync data to send</param> /// <param name="mode">The sync mode to use</param> /// <returns>The response from trakt</returns> public static TraktMovieSyncResponse SyncMovieLibrary(TraktMovieSync syncData, TraktSyncModes mode) { // check that we have everything we need if (syncData == null || syncData.MovieList.Count == 0) return null; // serialize data to JSON and send to server string response = TraktWeb.Transmit(string.Format(TraktURIs.SyncMovieLibrary, mode.ToString()), syncData.ToJSON()); // return success or failure return response.FromJSON<TraktMovieSyncResponse>(); }
/// <summary> /// Sends episode sync data to Trakt /// </summary> /// <param name="syncData">The sync data to send</param> /// <param name="mode">The sync mode to use</param> public static TraktResponse SyncEpisodeLibrary(TraktEpisodeSync syncData, TraktSyncModes mode) { // check that we have everything we need if (syncData == null || string.IsNullOrEmpty(syncData.SeriesID)) return null; // serialize data to JSON and send to server string response = TraktWeb.Transmit(string.Format(TraktURIs.SyncEpisodeLibrary, mode.ToString()), syncData.ToJSON()); // return success or failure return response.FromJSON<TraktResponse>(); }
/// <summary> /// Syncronize our collection on trakt /// </summary> /// <param name="episodes">local tvseries dbepisode list</param> /// <param name="mode">trakt sync mode</param> private void SyncLibrary(List<FileLocal> episodes, TraktSyncModes mode) { if (episodes.Count == 0) return; // get unique series ids var uniqueSeries = (from s in episodes where (s.AniDB_File != null && s.AniDB_File.AnimeSeries.TvDB_ID > 0) select s.AniDB_File.AnimeSeries.TvDB_ID).Distinct().ToList(); if (uniqueSeries.Count == 0) { TraktLogger.Info("TVDb info not available for series, can not sync '{0}' with trakt.", mode.ToString()); } // go over each series, can only send one series at a time foreach (int seriesid in uniqueSeries) { // There should only be one series List<AnimeSeries> series = AnimeSeries.GetSeriesWithSpecificTvDB(seriesid); if (series == null) continue; TraktLogger.Info("Synchronizing '{0}' episodes for series '{1}'.", mode.ToString(), series[0].ToString()); // upload to trakt TraktEpisodeSync episodeSync = CreateSyncData(series[0], episodes); if (episodeSync != null) { TraktResponse response = TraktAPI.TraktAPI.SyncEpisodeLibrary(episodeSync, mode); // check for any error and log result TraktAPI.TraktAPI.LogTraktResponse(response); // wait a short period before uploading another series Thread.Sleep(2000); } } }
/// <summary> /// Sends episode sync data to Trakt /// </summary> /// <param name="syncData">The sync data to send</param> /// <param name="mode">The sync mode to use</param> public static TraktResponse SyncEpisodeLibrary(TraktEpisodeSync syncData, TraktSyncModes mode) { // check that we have everything we need if (syncData == null || string.IsNullOrEmpty(syncData.SeriesID)) { return(null); } // serialize data to JSON and send to server string response = TraktWeb.Transmit(string.Format(TraktURIs.SyncEpisodeLibrary, mode.ToString()), syncData.ToJSON()); // return success or failure return(response.FromJSON <TraktResponse>()); }
/// <summary> /// Sends movie sync data to Trakt /// </summary> /// <param name="syncData">The sync data to send</param> /// <param name="mode">The sync mode to use</param> /// <returns>The response from trakt</returns> public static TraktMovieSyncResponse SyncMovieLibrary(TraktMovieSync syncData, TraktSyncModes mode) { // check that we have everything we need if (syncData == null || syncData.MovieList.Count == 0) { return(null); } // serialize data to JSON and send to server string response = TraktWeb.Transmit(string.Format(TraktURIs.SyncMovieLibrary, mode.ToString()), syncData.ToJSON()); // return success or failure return(response.FromJSON <TraktMovieSyncResponse>()); }
public static void SynchronizeLibrary(List <DBEpisode> episodes, TraktSyncModes mode) { if (episodes.Count == 0) { return; } // get unique series ids var uniqueSeriesIDs = (from seriesIDs in episodes select seriesIDs[DBEpisode.cSeriesID].ToString()).Distinct().ToList(); // go over each series, can only send one series at a time foreach (string seriesID in uniqueSeriesIDs) { DBSeries series = Helper.getCorrespondingSeries(int.Parse(seriesID)); if (series == null || series[DBOnlineSeries.cTraktIgnore]) { continue; } MPTVSeriesLog.Write("Trakt: Synchronizing '{0}' episodes for series '{1}'.", mode.ToString(), series.ToString()); TraktSync traktSync = GetTraktSyncObject(series, episodes); // upload to trakt TraktResponse response = TraktAPI.SyncEpisodeLibrary(traktSync, mode); if (response == null) { MPTVSeriesLog.Write("Trakt Error: Response from server was unexpected."); continue; } // check for any error and log result CheckTraktErrorAndNotify(response, false); if (response.Status == "success") { SQLCondition conditions = new SQLCondition(); // flag episodes and commit to database switch (mode) { case TraktSyncModes.seen: conditions.Add(new DBOnlineEpisode(), DBOnlineEpisode.cSeriesID, seriesID, SQLConditionType.Equal); conditions.Add(new DBOnlineEpisode(), DBOnlineEpisode.cWatched, 1, SQLConditionType.Equal); conditions.Add(new DBOnlineEpisode(), DBOnlineEpisode.cHidden, 0, SQLConditionType.Equal); conditions.Add(new DBOnlineEpisode(), DBOnlineEpisode.cTraktSeen, 0, SQLConditionType.Equal); // we always flag traktLibrary field as the 'traktSeen' field counts as part of library DBOnlineEpisode.GlobalSet(new DBOnlineEpisode(), DBOnlineEpisode.cTraktLibrary, 1, conditions); DBOnlineEpisode.GlobalSet(new DBOnlineEpisode(), DBOnlineEpisode.cTraktSeen, 1, conditions); break; case TraktSyncModes.library: // we can't do a global set as our conditions are from two different tables // where filename is not empty and traktLibrary = 0 foreach (DBEpisode ep in episodes.Where(e => e[DBEpisode.cSeriesID] == seriesID)) { ep[DBOnlineEpisode.cTraktLibrary] = 1; ep.Commit(); } break; case TraktSyncModes.unseen: conditions.Add(new DBOnlineEpisode(), DBOnlineEpisode.cSeriesID, seriesID, SQLConditionType.Equal); conditions.Add(new DBOnlineEpisode(), DBOnlineEpisode.cHidden, 0, SQLConditionType.Equal); conditions.Add(new DBOnlineEpisode(), DBOnlineEpisode.cTraktSeen, 2, SQLConditionType.Equal); DBOnlineEpisode.GlobalSet(new DBOnlineEpisode(), DBOnlineEpisode.cTraktSeen, 0, conditions); break; case TraktSyncModes.unlibrary: break; } } // wait a short period before uploading another series Thread.Sleep(2000); } }