private TvdbBanner GetLoadedBanner(TvdbDownloader downloader, int sId, int season, int episode, TvdbBanner fallback) { TvdbBanner result = GetEpisodeBanner(downloader, sId, season, episode); if (result != null && TryLoadBanner(result)) { return(result); } var bannerHits = downloader.DownloadBanners(sId); result = GetSeasonBanner(bannerHits, season); if (result != null && TryLoadBanner(result)) { return(result); } result = GetSeriesBanner(bannerHits); if (result != null && TryLoadBanner(result)) { return(result); } if (fallback != null && TryLoadBanner(fallback)) { return(fallback); } return(null); }
/// <summary> /// Gets the series with the given id either from cache (if it has already been loaded) or from /// the selected tvdb mirror. /// /// To check if this series has already been cached, use the Method IsCached(TvdbSeries _series) /// </summary> /// <param name="_seriesId">id of series</param> /// <param name="_language">language that should be retrieved</param> /// <param name="_full">if true, the full series record will be loaded (series + all episodes), otherwise only the base record will be loaded which contains only series information</param> /// <param name="_loadBanners">if true also loads the paths to the banners</param> /// <returns>Instance of TvdbSeries containing all gained information</returns> public TvdbSeries GetSeries(int _seriesId, TvdbLanguage _language, bool _loadEpisodes, bool _loadActors, bool _loadBanners) { Stopwatch watch = new Stopwatch(); watch.Start(); TvdbSeries series = GetSeriesFromCache(_seriesId); if (series == null) {//load complete series from tvdb series = m_downloader.DownloadSeries(_seriesId, _language, _loadEpisodes, _loadActors, _loadBanners); if (series == null) { return(null); } watch.Stop(); Log.Debug("Loaded series in " + watch.ElapsedMilliseconds + " milliseconds"); series.IsFavorite = m_userInfo == null ? false : CheckIfSeriesFavorite(_seriesId, m_userInfo.UserFavorites); AddSeriesToCache(series); return(series); } else { //some (if not all) information has already been loaded from tvdb at some point -> fill the missing details and return the series if (!_language.Abbriviation.Equals(series.Language.Abbriviation)) { //user wants a different language than the one that has been loaded if (series.GetAvailableLanguages().Contains(_language)) { series.SetLanguage(_language); } else { TvdbSeriesFields newFields = m_downloader.DownloadSeriesFields(_seriesId, _language); if (_loadEpisodes) { List <TvdbEpisode> epList = m_downloader.DownloadEpisodes(_seriesId, _language); if (epList != null) { newFields.Episodes = epList; } } if (newFields != null) { series.AddLanguage(newFields); series.SetLanguage(_language); } else { Log.Warn("Couldn't load new language " + _language.Abbriviation + " for series " + _seriesId); return(null); } } } if (_loadActors && !series.TvdbActorsLoaded) {//user wants actors loaded series.TvdbActors = m_downloader.DownloadActors(_seriesId); } if (_loadEpisodes && !series.EpisodesLoaded) {//user wants the full version but only the basic has been loaded (without episodes series.Episodes = m_downloader.DownloadEpisodes(_seriesId, _language); } if (_loadBanners && !series.BannersLoaded) {//user wants banners loaded but current series hasn't -> Do it baby series.Banners = m_downloader.DownloadBanners(_seriesId); } watch.Stop(); Log.Debug("Loaded series in " + watch.ElapsedMilliseconds + " milliseconds"); return(series); } }