public override async Task <List <EpisodeInfo> > SearchSeriesEpisodeAsync(EpisodeInfo episodeSearch, TvdbLanguage language) { language = language ?? PreferredLanguage; SeriesInfo seriesSearch = episodeSearch.CloneBasicInstance <SeriesInfo>(); if (episodeSearch.SeriesTvdbId <= 0 && string.IsNullOrEmpty(episodeSearch.SeriesImdbId)) { if (!await SearchSeriesUniqueAndUpdateAsync(seriesSearch, language).ConfigureAwait(false)) { return(null); } episodeSearch.CopyIdsFrom(seriesSearch); } List <EpisodeInfo> episodes = null; if ((episodeSearch.SeriesTvdbId > 0 || !string.IsNullOrEmpty(episodeSearch.SeriesImdbId)) && episodeSearch.SeasonNumber.HasValue) { int seriesId = 0; if (episodeSearch.SeriesTvdbId > 0) { seriesId = episodeSearch.SeriesTvdbId; } else if (!string.IsNullOrEmpty(episodeSearch.SeriesImdbId)) { TvdbSearchResult searchResult = await _tvdbHandler.GetSeriesByRemoteIdAsync(ExternalId.ImdbId, episodeSearch.SeriesImdbId); if (searchResult?.Id > 0) { seriesId = searchResult.Id; } } TvdbSeries seriesDetail = await _tvdbHandler.GetSeriesAsync(seriesId, language, true, false, false).ConfigureAwait(false); if (seriesDetail == null) { return(null); } foreach (TvdbEpisode episode in seriesDetail.Episodes.OrderByDescending(e => e.Id)) { if ((episodeSearch.EpisodeNumbers.Contains(episode.EpisodeNumber) || episodeSearch.EpisodeNumbers.Count == 0) && (episodeSearch.SeasonNumber == episode.SeasonNumber || episodeSearch.SeasonNumber.HasValue == false)) { if (episodes == null) { episodes = new List <EpisodeInfo>(); } EpisodeInfo info = new EpisodeInfo { TvdbId = episode.Id, SeriesName = new SimpleTitle(seriesDetail.SeriesName, false), SeasonNumber = episode.SeasonNumber, EpisodeName = new SimpleTitle(episode.EpisodeName, false), }; info.EpisodeNumbers.Add(episode.EpisodeNumber); info.CopyIdsFrom(seriesSearch); info.Languages.Add(episode.Language.Abbriviation); if (!episodes.Contains(info)) { episodes.Add(info); } } } if (episodes != null) { episodes.Sort(); } } if (episodes == null) { episodes = new List <EpisodeInfo>(); EpisodeInfo info = new EpisodeInfo { SeriesName = seriesSearch.SeriesName, SeasonNumber = episodeSearch.SeasonNumber, EpisodeName = episodeSearch.EpisodeName, }; info.CopyIdsFrom(seriesSearch); info.EpisodeNumbers = info.EpisodeNumbers.Union(episodeSearch.EpisodeNumbers).ToList(); info.Languages = seriesSearch.Languages; episodes.Add(info); } return(episodes); }