Пример #1
0
        /// <summary>
        /// Download the banners
        /// </summary>
        /// <param name="_seriesId"></param>
        /// <returns></returns>
        public List <TvdbBanner> DownloadBanners(int _seriesId)
        {
            String xml  = "";
            String link = "";

            try
            {
                link = TvdbLinkCreator.CreateSeriesBannersLink(m_apiKey, _seriesId);
                xml  = m_webClient.DownloadString(link);
                List <TvdbBanner> banners = m_xmlHandler.ExtractBanners(xml);
                return(banners);
            }
            catch (XmlException ex)
            {
                Log.Error("Error parsing the xml file " + link + "\n\n" + xml, ex);
                throw new TvdbInvalidXmlException("Error parsing the xml file " + link + "\n\n" + xml);
            }
            catch (WebException ex)
            {
                Log.Warn("Request not successfull", ex);
                if (ex.Message.Equals("The remote server returned an error: (404) Not Found."))
                {
                    throw new TvdbInvalidApiKeyException("Couldn't connect to Thetvdb.com to retrieve banners fo " + _seriesId +
                                                         ", you may use an invalid api key  or the series doesn't exists");
                }
                else
                {
                    throw new TvdbNotAvailableException("Couldn't connect to Thetvdb.com to retrieve banners for" + _seriesId +
                                                        ", check your internet connection and the status of http://thetvdb.com");
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Download the banners
        /// </summary>
        /// <param name="_seriesId"></param>
        /// <returns></returns>
        internal List <TvdbBanner> DownloadBanners(int _seriesId)
        {
            String xml;

            try
            {
                xml = m_webClient.DownloadString(TvdbLinks.CreateSeriesBannersLink(m_apiKey, _seriesId));
            }
            catch (WebException ex)
            {
                Log.Warn("Request not successfull", ex);
                if (ex.Message.Equals("The remote server returned an error: (404) Not Found."))
                {
                    throw new TvdbInvalidApiKeyException("Couldn't connect to Thetvdb.com to retrieve banners fo " + _seriesId +
                                                         ", it seems like you have an invalid api key (" + m_apiKey + ")");
                }
                else
                {
                    throw new TvdbNotAvailableException("Couldn't connect to Thetvdb.com to retrieve banners for" + _seriesId +
                                                        ", check your internet connection and the status of http://thetvdb.com");
                }
            }
            List <TvdbBanner> banners = m_xmlHandler.ExtractBanners(xml);

            return(banners);
        }
Пример #3
0
        /// <summary>
        /// Download the banners
        /// </summary>
        /// <param name="_seriesId"></param>
        /// <returns></returns>
        internal List <TvdbBanner> DownloadBanners(int _seriesId)
        {
            String            xml     = m_webClient.DownloadString(TvdbLinks.CreateSeriesBannersLink(m_apiKey, _seriesId));
            List <TvdbBanner> banners = m_xmlHandler.ExtractBanners(xml);

            return(banners);
        }
Пример #4
0
        /// <summary>
        /// Load the give series from cache
        /// </summary>
        /// <param name="_seriesId">Id of the series to load</param>
        /// <returns>Series that has been loaded or null if series doesn't exist</returns>
        public TvdbSeries LoadSeriesFromCache(int _seriesId)
        {
            String seriesRoot = m_rootFolder + Path.DirectorySeparatorChar + _seriesId;

            if (!Directory.Exists(seriesRoot))
            {
                return(null);
            }
            TvdbSeries series = new TvdbSeries();

            #region load series in all available languages
            String[] seriesLanguages = Directory.GetFiles(seriesRoot, "*.xml");
            foreach (String l in seriesLanguages)
            {
                if (!l.EndsWith("actors.xml") && !l.EndsWith("banners.xml"))
                {
                    String content = File.ReadAllText(l);
                    List <TvdbSeriesFields> seriesList = m_xmlReader.ExtractSeriesFields(content);
                    if (seriesList != null && seriesList.Count == 1)
                    {
                        TvdbSeriesFields s = seriesList[0];
                        //Load episodes
                        if (l.EndsWith("full.xml"))
                        {
                            List <TvdbEpisode> epList = m_xmlReader.ExtractEpisodes(content);
                            s.EpisodesLoaded = true;
                            s.Episodes.Clear();
                            s.Episodes.AddRange(epList);
                        }
                        series.AddLanguage(s);
                    }
                }
            }



            if (series.SeriesTranslations.Count > 0)
            {//change language of the series to the default language
                series.SetLanguage(series.SeriesTranslations.Keys.First());
            }
            else
            {//no series info could be loaded
                return(null);
            }

            if (!series.BannerPath.Equals(""))
            {
                series.Banners.Add(new TvdbSeriesBanner(series.Id, series.BannerPath, series.Language, TvdbSeriesBanner.Type.graphical));
            }

            if (!series.PosterPath.Equals(""))
            {
                series.Banners.Add(new TvdbPosterBanner(series.Id, series.PosterPath, series.Language));
            }

            if (!series.FanartPath.Equals(""))
            {
                series.Banners.Add(new TvdbFanartBanner(series.Id, series.FanartPath, series.Language));
            }

            Regex rex = new Regex("S(\\d+)E(\\d+)");
            if (Directory.Exists(seriesRoot + Path.DirectorySeparatorChar + "EpisodeImages"))
            {
                String[] episodeFiles = Directory.GetFiles(seriesRoot + Path.DirectorySeparatorChar + "EpisodeImages", "ep_*.jpg");
                foreach (String epImageFile in episodeFiles)
                {
                    try
                    {
                        Match match   = rex.Match(epImageFile);
                        int   season  = Int32.Parse(match.Groups[1].Value);
                        int   episode = Int32.Parse(match.Groups[2].Value);
                        foreach (TvdbEpisode e in series.Episodes)
                        {
                            if (e.SeasonNumber == season && e.EpisodeNumber == episode)
                            {
                                if (epImageFile.Contains("thumb"))
                                {
                                    e.Banner.LoadThumb(Image.FromFile(epImageFile));
                                }
                                else
                                {
                                    e.Banner.LoadBanner(Image.FromFile(epImageFile));
                                }
                                break;
                            }
                        }
                    }
                    catch (Exception)
                    {
                        Log.Warn("Couldn't load episode image file " + epImageFile);
                    }
                }
            }

            #endregion

            #region Banner loading
            String bannerFile = seriesRoot + Path.DirectorySeparatorChar + "banners.xml";
            //load cached banners
            if (File.Exists(bannerFile))
            {//banners have been already loaded
                List <TvdbBanner> bannerList = m_xmlReader.ExtractBanners(File.ReadAllText(bannerFile));

                String[] banners = Directory.GetFiles(seriesRoot, "banner*.jpg");
                foreach (String b in banners)
                {
                    try
                    {
                        int bannerId = Int32.Parse(b.Remove(b.IndexOf(".")).Remove(0, b.LastIndexOf("_") + 1));
                        foreach (TvdbBanner banner in bannerList)
                        {
                            if (banner.Id == bannerId)
                            {
                                if (b.Contains("thumb") && banner.GetType().BaseType == typeof(TvdbBannerWithThumb))
                                {
                                    ((TvdbBannerWithThumb)banner).LoadThumb(Image.FromFile(b));
                                }
                                else if (b.Contains("vignette") && banner.GetType() == typeof(TvdbFanartBanner))
                                {
                                    ((TvdbFanartBanner)banner).LoadVignette(Image.FromFile(b));
                                }
                                else
                                {
                                    banner.LoadBanner(Image.FromFile(b));
                                }
                            }
                        }
                    }
                    catch (Exception)
                    {
                        Log.Warn("Couldn't load image file " + b);
                    }
                }
                series.Banners = bannerList;
            }
            #endregion

            #region actor loading
            //load actor info
            String actorFile = seriesRoot + Path.DirectorySeparatorChar + "actors.xml";
            if (File.Exists(actorFile))
            {
                List <TvdbActor> actorList = m_xmlReader.ExtractActors(File.ReadAllText(actorFile));

                String[] banners = Directory.GetFiles(seriesRoot, "actor_*.jpg");
                foreach (String b in banners)
                {
                    try
                    {
                        int actorId = Int32.Parse(b.Remove(b.IndexOf(".")).Remove(0, b.LastIndexOf("_") + 1));
                        foreach (TvdbActor actor in actorList)
                        {
                            if (actor.Id == actorId)
                            {
                                actor.ActorImage.LoadBanner(Image.FromFile(b));
                            }
                        }
                    }
                    catch (Exception)
                    {
                        Log.Warn("Couldn't load image file " + b);
                    }
                }
                series.TvdbActors = actorList;
            }
            #endregion

            return(series);
        }
Пример #5
0
        /// <summary>
        /// Load the give series from cache
        /// </summary>
        /// <param name="_seriesId"></param>
        /// <returns></returns>
        public TvdbSeries LoadSeriesFromCache(int _seriesId)
        {
            String seriesRoot = m_rootFolder + "\\" + _seriesId;
            String xmlFile    = seriesRoot + "\\all.xml";

            if (!File.Exists(xmlFile))
            {
                return(null);
            }
            String            content    = File.ReadAllText(xmlFile);
            List <TvdbSeries> seriesList = m_xmlReader.ExtractSeries(content);

            if (seriesList != null && seriesList.Count == 1)
            {
                TvdbSeries         series = seriesList[0];
                List <TvdbEpisode> epList = m_xmlReader.ExtractEpisodes(content);
                series.Episodes = epList;
                String bannerFile = seriesRoot + "\\banners.xml";
                String actorFile  = seriesRoot + "\\actors.xml";
                Regex  rex        = new Regex("S(\\d+)E(\\d+)");


                if (Directory.Exists(seriesRoot + "\\EpisodeImages"))
                {
                    String[] episodeFiles = Directory.GetFiles(seriesRoot + "\\EpisodeImages", "*.jpg");
                    foreach (String epImageFile in episodeFiles)
                    {
                        try
                        {
                            Match match   = rex.Match(epImageFile);
                            int   season  = Int32.Parse(match.Groups[1].Value);
                            int   episode = Int32.Parse(match.Groups[2].Value);
                            foreach (TvdbEpisode e in series.Episodes)
                            {
                                if (e.SeasonNumber == season && e.EpisodeNumber == episode)
                                {
                                    e.Banner.LoadBanner(Image.FromFile(epImageFile));
                                    break;
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Log.Warn("Couldn't load episode image file " + epImageFile);
                        }
                    }
                }
                //load cached banners
                if (File.Exists(bannerFile))
                {//banners have been already loaded
                    List <TvdbBanner> bannerList = m_xmlReader.ExtractBanners(File.ReadAllText(bannerFile));

                    String[] banners = Directory.GetFiles(seriesRoot, "banner*.jpg");
                    foreach (String b in banners)
                    {
                        try
                        {
                            int bannerId = Int32.Parse(b.Remove(b.IndexOf(".")).Remove(0, b.LastIndexOf("_") + 1));
                            foreach (TvdbBanner banner in bannerList)
                            {
                                if (banner.Id == bannerId)
                                {
                                    if (b.Contains("thumb") && banner.GetType() == typeof(TvdbFanartBanner))
                                    {
                                        ((TvdbFanartBanner)banner).LoadThumb(Image.FromFile(b));
                                    }
                                    else if (b.Contains("vignette") && banner.GetType() == typeof(TvdbFanartBanner))
                                    {
                                        ((TvdbFanartBanner)banner).LoadVignette(Image.FromFile(b));
                                    }
                                    else
                                    {
                                        banner.LoadBanner(Image.FromFile(b));
                                    }
                                }
                            }
                        }
                        catch (Exception)
                        {
                            Log.Warn("Couldn't load image file " + b);
                        }
                    }
                    series.Banners = bannerList;
                }

                //load actor info
                if (File.Exists(actorFile))
                {
                    List <TvdbActor> actorList = m_xmlReader.ExtractActors(File.ReadAllText(actorFile));

                    String[] banners = Directory.GetFiles(seriesRoot, "actor_*.jpg");
                    foreach (String b in banners)
                    {
                        try
                        {
                            int actorId = Int32.Parse(b.Remove(b.IndexOf(".")).Remove(0, b.LastIndexOf("_") + 1));
                            foreach (TvdbActor actor in actorList)
                            {
                                if (actor.Id == actorId)
                                {
                                    actor.ActorImage.LoadBanner(Image.FromFile(b));
                                }
                            }
                        }
                        catch (Exception)
                        {
                            Log.Warn("Couldn't load image file " + b);
                        }
                    }
                    series.TvdbActors = actorList;
                }

                return(series);
            }
            else
            {
                return(null);
            }
        }