/// <summary> /// Extract a list of banners from the data when the data has the format: /// <![CDATA[ /// <?xml version="1.0" encoding="UTF-8" ?> /// <Banners> /// <Banner> /// <id>20106</id> /// <BannerPath>fanart/original/73739-1.jpg</BannerPath> /// <VignettePath>fanart/vignette/73739-1.jpg</VignettePath> /// <ThumbnailPath>_cache/fanart/original/73739-1.jpg</ThumbnailPath> /// <BannerType>fanart</BannerType> /// <BannerType2>1920x1080</BannerType2> /// <Colors>|68,69,59|69,70,58|78,78,68|</Colors> /// <Language>en</Language> /// </Banner> /// <Banner> /// <id>18953</id> /// <BannerPath>seasons/73739-2-2.jpg</BannerPath> /// <BannerType>Season</BannerType> /// <BannerType2>Season</BannerType2> /// <Language>es</Language> /// <Season>2</Season> /// </Banner> /// <Banner> /// <id>9529</id> /// <BannerPath>graphical/73739-g.jpg</BannerPath> /// <BannerType>series</BannerType> /// <BannerType2>graphical</BannerType2> /// <Language>en</Language> /// </Banner> /// </Banners> /// ]]> /// </summary> /// <param name="data"></param> /// <returns></returns> internal List <TvdbBanner> ExtractBanners(String data) { //Stopwatch watch = new Stopwatch(); //watch.Start(); XDocument xml = XDocument.Parse(data); //Extract the fanart banners var allFanartBanners = from banner in xml.Descendants("Banner") where banner.Element("BannerType").Value.Equals("fanart") select new TvdbFanartBanner { Id = banner.Element("id") != null?Util.Int32Parse(banner.Element("id").Value) : Util.NO_VALUE, BannerPath = banner.Element("BannerPath") != null?banner.Element("BannerPath").Value : "", VignettePath = banner.Element("id") != null?banner.Element("VignettePath").Value : "", ThumbPath = banner.Element("ThumbnailPath") != null?banner.Element("ThumbnailPath").Value : "", Resolution = banner.Element("BannerType2") != null? Util.ParseResolution(banner.Element("BannerType2").Value) : new Point(), Colors = banner.Element("Colors") != null?Util.ParseColors(banner.Element("Colors").Value) : null, Language = banner.Element("Language") != null? TvDbUtils.ParseLanguage(banner.Element("Language").Value) : TvdbLanguage.DefaultLanguage, ContainsSeriesName = banner.Element("SeriesName") != null? Util.ParseBoolean(banner.Element("SeriesName").Value) : false, LastUpdated = banner.Element("LastUpdated") != null? Util.UnixToDotNet(banner.Element("LastUpdated").Value) : DateTime.Now }; List <TvdbBanner> retList = (from TvdbBanner e in allFanartBanners where e.Id != Util.NO_VALUE select e).ToList(); //Extract the Season banners var allSeasonBanners = from banner in xml.Descendants("Banner") where banner.Element("BannerType").Value.Equals("season") select new TvdbSeasonBanner { Id = Util.Int32Parse(banner.Element("id").Value), BannerPath = banner.Element("BannerPath").Value, Season = Util.Int32Parse(banner.Element("Season").Value), BannerType = TvDbUtils.ParseSeasonBannerType(banner.Element("BannerType2").Value), Language = TvDbUtils.ParseLanguage(banner.Element("Language").Value), LastUpdated = banner.Element("LastUpdated") != null? Util.UnixToDotNet(banner.Element("LastUpdated").Value) : DateTime.Now }; retList.AddRange(from TvdbBanner e in allSeasonBanners where e.Id != Util.NO_VALUE select e); //Extract the series banners var allSeriesBanners = from banner in xml.Descendants("Banner") where banner.Element("BannerType").Value.Equals("series") select new TvdbSeriesBanner { Id = Util.Int32Parse(banner.Element("id").Value), BannerPath = banner.Element("BannerPath").Value, BannerType = TvDbUtils.ParseSeriesBannerType(banner.Element("BannerType2").Value), Language = TvDbUtils.ParseLanguage(banner.Element("Language").Value), LastUpdated = banner.Element("LastUpdated") != null? Util.UnixToDotNet(banner.Element("LastUpdated").Value) : DateTime.Now }; retList.AddRange(from TvdbBanner e in allSeriesBanners where e.Id != Util.NO_VALUE select e); //Extract the Poster banners var allPosterBanners = from banner in xml.Descendants("Banner") where banner.Element("BannerType").Value.Equals("poster") select new TvdbPosterBanner { Id = Util.Int32Parse(banner.Element("id").Value), BannerPath = banner.Element("BannerPath").Value, Resolution = Util.ParseResolution(banner.Element("BannerType2").Value), Language = TvDbUtils.ParseLanguage(banner.Element("Language").Value), LastUpdated = banner.Element("LastUpdated") != null? Util.UnixToDotNet(banner.Element("LastUpdated").Value) : DateTime.Now }; retList.AddRange(allPosterBanners.Where(e => e.Id != Util.NO_VALUE).Cast <TvdbBanner>()); //watch.Stop(); //Log.Debug("Extracted " + retList.Count + " banners in " + watch.ElapsedMilliseconds + " milliseconds"); return(retList); }
/// <summary> /// Extract the data of updated banners /// /// <![CDATA[ /// <?xml version="1.0" encoding="UTF-8" ?> /// <Data time="1203923101"> /// <Banner> /// <SeasonNum>1</SeasonNum> /// <Series>79302</Series> /// <format>standard</format> /// <language>en</language> /// <path>seasons/79302-1.jpg</path> /// <type>Season</type> /// </Banner> /// </Data> /// ]]> /// </summary> /// <param name="data"></param> /// <returns></returns> internal List <TvdbBanner> ExtractBannerUpdates(String data) { //todo: banner update -> problem is update.xml doesn't contain all information for fanart //Stopwatch watch = new Stopwatch(); //watch.Start(); XDocument xml = XDocument.Parse(data); //Extract the fanart banners var allEpisodes = from banner in xml.Descendants("Banner") where banner.Element("type").Value.Equals("fanart") select new TvdbFanartBanner { Id = banner.Element("path").Value.GetHashCode(),// -99,//Util.Int32Parse(episode.Element("Series").Value), BannerPath = banner.Element("path").Value, VignettePath = banner.Element("path").Value.Replace("/original/", "/vignette/"), ThumbPath = "_cache/" + banner.Element("path").Value, Resolution = Util.ParseResolution(banner.Element("format").Value), //Colors = Util.ParseColors(episode.Element("Colors").Value), //Language = TvDbUtils.ParseLanguage(episode.Element("Language").Value) SeriesId = Util.Int32Parse(banner.Element("Series").Value), LastUpdated = Util.UnixToDotNet(banner.Element("time").Value) }; List <TvdbBanner> retList = allEpisodes.Cast <TvdbBanner>().ToList(); //Extract the Season banners var allBanners = from banner in xml.Descendants("Banner") where banner.Element("type").Value.Equals("season") select new TvdbSeasonBanner { Id = banner.Element("path").Value.GetHashCode(), BannerPath = banner.Element("path").Value, Season = Util.Int32Parse(banner.Element("SeasonNum").Value), BannerType = TvDbUtils.ParseSeasonBannerType(banner.Element("format").Value), Language = TvDbUtils.ParseLanguage(banner.Element("language").Value), SeriesId = Util.Int32Parse(banner.Element("Series").Value), LastUpdated = Util.UnixToDotNet(banner.Element("time").Value) }; retList.AddRange(allBanners.Cast <TvdbBanner>()); //Extract the series banners var allBanners2 = from banner in xml.Descendants("Banner") where banner.Element("type").Value.Equals("series") select new TvdbSeriesBanner { Id = banner.Element("path").Value.GetHashCode(), BannerPath = banner.Element("path").Value, BannerType = TvDbUtils.ParseSeriesBannerType(banner.Element("format").Value), Language = TvDbUtils.ParseLanguage(banner.Element("language").Value), SeriesId = Util.Int32Parse(banner.Element("Series").Value), LastUpdated = Util.UnixToDotNet(banner.Element("time").Value) }; retList.AddRange(allBanners2.Cast <TvdbBanner>()); //Extract the Poster banners var allPosters = from banner in xml.Descendants("Banner") where banner.Element("type").Value.Equals("poster") select new TvdbPosterBanner { Id = banner.Element("path").Value.GetHashCode(), BannerPath = banner.Element("path").Value, Resolution = Util.ParseResolution(banner.Element("format").Value), Language = TvdbLanguage.UniversalLanguage, SeriesId = Util.Int32Parse(banner.Element("Series").Value), LastUpdated = Util.UnixToDotNet(banner.Element("time").Value) }; retList.AddRange(allPosters.Cast <TvdbBanner>()); //watch.Stop(); //Log.Debug("Extracted " + retList.Count + " bannerupdates in " + watch.ElapsedMilliseconds + " milliseconds"); return(retList); }