Exemplo n.º 1
0
 /// <summary>
 /// TvdbSeriesBanner constructor
 /// </summary>
 /// <param name="id">Id of banner</param>
 /// <param name="path">Path of banner image</param>
 /// <param name="lang">Language of this banner</param>
 /// <param name="type">Banner type (text, graphical, blank, None)</param>
 public TvdbSeriesBanner(int id, String path, TvdbLanguage lang, Type type)
 {
   BannerPath = path;
   Language = lang;
   Id = id;
   BannerType = type;
 }
Exemplo n.º 2
0
        /// <summary>
        /// Extract a list of languages when the data has the format:
        /// <![CDATA[
        ///
        /// <?xml version="1.0" encoding="UTF-8" ?>
        /// <Languages>
        ///  <Language>
        ///    <name>Español</name>
        ///    <abbreviation>es</abbreviation>
        ///    <id>16</id>
        ///  </Language>
        /// </Languages>
        ///
        /// ]]>
        /// </summary>
        /// <param name="_data"></param>
        /// <returns></returns>
        internal List <TvdbLanguage> ExtractLanguages(String _data)
        {
            XDocument xml = XDocument.Parse(_data);

            var allLanguages = from language in xml.Descendants("Language")
                               select new
            {
                name         = language.Element("name").Value,
                abbreviation = language.Element("abbreviation").Value,
                id           = language.Element("id").Value
            };

            List <TvdbLanguage> retList = new List <TvdbLanguage>();

            foreach (var l in allLanguages)
            {
                TvdbLanguage lang = new TvdbLanguage();
                lang.Name         = l.name;
                lang.Abbriviation = l.abbreviation;
                lang.Id           = Util.Int32Parse(l.id);

                if (lang.Id != -99)
                {
                    retList.Add(lang);
                }
            }
            return(retList);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Check if the series is cached in the given configuration
        /// </summary>
        /// <param name="seriesId">Id of the series</param>
        /// <param name="lang">Language of the series</param>
        /// <param name="checkEpisodesLoaded">are episodes loaded</param>
        /// <param name="checkBannersLoaded">are banners loaded</param>
        /// <param name="checkActorsLoaded">are actors loaded</param>
        /// <returns>true if the series is cached, false otherwise</returns>
        public bool IsCached(int seriesId, TvdbLanguage lang, bool checkEpisodesLoaded,
                             bool checkBannersLoaded, bool checkActorsLoaded)
        {
            String fName = _rootFolder + Path.DirectorySeparatorChar + seriesId +
                           Path.DirectorySeparatorChar + "series_" + seriesId + ".cfg";

            if (File.Exists(fName))
            {
                try
                {
                    FileStream          fs     = new FileStream(fName, FileMode.Open);
                    SeriesConfiguration config = (SeriesConfiguration)_formatter.Deserialize(fs);
                    fs.Close();

                    return(config.EpisodesLoaded || !checkEpisodesLoaded &&
                           config.BannersLoaded || !checkBannersLoaded &&
                           config.ActorsLoaded || !checkActorsLoaded);
                }
                catch (SerializationException)
                {
                    Log.Warn("Cannot deserialize SeriesConfiguration object");
                    return(false);
                }
            }
            return(false);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Download the episodes
        /// </summary>
        /// <param name="_seriesId"></param>
        /// <param name="_language"></param>
        /// <returns></returns>
        public List <TvdbEpisode> DownloadEpisodes(int _seriesId, TvdbLanguage _language)
        {
            String xml  = "";
            String link = "";

            try
            {
                link = TvdbLinkCreator.CreateSeriesEpisodesLink(m_apiKey, _seriesId, _language);
                xml  = m_webClient.DownloadString(link);
                List <TvdbEpisode> epList = m_xmlHandler.ExtractEpisodes(xml);
                return(epList);
            }
            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 episodes 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 episodes for" + _seriesId +
                                                        ", check your internet connection and the status of http://thetvdb.com");
                }
            }
        }
Exemplo n.º 5
0
        internal static String CreateSeriesLinkZipped(String _apiKey, int _seriesId, TvdbLanguage _lang)
        {
            String link = String.Format("{0}/api/{1}/series/{2}/all/{3}.zip", ActiveMirror.MirrorPath.ToString().Trim('/'), _apiKey, _seriesId,
                                        (_lang != null ? _lang.Abbriviation : "en"));

            return(link);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Initialise the form
        /// </summary>
        /// <param name="_userId"></param>
        public void InitialiseForm(String _userId, ICacheProvider _provider)
        {
            //m_tvdbHandler = new Tvdb(new BinaryCacheProvider(@"cachefile.bin"), Resources.API_KEY);new XmlCacheProvider("XmlCache")

            m_tvdbHandler = new TvdbHandler(_provider, Resources.API_KEY);
            m_tvdbHandler.InitCache();

            List <TvdbLanguage> m_languages = m_tvdbHandler.Languages;

            foreach (TvdbLanguage l in m_languages)
            {
                if (l.Abbriviation.Equals("en"))
                {
                    m_currentLanguage = l;
                }
                cbLanguage.Items.Add(l);
            }
            lblCurrentLanguage.Text = "[" + m_currentLanguage.ToString() + "]";

            //enable/disable community features
            if (_userId != null)
            {
                TvdbUser user = new TvdbUser("user", _userId);
                m_tvdbHandler.UserInfo = user;
                List <TvdbSeries> favList = null;
                try
                {
                    user.UserPreferredLanguage = m_tvdbHandler.GetPreferredLanguage();
                    favList = m_tvdbHandler.GetUserFavorites(user.UserPreferredLanguage);
                }
                catch (TvdbInvalidApiKeyException ex)
                {
                    MessageBox.Show(ex.Message);
                }
                catch (TvdbNotAvailableException ex)
                {
                    MessageBox.Show(ex.Message);
                }

                if (favList != null)
                {
                    foreach (TvdbSeries s in favList)
                    {
                        if (s != null)
                        {
                            cbUserFavourites.Items.Add(s);
                        }
                    }
                }
            }
            else
            {
                cbUserFavourites.Text    = "No userinfo set";
                cbUserFavourites.Enabled = false;
            }

            cmdAddRemoveFavorites.Enabled = false;
            cmdSendSeriesRating.Enabled   = false;
            raterSeriesYourRating.Enabled = false;
        }
Exemplo n.º 7
0
 /// <summary>
 /// TvdbSeriesBanner constructor
 /// </summary>
 /// <param name="id">Id of banner</param>
 /// <param name="path">Path of banner image</param>
 /// <param name="lang">Language of this banner</param>
 /// <param name="type">Banner type (text, graphical, blank, None)</param>
 public TvdbSeriesBanner(int id, String path, TvdbLanguage lang, Type type)
 {
     BannerPath = path;
     Language   = lang;
     Id         = id;
     BannerType = type;
 }
Exemplo n.º 8
0
 /// <summary>
 /// TvdbPosterBanner constructor
 /// </summary>
 /// <param name="_id">Id of fanart banner</param>
 /// <param name="_lang">Language for this banner</param>
 /// <param name="_path">Path of image for this banner</param>
 public TvdbPosterBanner(int _id, String _path, TvdbLanguage _lang)
     : this()
 {
     this.Id = _id;
       this.BannerPath = _path;
       this.Language = _lang;
 }
 /// <summary>
 /// TvdbPosterBanner constructor
 /// </summary>
 /// <param name="id">Id of fanart banner</param>
 /// <param name="lang">Language for this banner</param>
 /// <param name="path">Path of image for this banner</param>
 public TvdbPosterBanner(int id, String path, TvdbLanguage lang)
     : this()
 {
     Id         = id;
     BannerPath = path;
     Language   = lang;
 }
Exemplo n.º 10
0
        /// <summary>
        /// Gets the preferred language of the user
        ///
        /// user information has to be set, otherwise TvdbUserNotFoundException is thrown
        /// </summary>
        /// <returns>preferred language of user</returns>
        public TvdbLanguage GetPreferredLanguage()
        {
            if (m_userInfo != null)
            {
                TvdbLanguage userLang = m_downloader.DownloadUserPreferredLanguage(m_userInfo.UserIdentifier);

                if (userLang != null)
                {
                    //only one language is contained in the userlang file
                    foreach (TvdbLanguage l in m_loadedData.LanguageList)
                    {
                        if (l.Abbriviation.Equals(userLang.Abbriviation))
                        {
                            return(l);
                        }
                    }
                    return(userLang);//couldn't find language -> return new instance
                }
                else
                {
                    return(null); //problem with parsing xml file
                }
            }
            else
            {
                throw new TvdbUserNotFoundException("You can't get the preferred language when no user is specified");
            }
        }
Exemplo n.º 11
0
 /// <summary>
 /// TvdbSeriesBanner constructor
 /// </summary>
 /// <param name="_id">Id of banner</param>
 /// <param name="_path">Path of banner image</param>
 /// <param name="_lang">Language of this banner</param>
 /// <param name="_type">Banner type (text, graphical, blank, none)</param>
 public TvdbSeriesBanner(int _id, String _path, TvdbLanguage _lang, Type _type)
 {
     this.BannerPath = _path;
       this.Language = _lang;
       this.Id = _id;
       this.BannerType = _type;
 }
 private void Init()
 {
     seriesNameMapping = this.config.getSeriesNameMap();
     seriesIgnore      = this.config.getIgnoredSeries();
     this.language     = SetLanguage();
     this.IntializeRegexMappings();
 }
Exemplo n.º 13
0
        internal static String CreateSeriesLinkZipped(String _apiKey, int _seriesId, TvdbLanguage _lang)
        {
            String link = String.Format("{0}/api/{1}/series/{2}/all/{3}.zip", BASE_SERVER, _apiKey, _seriesId,
                                        (_lang != null ? _lang.Abbriviation : "en"));

            return(link);
        }
Exemplo n.º 14
0
 /// <summary>
 /// TvdbPosterBanner constructor
 /// </summary>
 /// <param name="id">Id of fanart banner</param>
 /// <param name="lang">Language for this banner</param>
 /// <param name="path">Path of image for this banner</param>
 public TvdbPosterBanner(int id, String path, TvdbLanguage lang)
   : this()
 {
   Id = id;
   BannerPath = path;
   Language = lang;
 }
Exemplo n.º 15
0
 /// <summary>
 /// TvdbSeriesBanner constructor
 /// </summary>
 /// <param name="_id"></param>
 /// <param name="_path"></param>
 /// <param name="_lang"></param>
 /// <param name="_type"></param>
 public TvdbSeriesBanner(int _id, String _path, TvdbLanguage _lang, Type _type)
 {
     this.BannerPath = _path;
     this.Language   = _lang;
     this.Id         = _id;
     this.BannerType = _type;
 }
Exemplo n.º 16
0
        internal static string CreateEpisodeLink(string _apiKey, int _seriesId, int _seasonNr,
                                                 int _episodeNr, string _order, TvdbLanguage _lang)
        {
            String link = String.Format("{0}/api/{1}/series/{2}/{3}/{4}//{5}/{6}.xml", BASE_SERVER, _apiKey,
                                        _seriesId, _order, _seasonNr, _episodeNr, (_lang != null ? _lang.Abbriviation : "en"));

            return(link);
        }
Exemplo n.º 17
0
        internal static String CreateSeriesEpisodesLink(String apiKey, int seriesId, TvdbLanguage lang)
        {
            //this in fact returns the "full series page (http://thetvdb.com/wiki/index.php/API:Full_Series_Record)
            //which sucks because to retrieve all episodes I have to also download the series information (which isn't)
            //all that big on the other hand
            String link = String.Format("{0}/api/{1}/series/{2}/all/{3}.xml", BASE_SERVER, apiKey, seriesId,
                                        (lang != null ? lang.Abbriviation : "en"));

            return(link);
        }
Exemplo n.º 18
0
        /// <summary>
        /// Check if the series is cached in the given configuration
        /// </summary>
        /// <param name="_seriesId">Id of the series</param>
        /// <param name="_lang">Language of the series</param>
        /// <param name="_episodesLoaded">are episodes loaded</param>
        /// <param name="_bannersLoaded">are banners loaded</param>
        /// <param name="_actorsLoaded">are actors loaded</param>
        /// <returns>true if the series is cached, false otherwise</returns>
        public bool IsCached(int _seriesId, TvdbLanguage _lang, bool _episodesLoaded,
                             bool _bannersLoaded, bool _actorsLoaded)
        {
            bool actorsLoaded   = false;
            bool episodesLoaded = false;
            bool bannersLoaded  = false;

            String seriesRoot = m_rootFolder + Path.DirectorySeparatorChar + _seriesId;

            if (Directory.Exists(seriesRoot))
            {
                if (File.Exists(seriesRoot + Path.DirectorySeparatorChar + _lang.Abbriviation + ".xml"))
                {
                    episodesLoaded = false;
                }
                else if (File.Exists(seriesRoot + Path.DirectorySeparatorChar + _lang.Abbriviation + "_full.xml"))
                {
                    episodesLoaded = true;
                }
                else
                {
                    return(false);
                }

                String bannerFile = seriesRoot + Path.DirectorySeparatorChar + "banners.xml";
                String actorFile  = seriesRoot + Path.DirectorySeparatorChar + "actors.xml";

                //load cached banners
                if (File.Exists(bannerFile))
                {//banners have been already loaded
                    bannersLoaded = true;
                }

                //load actor info
                if (File.Exists(actorFile))
                {
                    actorsLoaded = true;
                }

                if (episodesLoaded || !_episodesLoaded &&
                    bannersLoaded || !_bannersLoaded &&
                    actorsLoaded || !_actorsLoaded)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 19
0
        private int SaveBanners <TE>(IEnumerable <TE> banners, TvdbLanguage language) where TE : TvdbBanner
        {
            int idx = 0;

            foreach (TE tvdbBanner in banners)
            {
                if (tvdbBanner.Language != language)
                {
                    continue;
                }

                if (idx++ >= MAX_FANART_IMAGES)
                {
                    break;
                }

                if (!tvdbBanner.IsLoaded)
                {
                    // We need the image only loaded once, later we will access the cache directly
                    try
                    {
                        tvdbBanner.LoadBanner();
                        tvdbBanner.UnloadBanner();
                    }
                    catch (Exception ex)
                    {
                        ServiceRegistration.Get <ILogger>().Warn("SeriesTvDbMatcher: Exception saving FanArt image", ex);
                    }
                }
            }
            if (idx > 0)
            {
                return(idx);
            }

            // Try fallback languages if no images found for preferred
            if (language != TvdbLanguage.UniversalLanguage && language != TvdbLanguage.DefaultLanguage)
            {
                if (_useUniversalLanguage)
                {
                    idx = SaveBanners(banners, TvdbLanguage.UniversalLanguage);
                    if (idx > 0)
                    {
                        return(idx);
                    }
                }

                idx = SaveBanners(banners, TvdbLanguage.DefaultLanguage);
            }
            return(idx);
        }
Exemplo n.º 20
0
 private void cbLanguage_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (cbLanguage.SelectedItem != null && cbLanguage.SelectedItem.GetType() == typeof(TvdbLanguage))
     {
         lblCurrentLanguage.Text = "[" + ((TvdbLanguage)cbLanguage.SelectedItem).ToString() + "]";
         m_currentLanguage       = (TvdbLanguage)cbLanguage.SelectedItem;
         if (m_currentSeries != null &&
             MessageBox.Show("Change language of current series \"" + m_currentSeries.SeriesName + "\" to " +
                             m_currentLanguage.Name + "?", "Change language", MessageBoxButtons.YesNo) == DialogResult.Yes)
         {
             LoadSeries(m_currentSeries.Id);//reload series with new language
         }
     }
 }
Exemplo n.º 21
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="_episodeId"></param>
 /// <param name="_language"></param>
 /// <returns></returns>
 private TvdbEpisode GetEpisodeFromCache(int _episodeId, TvdbLanguage _language)
 {
     foreach (TvdbSeries s in m_loadedData.SeriesList)
     {
         foreach (TvdbEpisode e in s.Episodes)
         {
             if (e.Id == _episodeId)
             {
                 return(e);
             }
         }
     }
     return(null);
 }
Exemplo n.º 22
0
        /// <summary>
        /// Download the episode specified from http://thetvdb.com
        /// </summary>
        /// <param name="_seriesId">series id</param>
        /// <param name="_airDate">when did the episode air</param>
        /// <param name="_language">language</param>
        /// <returns>Episode</returns>
        public TvdbEpisode DownloadEpisode(int _seriesId, DateTime _airDate, TvdbLanguage _language)
        {
            String xml  = "";
            String link = "";

            try
            {
                link = TvdbLinkCreator.CreateEpisodeLink(m_apiKey, _seriesId, _airDate, _language);
                xml  = m_webClient.DownloadString(link);
                if (!xml.Contains("No Results from SP"))
                {
                    List <TvdbEpisode> epList = m_xmlHandler.ExtractEpisodes(xml);
                    if (epList != null && epList.Count == 1)
                    {
                        epList[0].Banner.SeriesId = _seriesId;
                        return(epList[0]);
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    return(null);
                }
            }
            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 TvdbContentNotFoundException("Couldn't download episode  for series " + _seriesId + " from " +
                                                           _airDate.ToShortDateString() + "(" + _language.Abbriviation +
                                                           "), maybe the episode doesn't exist");
                }
                else
                {
                    throw new TvdbNotAvailableException("Couldn't download episode  for series " + _seriesId + " from " +
                                                        _airDate.ToShortDateString() + "(" + _language.Abbriviation +
                                                        "), maybe the episode doesn't exist");
                }
            }
        }
Exemplo n.º 23
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="_episodeId"></param>
        /// <param name="_language"></param>
        /// <returns></returns>
        public TvdbEpisode GetEpisode(int _episodeId, TvdbLanguage _language)
        {
            TvdbEpisode episode = GetEpisodeFromCache(_episodeId, _language);

            if (episode != null)
            {
                return(episode);
            }
            else
            {
                episode = m_downloader.DownloadEpisode(_episodeId, _language);
                AddEpisodeToCache(episode);
                return(episode);
            }
        }
Exemplo n.º 24
0
        protected override void DownloadFanArt(int tvDbId)
        {
            try
            {
                ServiceRegistration.Get <ILogger>().Debug("SeriesTvDbMatcher Download: Started for ID {0}", tvDbId);

                if (!Init())
                {
                    return;
                }

                TvdbSeries seriesDetail;
                if (!_tv.GetSeriesFanArt(tvDbId, out seriesDetail))
                {
                    return;
                }

                // Save Banners
                ServiceRegistration.Get <ILogger>().Debug("SeriesTvDbMatcher Download: Begin saving banners for ID {0}", tvDbId);
                TvdbLanguage language = _tv.PreferredLanguage;
                SaveBanners(seriesDetail.SeriesBanners, language);

                // Save Season Banners
                ServiceRegistration.Get <ILogger>().Debug("SeriesTvDbMatcher Download: Begin saving season banners for ID {0}", tvDbId);
                // Build a key from Season number and banner type (season or seasonwide), so each combination is handled separately.
                var seasonLookup = seriesDetail.SeasonBanners.ToLookup(s => string.Format("{0}_{1}", s.Season, s.BannerType), v => v);
                foreach (IGrouping <string, TvdbSeasonBanner> tvdbSeasonBanners in seasonLookup)
                {
                    SaveBanners(seasonLookup[tvdbSeasonBanners.Key], language);
                }

                // Save Posters
                ServiceRegistration.Get <ILogger>().Debug("SeriesTvDbMatcher Download: Begin saving posters for ID {0}", tvDbId);
                SaveBanners(seriesDetail.PosterBanners, language);

                // Save FanArt
                ServiceRegistration.Get <ILogger>().Debug("SeriesTvDbMatcher Download: Begin saving fanarts for ID {0}", tvDbId);
                SaveBanners(seriesDetail.FanartBanners, language);
                ServiceRegistration.Get <ILogger>().Debug("SeriesTvDbMatcher Download: Finished ID {0}", tvDbId);

                // Remember we are finished
                FinishDownloadFanArt(tvDbId);
            }
            catch (Exception ex)
            {
                ServiceRegistration.Get <ILogger>().Debug("SeriesTvDbMatcher: Exception downloading FanArt for ID {0}", ex, tvDbId);
            }
        }
        private TvdbLanguage SetLanguage()
        {
            TvdbLanguage lang = TvdbLanguage.DefaultLanguage;

            List <TvdbLanguage> availableLanguages = this.tvDbService.Languages;
            string selectedLanguage = this.config.GetProperty("TvDbLanguage");

            // if there is a value for TvDbLanguage in the settings, set the right language
            if (!string.IsNullOrEmpty(selectedLanguage))
            {
                lang = availableLanguages.Find(x => x.Abbriviation == selectedLanguage);
                this.log.DebugFormat("Language: {0}", lang.Abbriviation);
            }

            return(lang);
        }
Exemplo n.º 26
0
 /// <summary>
 /// Returns if the series is locally cached
 /// </summary>
 /// <param name="_seriesId"></param>
 /// <param name="_language"></param>
 /// <param name="_full"></param>
 /// <returns></returns>
 public bool IsCached(int _seriesId, TvdbLanguage _language, bool _loadEpisodes,
                      bool _loadActors, bool _loadBanners)
 {
     foreach (TvdbSeries s in m_loadedData.SeriesList)
     {
         if (s.Id == _seriesId && s.Language.Abbriviation.Equals(_language.Abbriviation))
         {
             if ((s.BannersLoaded || !_loadActors) &&
                 (s.TvdbActorsLoaded || !_loadActors) &&
                 (s.EpisodesLoaded || !_loadEpisodes))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Exemplo n.º 27
0
        internal TvdbSeriesFields DownloadSeriesFields(int _seriesId, TvdbLanguage _language)
        {
            String xml  = "";
            String link = "";

            try
            {
                link = TvdbLinkCreator.CreateSeriesLink(m_apiKey, _seriesId, _language, false, false);
                xml  = m_webClient.DownloadString(link);

                //extract all series the xml file contains
                List <TvdbSeriesFields> seriesList = m_xmlHandler.ExtractSeriesFields(xml);

                if (seriesList != null && seriesList.Count == 1)
                {
                    return(seriesList[0]);
                }
                else
                {
                    return(null);
                }
            }
            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 " + _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 " + _seriesId +
                                                        ", check your internet connection and the status of http://thetvdb.com");
                }
            }
        }
Exemplo n.º 28
0
        /// <summary>
        /// Parse the short description of a tvdb language and returns the proper
        /// object. If no such language exists yet (maybe the list of available
        /// languages hasn't been downloaded yet), a placeholder is created
        /// </summary>
        /// <param name="shortLanguageDesc"></param>
        /// <returns></returns>
        internal static TvdbLanguage ParseLanguage(String shortLanguageDesc)
        {
            if (_languageList != null)
            {
                foreach (TvdbLanguage l in _languageList.Where(l => l.Abbriviation == shortLanguageDesc))
                {
                    return(l);
                }
            }
            else
            {
                _languageList = new List <TvdbLanguage>();
            }

            //the language doesn't exist yet -> create placeholder
            TvdbLanguage lang = new TvdbLanguage(Util.NO_VALUE, "unknown", shortLanguageDesc);

            _languageList.Add(lang);
            return(lang);
        }
Exemplo n.º 29
0
        /// <summary>
        /// Download the given episode from tvdb
        /// </summary>
        /// <param name="_episodeId"></param>
        /// <param name="_language"></param>
        /// <returns></returns>
        public TvdbEpisode DownloadEpisode(int _episodeId, TvdbLanguage _language)
        {
            String xml  = "";
            String link = "";

            try
            {
                link = TvdbLinkCreator.CreateEpisodeLink(m_apiKey, _episodeId, _language, false);
                xml  = m_webClient.DownloadString(link);
                List <TvdbEpisode> epList = m_xmlHandler.ExtractEpisodes(xml);

                if (epList != null && epList.Count == 1)
                {
                    return(epList[0]);
                }
                else
                {
                    return(null);
                }
            }
            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 TvdbContentNotFoundException("Couldn't download episode " + _episodeId + "(" + _language +
                                                           "), maybe the episode doesn't exist");
                }
                else
                {
                    throw new TvdbNotAvailableException("Couldn't connect to Thetvdb.com to retrieve " + _episodeId +
                                                        ", check your internet connection and the status of http://thetvdb.com");
                }
            }
        }
Exemplo n.º 30
0
        /// <summary>
        /// Saves the series to cache
        /// </summary>
        /// <param name="_series">The series to save</param>
        public void SaveToCache(TvdbSeries _series)
        {
            String root = m_rootFolder + Path.DirectorySeparatorChar + _series.Id;

            if (!Directory.Exists(root))
            {
                Directory.CreateDirectory(root);
            }
            try
            {//delete old cached content
                String[] files = Directory.GetFiles(root, "*.xml");
                foreach (String f in files)
                {
                    File.Delete(f);
                }
            }
            catch (Exception ex)
            {
                Log.Warn("Couldn't delete old cache files", ex);
            }

            TvdbLanguage currentLanguage = _series.Language;

            foreach (KeyValuePair <TvdbLanguage, TvdbSeriesFields> kvp in _series.SeriesTranslations)
            {//write all languages to file
                String fName = root + Path.DirectorySeparatorChar + kvp.Key.Abbriviation +
                               (kvp.Value.EpisodesLoaded ? "_full" : "") + ".xml";
                m_xmlWriter.WriteSeriesContent(new TvdbSeries(kvp.Value), fName);
            }

            if (_series.BannersLoaded)
            {//write the banners file
                m_xmlWriter.WriteSeriesBannerContent(_series.Banners, root + Path.DirectorySeparatorChar + "banners.xml");
            }

            if (_series.TvdbActorsLoaded)
            {//write the actors file
                m_xmlWriter.WriteActorFile(_series.TvdbActors, root + Path.DirectorySeparatorChar + "actors.xml");
            }
        }
Exemplo n.º 31
0
        /// <summary>
        /// Get the favorite series of the user (only basic series information will be loaded)
        /// </summary>
        /// <param name="_lang">Which language should be used</param>
        /// <returns>List of favorite series</returns>
        public List <TvdbSeries> GetUserFavorites(TvdbLanguage _lang)
        {
            if (m_userInfo != null)
            {
                if (_lang != null)
                {
                    List <int>        idList  = GetUserFavouritesList();
                    List <TvdbSeries> retList = new List <TvdbSeries>();

                    foreach (int sId in idList)
                    {
                        if (IsCached(sId, _lang, false, false, false))
                        {
                            retList.Add(GetSeriesFromCache(sId));
                        }
                        else
                        {
                            TvdbSeries series = m_downloader.DownloadSeries(sId, _lang, false, false, false);
                            if (series != null)
                            {
                                retList.Add(series);
                            }
                            AddSeriesToCache(series);
                        }
                    }
                    HandleUserFavoriteRetrieved(idList);
                    return(retList);
                }
                else
                {
                    throw new Exception("you have to define a language");
                }
            }
            else
            {
                throw new TvdbUserNotFoundException("You can't get the favourites when no user is defined");
            }
        }
Exemplo n.º 32
0
        /// <summary>
        /// Parse the short description of a tvdb language and returns the proper
        /// object. If no such language exists yet (maybe the list of available
        /// languages hasn't been downloaded yet), a placeholder is created
        /// </summary>
        /// <param name="_shortLanguageDesc"></param>
        /// <returns></returns>
        internal static TvdbLanguage ParseLanguage(String _shortLanguageDesc)
        {
            if (m_languageList != null)
            {
                foreach (TvdbLanguage l in m_languageList)
                {
                    if (l.Abbriviation == _shortLanguageDesc)
                    {
                        return(l);
                    }
                }
            }
            else
            {
                m_languageList = new List <TvdbLanguage>();
            }

            //the language doesn't exist yet -> create placeholder
            TvdbLanguage lang = new TvdbLanguage(-99, "unknown", _shortLanguageDesc);

            m_languageList.Add(lang);
            return(lang);
        }
Exemplo n.º 33
0
        /// <summary>
        /// Retrieve the episode with the given parameters
        /// </summary>
        /// <param name="_seriesId">id of the series</param>
        /// <param name="_seasonNr">season number of the episode</param>
        /// <param name="_episodeNr">number of the episode</param>
        /// <param name="_language">language of the episode</param>
        /// <param name="_order">The sorting order that should be user when downloading the episode</param>
        /// <returns>The retrieved episode</returns>
        public TvdbEpisode GetEpisode(int _seriesId, int _seasonNr, int _episodeNr,
                                      TvdbEpisode.EpisodeOrdering _order, TvdbLanguage _language)
        {
            String order = null;

            switch (_order)
            {
            case TvdbEpisode.EpisodeOrdering.AbsoluteOrder:
                order = "absolut";
                break;

            case TvdbEpisode.EpisodeOrdering.DefaultOrder:
                order = "default";
                break;

            case TvdbEpisode.EpisodeOrdering.DvdOrder:
                order = "dvd";
                break;
            }

            TvdbEpisode episode = m_downloader.DownloadEpisode(_seriesId, _seasonNr, _episodeNr, order, _language);

            return(episode);
        }
Exemplo n.º 34
0
 /// <summary>
 /// TvdbEpisodeBanner constructor
 /// </summary>
 public TvdbEpisodeBanner()
 {
   Language = new TvdbLanguage(Util.NO_VALUE, "Universal, valid for all languages", "all");
 }
Exemplo n.º 35
0
        private void GetTvDBInfo(string searchMedia, string selectedLang, string fallbackLang)
        {
            const string tvDBFanartPath = "http://thetvdb.com/banners/";

            InitLists();

            string regexSearch = AppSettings.TvDBParseString;

            regexSearch =
                regexSearch.Replace("%show%", @"(?<show>[\w\s]*)")
                .Replace("%season%", @"(?<season>[\d]*)")
                .Replace("%episode%", @"(?<episode>[\d]*)")
                .Replace("%episode_name%", @"(?<episodename>[\w\s]*)");

            Regex searchObj   = new Regex(regexSearch, RegexOptions.Multiline | RegexOptions.Singleline | RegexOptions.ExplicitCapture);
            Match matchResult = searchObj.Match(searchMedia);

            // check first if we can use the search string
            if (!matchResult.Success)
            {
                regexSearch = regexSearch.Replace(@"(?<episodename>[\w\s]*)", "").Trim().TrimEnd(new [] { '-' }).Trim();
                searchObj   = new Regex(regexSearch, RegexOptions.Multiline | RegexOptions.Singleline | RegexOptions.ExplicitCapture);
                matchResult = searchObj.Match(searchMedia);
                if (!matchResult.Success)
                {
                    return;
                }
            }

            TvdbLanguage dbLang = _tvDbclient.Languages.Single(language => language.Abbriviation == selectedLang) ??
                                  _tvDbclient.Languages.Single(language => language.Abbriviation == fallbackLang);

            List <TvdbSearchResult> searchResults = _tvDbclient.SearchSeries(matchResult.Groups["show"].Value, dbLang);

            if (searchResults == null)
            {
                return;
            }

            TvdbSearchResult resultShow = new TvdbSearchResult();

            if (searchResults.Count > 1)
            {
                DBMultipleSelection selectWindow = new DBMultipleSelection
                {
                    Owner             = this,
                    TvdbSearchResults = searchResults
                };
                if (selectWindow.ShowDialog() == true)
                {
                    resultShow = selectWindow.TvdbSelectionResult;
                }
            }
            else
            {
                resultShow = searchResults.Count > 0 ? searchResults.First() : null;
            }

            if (resultShow == null || resultShow.Id == 0)
            {
                return;
            }

            TvdbSeries series = _tvDbclient.GetSeries(resultShow.Id, dbLang, true, true, true, true);

            TvShowTitle.Text      = series.SeriesName;
            TvShowGenre.Text      = string.Join(" / ", series.Genre);
            TvShowRating.Text     = series.Rating.ToString("g", AppSettings.CInfo);
            TvShowRuntime.Text    = series.Runtime.ToString("g", AppSettings.CInfo);
            TvShowFirstAired.Text = series.FirstAired.ToString("yyyy-MM-dd");
            TvShowPlot.Text       = series.Overview;
            TvShowMpaaRating.Text = series.ContentRating;
            TvShowImdbId.Text     = series.ImdbId;
            TvShowNetwork.Text    = series.Network;

            foreach (TvdbEpisode episode in series.Episodes)
            {
                DBTvShowSeason season;
                try
                {
                    season = _seasonList.First(showSeason => showSeason.SeasonNumber == episode.SeasonNumber);
                }
                catch (InvalidOperationException)
                {
                    season = new DBTvShowSeason
                    {
                        SeasonNumber = episode.SeasonNumber,
                        Title        = episode.IsSpecial ? "Special" : "Season " + episode.SeasonNumber
                    };
                    _seasonList.Add(season);
                }

                season.Episodes.Add(new DBTvShowEpisode
                {
                    Directors             = episode.Directors,
                    Writers               = episode.Writer,
                    SeasonNumber          = episode.SeasonNumber,
                    Runtime               = (int)series.Runtime,
                    Rating                = episode.Rating,
                    Plot                  = episode.Overview,
                    IsSpecial             = episode.IsSpecial,
                    ImdbId                = episode.ImdbId,
                    GuestStars            = episode.GuestStars,
                    FirstAired            = episode.FirstAired,
                    EpisodeTitle          = episode.EpisodeName,
                    EpisodeNumber         = episode.EpisodeNumber,
                    DvdEpisodeNumber      = episode.DvdEpisodeNumber,
                    CombinedEpisodeNumber = episode.CombinedEpisodeNumber,
                    AbsoluteEpisodeNumber = episode.AbsoluteNumber,
                    EpisodeImageUrl       = tvDBFanartPath + episode.BannerPath,
                });
            }

            TvShowSeason.ItemsSource = _seasonList;

            int tempInt;

            int.TryParse(matchResult.Groups["season"].Value, NumberStyles.Integer, AppSettings.CInfo, out tempInt);
            TvShowSeason.SelectedIndex = _seasonList.ToList().FindIndex(season => season.SeasonNumber == tempInt);

            int.TryParse(matchResult.Groups["episode"].Value, NumberStyles.Integer, AppSettings.CInfo, out tempInt);
            TvShowEpisodeNumber.SelectedIndex =
                ((List <DBTvShowEpisode>)TvShowEpisodeNumber.Items.SourceCollection).FindIndex(
                    episode => episode.EpisodeNumber == tempInt);

            int imageCounter = 1;

            foreach (TvdbSeriesBanner banner in series.SeriesBanners)
            {
                _bannerList.Add(new MovieDBBannerImage
                {
                    UrlOriginal = tvDBFanartPath + banner.BannerPath,
                    UrlPreview  =
                        tvDBFanartPath + (!string.IsNullOrEmpty(banner.ThumbPath)
                                                  ? banner.ThumbPath
                                                  : "_cache/" + banner.BannerPath),
                    Title = "Online image " + imageCounter
                });
                imageCounter++;
            }
            foreach (TvdbSeasonBanner banner in series.SeasonBanners)
            {
                _seasonBannerList.Add(new MovieDBSeasonBannerImage
                {
                    UrlOriginal = tvDBFanartPath + banner.BannerPath,
                    UrlPreview  =
                        tvDBFanartPath + (!string.IsNullOrEmpty(banner.ThumbPath)
                                                  ? banner.ThumbPath
                                                  : "_cache/" + banner.BannerPath),
                    Title  = "Online image " + imageCounter,
                    Season = banner.Season
                });
                imageCounter++;
            }
            _bannerList.ToList().ForEach(image => _previewBannerList.Add(image));
            _seasonBannerList.ToList().ForEach(image => _previewBannerList.Add(image));

            imageCounter = 1;
            foreach (TvdbFanartBanner banner in series.FanartBanners)
            {
                _backdropsList.Add(new MovieDBImageInfo
                {
                    Title       = "Online image " + imageCounter,
                    UrlOriginal = tvDBFanartPath + banner.BannerPath,
                    UrlPreview  =
                        tvDBFanartPath + (!string.IsNullOrEmpty(banner.ThumbPath)
                                                  ? banner.ThumbPath
                                                  : "_cache/" + banner.BannerPath)
                });
                imageCounter++;
            }

            imageCounter = 1;
            foreach (TvdbPosterBanner banner in series.PosterBanners)
            {
                _postersList.Add(new MovieDBPosterImage
                {
                    Title       = "Online image " + imageCounter,
                    UrlOriginal = tvDBFanartPath + banner.BannerPath,
                    UrlPreview  =
                        tvDBFanartPath + (!string.IsNullOrEmpty(banner.ThumbPath)
                                                  ? banner.ThumbPath
                                                  : "_cache/" + banner.BannerPath)
                });
                imageCounter++;
            }
            TvShowBannerList.ItemsSource   = _previewBannerList;
            TvShowBannerList.SelectedValue = tvDBFanartPath + "_cache/" + series.BannerPath;

            TvShowFanartList.ItemsSource   = _backdropsList;
            TvShowFanartList.SelectedValue = tvDBFanartPath + "_cache/" + series.FanartPath;

            TvShowPosterList.ItemsSource   = _postersList;
            TvShowPosterList.SelectedValue = tvDBFanartPath + "_cache/" + series.PosterPath;

            foreach (TvdbActor actor in series.TvdbActors)
            {
                _castList.Casts.Add(new MovieDBCast
                {
                    Name      = actor.Name,
                    Role      = actor.Role,
                    Thumbnail =
                        actor.ActorImage != null && !string.IsNullOrEmpty(actor.ActorImage.BannerPath)
                                ? tvDBFanartPath + actor.ActorImage.BannerPath
                                : string.Empty
                });
            }
            TvShowCastList.ItemsSource = _castList.Casts;

            ResultTabControl.SelectedIndex = 2;
        }
Exemplo n.º 36
0
 /// <summary>
 /// TvdbFanartBanner constructor
 /// </summary>
 public TvdbFanartBanner(int _id, String _path, TvdbLanguage _lang)
 {
     this.Id = _id;
       this.BannerPath = _path;
       this.Language = _lang;
 }
Exemplo n.º 37
0
 /// <summary>
 /// TvdbFanartBanner constructor
 /// </summary>
 /// <param name="id">Id of fanart banner</param>
 /// <param name="lang">Language for this banner</param>
 /// <param name="path">Path of image for this banner</param>
 public TvdbFanartBanner(int id, String path, TvdbLanguage lang)
 {
   Id = id;
   BannerPath = path;
   Language = lang;
 }