public static DBSeason getCorrespondingSeason(int seriesID, int seasonIndex) { try { DBSeason cached = cache.getSeason(seriesID, seasonIndex); if (cached != null) { return(cached); } List <DBSeason> tmpSeasons = DBSeason.Get(seriesID); foreach (DBSeason season in tmpSeasons) { cache.addChangeSeason(season); if (season[DBSeason.cIndex] == seasonIndex) { return(season); } } return(null); } catch (Exception) { return(null); } }
void MarkEpisodeAsWatched(DBEpisode episode) { // Could be a double episode, so mark both as watched SQLCondition condition = new SQLCondition(); condition.Add(new DBEpisode(), DBEpisode.cFilename, episode[DBEpisode.cFilename], SQLConditionType.Equal); List <DBEpisode> episodes = DBEpisode.Get(condition, false); foreach (DBEpisode ep in episodes) { string date = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); ep[DBOnlineEpisode.cWatched] = 1; ep[DBOnlineEpisode.cPlayCount] = ep[DBOnlineEpisode.cPlayCount] + 1; ep[DBEpisode.cDateWatched] = date; ep[DBOnlineEpisode.cLastWatchedDate] = date; if (string.IsNullOrEmpty(ep[DBOnlineEpisode.cFirstWatchedDate])) { ep[DBOnlineEpisode.cFirstWatchedDate] = date; } ep.Commit(); } // Update Episode Counts DBSeries series = Helper.getCorrespondingSeries(m_currentEpisode[DBEpisode.cSeriesID]); DBSeason season = Helper.getCorrespondingSeason(episode[DBEpisode.cSeriesID], episode[DBEpisode.cSeasonIndex]); DBSeason.UpdateEpisodeCounts(series, season); }
public void HideSeries(bool hide) { MPTVSeriesLog.Write(string.Format("{0} series {1} from view", (hide ? "Hiding" : "UnHiding"), Helper.getCorrespondingSeries(this[DBSeries.cID]))); // respect 'Show Local Files Only' setting List <DBSeason> seasons = DBSeason.Get(this[DBSeries.cID]); if (seasons != null) { foreach (DBSeason season in seasons) { // Hide Seasons season.HideSeason(hide); } } // Hide Series this[DBSeries.cHidden] = hide; // Set Scan Ignore if (DBOption.GetOptions(DBOption.cSetHiddenSeriesAsScanIgnore)) { this[cScanIgnore] = hide; } this.Commit(); }
static string replaceSeasonTags(DBSeason s, string what) { if (s == null || what.Length < seasonIdentifier.Length) { return(what); } return(getValuesOfType(s, what, seasonParse, seasonIdentifier)); }
public static DBSeason getSeason(int SeriesID, int SeasonIndex) { singleSeriesRef = _cache.getSubItem(SeriesID); DBSeason s = singleSeriesRef == null ? null : singleSeriesRef.getItemOfSubItem(SeasonIndex); //MPTVSeriesLog.Write("Cache: Requested Season: " + SeriesID.ToString() + " S" + SeasonIndex.ToString() + (s == null ? " - Failed" : " - Sucess", MPTVSeriesLog.LogLevel.Debug)); return(s); }
static void DBSeason_dbSeasonUpdateOccured(DBSeason updated) { //MPTVSeriesLog.Write("Cache: Season Commit occured: ", updated.ToString(), MPTVSeriesLog.LogLevel.Debug); if (getSeason(updated[DBSeason.cSeriesID], updated[DBSeason.cIndex]) != null) { addChangeSeason(updated); } }
public List <string> deleteSeries(TVSeriesPlugin.DeleteMenuItems type) { List <string> resultMsg = new List <string>(); // Always delete from Local episode table if deleting from disk or database SQLCondition condition = new SQLCondition(); condition.Add(new DBSeason(), DBSeason.cSeriesID, this[DBSeries.cID], SQLConditionType.Equal); /* TODO dunno if to include or exclude hidden items. * if they are excluded then the if (resultMsg.Count is wrong and should do another select to get proper count * if (!DBOption.GetOptions(DBOption.cShowHiddenItems)) * { * //don't include hidden seasons unless the ShowHiddenItems option is set * condition.Add(new DBSeason(), DBSeason.cHidden, 0, SQLConditionType.Equal); * } */ List <DBSeason> seasons = DBSeason.Get(condition, false); if (seasons != null) { foreach (DBSeason season in seasons) { resultMsg.AddRange(season.deleteSeason(type)); } } #region Facade Remote Color // if we were successful at deleting all episodes of series from disk, set HasLocalFiles to false // note: we only do this if the database entries still exist if (resultMsg.Count == 0 && type == TVSeriesPlugin.DeleteMenuItems.disk) { this[DBOnlineSeries.cHasLocalFiles] = false; this.Commit(); } #endregion #region Cleanup // if there are no error messages and if we need to delete from db // Delete from online tables and season/series tables IsSeriesRemoved = false; if (resultMsg.Count == 0 && type != TVSeriesPlugin.DeleteMenuItems.disk) { condition = new SQLCondition(); condition.Add(new DBSeries(), DBSeries.cID, this[DBSeries.cID], SQLConditionType.Equal); DBSeries.Clear(condition); condition = new SQLCondition(); condition.Add(new DBOnlineSeries(), DBOnlineSeries.cID, this[DBSeries.cID], SQLConditionType.Equal); DBOnlineSeries.Clear(condition); IsSeriesRemoved = true; } #endregion return(resultMsg); }
public static void UpdateEpisodeCounts(DBSeries series, Dictionary <string, List <EpisodeCounter> > episodes) { if (series == null) { return; } string seriesId = series[DBSeries.cID]; int seriesEpsTotal = 0; int seriesEpsUnWatched = 0; bool airedOrder = series.IsAiredOrder; // dont worry about filtering season list, we already have a filtered episode list // query without std conditions for faster response. var conditions = new SQLCondition(new DBSeason(), DBSeason.cSeriesID, seriesId, SQLConditionType.Equal); var seasons = DBSeason.Get(conditions, false); // update season counts List <EpisodeCounter> eps = new List <EpisodeCounter>(); if (episodes.TryGetValue(seriesId, out eps)) { foreach (var season in seasons) { var seasonEps = eps.Where(e => airedOrder ? e.SeasonAirIdx == season[DBSeason.cIndex] : e.SeasonDvdIdx == season[DBSeason.cIndex]).ToList(); // dont commit seasons if are not viewing them // episodes for count is already filtered so can return 0 results if (seasonEps.Count == 0) { continue; } int count = seasonEps.Count(); int unWatchedCount = seasonEps.Where(e => e.EpisodeWatched != "1").Count(); season[DBSeason.cEpisodeCount] = count; season[DBSeason.cEpisodesUnWatched] = unWatchedCount; season[DBSeason.cUnwatchedItems] = unWatchedCount > 0; season.Commit(); seriesEpsTotal += count; // Count the Special (Season 0 (zero)) episodes as watched! if ((season[DBSeason.cIndex] != 0) || (season[DBSeason.cIndex] == 0 && !DBOption.GetOptions(DBOption.cCountSpecialEpisodesAsWatched))) { seriesEpsUnWatched += unWatchedCount; } } // update series counts series[DBOnlineSeries.cEpisodeCount] = seriesEpsTotal; series[DBOnlineSeries.cEpisodesUnWatched] = seriesEpsUnWatched; series[DBOnlineSeries.cUnwatchedItems] = seriesEpsUnWatched > 0; series.Commit(); } }
public List <DBSeason> getSeasonItems(int stepIndex, string[] currentStepSelection) { MPTVSeriesLog.Write("View: Get Seasons", MPTVSeriesLog.LogLevel.Debug); SQLCondition conditions = null; if (stepIndex >= m_steps.Count) { return(null); // wrong index specified!! } addHierarchyConditions(ref stepIndex, ref currentStepSelection, ref conditions); MPTVSeriesLog.Write("View: Get Seasons: Executing SQL", MPTVSeriesLog.LogLevel.Debug); return(DBSeason.Get(conditions)); }
public static void UpdateEpisodeCounts(DBSeries series) { if (series == null) { return; } int seriesEpsTotal = 0; int seriesEpsUnWatched = 0; int epsTotal = 0; int epsUnWatched = 0; // Update for each season in series and add each to total series count SQLCondition condition = new SQLCondition(); if (!DBOption.GetOptions(DBOption.cShowHiddenItems)) { //don't include hidden seasons unless the ShowHiddenItems option is set condition.Add(new DBSeason(), DBSeason.cHidden, 0, SQLConditionType.Equal); } List <DBSeason> Seasons = DBSeason.Get(series[DBSeries.cID], condition); foreach (DBSeason season in Seasons) { epsTotal = 0; epsUnWatched = 0; DBEpisode.GetSeasonEpisodeCounts(series, season, out epsTotal, out epsUnWatched); season[DBSeason.cEpisodeCount] = epsTotal; season[DBSeason.cEpisodesUnWatched] = epsUnWatched; season[DBSeason.cUnwatchedItems] = epsUnWatched > 0; season.Commit(); seriesEpsTotal += epsTotal; // Count the Special (Season 0 (zero)) episodes as watched! if ((season[DBSeason.cIndex] != 0) || (season[DBSeason.cIndex] == 0 && !DBOption.GetOptions(DBOption.cCountSpecialEpisodesAsWatched))) { seriesEpsUnWatched += epsUnWatched; } MPTVSeriesLog.Write(string.Format("Series \"{0} Season {1}\" has {2}/{3} unwatched episodes", series.ToString(), season[DBSeason.cIndex], epsUnWatched, epsTotal), MPTVSeriesLog.LogLevel.Debug); } MPTVSeriesLog.Write(string.Format("Series \"{0}\" has {1}/{2} unwatched episodes", series.ToString(), seriesEpsUnWatched, seriesEpsTotal), MPTVSeriesLog.LogLevel.Debug); series[DBOnlineSeries.cEpisodeCount] = seriesEpsTotal; series[DBOnlineSeries.cEpisodesUnWatched] = seriesEpsUnWatched; series[DBOnlineSeries.cUnwatchedItems] = seriesEpsUnWatched > 0; series.Commit(); }
public static void addChangeSeason(DBSeason season) { if (season == null) { return; } // does the series exist already, if not create a dummy _cache.AddDummy(season[DBSeason.cSeriesID]); //MPTVSeriesLog.Write("Cache: Adding/Changing Season: " + season[DBSeason.cSeriesID] + " S" + season[DBSeason.cIndex], MPTVSeriesLog.LogLevel.Debug); var hc = _cache.getSubItem(season[DBSeason.cSeriesID]); if (hc != null) { hc.Add(season[DBSeason.cIndex], season); } }
public static string getLogos(ref DBSeason season, int imgHeight, int imgWidth) { if (season == null) { return(null); } DBSeason inCache = !Settings.isConfig ? cache.getSeason(season[DBSeason.cSeriesID], season[DBSeason.cIndex]) : null; tmpSeason = inCache == null ? season : inCache; lastResult = getLogos(Level.Season, imgHeight, imgWidth, ref tmpSeason.cachedLogoResults); if (!lastWasCached) { cache.addChangeSeason(tmpSeason); } return(lastResult); }
static void getTableFieldname(string what, out DBTable table, out string fieldname) { string sTable = string.Empty; fieldname = string.Empty; table = null; what = what.Replace("<", "").Replace(">", "").Trim(); sTable = what.Split('.')[0]; switch (sTable) { case "Series": if (new DBOnlineSeries().FieldNames.Contains(what.Split('.')[1])) { table = new DBOnlineSeries(); fieldname = what.Split('.')[1]; } else { table = new DBSeries(); fieldname = what.Split('.')[1]; } break; case "Season": table = new DBSeason(); fieldname = what.Split('.')[1]; break; case "Episode": if (new DBOnlineEpisode().FieldNames.Contains(what.Split('.')[1])) { table = new DBOnlineEpisode(); fieldname = what.Split('.')[1]; } else { table = new DBEpisode(); fieldname = what.Split('.')[1]; } break; } }
public static String GetSeasonBanner(DBSeason season, bool createIfNotExist, bool isCoverflow) { Size size = isCoverflow ? reqSeasonPosterCFSize : reqSeasonPosterSize; String sFileName = season.Banner; String sTextureName = null; if (sFileName.Length > 0 && System.IO.File.Exists(sFileName)) { if (DBOption.GetOptions(DBOption.cAltImgLoading)) { sTextureName = sFileName; // bypass memoryimagebuilder } else { sTextureName = buildMemoryImageFromFile(sFileName, size); } } if (createIfNotExist && string.IsNullOrEmpty(sTextureName)) { // no image, use text, create our own string text = (season[DBSeason.cIndex] == 0) ? Translation.specials : Translation.Season + season[DBSeason.cIndex]; string ident = season[DBSeason.cSeriesID] + "S" + season[DBSeason.cIndex]; sTextureName = buildMemoryImage(drawSimpleBanner(size, text), ident, size, true); } // nothing left we can do, so return empty if still nothing if (string.IsNullOrEmpty(sTextureName)) { return(string.Empty); } s_SeasonsImageList.Add(sTextureName); return(sTextureName); }
/// <summary> /// Updates the movie metadata on the playback screen (for when the user clicks info). /// The delay is neccesary because Player tries to use metadata from the MyVideos database. /// We want to update this after that happens so the correct info is there. /// </summary> /// <param name="item">Playlist item</param> /// <param name="clear">Clears the properties instead of filling them if True</param> private void SetProperties(PlayListItem item, bool clear) { if (item == null) { return; } string title = string.Empty; DBSeries series = null; DBSeason season = null; if (!clear) { title = string.Format("{0} - {1}x{2} - {3}", item.SeriesName, item.SeasonIndex, item.EpisodeIndex, item.EpisodeName); series = Helper.getCorrespondingSeries(item.Episode[DBEpisode.cSeriesID]); season = Helper.getCorrespondingSeason(item.Episode[DBEpisode.cSeriesID], int.Parse(item.SeasonIndex)); } // Show Plot in OSD or Hide Spoilers (note: FieldGetter takes care of that) GUIPropertyManager.SetProperty("#Play.Current.Plot", clear ? " " : FieldGetter.resolveDynString(TVSeriesPlugin.m_sFormatEpisodeMain, item.Episode)); // Show Episode Thumbnail or Series Poster if Hide Spoilers is enabled string osdImage = string.Empty; if (!clear) { foreach (KeyValuePair <string, string> kvp in SkinSettings.VideoOSDImages) { switch (kvp.Key) { case "episode": osdImage = ImageAllocator.GetEpisodeImage(item.Episode); break; case "season": osdImage = season.Banner; break; case "series": osdImage = series.Poster; break; case "custom": string value = replaceDynamicFields(kvp.Value, item.Episode); string file = Helper.getCleanAbsolutePath(value); if (System.IO.File.Exists(file)) { osdImage = file; } break; } osdImage = osdImage.Trim(); if (string.IsNullOrEmpty(osdImage)) { continue; } else { break; } } } GUIPropertyManager.SetProperty("#Play.Current.Thumb", clear ? " " : osdImage); foreach (KeyValuePair <string, string> kvp in SkinSettings.VideoPlayImages) { if (!clear) { string value = replaceDynamicFields(kvp.Value, item.Episode); string file = Helper.getCleanAbsolutePath(value); if (System.IO.File.Exists(file)) { MPTVSeriesLog.Write(string.Format("Setting play image {0} for property {1}", file, kvp.Key), MPTVSeriesLog.LogLevel.Debug); GUIPropertyManager.SetProperty(kvp.Key, clear ? " " : file); } } else { MPTVSeriesLog.Write(string.Format("Clearing play image for property {0}", kvp.Key), MPTVSeriesLog.LogLevel.Debug); GUIPropertyManager.SetProperty(kvp.Key, " "); } } GUIPropertyManager.SetProperty("#Play.Current.Title", clear ? "" : title); GUIPropertyManager.SetProperty("#Play.Current.Year", clear ? "" : FieldGetter.resolveDynString("<" + DBEpisode.cOutName + "." + DBOnlineEpisode.cFirstAired + ">", item.Episode, false)); GUIPropertyManager.SetProperty("#Play.Current.Genre", clear ? "" : FieldGetter.resolveDynString(TVSeriesPlugin.m_sFormatEpisodeSubtitle, item.Episode)); }
public void addSQLCondition(string what, string type, string condition) { if ((!what.Contains("<") || !what.Contains(".")) && !what.Contains("custom:")) { return; } SQLConditionType condtype; switch (type) { case "=": condtype = SQLConditionType.Equal; break; case ">": condtype = SQLConditionType.GreaterThan; break; case ">=": condtype = SQLConditionType.GreaterEqualThan; break; case "<": condtype = SQLConditionType.LessThan; break; case "<=": condtype = SQLConditionType.LessEqualThan; break; case "!=": condtype = SQLConditionType.NotEqual; break; case "like": condtype = SQLConditionType.Like; break; default: condtype = SQLConditionType.Equal; break; } DBTable table = null; string tableField = string.Empty; getTableFieldname(what, out table, out tableField); Type lType = table.GetType(); SQLCondition fullSubCond = new SQLCondition(); if (logicalViewStep.type.series == Type && (lType != typeof(DBSeries) && lType != typeof(DBOnlineSeries))) { if (lType == typeof(DBSeason)) { fullSubCond.AddCustom(DBSeason.Q(DBSeason.cSeriesID), DBOnlineSeries.Q(DBOnlineSeries.cID), SQLConditionType.Equal); fullSubCond.AddCustom(DBSeason.Q(tableField), condition, condtype, true); conds.AddCustom(" exists( " + DBSeason.stdGetSQL(fullSubCond, false) + " )"); } else if (lType == typeof(DBOnlineEpisode)) { fullSubCond.AddCustom(DBOnlineEpisode.Q(tableField), condition, condtype, true); conds.AddCustom(" online_series.id in ( " + DBEpisode.stdGetSQL(fullSubCond, false, true, DBOnlineEpisode.Q(DBOnlineEpisode.cSeriesID)) + " )"); } else if (lType == typeof(DBEpisode)) { fullSubCond.AddCustom(DBEpisode.Q(tableField), condition, condtype, true); conds.AddCustom(" online_series.id in ( " + DBEpisode.stdGetSQL(fullSubCond, false, true, DBOnlineEpisode.Q(DBOnlineEpisode.cSeriesID)) + " )"); } } else if (logicalViewStep.type.season == Type && lType != typeof(DBSeason)) { if (lType == typeof(DBOnlineSeries) || lType == typeof(DBSeries)) { fullSubCond.AddCustom(DBOnlineSeries.Q(DBOnlineSeries.cID), DBSeason.Q(DBSeason.cSeriesID), SQLConditionType.Equal); fullSubCond.AddCustom(DBOnlineSeries.Q(tableField), condition, condtype, true); conds.AddCustom(" exists( " + DBSeries.stdGetSQL(fullSubCond, false) + " )"); } else if (lType == typeof(DBOnlineEpisode)) { // we rely on the join in dbseason for this (much, much faster) conds.AddCustom(DBOnlineEpisode.Q(tableField), condition, condtype, true); } else if (lType == typeof(DBEpisode)) { fullSubCond.AddCustom(DBOnlineEpisode.Q(DBOnlineEpisode.cSeriesID), DBSeason.Q(DBSeason.cSeriesID), SQLConditionType.Equal); fullSubCond.AddCustom(DBOnlineEpisode.Q(DBOnlineEpisode.cSeasonIndex), DBSeason.Q(DBSeason.cIndex), SQLConditionType.Equal); fullSubCond.AddCustom(DBEpisode.Q(tableField), condition, condtype); conds.AddCustom(" exists( " + DBEpisode.stdGetSQL(fullSubCond, false) + " )"); } } else if (logicalViewStep.type.episode == Type && (lType != typeof(DBEpisode) && lType != typeof(DBOnlineEpisode))) { if (lType == typeof(DBOnlineSeries) || lType == typeof(DBSeries)) { fullSubCond.AddCustom(DBOnlineSeries.Q(DBOnlineSeries.cID), DBOnlineEpisode.Q(DBOnlineEpisode.cSeriesID), SQLConditionType.Equal); fullSubCond.AddCustom(DBOnlineSeries.Q(tableField), condition, condtype, true); conds.AddCustom(" exists( " + DBSeries.stdGetSQL(fullSubCond, false) + " )"); } if (lType == typeof(DBSeason)) { fullSubCond.AddCustom(DBSeason.Q(DBSeason.cSeriesID), DBOnlineEpisode.Q(DBOnlineEpisode.cSeriesID), SQLConditionType.Equal); fullSubCond.AddCustom(DBSeason.Q(DBSeason.cIndex), DBOnlineEpisode.Q(DBOnlineEpisode.cSeasonIndex), SQLConditionType.Equal); fullSubCond.AddCustom(DBSeason.Q(tableField), condition, condtype, true); conds.AddCustom(" exists( " + DBSeason.stdGetSQL(fullSubCond, false) + " )"); } } else { // condition is on current table itself conds.Add(table, tableField, condition.Trim(), condtype); } }
public static String GetSeasonBannerAsFilename(DBSeason season) { String sFileName = season.Banner; return(sFileName); }
/// <summary> /// Sets the following Properties: /// "#Play.Current.Title" /// "#Play.Current.Plot" /// "#Play.Current.Thumb" /// "#Play.Current.Year" /// </summary> /// <param name="clear">Clears the properties instead of filling them if True</param> void SetGUIProperties(bool clear) { if (m_currentEpisode == null) { return; } DBSeries series = null; if (!clear) { series = Helper.getCorrespondingSeries(m_currentEpisode[DBEpisode.cSeriesID]); } DBSeason season = null; if (!clear) { season = Helper.getCorrespondingSeason(m_currentEpisode[DBEpisode.cSeriesID], m_currentEpisode[DBEpisode.cSeasonIndex]); } // Show Plot in OSD or Hide Spoilers (note: FieldGetter takes care of that) GUIPropertyManager.SetProperty("#Play.Current.Plot", clear ? " " : FieldGetter.resolveDynString(TVSeriesPlugin.m_sFormatEpisodeMain, m_currentEpisode)); // Show Episode Thumbnail or Series Poster if Hide Spoilers is enabled string osdImage = string.Empty; if (!clear) { foreach (KeyValuePair <string, string> kvp in SkinSettings.VideoOSDImages) { switch (kvp.Key) { case "episode": osdImage = ImageAllocator.GetEpisodeImage(m_currentEpisode); break; case "season": osdImage = season.Banner; break; case "series": osdImage = series.Poster; break; case "custom": string value = replaceDynamicFields(kvp.Value); string file = Helper.getCleanAbsolutePath(value); if (System.IO.File.Exists(file)) { osdImage = file; } break; } osdImage = osdImage.Trim(); if (string.IsNullOrEmpty(osdImage)) { continue; } else { break; } } } GUIPropertyManager.SetProperty("#Play.Current.Thumb", clear ? " " : osdImage); // double check, i don't want play images to be cleared on ended or stopped... if (PlayPropertyUpdater.CancellationPending) { return; } foreach (KeyValuePair <string, string> kvp in SkinSettings.VideoPlayImages) { if (!clear) { string value = replaceDynamicFields(kvp.Value); string file = Helper.getCleanAbsolutePath(value); if (System.IO.File.Exists(file)) { MPTVSeriesLog.Write(string.Format("Setting play image {0} for property {1}", file, kvp.Key), MPTVSeriesLog.LogLevel.Debug); GUIPropertyManager.SetProperty(kvp.Key, clear ? " " : file); } } else { MPTVSeriesLog.Write(string.Format("Clearing play image for property {0}", kvp.Key), MPTVSeriesLog.LogLevel.Debug); GUIPropertyManager.SetProperty(kvp.Key, " "); } } GUIPropertyManager.SetProperty("#Play.Current.Title", clear ? " " : m_currentEpisode.onlineEpisode.CompleteTitle); GUIPropertyManager.SetProperty("#Play.Current.Year", clear ? " " : FieldGetter.resolveDynString("<" + DBEpisode.cOutName + "." + DBOnlineEpisode.cFirstAired + ">", m_currentEpisode, false)); GUIPropertyManager.SetProperty("#Play.Current.Genre", clear ? " " : FieldGetter.resolveDynString(TVSeriesPlugin.m_sFormatEpisodeSubtitle, m_currentEpisode)); }
public void DownloadBanners(string onlineLanguage) { int maxConsecutiveDownloadErrors; var consecutiveDownloadErrors = 0; if (!int.TryParse(DBOption.GetOptions(DBOption.cMaxConsecutiveDownloadErrors).ToString(), out maxConsecutiveDownloadErrors)) { maxConsecutiveDownloadErrors = 3; } // now that we have all the paths, download all the files foreach (SeriesBannersMap map in SeriesBannersMap) { #region Series Wide Banners var seriesWideBanners = new List <WideBannerSeries>(map.SeriesWideBanners); var seriesWideBannersToKeep = new List <WideBannerSeries>(); // if localized and english banners exist then only get them // if none exist, then get what's left over if (seriesWideBanners.Exists(b => b.Language == onlineLanguage || b.Language == "en" || b.Language == string.Empty)) { seriesWideBanners.RemoveAll(b => b.Language != onlineLanguage && b.Language != "en" && b.Language != string.Empty); } foreach (var seriesWideBanner in seriesWideBanners) { if (consecutiveDownloadErrors >= maxConsecutiveDownloadErrors) { MPTVSeriesLog.Write("Too many consecutive download errors. Aborting."); return; } // mark the filename with the language seriesWideBanner.FileName = Helper.cleanLocalPath(seriesWideBanner.SeriesName) + @"\-lang" + seriesWideBanner.Language + "-" + seriesWideBanner.OnlinePath; string file = OnlineAPI.DownloadBanner(seriesWideBanner.OnlinePath, Settings.Path.banners, seriesWideBanner.FileName); if (BannerDownloadDone != null) { BannerDownloadDone(file); seriesWideBannersToKeep.Add(seriesWideBanner); consecutiveDownloadErrors = 0; } else { consecutiveDownloadErrors++; } } map.SeriesWideBanners = seriesWideBannersToKeep; #endregion #region Series Posters var seriesPosters = new List <PosterSeries>(map.SeriesPosters); var seriesPostersToKeep = new List <PosterSeries>(); // if localized and english banners exist then only get them // if none exist, then get what's left over if (seriesPosters.Exists(p => p.Language == onlineLanguage || p.Language == "en" || p.Language == string.Empty)) { seriesPosters.RemoveAll(p => p.Language != onlineLanguage && p.Language != "en" && p.Language != string.Empty); } foreach (var seriesPoster in seriesPosters) { if (consecutiveDownloadErrors >= maxConsecutiveDownloadErrors) { MPTVSeriesLog.Write("Too many consecutive download errors. Aborting."); return; } // mark the filename with the language seriesPoster.FileName = Helper.cleanLocalPath(seriesPoster.SeriesName) + @"\-lang" + seriesPoster.Language + "-" + seriesPoster.OnlinePath; string file = OnlineAPI.DownloadBanner(seriesPoster.OnlinePath, Settings.Path.banners, seriesPoster.FileName); if (BannerDownloadDone != null) { BannerDownloadDone(file); seriesPostersToKeep.Add(seriesPoster); consecutiveDownloadErrors = 0; } else { consecutiveDownloadErrors++; } } map.SeriesPosters = seriesPostersToKeep; #endregion #region Season Posters List <DBSeason> localSeasons = DBSeason.Get(new SQLCondition(new DBSeason(), DBSeason.cSeriesID, map.SeriesID, SQLConditionType.Equal), false); var seasonPosters = new List <PosterSeason>(map.SeasonPosters); var seasonPostersToKeep = new List <PosterSeason>(); // if localized and english banners exist then only get them // if none exist, then get what's left over if (seasonPosters.Exists(p => p.Language == onlineLanguage || p.Language == "en" || p.Language == string.Empty)) { seasonPosters.RemoveAll(p => p.Language != onlineLanguage && p.Language != "en" && p.Language != string.Empty); } foreach (var seasonPoster in seasonPosters) { if (consecutiveDownloadErrors >= maxConsecutiveDownloadErrors) { MPTVSeriesLog.Write("Too many consecutive download errors. Aborting."); return; } // only download season banners if we have online season in database if (!localSeasons.Any(s => s[DBSeason.cIndex] == seasonPoster.SeasonIndex)) { continue; } seasonPoster.FileName = Helper.cleanLocalPath(seasonPoster.SeriesName) + @"\-lang" + seasonPoster.Language + "-" + seasonPoster.OnlinePath; string file = OnlineAPI.DownloadBanner(seasonPoster.OnlinePath, Settings.Path.banners, seasonPoster.FileName); if (BannerDownloadDone != null) { BannerDownloadDone(file); seasonPostersToKeep.Add(seasonPoster); consecutiveDownloadErrors = 0; } else { consecutiveDownloadErrors++; } } map.SeasonPosters = seasonPostersToKeep; #endregion } }