Пример #1
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);
        }
        /// <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);
        }
Пример #3
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);
        }