private TraktMovieScrobble CreateMovieScrobbleData(ITrackingInfo info) { try { // create scrobble data TraktMovieScrobble scrobbleData = new TraktMovieScrobble { Title = info.Title, Year = info.Year > 1900 ? info.Year.ToString() : null, IMDBID = info.ID_IMDB, TMDBID = info.ID_TMDB, PluginVersion = TraktSettings.Version, MediaCenter = "Mediaportal", MediaCenterVersion = Assembly.GetEntryAssembly().GetName().Version.ToString(), MediaCenterBuildDate = String.Empty, UserName = TraktSettings.Username, Password = TraktSettings.Password }; return(scrobbleData); } catch (Exception e) { TraktLogger.Error("Error creating scrobble data: {0}", e.Message); return(null); } }
// alternate way of checking: //private const int TraktWindowId = 87258; //private static bool traktLoaded = GUIWindowManager.GetWindow(TraktWindowId) != null; public static bool IsWatched(ITrackingInfo trackingInfo) { if (traktPresent && trackingInfo != null) { try { switch (trackingInfo.VideoKind) { case VideoKind.TvSeries: return SafeIsWatchedSeriesSimple(trackingInfo); case VideoKind.Movie: return SafeIsWatchedMovie(trackingInfo); case VideoKind.Other: break; default: { OnlineVideos.Log.Error("{0} not supported for Trakt", trackingInfo.VideoKind); break; } } } catch (Exception e) { OnlineVideos.Log.Error("Exception getting watched status: {0}", e.Message); } } return false; }
private TraktScrobbleEpisode CreateEpisodeScrobbleData(ITrackingInfo info, double progress = 0) { var scrobbleData = new TraktScrobbleEpisode { Episode = new TraktEpisode { Ids = new TraktEpisodeId(), Number = (int)info.Episode, Season = (int)info.Season }, Show = new TraktShow { Ids = new TraktShowId { Imdb = info.ID_IMDB, Tmdb = info.ID_TMDB.ToNullableInt32(), Tvdb = info.ID_TVDB.ToNullableInt32() }, Title = info.Title, Year = info.Year > 0 ? (int?)info.Year : null }, AppDate = TraktSettings.BuildDate, AppVersion = TraktSettings.Version, Progress = progress }; return(scrobbleData); }
// alternate way of checking: //private const int TraktWindowId = 87258; //private static bool traktLoaded = GUIWindowManager.GetWindow(TraktWindowId) != null; public static bool IsWatched(ITrackingInfo trackingInfo) { if (traktPresent && trackingInfo != null) { try { switch (trackingInfo.VideoKind) { case VideoKind.TvSeries: return(SafeIsWatchedSeriesSimple(trackingInfo)); case VideoKind.Movie: return(SafeIsWatchedMovie(trackingInfo)); case VideoKind.Other: break; default: { OnlineVideos.Log.Error("{0} not supported for Trakt", trackingInfo.VideoKind); break; } } } catch (Exception e) { OnlineVideos.Log.Error("Exception getting watched status: {0}", e.Message); } } return(false); }
/// <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; // not enabled } TraktLogger.Debug("Showing rate dialog for '{0}'", videoInfo.Title); new Thread((o) => { ITrackingInfo itemToRate = o as ITrackingInfo; if (itemToRate == null) { return; } int rating = 0; if (itemToRate.VideoKind == VideoKind.TvSeries) { TraktRateEpisode rateObject = new TraktRateEpisode { SeriesID = itemToRate.ID_TVDB, Title = itemToRate.Title, Year = itemToRate.Year > 1900 ? itemToRate.Year.ToString() : null, Episode = itemToRate.Episode.ToString(), Season = itemToRate.Season.ToString(), UserName = TraktSettings.Username, Password = TraktSettings.Password }; // get the rating submitted to trakt rating = int.Parse(GUIUtils.ShowRateDialog <TraktRateEpisode>(rateObject)); } else if (itemToRate.VideoKind == VideoKind.Movie) { TraktRateMovie rateObject = new TraktRateMovie { IMDBID = itemToRate.ID_IMDB, TMDBID = itemToRate.ID_TMDB, Title = itemToRate.Title, Year = itemToRate.Year > 1900 ? itemToRate.Year.ToString() : null, UserName = TraktSettings.Username, Password = TraktSettings.Password }; // get the rating submitted to trakt rating = int.Parse(GUIUtils.ShowRateDialog <TraktRateMovie>(rateObject)); } if (rating > 0) { TraktLogger.Debug("Rating {0} as {1}/10", itemToRate.Title, rating.ToString()); // note: no user rating field to set } }) { Name = "Rate", IsBackground = true }.Start(videoInfo); }
public void StopScrobble() { currentVideo = null; if (TraktTimer != null) { TraktTimer.Dispose(); } }
private void setSubtitleText(VideoInfo video, ITrackingInfo it) { ISubtitleDownloader sd = (ISubtitleDownloader)sdObject; List <Subtitle> results; if (it.VideoKind == VideoKind.Movie) { SearchQuery qu = new SearchQuery(it.Title); qu.Year = (int)it.Year; qu.LanguageCodes = languagePrios.Keys.ToArray(); results = sd.SearchSubtitles(qu); } else { EpisodeSearchQuery qu = new EpisodeSearchQuery(it.Title, (int)it.Season, (int)it.Episode, null); qu.LanguageCodes = languagePrios.Keys.ToArray(); results = sd.SearchSubtitles(qu); } Log.Debug("Subtitles found:" + results.Count.ToString()); if (results.Count > 0) { int minValue = int.MaxValue; Subtitle minSub = results[0]; foreach (Subtitle sub in results) { Log.Debug("Subtitle " + sub.ProgramName + " " + sub.LanguageCode); if (languagePrios.ContainsKey(sub.LanguageCode)) { int prio = languagePrios[sub.LanguageCode]; if (prio < minValue) { minValue = prio; minSub = sub; } } } List <FileInfo> subtitleFiles = sd.SaveSubtitle(minSub); if (subtitleFiles.Count > 0) { string s = File.ReadAllText(subtitleFiles[0].FullName, System.Text.Encoding.UTF8); if (s.IndexOf('�') != -1) { video.SubtitleText = File.ReadAllText(subtitleFiles[0].FullName, System.Text.Encoding.Default); } else { video.SubtitleText = s; } } foreach (FileInfo fi in subtitleFiles) { fi.Delete(); } } }
private void SafeSetSubtitleText(VideoInfo video, ITrackingInfo trackingInfo) { try { setSubtitleText(video, trackingInfo); } catch (Exception e) { Log.Warn("SubtitleDownloader: " + e.ToString()); } }
public override string GetFileNameForDownload(VideoInfo video, Category category, string url) { //Extension always .f4m ITrackingInfo ti = GetTrackingInfo(video); if (ti != null && ti.VideoKind == VideoKind.TvSeries) { return(Helpers.FileUtils.GetSaveFilename(ti.Title) + ".S" + (ti.Season > 9 ? ti.Season.ToString() : "0" + ti.Season.ToString()) + "E" + (ti.Episode > 9 ? ti.Episode.ToString() : "0" + ti.Episode.ToString()) + ".f4m"); } return(Helpers.FileUtils.GetSaveFilename(video.Title) + ".f4m"); }
// keep all references to TraktPlugin in separate methods, so that methods that are called from GUIOnlineVideos don't throw an ecxeption it Trakt isn't loaded /* for the time being: disabled because of too much requests to trakt in some cases private static Dictionary<string, int> seriesTitleCache = new Dictionary<string, int>(); private static bool SafeIsWatchedSeriesFuzzy(ITrackingInfo trackingInfo) { string cacheKey = trackingInfo.Title.ToLowerInvariant(); if (!seriesTitleCache.ContainsKey(cacheKey)) { var shows = TraktAPI.SearchShows(cacheKey, 1); var first = shows.FirstOrDefault(); if (first != null && first.Show.Ids.Trakt.HasValue) seriesTitleCache.Add(cacheKey, first.Show.Ids.Trakt.Value); } if (seriesTitleCache.ContainsKey(cacheKey)) { int id = seriesTitleCache[cacheKey]; { var watchedEpisodes = TraktCache.GetWatchedEpisodesFromTrakt(true); foreach (var episode in watchedEpisodes) { if (id == episode.ShowId && episode.Season == trackingInfo.Season && episode.Number == trackingInfo.Episode) return true; } }; }; return false; } */ private static bool SafeIsWatchedSeriesSimple(ITrackingInfo trackingInfo) { var watchedEpisodes = TraktCache.GetWatchedEpisodesFromTrakt(true); if (watchedEpisodes != null) foreach (var episode in watchedEpisodes) { if (episode.ShowTitle.ToLowerInvariant() == trackingInfo.Title.ToLowerInvariant() && episode.Season == trackingInfo.Season && episode.Number == trackingInfo.Episode) return true; } return false; }
public void SetSubtitleText(VideoInfo video, GetTrackingInfo getTrackingInfo, out Thread thread) { thread = null; if (tryLoadSubtitles) { ITrackingInfo it = getTrackingInfo(video); if (sdObject != null && it != null && String.IsNullOrEmpty(video.SubtitleText)) { thread = new Thread( delegate() { SafeSetSubtitleText(video, it); }); thread.Start(); } } }
// keep all references to TraktPlugin in separate methods, so that methods that are called from GUIOnlineVideos don't throw an ecxeption it Trakt isn't loaded /* * for the time being: disabled because of too much requests to trakt in some cases * private static Dictionary<string, int> seriesTitleCache = new Dictionary<string, int>(); * private static bool SafeIsWatchedSeriesFuzzy(ITrackingInfo trackingInfo) * { * string cacheKey = trackingInfo.Title.ToLowerInvariant(); * if (!seriesTitleCache.ContainsKey(cacheKey)) * { * var shows = TraktAPI.SearchShows(cacheKey, 1); * var first = shows.FirstOrDefault(); * if (first != null && first.Show.Ids.Trakt.HasValue) * seriesTitleCache.Add(cacheKey, first.Show.Ids.Trakt.Value); * } * * if (seriesTitleCache.ContainsKey(cacheKey)) * { * int id = seriesTitleCache[cacheKey]; * { * var watchedEpisodes = TraktCache.GetWatchedEpisodesFromTrakt(true); * foreach (var episode in watchedEpisodes) * { * if (id == episode.ShowId && episode.Season == trackingInfo.Season && episode.Number == trackingInfo.Episode) * return true; * } * }; * }; * return false; * } */ private static bool SafeIsWatchedSeriesSimple(ITrackingInfo trackingInfo) { var watchedEpisodes = TraktCache.GetWatchedEpisodesFromTrakt(true); if (watchedEpisodes != null) { foreach (var episode in watchedEpisodes) { if (episode.ShowTitle.ToLowerInvariant() == trackingInfo.Title.ToLowerInvariant() && episode.Season == trackingInfo.Season && episode.Number == trackingInfo.Episode) { return(true); } } } return(false); }
private static bool SafeIsWatchedMovie(ITrackingInfo trackingInfo) { var watchedMovies = TraktCache.GetWatchedMoviesFromTrakt(true); if (watchedMovies != null) { foreach (var movies in watchedMovies) { if ((trackingInfo.Year == 0 || trackingInfo.Year == movies.Movie.Year) && (String.IsNullOrEmpty(trackingInfo.ID_IMDB) || String.IsNullOrEmpty(movies.Movie.Ids.Imdb) || trackingInfo.ID_IMDB == movies.Movie.Ids.Imdb) && trackingInfo.Title.ToLowerInvariant() == movies.Movie.Title.ToLowerInvariant()) { return(true); } } } return(false); }
private TraktScrobbleMovie CreateMovieScrobbleData(ITrackingInfo info, double progress = 0) { var scrobbleData = new TraktScrobbleMovie { Movie = new TraktMovie { Ids = new TraktMovieId { Imdb = info.ID_IMDB, Tmdb = info.ID_TMDB.ToNullableInt32() }, Title = info.Title, Year = (int)info.Year }, AppDate = TraktSettings.BuildDate, AppVersion = TraktSettings.Version, Progress = progress }; return(scrobbleData); }
private static bool SafeIsWatchedMovie(ITrackingInfo trackingInfo) { var watchedMovies = TraktCache.GetWatchedMoviesFromTrakt(true); if (watchedMovies != null) { foreach (var movies in watchedMovies) { if (!String.IsNullOrEmpty(trackingInfo.ID_IMDB) && trackingInfo.ID_IMDB == movies.Movie.Ids.Imdb) { //if imdb is filled in and equal then match is found regardless of the rest of the properties return(true); } if ((trackingInfo.Year == 0 || trackingInfo.Year == movies.Movie.Year) && (String.IsNullOrEmpty(trackingInfo.ID_IMDB) || String.IsNullOrEmpty(movies.Movie.Ids.Imdb) || trackingInfo.ID_IMDB == movies.Movie.Ids.Imdb) && trackingInfo.Title.ToLowerInvariant() == movies.Movie.Title.ToLowerInvariant()) { return(true); } } } return(false); }
private TraktMovieScrobble CreateMovieScrobbleData(ITrackingInfo info) { try { // create scrobble data TraktMovieScrobble scrobbleData = new TraktMovieScrobble { Title = info.Title, Year = info.Year > 1900 ? info.Year.ToString() : null, IMDBID = info.ID_IMDB, TMDBID = info.ID_TMDB, PluginVersion = TraktSettings.Version, MediaCenter = "Mediaportal", MediaCenterVersion = Assembly.GetEntryAssembly().GetName().Version.ToString(), MediaCenterBuildDate = String.Empty, UserName = TraktSettings.Username, Password = TraktSettings.Password }; return scrobbleData; } catch (Exception e) { TraktLogger.Error("Error creating scrobble data: {0}", e.Message); return null; } }
public bool Scrobble(string filename) { if (currentVideo == null) { return(false); } if (currentVideo.VideoKind == VideoKind.TvSeries) { TraktLogger.Info("Detected tv series '{0} - {1}x{2}' playing in OnlineVideos", currentVideo.Title, currentVideo.Season.ToString(), currentVideo.Episode.ToString()); } else { TraktLogger.Info("Detected movie '{0}' playing in OnlineVideos", currentVideo.Title); } #region scrobble timer TraktTimer = new Timer(new TimerCallback((stateInfo) => { Thread.CurrentThread.Name = "Scrobble"; ITrackingInfo videoInfo = stateInfo as ITrackingInfo; // get duration in minutes double duration = g_Player.Duration / 60; double progress = 0.0; // get current progress of player if (g_Player.Duration > 0.0) { progress = (g_Player.CurrentPosition / g_Player.Duration) * 100.0; } TraktEpisodeScrobble scrobbleEpisodeData = null; TraktMovieScrobble scrobbleMovieData = null; TraktResponse response = null; if (videoInfo.VideoKind == VideoKind.TvSeries) { scrobbleEpisodeData = CreateEpisodeScrobbleData(videoInfo); if (scrobbleEpisodeData == null) { return; } scrobbleEpisodeData.Duration = Convert.ToInt32(duration).ToString(); scrobbleEpisodeData.Progress = Convert.ToInt32(progress).ToString(); response = TraktAPI.TraktAPI.ScrobbleEpisodeState(scrobbleEpisodeData, TraktScrobbleStates.watching); } else { scrobbleMovieData = CreateMovieScrobbleData(videoInfo); if (scrobbleMovieData == null) { return; } scrobbleMovieData.Duration = Convert.ToInt32(duration).ToString(); scrobbleMovieData.Progress = Convert.ToInt32(progress).ToString(); response = TraktAPI.TraktAPI.ScrobbleMovieState(scrobbleMovieData, TraktScrobbleStates.watching); } TraktAPI.TraktAPI.LogTraktResponse(response); }), currentVideo, 3000, 900000); #endregion return(true); }
/// <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); }
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 /// and Playback Stopped (if percentage watched is greater than 0.8). /// </summary> private void TrackVideoPlayback(ITrackingInfo info, double percentPlayed) { if (info.VideoKind == VideoKind.Movie || info.VideoKind == VideoKind.TvSeries) { // Started Playback // Bug in OnlineVideos 0.31 reports incorrect percentage if (percentPlayed > 1.0) { percentPlayed = 1 / percentPlayed; } if (percentPlayed < 0.8) { currentVideo = info; return; } // Show Rating Dialog ShowRateDialog(info); // Playback Ended or Stopped and Considered Watched // TrackVideoPlayback event only gets fired on Stopped if > 80% watched TraktLogger.Info("Playback of '{0}' is considered watched at {1:0.00}%", info.Title, (percentPlayed * 100).ToString()); Thread scrobbleThread = new Thread(delegate(object o) { ITrackingInfo videoInfo = o as ITrackingInfo; // duration in minutes double duration = g_Player.Duration / 60; double progress = 100.0; TraktEpisodeScrobble scrobbleEpisodeData = null; TraktMovieScrobble scrobbleMovieData = null; TraktResponse response = null; if (videoInfo.VideoKind == VideoKind.TvSeries) { scrobbleEpisodeData = CreateEpisodeScrobbleData(videoInfo); if (scrobbleEpisodeData == null) { return; } scrobbleEpisodeData.Duration = Convert.ToInt32(duration).ToString(); scrobbleEpisodeData.Progress = Convert.ToInt32(progress).ToString(); response = TraktAPI.TraktAPI.ScrobbleEpisodeState(scrobbleEpisodeData, TraktScrobbleStates.scrobble); } else { scrobbleMovieData = CreateMovieScrobbleData(videoInfo); if (scrobbleMovieData == null) { return; } scrobbleMovieData.Duration = Convert.ToInt32(duration).ToString(); scrobbleMovieData.Progress = Convert.ToInt32(progress).ToString(); response = TraktAPI.TraktAPI.ScrobbleMovieState(scrobbleMovieData, TraktScrobbleStates.scrobble); } TraktAPI.TraktAPI.LogTraktResponse(response); }) { IsBackground = true, Name = "Scrobble" }; scrobbleThread.Start(info); } }
public ActiveConnectionLicenseInfo() { trackInfo = createTrackingInfo (); int interval = int.Parse(ConfigurationSettings.AppSettings["license.activeconnections.tracking.interval"] ?? "300"); string licensePath = ConfigurationSettings.AppSettings["license.file.path"]; trackInfo.setLicense(createLicenseReader(licensePath)); }
private void setSubtitleText(VideoInfo video, ITrackingInfo it) { ISubtitleDownloader sd = (ISubtitleDownloader)sdObject; List<Subtitle> results; if (it.VideoKind == VideoKind.Movie) { SearchQuery qu = new SearchQuery(it.Title); qu.Year = (int)it.Year; qu.LanguageCodes = languagePrios.Keys.ToArray(); results = sd.SearchSubtitles(qu); } else { EpisodeSearchQuery qu = new EpisodeSearchQuery(it.Title, (int)it.Season, (int)it.Episode, null); qu.LanguageCodes = languagePrios.Keys.ToArray(); results = sd.SearchSubtitles(qu); } Log.Debug("Subtitles found:" + results.Count.ToString()); if (results.Count > 0) { int minValue = int.MaxValue; Subtitle minSub = results[0]; foreach (Subtitle sub in results) { Log.Debug("Subtitle " + sub.ProgramName + " " + sub.LanguageCode); if (languagePrios.ContainsKey(sub.LanguageCode)) { int prio = languagePrios[sub.LanguageCode]; if (prio < minValue) { minValue = prio; minSub = sub; } } } List<FileInfo> subtitleFiles = sd.SaveSubtitle(minSub); if (subtitleFiles.Count > 0) { string s = File.ReadAllText(subtitleFiles[0].FullName, System.Text.Encoding.UTF8); if (s.IndexOf('�') != -1) video.SubtitleText = File.ReadAllText(subtitleFiles[0].FullName, System.Text.Encoding.Default); else video.SubtitleText = s; } foreach (FileInfo fi in subtitleFiles) fi.Delete(); } }
private TraktScrobbleEpisode CreateEpisodeScrobbleData(ITrackingInfo info, double progress = 0) { var scrobbleData = new TraktScrobbleEpisode { Episode = new TraktEpisode { Ids = new TraktEpisodeId(), Number = (int)info.Episode, Season = (int)info.Season }, Show = new TraktShow { Ids = new TraktShowId { Imdb = info.ID_IMDB, Tmdb = info.ID_TMDB.ToNullableInt32(), Tvdb = info.ID_TVDB.ToNullableInt32() }, Title = info.Title, Year = info.Year > 0 ? (int?)info.Year : null }, AppDate = TraktSettings.BuildDate, AppVersion = TraktSettings.Version, Progress = progress }; return scrobbleData; }
private TraktScrobbleMovie CreateMovieScrobbleData(ITrackingInfo info, double progress = 0) { var scrobbleData = new TraktScrobbleMovie { Movie = new TraktMovie { Ids = new TraktMovieId { Imdb = info.ID_IMDB, Tmdb = info.ID_TMDB.ToNullableInt32() }, Title = info.Title, Year = (int)info.Year }, AppDate = TraktSettings.BuildDate, AppVersion = TraktSettings.Version, Progress = progress }; return scrobbleData; }
public void StopScrobble() { currentVideo = null; if (TraktTimer != null) TraktTimer.Dispose(); }
/// <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); } } }
/// <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); }
private static bool SafeIsWatchedMovie(ITrackingInfo trackingInfo) { var watchedMovies = TraktCache.GetWatchedMoviesFromTrakt(true); if (watchedMovies != null) foreach (var movies in watchedMovies) { if ((trackingInfo.Year == 0 || trackingInfo.Year == movies.Movie.Year) && (String.IsNullOrEmpty(trackingInfo.ID_IMDB) || String.IsNullOrEmpty(movies.Movie.Ids.Imdb) || trackingInfo.ID_IMDB == movies.Movie.Ids.Imdb) && trackingInfo.Title.ToLowerInvariant() == movies.Movie.Title.ToLowerInvariant()) return true; } return false; }
/// <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; // not enabled TraktLogger.Debug("Showing rate dialog for '{0}'", videoInfo.Title); new Thread((o) => { ITrackingInfo itemToRate = o as ITrackingInfo; if (itemToRate == null) return; int rating = 0; if (itemToRate.VideoKind == VideoKind.TvSeries) { TraktRateEpisode rateObject = new TraktRateEpisode { SeriesID = itemToRate.ID_TVDB, Title = itemToRate.Title, Year = itemToRate.Year > 1900 ? itemToRate.Year.ToString() : null, Episode = itemToRate.Episode.ToString(), Season = itemToRate.Season.ToString(), UserName = TraktSettings.Username, Password = TraktSettings.Password }; // get the rating submitted to trakt rating = int.Parse(GUIUtils.ShowRateDialog<TraktRateEpisode>(rateObject)); } else if (itemToRate.VideoKind == VideoKind.Movie) { TraktRateMovie rateObject = new TraktRateMovie { IMDBID = itemToRate.ID_IMDB, TMDBID = itemToRate.ID_TMDB, Title = itemToRate.Title, Year = itemToRate.Year > 1900 ? itemToRate.Year.ToString() : null, UserName = TraktSettings.Username, Password = TraktSettings.Password }; // get the rating submitted to trakt rating = int.Parse(GUIUtils.ShowRateDialog<TraktRateMovie>(rateObject)); } if (rating > 0) { TraktLogger.Debug("Rating {0} as {1}/10", itemToRate.Title, rating.ToString()); // note: no user rating field to set } }) { Name = "Rate", IsBackground = true }.Start(videoInfo); }
/// <summary> /// Event gets triggered on playback events in OnlineVideos /// The TrackVideoPlayback event gets fired on Playback Start, Playback Ended /// and Playback Stopped (if percentage watched is greater than 0.8). /// </summary> private void TrackVideoPlayback(ITrackingInfo info, double percentPlayed) { if (info.VideoKind == VideoKind.Movie || info.VideoKind == VideoKind.TvSeries) { // Started Playback // Bug in OnlineVideos 0.31 reports incorrect percentage if (percentPlayed > 1.0) percentPlayed = 1 / percentPlayed; if (percentPlayed < 0.8) { currentVideo = info; return; } // Show Rating Dialog ShowRateDialog(info); // Playback Ended or Stopped and Considered Watched // TrackVideoPlayback event only gets fired on Stopped if > 80% watched TraktLogger.Info("Playback of '{0}' is considered watched at {1:0.00}%", info.Title, (percentPlayed * 100).ToString()); Thread scrobbleThread = new Thread(delegate(object o) { ITrackingInfo videoInfo = o as ITrackingInfo; // duration in minutes double duration = g_Player.Duration / 60; double progress = 100.0; TraktEpisodeScrobble scrobbleEpisodeData = null; TraktMovieScrobble scrobbleMovieData = null; TraktResponse response = null; if (videoInfo.VideoKind == VideoKind.TvSeries) { scrobbleEpisodeData = CreateEpisodeScrobbleData(videoInfo); if (scrobbleEpisodeData == null) return; scrobbleEpisodeData.Duration = Convert.ToInt32(duration).ToString(); scrobbleEpisodeData.Progress = Convert.ToInt32(progress).ToString(); response = TraktAPI.TraktAPI.ScrobbleEpisodeState(scrobbleEpisodeData, TraktScrobbleStates.scrobble); } else { scrobbleMovieData = CreateMovieScrobbleData(videoInfo); if (scrobbleMovieData == null) return; scrobbleMovieData.Duration = Convert.ToInt32(duration).ToString(); scrobbleMovieData.Progress = Convert.ToInt32(progress).ToString(); response = TraktAPI.TraktAPI.ScrobbleMovieState(scrobbleMovieData, TraktScrobbleStates.scrobble); } TraktAPI.TraktAPI.LogTraktResponse(response); }) { IsBackground = true, Name = "Scrobble" }; scrobbleThread.Start(info); } }
/// <summary> /// Create a Matroska Xml Tag (http://www.matroska.org/technical/specs/tagging/index.html) for the Video. With Title, Description and Airdate. /// </summary> /// <returns>Utf-8 encoded xml</returns> public virtual string CreateMatroskaXmlTag(string niceTitle, ITrackingInfo trackingInfo) { var tags = new XElement("Tags"); if (trackingInfo != null && trackingInfo.Season != 0 && trackingInfo.VideoKind == VideoKind.TvSeries) { //show: tags.Add( new XElement("Tag", new XElement("Targets", new XElement("TargetTypeValue", 70)), new XElement("Simple", new XElement("Name", "TITLE"), new XElement("String", trackingInfo.Title)) ), //season: new XElement("Tag", new XElement("Targets", new XElement("TargetTypeValue", 60)), new XElement("Simple", new XElement("Name", "PART_NUMBER"), new XElement("String", trackingInfo.Season)) ) ); } ; tags.Add( new XElement("Tag", new XElement("Targets", new XElement("TargetTypeValue", 50)), new XElement("Simple", new XElement("Name", "TITLE"), new XElement("String", trackingInfo != null && trackingInfo.VideoKind == VideoKind.Movie && !String.IsNullOrEmpty(trackingInfo.Title) ? trackingInfo.Title : niceTitle) ), new XElement("Simple", new XElement("Name", "DESCRIPTION"), new XElement("String", Description)), trackingInfo != null && trackingInfo.VideoKind != VideoKind.Other ? new XElement("Simple", new XElement("Name", "CONTENT_TYPE"), new XElement("String", trackingInfo.VideoKind)) : null, new XElement("Simple", new XElement("Name", "DATE_RELEASED"), new XElement("String", trackingInfo != null && trackingInfo.Year != 0 ? trackingInfo.Year.ToString() : Airdate)), trackingInfo != null && trackingInfo.Episode != 0 ? new XElement("Simple", new XElement("Name", "PART_NUMBER"), new XElement("String", trackingInfo.Episode)) : null, trackingInfo != null && !String.IsNullOrEmpty(trackingInfo.ID_IMDB) ? new XElement("Simple", new XElement("Name", "IMDB"), new XElement("String", trackingInfo.ID_IMDB)) : null )); return(new XDocument(new XDeclaration("1.0", "utf-8", "true"), tags).ToString()); }