예제 #1
0
        private void OnRateSeries(AnimeSeries series, string rateValue)
        {
            if (TraktSettings.AccountStatus != ConnectionState.Connected)
            {
                return;
            }

            TraktLogger.Info("Received rating event for series from my anime");

            Thread rateThread = new Thread(delegate()
            {
                TraktRateSeries seriesRateData = CreateSeriesRateData(series, rateValue);
                if (seriesRateData == null)
                {
                    return;
                }
                TraktRateResponse response = TraktAPI.TraktAPI.RateSeries(seriesRateData);

                // check for any error and notify
                TraktAPI.TraktAPI.LogTraktResponse(response);
            })
            {
                IsBackground = true,
                Name         = "Rate"
            };

            rateThread.Start();
        }
예제 #2
0
        public static void RateSeries(DBSeries series)
        {
            if (string.IsNullOrEmpty(TraktAPI.Username) || string.IsNullOrEmpty(TraktAPI.Password))
            {
                return;
            }

            new Thread(delegate()
            {
                TraktRateValue loveorhate = series[DBOnlineSeries.cMyRating] >= 7.0 ? TraktRateValue.love : TraktRateValue.hate;

                TraktRateSeries seriesData = new TraktRateSeries()
                {
                    Rating   = loveorhate.ToString(),
                    SeriesID = series[DBOnlineSeries.cID],
                    Year     = series.Year,
                    Title    = series[DBOnlineSeries.cOriginalName],
                    UserName = TraktAPI.Username,
                    Password = TraktAPI.Password,
                };

                TraktRateResponse response = TraktAPI.RateSeries(seriesData);

                // check for any error and notify
                CheckTraktErrorAndNotify(response, false);
            })
            {
                IsBackground = true,
                Name         = "Trakt Rate Series"
            }.Start();
        }
예제 #3
0
        /// <summary>
        /// Sends series rate data to Trakt
        /// </summary>
        /// <param name="episode">The Trakt rate data to Send</param>
        /// <returns>The response from Trakt</returns>
        public static TraktRateResponse SendRateSeries(TraktRateSeries series)
        {
            if (series == null)
            {
                return(null);
            }
            string response = Transmit(string.Format(TraktURIs.SENDRating, TraktItemType.show.ToString()), series.ToJSON());

            return(response.FromJSON <TraktRateResponse>());
        }
예제 #4
0
        public static TraktRateSeries CreateShowRateData(string title, string tvdb)
        {
            TraktRateSeries rateObject = new TraktRateSeries
            {
                Title    = title,
                SeriesID = tvdb,
                Rating   = TraktSettings.ShowAdvancedRatingsDialog ? "7" : "10",
                UserName = TraktSettings.Username,
                Password = TraktSettings.Password
            };

            return(rateObject);
        }
예제 #5
0
        private TraktRateSeries CreateSeriesRateData(AnimeSeries series, string rateValue)
        {
            if (series == null || series.TvDB_ID == null)
            {
                return(null);
            }

            string rating = Convert.ToInt32(rateValue).ToString();

            TraktRateSeries seriesData = new TraktRateSeries()
            {
                Rating   = rating,
                SeriesID = series.TvDB_ID.ToString(),
                Year     = GetStartYear(series),
                Title    = series.TvDB_Name,
                UserName = TraktSettings.Username,
                Password = TraktSettings.Password,
            };

            TraktLogger.Info("Rating '{0}' as '{1}'", series.TvDB_Name, rating.ToString());
            return(seriesData);
        }
예제 #6
0
        /// <summary>
        /// Shows a Trakt Rate Dialog (Love/Hate) or 10-Heart based on settings
        /// </summary>
        /// <param name="rateObject">Type of object being rated</param>
        public static string ShowRateDialog <T>(T rateObject)
        {
            if (GUIGraphicsContext.form.InvokeRequired)
            {
                ShowRateDialogDelegate <T> d = ShowRateDialog <T>;
                return((string)GUIGraphicsContext.form.Invoke(d, rateObject));
            }

            TraktRateValue currentRating = TraktRateValue.unrate;

            GUIRateDialog ratingDlg = (GUIRateDialog)GUIWindowManager.GetWindow(GUIRateDialog.ID);

            ratingDlg.Reset();

            ratingDlg.SetHeading(Translation.RateHeading);

            // show simple love/hate icons or 10-heart icons
            ratingDlg.ShowAdvancedRatings = TraktSettings.ShowAdvancedRatingsDialog;

            // if item is not rated, it will default to love
            if (rateObject is TraktRateEpisode)
            {
                TraktRateEpisode item = rateObject as TraktRateEpisode;
                ratingDlg.SetLine(1, string.Format("{0} - {1}x{2}", item.Title, item.Season, item.Episode));
                if (ratingDlg.ShowAdvancedRatings)
                {
                    ratingDlg.Rated = item.Rating == "0" || !item.Rating.IsNumber() ? TraktRateValue.seven : (TraktRateValue)Convert.ToInt32(item.Rating);
                }
                else
                {
                    ratingDlg.Rated = item.Rating == "0" || !item.Rating.IsNumber() ? TraktRateValue.ten : (TraktRateValue)Convert.ToInt32(item.Rating);
                }
            }
            else if (rateObject is TraktRateSeries)
            {
                TraktRateSeries item = rateObject as TraktRateSeries;
                ratingDlg.SetLine(1, item.Title);
                if (ratingDlg.ShowAdvancedRatings)
                {
                    ratingDlg.Rated = item.Rating == "0" || !item.Rating.IsNumber() ? TraktRateValue.seven : (TraktRateValue)Convert.ToInt32(item.Rating);
                }
                else
                {
                    ratingDlg.Rated = item.Rating == "0" || !item.Rating.IsNumber() ? TraktRateValue.ten : (TraktRateValue)Convert.ToInt32(item.Rating);
                }
            }
            else
            {
                TraktRateMovie item = rateObject as TraktRateMovie;
                ratingDlg.SetLine(1, item.Title);
                if (ratingDlg.ShowAdvancedRatings)
                {
                    ratingDlg.Rated = item.Rating == "0" || !item.Rating.IsNumber() ? TraktRateValue.seven : (TraktRateValue)Convert.ToInt32(item.Rating);
                }
                else
                {
                    ratingDlg.Rated = item.Rating == "0" || !item.Rating.IsNumber() ? TraktRateValue.ten : (TraktRateValue)Convert.ToInt32(item.Rating);
                }
            }

            // show dialog
            ratingDlg.DoModal(ratingDlg.GetID);

            if (!ratingDlg.IsSubmitted)
            {
                return("-1");
            }

            if (rateObject is TraktRateEpisode)
            {
                TraktRateEpisode item = rateObject as TraktRateEpisode;
                currentRating = ratingDlg.Rated;
                item.Rating   = (int)currentRating != 0 ? ((int)currentRating).ToString() : "unrate";
                Thread rateThread = new Thread(delegate(object obj)
                {
                    TraktRateResponse response = TraktAPI.TraktAPI.RateEpisode(item);
                    TraktLogger.LogTraktResponse(response);
                })
                {
                    IsBackground = true,
                    Name         = "Rate"
                };
                rateThread.Start(item);
            }
            else if (rateObject is TraktRateSeries)
            {
                TraktRateSeries item = rateObject as TraktRateSeries;
                currentRating = ratingDlg.Rated;
                item.Rating   = (int)currentRating != 0 ? ((int)currentRating).ToString() : "unrate";
                Thread rateThread = new Thread(delegate(object obj)
                {
                    TraktRateResponse response = TraktAPI.TraktAPI.RateSeries(item);
                    TraktLogger.LogTraktResponse(response);
                })
                {
                    IsBackground = true,
                    Name         = "Rate"
                };
                rateThread.Start(item);
            }
            else
            {
                TraktRateMovie item = rateObject as TraktRateMovie;
                currentRating = ratingDlg.Rated;
                item.Rating   = (int)currentRating != 0 ? ((int)currentRating).ToString() : "unrate";
                Thread rateThread = new Thread(delegate(object obj)
                {
                    TraktRateResponse response = TraktAPI.TraktAPI.RateMovie(item);
                    TraktLogger.LogTraktResponse(response);
                })
                {
                    IsBackground = true,
                    Name         = "Rate"
                };
                rateThread.Start(item);
            }

            // return new rating (0 - 10)
            // old love / hate enum values are deprecated
            // if using basic ratings 1 = hate and 10 = love
            // 0 is unrate
            return(((int)currentRating).ToString());
        }