public static TraktSyncResponse AddMovieToCollection(TraktSyncMovieCollected movie) { var movies = new TraktSyncMoviesCollected { Movies = new List<TraktSyncMovieCollected>() { movie } }; return AddMoviesToCollecton(movies); }
/// <summary> /// Fired when an object is inserted in the Moving Pictures Database /// </summary> private void DatabaseManager_ObjectInserted(DatabaseTable obj) { // check connection state if (TraktSettings.AccountStatus != ConnectionState.Connected) return; if (obj.GetType() == typeof(DBWatchedHistory)) { // movie has just been watched DBWatchedHistory watchedEvent = (DBWatchedHistory)obj; if (!TraktSettings.BlockedFilenames.Contains(watchedEvent.Movie.LocalMedia[0].FullPath) && !TraktSettings.BlockedFolders.Any(f => watchedEvent.Movie.LocalMedia[0].FullPath.ToLowerInvariant().Contains(f.ToLowerInvariant()))) { TraktLogger.Info("Watched History updated in MovingPictures. Title = '{0}', Year = '{1}', IMDb ID = '{2}', TMDb ID = '{3}'", watchedEvent.Movie.Title, watchedEvent.Movie.Year, watchedEvent.Movie.ImdbID ?? "<empty>", GetTmdbID(watchedEvent.Movie) ?? "<empty>"); ShowRateDialog(watchedEvent.Movie); StopMovieScrobble(watchedEvent.Movie); // remove from watchlist and recommendation categories and filters menu // watched items are auto-removed online for these lists so we can do this now locally RemoveMovieCriteriaFromRecommendationsNode(watchedEvent.Movie.ImdbID); RemoveMovieCriteriaFromWatchlistNode(watchedEvent.Movie.ImdbID); } else { TraktLogger.Info("Movie was blocked and not added to watched history on trakt.tv. Title = '{0}', Year = '{1}', IMDb ID = '{2}', TMDb ID = '{3}'", watchedEvent.Movie.Title, watchedEvent.Movie.Year, watchedEvent.Movie.ImdbID ?? "<empty>", GetTmdbID(watchedEvent.Movie) ?? "<empty>"); } } else if (obj.GetType() == typeof(DBMovieInfo) && TraktSettings.SyncLibrary) { // movie was inserted into the database var insertedMovie = obj as DBMovieInfo; if (!TraktSettings.BlockedFilenames.Contains(insertedMovie.LocalMedia[0].FullPath) && !TraktSettings.BlockedFolders.Any(f => insertedMovie.LocalMedia[0].FullPath.ToLowerInvariant().Contains(f.ToLowerInvariant()))) { var syncThread = new Thread((objMovie) => { // wait for import to be 100% complete including MediaInfo Thread.Sleep(30000); var tMovie = objMovie as DBMovieInfo; var traktMovie = new TraktSyncMovieCollected { Ids = new TraktMovieId { Imdb = tMovie.ImdbID, Tmdb = GetTmdbID(tMovie).ToNullableInt32() }, Title = tMovie.Title, Year = tMovie.Year, CollectedAt = DateTime.UtcNow.ToISO8601(), MediaType = GetMovieMediaType(tMovie), Resolution = GetMovieResolution(tMovie), AudioCodec = GetMovieAudioCodec(tMovie), AudioChannels = GetMovieAudioChannels(tMovie), Is3D = IsMovie3D(tMovie) }; TraktLogger.Info("New movie added into MovingPictures, adding to trakt.tv collection. Title = '{0}', Year = '{1}', IMDb ID = '{2}', TMDb ID = '{3}', Date Added = '{4}', MediaType = '{5}', Resolution = '{6}', Audio Codec = '{7}', Audio Channels = '{8}'", traktMovie.Title, traktMovie.Year.HasValue ? traktMovie.Year.ToString() : "<empty>", traktMovie.Ids.Imdb ?? "<empty>", traktMovie.Ids.Tmdb.HasValue ? traktMovie.Ids.Tmdb.ToString() : "<empty>", traktMovie.CollectedAt, traktMovie.MediaType ?? "<empty>", traktMovie.Resolution ?? "<empty>", traktMovie.AudioCodec ?? "<empty>", traktMovie.AudioChannels ?? "<empty>"); // check if we already have the movie collected online if (traktMovie.IsCollected()) { TraktLogger.Info("Skipping movie addition to trakt.tv collection, movie already exists in online collection."); return; } // insert movie into local cache - with title/year TraktCache.AddMovieToCollection(traktMovie); // check for valid IDs if (TraktSettings.SkipMoviesWithNoIdsOnSync) { traktMovie.Title = null; traktMovie.Year = null; if (!BasicHandler.IsValidImdb(traktMovie.Ids.Imdb) && traktMovie.Ids.Tmdb == null) { TraktLogger.Info("Skipping movie addition to trakt.tv collection, movie has no valid online ID's."); return; } } // insert online var response = TraktAPI.TraktAPI.AddMovieToCollection(traktMovie); TraktLogger.LogTraktResponse(response); }) { IsBackground = true, Name = "Sync" }; syncThread.Start(insertedMovie); } else { TraktLogger.Info("Movie was blocked and not added to collection on trakt.tv. Title = '{0}', Year = '{1}', IMDb ID = '{2}', TMDb ID = '{3}'", insertedMovie.Title, insertedMovie.Year, insertedMovie.ImdbID ?? "<empty>", GetTmdbID(insertedMovie) ?? "<empty>"); } } }
public static void AddMovieToCollection(string title, int? year, string imdbid, int? tmdbid, int? traktid) { if (!GUICommon.CheckLogin(false)) return; var movie = new TraktSyncMovieCollected { Ids = new TraktMovieId { Trakt = traktid, Imdb = imdbid, Tmdb = tmdbid }, Title = title, Year = year }; var syncThread = new Thread((objSyncData) => { var response = TraktAPI.TraktAPI.AddMovieToCollection(objSyncData as TraktSyncMovieCollected); }) { IsBackground = true, Name = "AddCollection" }; syncThread.Start(movie); TraktCache.AddMovieToCollection(movie); }