/// <summary> /// Stops scrobbing an episode on trakt.tv /// </summary> /// <param name="watched">Determines if we should force watched on stop</param> internal static bool StopScrobbleEpisode(VideoInfo videoInfo, bool watched = false) { // get scrobble data to send to api var scrobbleData = CreateEpisodeScrobbleData(videoInfo); if (scrobbleData == null) { return(false); } // force watched if (watched && scrobbleData.Progress < 80) { scrobbleData.Progress = 100; } var response = TraktAPI.TraktAPI.StopEpisodeScrobble(scrobbleData); if (response != null && response.Show != null) { // add 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); } } return(TraktLogger.LogTraktResponse(response)); }
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; }
/// <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); } } }