protected override TvdbLanguage FindMatchingLanguage(string shortLanguageString) { TvdbLanguage returnVal = TvDbUtils.ParseLanguage(shortLanguageString); if (returnVal.Id != Util.NO_VALUE) { return(returnVal); } return(TvdbLanguage.DefaultLanguage); }
/// <summary> /// Extract user data from /// </summary> /// <param name="data"></param> /// <returns></returns> internal List <TvdbUser> ExtractUser(String data) { //Stopwatch watch = new Stopwatch(); //watch.Start(); XDocument xml = XDocument.Parse(data); var allUsers = from episode in xml.Descendants("User") select new { Identifier = episode.Element("Identifier").Value, Name = episode.Element("Name").Value, Favorites = episode.Element("Favorites"), Preferred = episode.Element("PreferredLanguage") }; List <TvdbUser> userList = new List <TvdbUser>(); foreach (var a in allUsers) { TvdbUser user = new TvdbUser { UserIdentifier = a.Identifier, UserName = a.Name, UserPreferredLanguage = a.Preferred.HasAttributes ? TvDbUtils.ParseLanguage(a.Preferred.FirstAttribute.NextAttribute.Value) : TvdbLanguage.DefaultLanguage }; List <int> favList = new List <int>(); foreach (String f in a.Favorites.Value.Split(',')) { int val; if (Int32.TryParse(f, out val)) { favList.Add(val); } } user.UserFavorites = favList; userList.Add(user); } //watch.Stop(); //Log.Debug("Extracted " + userList.Count + " actors in " + watch.ElapsedMilliseconds + " milliseconds"); return(userList); }
/// <summary> /// Extract the results of a series search with format: /// <![CDATA[ /// <?xml version="1.0" encoding="UTF-8" ?> /// <Data> /// <Series> /// <seriesid>73739</seriesid> /// <language>en</language> /// <SeriesName>Lost</SeriesName> /// <banner>graphical/24313-g2.jpg</banner> /// <Overview>After Oceanic Air flight 815...</Overview> /// <FirstAired>2004-09-22</FirstAired> /// <IMDB_ID>tt0411008</IMDB_ID> /// <zap2it_id>SH672362</zap2it_id> /// <id>73739</id> /// </Series> /// </Data> /// ]]> /// </summary> /// <param name="data"></param> /// <returns></returns> internal List <TvdbSearchResult> ExtractSeriesSearchResults(String data) { XDocument xml = XDocument.Parse(data); var allSeries = from series in xml.Descendants("Series") where series.HasElements select new { Id = Util.Int32Parse(series.Element("seriesid").Value), FirstAired = series.Element("FirstAired") != null?series.Element("FirstAired").Value : "", Language = series.Element("language") != null?series.Element("language").Value : "", Overview = series.Element("Overview") != null?series.Element("Overview").Value : "", SeriesName = series.Element("SeriesName") != null?series.Element("SeriesName").Value : "", IMDB_ID = series.Element("IMDB_ID") != null?series.Element("IMDB_ID").Value : "", BannerPath = series.Element("banner") != null?series.Element("banner").Value : "" }; List <TvdbSearchResult> retList = new List <TvdbSearchResult>(); foreach (var s in allSeries) { TvdbSearchResult res = new TvdbSearchResult { Id = s.Id, ImdbId = s.IMDB_ID }; if (!s.FirstAired.Equals("")) { res.FirstAired = DateTime.Parse(s.FirstAired); } if (!s.Language.Equals("")) { res.Language = TvDbUtils.ParseLanguage(s.Language); } res.SeriesName = s.SeriesName; res.Overview = s.Overview; res.Banner = !s.BannerPath.Equals("") ? new TvdbSeriesBanner(0, s.BannerPath, null, TvdbSeriesBanner.Type.None) : new TvdbSeriesBanner(s.Id, null, null, TvdbSeriesBanner.Type.None); retList.Add(res); } return(retList); }
protected override TvdbLanguage FindBestMatchingLanguage(List <string> mediaLanguages) { TvdbLanguage returnVal; CultureInfo mpLocal = new CultureInfo(PreferredLanguageCulture); // If we don't have movie languages available, or the MP2 setting language is available, prefer it. if (mediaLanguages.Count == 0 || mediaLanguages.Contains(mpLocal.TwoLetterISOLanguageName)) { returnVal = TvDbUtils.ParseLanguage(mpLocal.TwoLetterISOLanguageName); if (returnVal.Id != Util.NO_VALUE) { return(returnVal); } } // If there is one language available, use this one. if (UseMediaAudioIfUnmatched && mediaLanguages.Count > 0) { returnVal = TvDbUtils.ParseLanguage(mediaLanguages[0]); if (returnVal.Id != Util.NO_VALUE) { return(returnVal); } } // If there are multiple languages, that are different to MP2 setting, we cannot guess which one is the "best". // Use preferred language if available. returnVal = TvDbUtils.ParseLanguage(mpLocal.TwoLetterISOLanguageName); if (returnVal.Id != Util.NO_VALUE) { return(returnVal); } // By returning null we allow fallback to the default language of the online source (en). return(TvdbLanguage.DefaultLanguage); }
/// <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); }
/// <summary> /// Extract a list of episodes from the given data when the data has the following format: /// <![CDATA[ /// <?xml version="1.0" encoding="UTF-8" ?> /// <Episode> /// <id>332179</id> /// <DVD_chapter></DVD_chapter> /// <DVD_discid></DVD_discid> /// <DVD_episodenumber></DVD_episodenumber> /// <DVD_season></DVD_season> /// <Director>|Joseph McGinty Nichol|</Director> /// <EpisodeName>Chuck Versus the World</EpisodeName> /// <EpisodeNumber>1</EpisodeNumber> /// <FirstAired>2007-09-24</FirstAired> /// <GuestStars>|Julia Ling|Vik Sahay|Mieko Hillman|</GuestStars> /// <IMDB_ID></IMDB_ID> /// <Language>English</Language> /// <Overview>Chuck Bartowski is an average computer geek...</Overview> /// <ProductionCode></ProductionCode> /// <Rating>9.0</Rating> /// <SeasonNumber>1</SeasonNumber> /// <Writer>|Josh Schwartz|Chris Fedak|</Writer> /// <absolute_number></absolute_number> /// <airsafter_season></airsafter_season> /// <airsbefore_episode></airsbefore_episode> /// <airsbefore_season></airsbefore_season> /// <filename>episodes/80348-332179.jpg</filename> /// <lastupdated>1201292806</lastupdated> /// <seasonid>27985</seasonid> /// <seriesid>80348</seriesid> /// </Episode> /// ]]> /// </summary> /// <param name="_data"></param> /// <returns></returns> internal List <TvdbEpisode> ExtractEpisodes(String _data) { //Stopwatch watch = new Stopwatch(); //watch.Start(); XDocument xml = XDocument.Parse(_data); var allEpisodes = from episode in xml.Descendants("Episode") select new { Id = episode.Element("id").Value, Combined_episodenumber = episode.Elements("Combined_episodenumber").Count() == 1 ? episode.Element("Combined_episodenumber").Value : "0", Combined_season = episode.Elements("Combined_season").Count() == 1 ? episode.Element("Combined_season").Value : "0", DVD_chapter = episode.Element("DVD_chapter").Value, DVD_discid = episode.Element("DVD_discid").Value, DVD_episodenumber = episode.Element("DVD_episodenumber").Value, DVD_season = episode.Elements("DVD_season").Count() == 1 ? episode.Element("DVD_season").Value : episode.Element("DVD_Season").Value, Director = episode.Element("Director").Value, EpisodeName = episode.Element("EpisodeName").Value, EpisodeNumber = episode.Element("EpisodeNumber").Value, FirstAired = episode.Element("FirstAired").Value, GuestStars = episode.Element("GuestStars").Value, IMDB_ID = episode.Element("IMDB_ID").Value, Language = episode.Elements("Language").Count() == 1 ? episode.Element("Language").Value : "en", Overview = episode.Element("Overview").Value, ProductionCode = episode.Element("ProductionCode").Value, Rating = episode.Element("Rating").Value, SeasonNumber = episode.Element("SeasonNumber").Value, Writer = episode.Element("Writer").Value, absolute_number = episode.Element("absolute_number").Value, filename = episode.Element("filename").Value, lastupdated = episode.Element("lastupdated").Value, seasonid = episode.Element("seasonid").Value, seriesid = episode.Element("seriesid").Value, airsafter_season = episode.Elements("airsafter_season").Count() == 1 ? episode.Element("airsafter_season").Value : Util.NO_VALUE.ToString(), airsbefore_episode = episode.Elements("airsbefore_episode").Count() == 1 ? episode.Element("airsbefore_episode").Value : Util.NO_VALUE.ToString(), airsbefore_season = episode.Elements("airsbefore_season").Count() == 1 ? episode.Element("airsbefore_season").Value : Util.NO_VALUE.ToString() }; //Log.Debug("Parsed xml file in " + watch.ElapsedMilliseconds + " milliseconds"); List <TvdbEpisode> retList = new List <TvdbEpisode>(); foreach (var e in allEpisodes) { int id = Util.Int32Parse(e.Id); if (id == Util.NO_VALUE) { continue; } TvdbEpisode ep = new TvdbEpisode { Id = id, CombinedEpisodeNumber = Util.DoubleParse(e.Combined_episodenumber), CombinedSeason = Util.DoubleParse(e.Combined_season), DvdChapter = Util.Int32Parse(e.DVD_chapter), DvdDiscId = Util.Int32Parse(e.DVD_discid), DvdEpisodeNumber = Util.DoubleParse(e.DVD_episodenumber), DvdSeason = Util.Int32Parse(e.DVD_season), Directors = Util.SplitTvdbString(e.Director, true), EpisodeName = e.EpisodeName, EpisodeNumber = Util.Int32Parse(e.EpisodeNumber), AirsAfterSeason = Util.Int32Parse(e.airsafter_season), AirsBeforeEpisode = Util.Int32Parse(e.airsbefore_episode), AirsBeforeSeason = Util.Int32Parse(e.airsbefore_season), GuestStars = Util.SplitTvdbString(e.GuestStars, true), ImdbId = e.IMDB_ID, Language = TvDbUtils.ParseLanguage(e.Language), Overview = e.Overview, ProductionCode = e.ProductionCode, Rating = Util.DoubleParse(e.Rating), SeasonNumber = Util.Int32Parse(e.SeasonNumber), Writer = Util.SplitTvdbString(e.Writer, true), AbsoluteNumber = Util.Int32Parse(e.absolute_number), BannerPath = e.filename, LastUpdated = Util.UnixToDotNet(e.lastupdated), SeasonId = Util.Int32Parse(e.seasonid), SeriesId = Util.Int32Parse(e.seriesid), Banner = new TvdbEpisodeBanner(id, e.filename) }; DateTime firstAired; ep.FirstAired = DateTime.TryParse(e.FirstAired, out firstAired) ? firstAired : DateTime.MinValue; retList.Add(ep); } //watch.Stop(); //Log.Debug("Extracted " + retList.Count + " Episodes in " + watch.ElapsedMilliseconds + " milliseconds"); return(retList); }
/// <summary> /// Extract all the series fields that are available on thetvdb /// <![CDATA[ /// <?xml version="1.0" encoding="UTF-8" ?> /// <Data> /// <Series> /// <id>73739</id> /// <Actors>|Malcolm David Kelley|Jorge Garcia|Maggie Grace|...|</Actors> /// <Airs_DayOfWeek>Thursday</Airs_DayOfWeek> /// <Airs_Time>9:00 PM</Airs_Time> /// <ContentRating>TV-14</ContentRating> /// <FirstAired>2004-09-22</FirstAired> /// <Genre>|Action and Adventure|Drama|Science-Fiction|</Genre> /// <IMDB_ID>tt0411008</IMDB_ID> /// <Language>en</Language> /// <Network>ABC</Network> /// <Overview>After Oceanic Air flight 815...</Overview> /// <Rating>8.9</Rating> /// <Runtime>60</Runtime> /// <SeriesID>24313</SeriesID> /// <SeriesName>Lost</SeriesName> /// <Status>Continuing</Status> /// <banner>graphical/24313-g2.jpg</banner> /// <fanart>fanart/original/73739-1.jpg</fanart> /// <lastupdated>1205694666</lastupdated> /// <zap2it_id>SH672362</zap2it_id> /// </Series> /// /// </Data> /// ]]> /// </summary> /// <param name="data"></param> /// <returns></returns> internal List <TvdbSeriesFields> ExtractSeriesFields(String data) { //Stopwatch watch = new Stopwatch(); //watch.Start(); XDocument xml = XDocument.Parse(data); var allSeries = from series in xml.Descendants("Series") select new { Id = series.Element("id").Value, Actors = series.Element("Actors").Value, Airs_DayOfWeek = series.Element("Airs_DayOfWeek").Value, Airs_Time = series.Element("Airs_Time").Value, ContentRating = series.Element("ContentRating").Value, FirstAired = series.Element("FirstAired").Value, Genre = series.Element("Genre").Value, IMDB_ID = series.Element("IMDB_ID").Value, Language = series.Element("Language").Value, Network = series.Element("Network").Value, Overview = series.Element("Overview").Value, Rating = series.Element("Rating").Value, Runtime = series.Element("Runtime").Value, SeriesID = series.Element("SeriesID").Value, SeriesName = series.Element("SeriesName").Value, Status = series.Element("Status").Value, banner = series.Elements("banner").Count() == 1 ? series.Element("banner").Value : string.Empty, fanart = series.Elements("fanart").Count() == 1 ? series.Element("fanart").Value : string.Empty, poster = series.Elements("poster").Count() == 1 ? series.Element("poster").Value : string.Empty, lastupdated = series.Element("lastupdated").Value, zap2it_id = series.Element("zap2it_id").Value }; List <TvdbSeriesFields> retList = new List <TvdbSeriesFields>(); foreach (var s in allSeries) { int id = Util.Int32Parse(s.Id); if (id == Util.NO_VALUE) { continue; } TvdbSeriesFields series = new TvdbSeriesFields { Id = id, Actors = Util.SplitTvdbString(s.Actors, true), AirsDayOfWeek = Util.GetDayOfWeek(s.Airs_DayOfWeek), AirsTime = s.Airs_Time, ContentRating = s.ContentRating, FirstAired = Util.ParseDateTime(s.FirstAired), Genre = Util.SplitTvdbString(s.Genre, true), ImdbId = s.IMDB_ID, Language = TvDbUtils.ParseLanguage(s.Language), Network = s.Network, Overview = s.Overview, Rating = Util.DoubleParse(s.Rating), Runtime = Util.DoubleParse(s.Runtime), TvDotComId = Util.Int32Parse(s.SeriesID), SeriesName = s.SeriesName, Status = s.Status, BannerPath = s.banner, FanartPath = s.fanart, PosterPath = s.poster, LastUpdated = Util.UnixToDotNet(s.lastupdated), Zap2itId = s.zap2it_id }; retList.Add(series); } //watch.Stop(); //Log.Debug("Extracted " + retList.Count + " series in " + watch.ElapsedMilliseconds + " milliseconds"); return(retList); }