コード例 #1
0
        protected override TvdbLanguage FindMatchingLanguage(string shortLanguageString)
        {
            TvdbLanguage returnVal = TvDbUtils.ParseLanguage(shortLanguageString);

            if (returnVal.Id != Util.NO_VALUE)
            {
                return(returnVal);
            }

            return(TvdbLanguage.DefaultLanguage);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        /// <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);
        }
コード例 #4
0
        /// <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);
        }