private void MatchEpisodeAndMarkAsWatched(RestoreResult result, ILookup <string, MediaLibraryEpisode> loadedEpisodes, MediaItem episode) { string tvdbKey = CreateLookupKey(episode); MediaLibraryEpisode watchedEpisode = loadedEpisodes[tvdbKey].FirstOrDefault(); if (watchedEpisode != null) { if (_mediaPortalServices.MarkAsWatched(episode).Result) { _mediaPortalServices.GetLogger().Info( "FlagMover: Marking episode as watched in library. Title = '{0}, Season = '{1}', Episode = '{2}', Show TVDb ID = '{3}', Show IMDb ID = '{4}'", watchedEpisode.ShowTitle, watchedEpisode.Season, watchedEpisode.Number, watchedEpisode.ShowTvdb ?? "<empty>", watchedEpisode.ShowImdb ?? "<empty>"); IncreaseResultCount(result, episode); } } }
private string CreateLookupKey(MediaLibraryEpisode episode) { string show; if (episode.ShowTvdb != null) { show = episode.ShowTvdb; } else if (episode.ShowImdb != null) { show = episode.ShowImdb; } else { if (episode.ShowTitle == null) { return(episode.GetHashCode().ToString()); } show = episode.ShowTitle; } return(string.Format("{0}_{1}_{2}", show, episode.Season, episode.Number)); }