Пример #1
0
        /// <summary>
        /// Shows the Rate Dialog after playback has ended
        /// </summary>
        /// <param name="episode">The item being rated</param>
        internal static void ShowRateDialog(VideoInfo videoInfo)
        {
            if (!TraktSettings.ShowRateDialogOnWatched) return;     // not enabled

            TraktLogger.Debug("Showing rate dialog for '{0}'", videoInfo.Title);

            var rateThread = new System.Threading.Thread((o) =>
            {
                var itemToRate = o as VideoInfo;
                if (itemToRate == null) return;

                int rating = 0;

                if (itemToRate.Type == VideoType.Series)
                {
                    var rateObject = new TraktSyncShowRatedEx
                    {
                        Title = itemToRate.Title,
                        Year = itemToRate.Year.ToNullableInt32(),
                        Seasons = new List<TraktSyncShowRatedEx.Season>
                        {
                            new TraktSyncShowRatedEx.Season
                            {
                                Number = itemToRate.SeasonIdx.ToInt(),
                                Episodes = new List<TraktSyncShowRatedEx.Season.Episode>
                                {
                                    new TraktSyncShowRatedEx.Season.Episode
                                    {
                                        Number = itemToRate.EpisodeIdx.ToInt(),
                                        RatedAt = DateTime.UtcNow.ToISO8601()
                                    }
                                }
                            }
                        }
                    };
                    // get the rating submitted to trakt
                    rating = GUIUtils.ShowRateDialog<TraktSyncShowRatedEx>(rateObject);

                    // add episode rated to cache
                    if (rating > 0)
                    {
                        TraktCache.AddEpisodeToRatings(
                            new TraktShow
                            {
                                Ids = new TraktShowId(),
                                Title = rateObject.Title,
                                Year = rateObject.Year,
                            },
                            new TraktEpisode
                            {
                                Ids = new TraktEpisodeId(),
                                Season = rateObject.Seasons[0].Number,
                                Number = rateObject.Seasons[0].Episodes[0].Number
                            },
                            rating
                        );
                    }
                }
                else if (itemToRate.Type == VideoType.Movie)
                {
                    var rateObject = new TraktSyncMovieRated
                    {
                        Ids = new TraktMovieId(),
                        Title = itemToRate.Title,
                        Year = itemToRate.Year.ToNullableInt32(),
                        RatedAt = DateTime.UtcNow.ToISO8601()
                    };

                    // get the rating submitted to trakt
                    rating = GUIUtils.ShowRateDialog<TraktSyncMovieRated>(rateObject);

                    // add movie rated to cache
                    if (rating > 0)
                    {
                        TraktCache.AddMovieToRatings(rateObject, rating);
                    }
                    else
                    {
                        TraktCache.RemoveMovieFromRatings(rateObject);
                    }
                }

                if (rating > 0)
                {
                    TraktLogger.Debug("Rating {0} as {1}/10", itemToRate.Title, rating.ToString());
                }
            })
            {
                Name = "Rate",
                IsBackground = true
            };

            rateThread.Start(videoInfo);
        }
Пример #2
0
        /// <summary>
        /// Shows the Rate Dialog after playback has ended
        /// </summary>
        /// <param name="episode">The item being rated</param>
        private void ShowRateDialog(ITrackingInfo videoInfo)
        {
            if (!TraktSettings.ShowRateDialogOnWatched)
                return;

            var rateThread = new Thread((objInfo) =>
            {
                var itemToRate = objInfo as ITrackingInfo;
                if (itemToRate == null) return;

                int rating = -1;

                if (itemToRate.VideoKind == VideoKind.TvSeries)
                {
                    TraktLogger.Info("Showing rate dialog for episode. Title = '{0}', Year = '{1}', IMDb ID = '{2}', TMDb ID = '{3}', Season = '{4}', Episode = '{5}'", itemToRate.Title, itemToRate.Year == 0 ? "<empty>" : itemToRate.Year.ToString(), itemToRate.ID_IMDB.ToLogString(), itemToRate.ID_TMDB.ToLogString(), itemToRate.Episode, itemToRate.Season);

                    // this gets complicated when the episode IDs are not available!
                    var rateObject = new TraktSyncShowRatedEx
                    {
                        Ids = new TraktShowId { Tvdb = itemToRate.ID_TVDB.ToNullableInt32(), Tmdb = itemToRate.ID_TMDB.ToNullableInt32() },
                        Title = itemToRate.Title,
                        Year = itemToRate.Year > 0 ? (int?)itemToRate.Year : null,
                        Seasons = new List<TraktSyncShowRatedEx.Season>
                        {
                            new TraktSyncShowRatedEx.Season
                            {
                                Number = (int)itemToRate.Season,
                                Episodes = new List<TraktSyncShowRatedEx.Season.Episode>
                                {
                                    new TraktSyncShowRatedEx.Season.Episode
                                    {
                                        Number = (int)itemToRate.Episode,
                                        RatedAt = DateTime.UtcNow.ToISO8601()
                                    }
                                }
                            }
                        }
                    };
                    // get the rating submitted to trakt
                    rating = GUIUtils.ShowRateDialog<TraktSyncShowRatedEx>(rateObject);

                    // add episode rated to cache
                    if (rating > 0)
                    {
                        TraktCache.AddEpisodeToRatings(
                            new TraktShow
                            {
                                Ids = rateObject.Ids,
                                Title = rateObject.Title,
                                Year = rateObject.Year,
                            },
                            new TraktEpisode
                            {
                                Ids = new TraktEpisodeId(),
                                Season = rateObject.Seasons[0].Number,
                                Number = rateObject.Seasons[0].Episodes[0].Number
                            },
                            rating
                        );
                    }
                }
                else if (itemToRate.VideoKind == VideoKind.Movie)
                {
                    TraktLogger.Info("Showing rate dialog for movie. Title = '{0}', Year = '{1}', IMDb Id = '{2}', TMDb ID = '{3}'", itemToRate.Title, itemToRate.Year, itemToRate.ID_IMDB.ToLogString(), itemToRate.ID_TMDB.ToLogString());

                    var rateObject = new TraktSyncMovieRated
                    {
                        Ids = new TraktMovieId { Imdb = itemToRate.ID_IMDB, Tmdb = itemToRate.ID_TMDB.ToNullableInt32() },
                        Title = itemToRate.Title,
                        Year = (int)itemToRate.Year,
                        RatedAt = DateTime.UtcNow.ToISO8601()
                    };
                    // get the rating submitted to trakt
                    rating = GUIUtils.ShowRateDialog<TraktSyncMovieRated>(rateObject);

                    // add movie rated to cache
                    if (rating > 0)
                    {
                        TraktCache.AddMovieToRatings(rateObject, rating);
                    }
                    else
                    {
                        TraktCache.RemoveMovieFromRatings(rateObject);
                    }
                }
            })
            {
                Name = "Rate",
                IsBackground = true
            };

            rateThread.Start(videoInfo);
        }
Пример #3
0
        /// <summary>
        /// Shows the Rate Movie Dialog after playback has ended
        /// </summary>
        /// <param name="movie">The movie being rated</param>
        private void ShowRateDialog(IMDBMovie movie)
        {
            if (!TraktSettings.ShowRateDialogOnWatched) return;
            if (!TraktSettings.ShowRateDlgForPlaylists && PlayListPlayer.SingletonPlayer.CurrentPlaylistType == PlayListType.PLAYLIST_VIDEO) return;

            TraktLogger.Debug("Showing rate dialog for movie. Title = '{0}', Year = '{1}', IMDb ID = '{2}'", movie.Title, movie.Year, movie.IMDBNumber ?? "<empty>");

            var rateThread = new Thread((o) =>
            {
                var movieToRate = o as IMDBMovie;
                if (movieToRate == null) return;

                var rateObject = new TraktSyncMovieRated
                {
                    Ids = new TraktMovieId { Imdb = movieToRate.IMDBNumber.ToNullIfEmpty() },
                    Title = movieToRate.Title,
                    Year = movieToRate.Year,
                    RatedAt = DateTime.UtcNow.ToISO8601(),
                };

                // get the rating submitted to trakt.tv
                int rating = GUI.GUIUtils.ShowRateDialog<TraktSyncMovieRated>(rateObject);

                if (rating > 0)
                {
                    // update local cache
                    TraktCache.AddMovieToRatings(rateObject, rating);

                    TraktLogger.Debug("Rating {0} ({1}) as {2}/10", movieToRate.Title, movie.Year, rating.ToString());
                }
                else if (rating == 0)
                {
                    TraktCache.RemoveMovieFromRatings(rateObject);
                }
            })
            {
                Name = "Rate",
                IsBackground = true
            };

            rateThread.Start(movie);
        }
Пример #4
0
        /// <summary>
        /// Fired when an object is updated in the Moving Pictures Database
        /// </summary>
        /// <param name="obj"></param>
        private void DatabaseManager_ObjectUpdatedEx(DatabaseTable dbObject, TableUpdateInfo ui)
        {
            // check connection state
            if (TraktSettings.AccountStatus != ConnectionState.Connected)
                return;

            // If it is user settings for a movie
            if (dbObject.GetType() != typeof(DBUserMovieSettings))
                return;

            // if we are syncing, we maybe manually setting state from trakt
            // in this case we dont want to resend to trakt
            if (SyncLibraryInProgress) return;

            DBUserMovieSettings userMovieSettings = (DBUserMovieSettings)dbObject;
            DBMovieInfo movie = userMovieSettings.AttachedMovies[0];

            // don't do anything if movie is blocked
            if (TraktSettings.BlockedFilenames.Contains(movie.LocalMedia[0].FullPath) || TraktSettings.BlockedFolders.Any(f => movie.LocalMedia[0].FullPath.ToLowerInvariant().Contains(f.ToLowerInvariant())))
            {
                TraktLogger.Info("Movie is on the blocked list so we didn't update trakt.tv. Title = '{0}', Year = '{1}', IMDB ID = '{2}', TMDb ID = '{3}'", movie.Title, movie.Year, movie.ImdbID ?? "<empty>", GetTmdbID(movie) ?? "<empty>");
                return;
            }

            // we check the watched flag and update Trakt respectfully
            // ignore if movie is the current movie being scrobbled, this will be set to watched automatically
            if (ui.WatchedCountChanged() && movie != currentMovie)
            {
                if (userMovieSettings.WatchedCount == 0)
                {
                    #region Unwatched Event
                    TraktLogger.Info("Received Un-Watched event in MovingPictures for movie. Title = '{0}', Year = '{1}', IMDB ID = '{2}', TMDb ID = '{3}'", movie.Title, movie.Year, movie.ImdbID ?? "<empty>", GetTmdbID(movie) ?? "<empty>");

                    var syncThread = new Thread((objMovie) =>
                    {
                        var tMovie = objMovie as DBMovieInfo;

                        var traktMovie = new TraktMovie
                        {
                            Ids = new TraktMovieId { Imdb = tMovie.ImdbID, Tmdb = GetTmdbID(tMovie).ToNullableInt32() },
                            Title = tMovie.Title,
                            Year = tMovie.Year
                        };

                        // update local cache
                        TraktCache.RemoveMovieFromWatchHistory(traktMovie);

                        var response = TraktAPI.TraktAPI.RemoveMovieFromWatchedHistory(traktMovie);
                        TraktLogger.LogTraktResponse(response);
                    })
                    {
                        IsBackground = true,
                        Name = "Sync"
                    };

                    syncThread.Start(movie);
                    #endregion
                }
                else
                {
                    #region Watched Event
                    TraktLogger.Info("Received Watched event in MovingPictures for movie. Title = '{0}', Year = '{1}', IMDB ID = '{2}', TMDb ID = '{3}'", movie.Title, movie.Year, movie.ImdbID ?? "<empty>", GetTmdbID(movie) ?? "<empty>");
                    if (!g_Player.IsVideo)
                    {
                        var syncThread = new Thread((objMovie) =>
                        {
                            var tMovie = objMovie as DBMovieInfo;

                            var traktMovie = new TraktSyncMovieWatched
                            {
                                Ids = new TraktMovieId { Imdb = tMovie.ImdbID, Tmdb = GetTmdbID(tMovie).ToNullableInt32() },
                                Title = tMovie.Title,
                                Year = tMovie.Year,
                                WatchedAt = DateTime.UtcNow.ToISO8601()
                            };

                            var response = TraktAPI.TraktAPI.AddMovieToWatchedHistory(traktMovie);
                            TraktLogger.LogTraktResponse(response);

                            if (response != null && response.NotFound != null && response.NotFound.Movies.Count == 0)
                            {
                                // update internal cache
                                TraktCache.AddMovieToWatchHistory(traktMovie);
                            }

                            // don't need to keep this movie anymore in categories/filter menu if it's watched
                            RemoveMovieCriteriaFromRecommendationsNode(tMovie.ImdbID);
                            RemoveMovieCriteriaFromWatchlistNode(tMovie.ImdbID);
                        })
                        {
                            IsBackground = true,
                            Name = "Sync"
                        };

                        syncThread.Start(movie);
                    }
                    #endregion
                }
            }

            // we will update the Trakt rating of the Movie
            // ignore if we rated using trakt rate dialog
            if (ui.RatingChanged() && userMovieSettings.UserRating > 0 && !TraktRateSent)
            {
                TraktLogger.Info("Received Rate event in MovingPictures for movie. Rating = '{0}/5', Title = '{1}', Year = '{2}', IMDB ID = '{3}', TMDb ID = '{4}'", userMovieSettings.UserRating, movie.Title, movie.Year, movie.ImdbID ?? "<empty>", GetTmdbID(movie) ?? "<empty>");

                var syncThread = new Thread((objMovie) =>
                {
                    var tMovie = objMovie as DBMovieInfo;

                    var traktMovie = new TraktSyncMovieRated
                    {
                        Ids = new TraktMovieId { Imdb = tMovie.ImdbID, Tmdb = GetTmdbID(tMovie).ToNullableInt32() },
                        Title = tMovie.Title,
                        Year = tMovie.Year,
                        RatedAt = DateTime.UtcNow.ToISO8601(),
                        Rating = (int)userMovieSettings.UserRating * 2
                    };

                    var response = TraktAPI.TraktAPI.AddMovieToRatings(traktMovie);
                    TraktLogger.LogTraktResponse(response);
                })
                {
                    IsBackground = true,
                    Name = "Sync"
                };
                syncThread.Start(movie);
            }
        }
Пример #5
0
        /// <summary>
        /// Shows the Rate Movie Dialog after playback has ended
        /// </summary>
        /// <param name="movie">The movie being rated</param>
        private void ShowRateDialog(DBMovieInfo movie)
        {
            if (MovingPicturesCore.Settings.AutoPromptForRating) return;    // movpics dialog is enabled
            if (!TraktSettings.ShowRateDialogOnWatched) return;             // not enabled
            if (movie.ActiveUserSettings.UserRating > 0) return;            // already rated
            if (AdvancedRatings && HasAdvancedRating(movie)) return;        // already rated (advanced)

            var rateThread = new Thread((objMovie) =>
            {
                TraktLogger.Info("Showing rate dialog for movie. Title = '{0}', Year = '{1}', IMDB ID = '{2}', TMDb ID = '{3}'", movie.Title, movie.Year, movie.ImdbID ?? "<empty>", GetTmdbID(movie) ?? "<empty>");

                // added a delay due to bug in MovingPictures blocking OnPageLoad()
                // a call to GUIWindowManager.Process() causes MediaPortal to wait until any modal dialog is closed.
                // the value may need to be tweaked on some systems
                // visible symtoms of issue is wrong backdrop / progress in background whilst dialog is modal
                Thread.Sleep(TraktSettings.MovPicsRatingDlgDelay);

                var movieToRate = objMovie as DBMovieInfo;
                if (movieToRate == null) return;

                var rateObject = new TraktSyncMovieRated
                {
                    Ids = new TraktMovieId { Imdb = movieToRate.ImdbID.ToNullIfEmpty(), Tmdb = GetTmdbID(movieToRate).ToNullableInt32() },
                    Title = movieToRate.Title,
                    Year = movieToRate.Year,
                    RatedAt = DateTime.UtcNow.ToISO8601()
                };

                // get the rating submitted to trakt
                int rating = GUIUtils.ShowRateDialog<TraktSyncMovieRated>(rateObject);
                if (rating == -1) return;

                // flag to ignore event handler
                TraktRateSent = true;

                if (rating > 0)
                {
                    TraktLogger.Info("Applying rating for movie. Rating = '{0}/10', Title = '{1}', Year = '{2}', IMDB ID = '{3}', TMDb ID = '{4}'", rating,  movie.Title, movie.Year, movie.ImdbID ?? "<empty>", GetTmdbID(movie) ?? "<empty>");
                    if (!AdvancedRatings)
                    {
                        movieToRate.ActiveUserSettings.UserRating = (int)(Math.Round(rating / 2.0, MidpointRounding.AwayFromZero));
                    }
                    else
                    {
                        SetAdvancedRating(movieToRate, rating);
                    }

                    // update local cache
                    TraktCache.AddMovieToRatings(rateObject, rating);

                    // Publish to skin - same as how MovingPictures does it i.e. lose precision due to rounding
                    // Make sure we're still showing the active movie
                    if (GUIUtils.GetProperty("#MovingPictures.SelectedMovie.title").Equals(movieToRate.Title))
                    {
                        if (!AdvancedRatings)
                        {
                            GUICommon.SetProperty("#MovingPictures.UserMovieSettings.user_rating", movieToRate.ActiveUserSettings.UserRating.ToString());
                            GUICommon.SetProperty("#MovingPictures.UserMovieSettings.10point_user_rating", (movieToRate.ActiveUserSettings.UserRating * 2).ToString());
                        }
                        else
                        {
                            GUICommon.SetProperty("#MovingPictures.UserMovieSettings.10point_user_rating", rating);
                        }
                    }

                    if (movieToRate.Popularity == 0 && movieToRate.Score == 0)
                    {
                        movieToRate.Score = rating;
                        movieToRate.Popularity = 1;
                    }
                }
                else
                {
                    // unrate
                    TraktLogger.Info("Removing rating for movie. Title = '{0}', Year = '{1}', IMDB ID = '{2}', TMDb ID = '{3}'", movie.Title, movie.Year, movie.ImdbID ?? "<empty>", GetTmdbID(movie) ?? "<empty>");
                    movieToRate.ActiveUserSettings.UserRating = 0;
                    if (AdvancedRatings) SetAdvancedRating(movieToRate, 0);

                    // update local cache
                    TraktCache.RemoveMovieFromRatings(rateObject);

                    // Make sure we're still showing the active movie
                    if (GUIUtils.GetProperty("#MovingPictures.SelectedMovie.title").Equals(movieToRate.Title))
                    {
                        GUICommon.SetProperty("#MovingPictures.UserMovieSettings.user_rating", " ");
                        GUICommon.SetProperty("#MovingPictures.UserMovieSettings.10point_user_rating", " ");
                    }
                }

                movieToRate.Commit();
                TraktRateSent = false;
            })
            {
                Name = "Rate",
                IsBackground = true
            };

            rateThread.Start(movie);
        }
Пример #6
0
        internal static bool RateMovie(TraktMovieSummary movie)
        {
            var rateObject = new TraktSyncMovieRated
            {
                Ids = new TraktMovieId
                {
                    Trakt = movie.Ids.Trakt,
                    Imdb = movie.Ids.Imdb.ToNullIfEmpty(),
                    Tmdb = movie.Ids.Tmdb
                },
                Title = movie.Title,
                Year = movie.Year,
                RatedAt = DateTime.UtcNow.ToISO8601()
            };

            int? prevRating = movie.UserRating();
            int newRating = 0;

            newRating = GUIUtils.ShowRateDialog<TraktSyncMovieRated>(rateObject);
            if (newRating == -1) return false;

            // If previous rating not equal to current rating then
            // update skin properties to reflect changes
            if (prevRating == newRating)
                return false;

            if (prevRating == null || prevRating == 0)
            {
                // add to ratings
                TraktCache.AddMovieToRatings(movie, newRating);
                movie.Votes++;
            }
            else if (newRating == 0)
            {
                // remove from ratings
                TraktCache.RemoveMovieFromRatings(movie);
                movie.Votes--;
            }
            else
            {
                // rating changed, remove then add
                TraktCache.RemoveMovieFromRatings(movie);
                TraktCache.AddMovieToRatings(movie, newRating);
            }

            // update ratings until next online update
            // if we have the ratings distribution we could calculate correctly
            if (movie.Votes == 0)
            {
                movie.Rating = 0;
            }
            else if (movie.Votes == 1 && newRating > 0)
            {
                movie.Rating = newRating;
            }

            return true;
        }
Пример #7
0
        public static bool ShowTraktExtMovieMenu(string title, string year, string imdbid, bool isWatched, string fanart, SearchPeople people, bool showAll)
        {
            var dlg = (IDialogbox)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU);
            dlg.Reset();
            dlg.SetHeading(GUIUtils.PluginName());

            GUIListItem pItem = new GUIListItem(Translation.Comments);
            dlg.Add(pItem);
            pItem.ItemId = (int)TraktMenuItems.Shouts;

            pItem = new GUIListItem(Translation.Rate);
            dlg.Add(pItem);
            pItem.ItemId = (int)TraktMenuItems.Rate;

            pItem = new GUIListItem(Translation.RelatedMovies);
            dlg.Add(pItem);
            pItem.ItemId = (int)TraktMenuItems.Related;

            pItem = new GUIListItem(Translation.AddToWatchList);
            dlg.Add(pItem);
            pItem.ItemId = (int)TraktMenuItems.AddToWatchList;

            pItem = new GUIListItem(Translation.AddToList);
            dlg.Add(pItem);
            pItem.ItemId = (int)TraktMenuItems.AddToCustomList;

            pItem = new GUIListItem(Translation.Cast);
            dlg.Add(pItem);
            pItem.ItemId = (int)TraktMenuItems.Cast;

            pItem = new GUIListItem(Translation.Crew);
            dlg.Add(pItem);
            pItem.ItemId = (int)TraktMenuItems.Crew;

            // Show Search By...
            if (people != null && people.Count != 0)
            {
                pItem = new GUIListItem(Translation.SearchBy + "...");
                dlg.Add(pItem);
                pItem.ItemId = (int)TraktMenuItems.SearchBy;
            }

            // also show non-context sensitive items related to movies
            if (showAll)
            {
                // might want to check your recently watched, stats etc
                pItem = new GUIListItem(Translation.UserProfile);
                dlg.Add(pItem);
                pItem.ItemId = (int)TraktMenuItems.UserProfile;

                pItem = new GUIListItem(Translation.Network);
                dlg.Add(pItem);
                pItem.ItemId = (int)TraktMenuItems.Network;

                pItem = new GUIListItem(Translation.Recommendations);
                dlg.Add(pItem);
                pItem.ItemId = (int)TraktMenuItems.Recommendations;

                pItem = new GUIListItem(Translation.Trending);
                dlg.Add(pItem);
                pItem.ItemId = (int)TraktMenuItems.Trending;

                pItem = new GUIListItem(Translation.Popular);
                dlg.Add(pItem);
                pItem.ItemId = (int)TraktMenuItems.Popular;

                pItem = new GUIListItem(Translation.Anticipated);
                dlg.Add(pItem);
                pItem.ItemId = (int)TraktMenuItems.Anticipated;

                pItem = new GUIListItem(Translation.WatchList);
                dlg.Add(pItem);
                pItem.ItemId = (int)TraktMenuItems.WatchList;

                pItem = new GUIListItem(Translation.Lists);
                dlg.Add(pItem);
                pItem.ItemId = (int)TraktMenuItems.Lists;
            }

            // Show Context Menu
            dlg.DoModal(GUIWindowManager.ActiveWindow);
            if (dlg.SelectedId < 0) return false;

            switch (dlg.SelectedId)
            {
                case ((int)TraktMenuItems.Rate):
                    TraktLogger.Info("Displaying rate dialog for movie. Title = '{0}', Year = '{1}', IMDb ID = '{2}'", title, year.ToLogString(), imdbid.ToLogString());
                    var movie = new TraktSyncMovieRated
                        {
                            Ids = new TraktMovieId { Imdb = imdbid.ToNullIfEmpty() },
                            Title = title,
                            Year = year.ToNullableInt32()
                        };

                    int rating = GUIUtils.ShowRateDialog<TraktSyncMovieRated>(movie);

                    // update local databases
                    if (rating >= 0)
                    {
                        switch (GUIWindowManager.ActiveWindow)
                        {
                            case (int)ExternalPluginWindows.MovingPictures:
                                TraktHandlers.MovingPictures.SetUserRating(rating);
                                break;
                            case (int)ExternalPluginWindows.MyFilms:
                                TraktHandlers.MyFilmsHandler.SetUserRating(rating, title, year.ToNullableInt32(), imdbid.ToNullIfEmpty());
                                break;
                        }

                        if (rating == 0)
                            TraktCache.RemoveMovieFromRatings(movie);
                        else
                            TraktCache.AddMovieToRatings(movie, rating);
                    }
                    break;

                case ((int)TraktMenuItems.Shouts):
                    TraktLogger.Info("Displaying Shouts for movie. Title = '{0}', Year = '{1}', IMDb ID = '{2}'", title, year.ToLogString(), imdbid.ToLogString());
                    TraktHelper.ShowMovieShouts(imdbid, title, year, fanart);
                    break;

                case ((int)TraktMenuItems.Related):
                    TraktLogger.Info("Displaying Related Movies for. Title = '{0}', Year = '{1}', IMDb ID = '{2}'", title, year.ToLogString(), imdbid.ToLogString());
                    TraktHelper.ShowRelatedMovies(title, year, imdbid);
                    break;

                case ((int)TraktMenuItems.AddToWatchList):
                    TraktLogger.Info("Adding movie to Watchlist. Title = '{0}', Year = '{1}', IMDb ID = '{2}'", title, year.ToLogString(), imdbid.ToLogString());
                    TraktHelper.AddMovieToWatchList(title, year, imdbid, true);
                    break;

                case ((int)TraktMenuItems.AddToCustomList):
                    TraktLogger.Info("Adding movie to Custom List. Title = '{0}', Year = '{1}', IMDb ID = '{2}'", title, year.ToLogString(), imdbid.ToLogString());
                    TraktHelper.AddRemoveMovieInUserList(title, year, imdbid, false);
                    break;

                case ((int)TraktMenuItems.Cast):
                    TraktLogger.Info("Displaying Cast for movie. Title = '{0}', Year = '{1}', IMDb ID = '{2}'", title, year.ToLogString(), imdbid.ToLogString());
                    GUICreditsMovie.Movie = null;
                    GUICreditsMovie.Type = GUICreditsMovie.CreditType.Cast;
                    GUICreditsMovie.Fanart = fanart;
                    GUIWindowManager.ActivateWindow((int)TraktGUIWindows.CreditsMovie, imdbid);
                    break;

                    case ((int)TraktMenuItems.Crew):
                    TraktLogger.Info("Displaying Crew for movie. Title = '{0}', Year = '{1}', IMDb ID = '{2}'", title, year.ToLogString(), imdbid.ToLogString());
                    GUICreditsMovie.Movie = null;
                    GUICreditsMovie.Type = GUICreditsMovie.CreditType.Crew;
                    GUICreditsMovie.Fanart = fanart;
                    GUIWindowManager.ActivateWindow((int)TraktGUIWindows.CreditsMovie, imdbid);
                    break;

                case ((int)TraktMenuItems.SearchBy):
                    ShowSearchByMenu(people, title, fanart);
                    break;

                case ((int)TraktMenuItems.UserProfile):
                    GUIWindowManager.ActivateWindow((int)TraktGUIWindows.UserProfile);
                    break;

                case ((int)TraktMenuItems.Network):
                    GUIWindowManager.ActivateWindow((int)TraktGUIWindows.Network);
                    break;

                case ((int)TraktMenuItems.Recommendations):
                    GUIWindowManager.ActivateWindow((int)TraktGUIWindows.RecommendationsMovies);
                    break;

                case ((int)TraktMenuItems.Trending):
                    GUIWindowManager.ActivateWindow((int)TraktGUIWindows.TrendingMovies);
                    break;

                case ((int)TraktMenuItems.Popular):
                    GUIWindowManager.ActivateWindow((int)TraktGUIWindows.PopularMovies);
                    break;

                case ((int)TraktMenuItems.Anticipated):
                    GUIWindowManager.ActivateWindow((int)TraktGUIWindows.AnticipatedMovies);
                    break;

                case ((int)TraktMenuItems.WatchList):
                    GUIWindowManager.ActivateWindow((int)TraktGUIWindows.WatchedListMovies);
                    break;

                case ((int)TraktMenuItems.Lists):
                    GUIWindowManager.ActivateWindow((int)TraktGUIWindows.CustomLists);
                    break;
            }
            return true;
        }
Пример #8
0
        private void OnRateItem(MFMovie movie, string value)
        {
            TraktLogger.Info("Received rating event from MyFilms. Title = '{0}', Year = '{1}', IMDb ID = '{2}', TMDb ID = '{3}'", movie.Title, movie.Year, movie.IMDBNumber ?? "<empty>", movie.TMDBNumber ?? "<empty>");

            if (TraktSettings.AccountStatus != ConnectionState.Connected) return;

            // don't do anything if movie is blocked
            if (TraktSettings.BlockedFilenames.Contains(movie.File) || TraktSettings.BlockedFolders.Any(f => movie.File.ToLowerInvariant().Contains(f.ToLowerInvariant())))
            {
                TraktLogger.Info("Movie {0} is on the blocked list so we didn't update Trakt", movie.Title);
                return;
            }

            var rateThread = new Thread((o) =>
            {
                var tMovie = o as MFMovie;

                // My Films is a 100 point scale out of 10. Treat as decimal and then round off
                int rating = Convert.ToInt32(Math.Round(Convert.ToDecimal(value), MidpointRounding.AwayFromZero));

                var rateMovie = new TraktSyncMovieRated
                {
                    Ids = new TraktMovieId { Imdb = tMovie.IMDBNumber, Tmdb = tMovie.TMDBNumber.ToNullableInt32() },
                    Title = tMovie.Title,
                    Year = tMovie.Year,
                    Rating = rating,
                    RatedAt = DateTime.UtcNow.ToISO8601()
                };

                var response = TraktAPI.TraktAPI.AddMovieToRatings(rateMovie);

                TraktLogger.LogTraktResponse(response);

                if (response != null && response.NotFound != null && response.NotFound.Movies.Count == 0)
                {
                    // update local cache
                    if (rating > 0)
                    {
                        TraktCache.AddMovieToRatings(rateMovie, rating);
                    }
                }
            })
            {
                IsBackground = true,
                Name = "Rate"
            };

            rateThread.Start(movie);
        }
Пример #9
0
        /// <summary>
        /// Shows the Rate Movie Dialog after playback has ended
        /// </summary>
        /// <param name="movie">The movie being rated</param>
        private void ShowRateDialog(MFMovie movie)
        {
            if (!TraktSettings.ShowRateDialogOnWatched) return;     // not enabled
            if (movie.RatingUser > 0) return;                       // already rated

            TraktLogger.Debug("Showing rate dialog for movie. Title = '{0}', Year = '{1}', IMDb ID = '{2}', TMDb ID = '{3}'", movie.Title, movie.Year, movie.IMDBNumber ?? "<empty>", movie.TMDBNumber ?? "<empty>");

            var rateThread = new Thread((objMovie) =>
            {
                var movieToRate = objMovie as MFMovie;
                if (movieToRate == null) return;

                var rateObject = new TraktSyncMovieRated
                {
                    Ids = new TraktMovieId { Imdb = movieToRate.IMDBNumber.ToNullIfEmpty(), Tmdb = movie.TMDBNumber.ToNullableInt32() },
                    Title = movieToRate.Title,
                    Year = movieToRate.Year,
                    RatedAt = DateTime.UtcNow.ToISO8601()
                };

                // get the rating submitted to trakt.tv
                int rating = GUI.GUIUtils.ShowRateDialog<TraktSyncMovieRated>(rateObject);

                if (rating > 0)
                {
                    TraktLogger.Debug("Rating {0} ({1}) as {2}/10", movieToRate.Title, movie.Year, rating.ToString());
                    movieToRate.RatingUser = (float)rating;
                    movieToRate.Username = TraktSettings.Username;
                    movieToRate.Commit();

                    // update skin properties if movie is still selected
                    if (GUICommon.GetProperty("#myfilms.user.mastertitle.value").Equals(movieToRate.Title))
                    {
                        GUICommon.SetProperty("#myfilms.user.rating.value", movieToRate.RatingUser.ToString());
                    }

                    // add to cache
                    TraktCache.AddMovieToRatings(rateObject, rating);
                }
            })
            {
                Name = "Rate",
                IsBackground = true
            };

            rateThread.Start(movie);
        }
Пример #10
0
        /// <summary>
        /// Rate a single movie on trakt.tv
        /// </summary>
        public static TraktSyncResponse AddMovieToRatings(TraktSyncMovieRated movie)
        {
            var movies = new TraktSyncMoviesRated
            {
                Movies = new List<TraktSyncMovieRated>() { movie }
            };

            return AddMoviesToRatings(movies);
        }