/// <summary>
        /// Stops scrobbing a movie on trakt.tv
        /// </summary>
        /// <param name="watched">Determines if we should force watched on stop</param>
        internal static bool StopScrobbleMovie(VideoInfo videoInfo, bool watched = false)
        {
            // get scrobble data to send to api
            var scrobbleData = CreateMovieScrobbleData(videoInfo);

            if (scrobbleData == null)
            {
                return(false);
            }

            // force watched
            if (watched && scrobbleData.Progress < 80)
            {
                scrobbleData.Progress = 100;
            }

            var response = TraktAPI.TraktAPI.StopMovieScrobble(scrobbleData);

            if (response != null && response.Movie != null)
            {
                // add to cache
                if (response.Action == "scrobble")
                {
                    TraktCache.AddMovieToWatchHistory(response.Movie);
                }
                else if (response.Action == "pause")
                {
                    TraktCache.AddMovieToPausedData(response.Movie, response.Progress);
                }
            }

            return(TraktLogger.LogTraktResponse(response));
        }
Пример #2
0
        public void StopScrobble()
        {
            if (CurrentMovie == null)
            {
                return;
            }

            var scrobbleData = CreateScrobbleData(CurrentMovie);

            // check if movie is considered 'watched'
            if (scrobbleData.Progress >= WatchedPercent)
            {
                ShowRateDialog(CurrentMovie);
            }

            var scrobbleMovie = new Thread((objScrobble) =>
            {
                var tScrobbleData = objScrobble as TraktScrobbleMovie;
                if (tScrobbleData == null)
                {
                    return;
                }

                TraktScrobbleResponse response = null;

                if (tScrobbleData.Progress >= WatchedPercent)
                {
                    TraktLogger.Info("Sending 'stop' scrobble of movie to trakt.tv. Title = '{0}', Year = '{1}', IMDb ID = '{2}'", tScrobbleData.Movie.Title, tScrobbleData.Movie.Year, tScrobbleData.Movie.Ids.Imdb ?? "<empty>");
                    response = TraktAPI.TraktAPI.StopMovieScrobble(tScrobbleData);

                    if (response != null && response.Movie != null && response.Action == "scrobble")
                    {
                        // add to cache
                        TraktCache.AddMovieToWatchHistory(response.Movie);
                    }
                }
                else
                {
                    TraktLogger.Info("Sending 'pause' scrobble of movie to trakt.tv. Title = '{0}', Year = '{1}', IMDb ID = '{2}'", tScrobbleData.Movie.Title, tScrobbleData.Movie.Year, tScrobbleData.Movie.Ids.Imdb ?? "<empty>");
                    response = TraktAPI.TraktAPI.PauseMovieScrobble(tScrobbleData);

                    if (response != null && response.Movie != null && response.Action == "pause")
                    {
                        // add to cache
                        TraktCache.AddMovieToPausedData(response.Movie, response.Progress);
                    }
                }

                TraktLogger.LogTraktResponse(response);
            })
            {
                IsBackground = true,
                Name         = "Scrobble"
            };

            scrobbleMovie.Start(scrobbleData);

            CurrentMovie = null;
        }
Пример #3
0
        public void StopScrobble()
        {
            if (CurrentVideo != null)
            {
                // onlinevideos can split videos into multiple parts
                // we only need to handle a pause event if the progress is less than 80%

                double position = g_Player.CurrentPosition;
                double duration = g_Player.Duration;

                if (duration != 0)
                {
                    double progress = position / duration;
                    if (progress < 0.8)
                    {
                        // send pause event to trakt.tv
                        TraktLogger.Info("Playback stopped in OnlineVideos but video is not considered watched, Progress = '{0}%', Duration = '{1}', Current Position = '{2}'", Math.Round(progress * 100, 2), g_Player.Duration, g_Player.CurrentPosition);

                        if (CurrentVideo.VideoKind == VideoKind.TvSeries)
                        {
                            var scrobbleEpisodeData = CreateEpisodeScrobbleData(CurrentVideo, Math.Round(progress * 100, 2));

                            var scrobbleThread = new Thread((objInfo) =>
                            {
                                var response = TraktAPI.TraktAPI.PauseEpisodeScrobble(objInfo as TraktScrobbleEpisode);
                                TraktLogger.LogTraktResponse(response);

                                if (response != null && response.Code == 0)
                                {
                                    //  add episode paused to cache
                                    if (response.Action == "pause")
                                    {
                                        TraktCache.AddEpisodeToPausedData(response.Show, response.Episode, response.Progress);
                                    }
                                }
                            })
                            {
                                IsBackground = true,
                                Name         = "Scrobble"
                            };

                            scrobbleThread.Start(scrobbleEpisodeData);
                        }
                        else
                        {
                            var scrobbleMovieData = CreateMovieScrobbleData(CurrentVideo, Math.Round(progress * 100, 2));

                            var scrobbleThread = new Thread((objInfo) =>
                            {
                                var response = TraktAPI.TraktAPI.PauseMovieScrobble(objInfo as TraktScrobbleMovie);
                                TraktLogger.LogTraktResponse(response);

                                if (response != null && response.Code == 0)
                                {
                                    //  add movie paused to cache
                                    if (response.Action == "pause")
                                    {
                                        TraktCache.AddMovieToPausedData(response.Movie, response.Progress);
                                    }
                                }
                            })
                            {
                                IsBackground = true,
                                Name         = "Scrobble"
                            };

                            scrobbleThread.Start(scrobbleMovieData);
                        }
                    }
                    else
                    {
                        // either completely watched or finished watching part of a mult-part file
                        TraktLogger.Info("Playback stopped in OnlineVideos, awaiting next playback event.");
                    }
                }

                CurrentVideo = null;
            }

            return;
        }
Пример #4
0
        /// <summary>
        /// Event gets triggered on playback events in OnlineVideos
        /// The TrackVideoPlayback event gets fired on Playback Start, Playback Ended (100%)
        /// and Playback Stopped (if percentage watched is greater than 0.8).
        /// </summary>
        private void TrackVideoPlayback(ITrackingInfo info, double percentPlayed)
        {
            CurrentVideo = null;

            TraktLogger.Debug("Received Video Playback event from OnlineVideos");

            if (info.VideoKind == VideoKind.Movie || info.VideoKind == VideoKind.TvSeries)
            {
                // Started Playback
                if (percentPlayed < 0.8)
                {
                    CurrentVideo = info;

                    // start scrobble
                    if (info.VideoKind == VideoKind.TvSeries)
                    {
                        var scrobbleEpisodeData = CreateEpisodeScrobbleData(info, Math.Round(percentPlayed * 100, 2));

                        var scrobbleThread = new Thread((objInfo) =>
                        {
                            var response = TraktAPI.TraktAPI.StartEpisodeScrobble(objInfo as TraktScrobbleEpisode);
                            TraktLogger.LogTraktResponse(response);
                        })
                        {
                            IsBackground = true,
                            Name         = "Scrobble"
                        };

                        scrobbleThread.Start(scrobbleEpisodeData);
                    }
                    else
                    {
                        var scrobbleMovieData = CreateMovieScrobbleData(info, Math.Round(percentPlayed * 100, 2));

                        var scrobbleThread = new Thread((objInfo) =>
                        {
                            var response = TraktAPI.TraktAPI.StartMovieScrobble(objInfo as TraktScrobbleMovie);
                            TraktLogger.LogTraktResponse(response);
                        })
                        {
                            IsBackground = true,
                            Name         = "Scrobble"
                        };

                        scrobbleThread.Start(scrobbleMovieData);
                    }

                    return;
                }

                // Playback Ended or Stopped and Considered Watched
                // TrackVideoPlayback event only gets fired on Stopped if > 80% watched
                if (info.VideoKind == VideoKind.TvSeries)
                {
                    TraktLogger.Info("Playback of episode has ended and is considered watched. Progress = '{0}%', Title = '{1} - {2}x{3}', Year = '{4}', IMDb ID = '{5}', TMDb ID = '{6}', TVDb ID = '{7}'", Math.Round(percentPlayed * 100, 2), info.Title, info.Season, info.Episode, info.Year == 0 ? "<empty>" : info.Year.ToString(), info.ID_IMDB.ToLogString(), info.ID_TMDB.ToLogString(), info.ID_TVDB.ToLogString());
                }
                else
                {
                    TraktLogger.Info("Playback of movie has ended and is considered watched. Progress = '{0}%', Title = '{1}', Year = '{2}', IMDb ID = '{3}', TMDb ID = '{4}'", Math.Round(percentPlayed * 100, 2), info.Title, info.Year, info.ID_IMDB.ToLogString(), info.ID_TMDB.ToLogString());
                }

                // Show Rating Dialog after watched
                ShowRateDialog(info);

                // stop scrobble
                if (info.VideoKind == VideoKind.TvSeries)
                {
                    var scrobbleEpisodeData = CreateEpisodeScrobbleData(info, Math.Round(percentPlayed * 100, 2));

                    var scrobbleThread = new Thread((objInfo) =>
                    {
                        var threadParam = objInfo as TraktScrobbleEpisode;

                        var response = TraktAPI.TraktAPI.StopEpisodeScrobble(threadParam);
                        TraktLogger.LogTraktResponse(response);

                        if (response != null && response.Code == 0)
                        {
                            //  add episode to cache
                            if (response.Action == "scrobble")
                            {
                                TraktCache.AddEpisodeToWatchHistory(response.Show, response.Episode);
                            }
                            else if (response.Action == "pause")
                            {
                                TraktCache.AddEpisodeToPausedData(response.Show, response.Episode, response.Progress);
                            }
                        }
                    })
                    {
                        IsBackground = true,
                        Name         = "Scrobble"
                    };

                    scrobbleThread.Start(scrobbleEpisodeData);
                }
                else
                {
                    var scrobbleMovieData = CreateMovieScrobbleData(info, Math.Round(percentPlayed * 100, 2));

                    var scrobbleThread = new Thread((objInfo) =>
                    {
                        var threadParam = objInfo as TraktScrobbleMovie;

                        var response = TraktAPI.TraktAPI.StopMovieScrobble(threadParam);
                        TraktLogger.LogTraktResponse(response);

                        if (response != null && response.Code == 0)
                        {
                            // add movie to cache
                            if (response.Action == "scrobble")
                            {
                                TraktCache.AddMovieToWatchHistory(response.Movie);
                            }
                            else if (response.Action == "pause")
                            {
                                TraktCache.AddMovieToPausedData(response.Movie, response.Progress);
                            }
                        }
                    })
                    {
                        IsBackground = true,
                        Name         = "Scrobble"
                    };

                    scrobbleThread.Start(scrobbleMovieData);
                }
            }
        }