コード例 #1
0
 private void Init()
 {
     seriesNameMapping = this.config.getSeriesNameMap();
     seriesIgnore = this.config.getIgnoredSeries();
     this.language = SetLanguage();
     this.IntializeRegexMappings();
 }
コード例 #2
0
ファイル: TvdbSeries.cs プロジェクト: revenz/iMeta
 /// <summary>
 /// Set the language of the series to one of the languages that have
 /// already been loaded
 /// </summary>
 /// <param name="_language">The new language for this series</param>
 /// <returns>true if success, false otherwise</returns>
 public bool SetLanguage(TvdbLanguage _language)
 {
     return SetLanguage(_language.Abbriviation);
 }
コード例 #3
0
ファイル: TvdbHandler.cs プロジェクト: svn2github/tvdblib
        /// <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);
              }

              //since we have downloaded the basic series -> if we have a cache provider, also
              //save the series via our CacheProvider
              if (m_cacheProvider != null && m_cacheProvider.Initialised)
              {
                m_cacheProvider.SaveToCache(series);
              }
            }
              }
              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");
              }
        }
コード例 #4
0
ファイル: TvdbHandler.cs プロジェクト: svn2github/tvdblib
 /// <summary>
 /// Gets the series with the given id either from cache (if it has already been loaded) or from 
 /// the selected tvdb mirror.
 /// 
 /// To check if this series has already been cached, use the Method IsCached(TvdbSeries _series)
 /// </summary>
 /// <exception cref="TvdbNotAvailableException">Tvdb is not available</exception>
 /// <exception cref="TvdbInvalidApiKeyException">The given api key is not valid</exception>
 /// <param name="_seriesId">id of series</param>
 /// <param name="_language">language that should be retrieved</param>
 /// <param name="_loadEpisodes">if true, the full series record will be loaded (series + all episodes), otherwise only the base record will be loaded which contains only series information</param>
 /// <param name="_loadActors">if true also loads the extended actor information</param>
 /// <param name="_loadBanners">if true also loads the paths to the banners</param>
 /// <returns>Instance of TvdbSeries containing all gained information</returns>
 public TvdbSeries GetSeries(int _seriesId, TvdbLanguage _language, bool _loadEpisodes,
     bool _loadActors, bool _loadBanners)
 {
     return GetSeries(_seriesId, _language, _loadEpisodes, _loadActors, _loadBanners, false);
 }
コード例 #5
0
ファイル: TvdbHandler.cs プロジェクト: svn2github/tvdblib
 /// <summary>
 /// Retrieve the episode with the given parameters
 /// </summary>
 /// <param name="_seriesId">id of the series</param>
 /// <param name="_airDate">When did the episode air</param>
 /// <param name="_language">language of the episode</param>
 /// <exception cref="TvdbInvalidApiKeyException">The given api key is not valid</exception>
 /// <returns>The retrieved episode</returns>
 public TvdbEpisode GetEpisode(int _seriesId, DateTime _airDate, TvdbLanguage _language)
 {
     TvdbEpisode ep = m_downloader.DownloadEpisode(_seriesId, _airDate, _language);
       return ep;
 }
コード例 #6
0
ファイル: TvdbHandler.cs プロジェクト: svn2github/tvdblib
 /// <summary>
 /// Retrieve the episode with the given id in the given language
 /// 
 /// Note that the episode is always downloaded from thetvdb since it would
 /// be practical to load each and every cached series to look for the 
 /// episode id
 /// </summary>
 /// <param name="_episodeId">id of the episode</param>
 /// <param name="_language">languageof the episode</param>
 /// <returns>The retrieved episode</returns>
 public TvdbEpisode GetEpisode(int _episodeId, TvdbLanguage _language)
 {
     return m_downloader.DownloadEpisode(_episodeId, _language);
 }
コード例 #7
0
ファイル: TvdbHandler.cs プロジェクト: svn2github/tvdblib
 /// <summary>
 /// Gets the series with the given id either from cache (if it has already been loaded) or from 
 /// the selected tvdb mirror. If this series is not already cached and the series has to be 
 /// downloaded, the zipped version will be downloaded
 /// 
 /// To check if this series has already been cached, use the Method IsCached(TvdbSeries _series)
 /// </summary>
 /// <exception cref="TvdbNotAvailableException">Tvdb is not available</exception>
 /// <exception cref="TvdbInvalidApiKeyException">The given api key is not valid</exception>
 /// <param name="_seriesId">id of series</param>
 /// <param name="_language">language that should be retrieved</param>
 /// <returns>Instance of TvdbSeries containing all gained information</returns>
 internal TvdbSeries GetSeriesZipped(int _seriesId, TvdbLanguage _language)
 {
     return GetSeries(_seriesId, _language, true, true, true, true);
 }
コード例 #8
0
ファイル: TvdbLinkCreator.cs プロジェクト: svn2github/tvdblib
        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;
        }
コード例 #9
0
ファイル: TvdbDownloader.cs プロジェクト: svn2github/tvdblib
 /// <summary>
 /// Download the episodes for the given series
 /// </summary>
 /// <param name="_seriesId">the id of the series</param>
 /// <param name="_language">the language in which the episodes should be downloaded</param>
 /// <returns>An episode object or null if no episodes could be found</returns>
 /// <exception cref="TvdbInvalidXmlException"><para>Exception is thrown when there was an error parsing the xml files. </para>
 ///                                           <para>Feel free to post a detailed description of this issue on http://code.google.com/p/tvdblib 
 ///                                           or http://forums.thetvdb.com/</para></exception>  
 /// <exception cref="TvdbInvalidApiKeyException">The stored api key is invalid</exception>
 /// <exception cref="TvdbNotAvailableException">The tvdb database is unavailable</exception>
 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");
     }
       }
 }
コード例 #10
0
ファイル: TvdbDownloader.cs プロジェクト: svn2github/tvdblib
 /// <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>
 /// <exception cref="TvdbInvalidXmlException"><para>Exception is thrown when there was an error parsing the xml files. </para>
 ///                                           <para>Feel free to post a detailed description of this issue on http://code.google.com/p/tvdblib 
 ///                                           or http://forums.thetvdb.com/</para></exception>  
 /// <exception cref="TvdbContentNotFoundException">The episode/series/banner couldn't be located on the tvdb server.</exception>
 /// <exception cref="TvdbNotAvailableException">Exception is thrown when thetvdb isn't available.</exception>
 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");
     }
       }
 }
コード例 #11
0
ファイル: TvdbDownloader.cs プロジェクト: svn2github/tvdblib
        /// <summary>
        /// <para>Download the episode (specified by series id, season number, episode number, language and episode order) from http://thetvdb.com.</para>
        /// <para>It is possible to retrieve episodes by aired order (aka default order), DVD order and absolute order. For a detailled description of these
        /// options see: http://thetvdb.com/wiki/index.php/Category:Episodes</para>
        /// </summary>
        /// <param name="_seriesId">series id</param>
        /// <param name="_seasonNr">season nr</param>
        /// <param name="_episodeNr">episode nr</param>
        /// <param name="_language">language</param>
        /// <param name="_order">order</param>
        /// <returns>The episode object or null if the episode could't be found</returns>
        /// <exception cref="TvdbInvalidXmlException"><para>Exception is thrown when there was an error parsing the xml files. </para>
        ///                                           <para>Feel free to post a detailed description of this issue on http://code.google.com/p/tvdblib 
        ///                                           or http://forums.thetvdb.com/</para></exception>  
        /// <exception cref="TvdbContentNotFoundException">The episode/series/banner couldn't be located on the tvdb server.</exception>
        /// <exception cref="TvdbNotAvailableException">Exception is thrown when thetvdb isn't available.</exception>
        public TvdbEpisode DownloadEpisode(int _seriesId, int _seasonNr, int _episodeNr, TvdbEpisode.EpisodeOrdering _order, TvdbLanguage _language)
        {
            String xml = "";
              String link = "";
              String order = null;
              switch (_order)
              {
            case TvdbEpisode.EpisodeOrdering.AbsoluteOrder:
              order = "absolute";
              break;
            case TvdbEpisode.EpisodeOrdering.DefaultOrder:
              order = "default";
              break;
            case TvdbEpisode.EpisodeOrdering.DvdOrder:
              order = "dvd";
              break;
              }

              try
              {
            link = TvdbLinkCreator.CreateEpisodeLink(m_apiKey, _seriesId, _seasonNr, _episodeNr, order, _language);
            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 " + _seriesId + "/" +
                                                 _order + "/" + _seasonNr + "/" + _episodeNr + "/" + _language.Abbriviation +
                                                 ", maybe the episode or the ordering doesn't exist");
            }
            else
            {
              throw new TvdbNotAvailableException("Couldn't connect to Thetvdb.com to retrieve " + _seriesId + "/" +
                                              _order + "/" + _seasonNr + "/" + _episodeNr + "/" + _language.Abbriviation +
                                              ", check your internet connection and the status of http://thetvdb.com");
            }
              }
        }
コード例 #12
0
ファイル: TvdbDownloader.cs プロジェクト: svn2github/tvdblib
        /// <summary>
        /// Download the given episode from tvdb
        /// </summary>
        /// <param name="_episodeId">Id of episode</param>
        /// <param name="_language">Language in which the episode should be downloaded</param>
        /// <returns>The episode object</returns>
        /// <exception cref="TvdbInvalidXmlException"><para>Exception is thrown when there was an error parsing the xml files. </para>
        ///                                           <para>Feel free to post a detailed description of this issue on http://code.google.com/p/tvdblib 
        ///                                           or http://forums.thetvdb.com/</para></exception>  
        /// <exception cref="TvdbContentNotFoundException">The episode/series/banner couldn't be located on the tvdb server.</exception>
        /// <exception cref="TvdbNotAvailableException">Exception is thrown when thetvdb isn't available.</exception>
        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");
            }
              }
        }
コード例 #13
0
ファイル: TvdbDownloader.cs プロジェクト: svn2github/tvdblib
        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");
            }
              }
        }
コード例 #14
0
 /// <summary>
 /// Set the language of the series to one of the languages that have
 /// already been loaded
 /// </summary>
 /// <param name="_language">The new language for this series</param>
 /// <returns>true if success, false otherwise</returns>
 public bool SetLanguage(TvdbLanguage _language)
 {
     return(SetLanguage(_language.Abbriviation));
 }
コード例 #15
0
ファイル: Util.cs プロジェクト: MichelZ/TheTVDBlib
        /// <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;
        }
コード例 #16
0
ファイル: TvdbLinkCreator.cs プロジェクト: svn2github/tvdblib
 internal static String CreateSeriesLink(String _apiKey, int _seriesId, TvdbLanguage _lang, bool _full, bool _zipped)
 {
     return String.Format("{0}/api/{1}/series/{2}{3}{4}.xml", BASE_SERVER, _apiKey,
                    _seriesId, (_full ? "/all/" : "/"), (_lang != null ? _lang.Abbriviation : "en"));
 }
コード例 #17
0
ファイル: TvdbDownloader.cs プロジェクト: svn2github/tvdblib
 /// <summary>
 /// Download search results for a series search
 /// </summary>
 /// <param name="_name">name of the series</param>
 /// <param name="_language">language of the search</param>
 /// <returns>List of possible matches for the search</returns>
 /// <exception cref="TvdbInvalidXmlException"><para>Exception is thrown when there was an error parsing the xml files. </para>
 ///                                           <para>Feel free to post a detailed description of this issue on http://code.google.com/p/tvdblib 
 ///                                           or http://forums.thetvdb.com/</para></exception>  
 /// <exception cref="TvdbInvalidApiKeyException">The stored api key is invalid</exception>
 /// <exception cref="TvdbNotAvailableException">Exception is thrown when thetvdb isn't available.</exception>
 public List<TvdbSearchResult> DownloadSearchResults(String _name, TvdbLanguage _language)
 {
     String xml = "";
       String link = "";
       try
       {
     link = TvdbLinkCreator.CreateSearchLink(_name, _language);
     xml = m_webClient.DownloadString(link);
     return m_xmlHandler.ExtractSeriesSearchResults(xml);
       }
       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 search results for " + _name +
                                        ", you may use an invalid api key");
     }
     else
     {
       throw new TvdbNotAvailableException("Couldn't connect to Thetvdb.com to retrieve search results for " + _name +
                                       ", check your internet connection and the status of http://thetvdb.com");
     }
       }
 }
コード例 #18
0
ファイル: TvdbDownloader.cs プロジェクト: svn2github/tvdblib
        /// <summary>
        /// <para>Download series from tvdb (specified by series id and language)</para>
        /// </summary>
        /// <param name="_seriesId">id of series</param>
        /// <param name="_language">language of series</param>
        /// <param name="_loadEpisodes">load episodes</param>
        /// <param name="_loadActors">load actors</param>
        /// <param name="_loadBanners">load banners</param>
        /// <returns>The series object or null if the series couldn't be found</returns>
        /// <exception cref="TvdbInvalidXmlException"><para>Exception is thrown when there was an error parsing the xml files. </para>
        ///                                           <para>Feel free to post a detailed description of this issue on http://code.google.com/p/tvdblib 
        ///                                           or http://forums.thetvdb.com/</para></exception>  
        /// <exception cref="TvdbInvalidApiKeyException">The stored api key is invalid</exception>
        /// <exception cref="TvdbNotAvailableException">The tvdb database is unavailable</exception>
        public TvdbSeries DownloadSeries(int _seriesId, TvdbLanguage _language, bool _loadEpisodes, bool _loadActors, bool _loadBanners)
        {
            //download the xml data from this request
              String xml = "";
              String link = "";
              try
              {
            link = TvdbLinkCreator.CreateSeriesLink(m_apiKey, _seriesId, _language, _loadEpisodes, false);
            xml = m_webClient.DownloadString(link);

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

            //if a request is made on a series id, one and only one result
            //should be returned, otherwise there obviously was an error
            if (seriesList != null && seriesList.Count == 1)
            {
              TvdbSeries series = seriesList[0];
              if (_loadEpisodes)
              {
            //add episode info to series
            List<TvdbEpisode> epList = m_xmlHandler.ExtractEpisodes(xml);
            if (epList != null)
            {
              foreach (KeyValuePair<TvdbLanguage, TvdbSeriesFields> kvp in series.SeriesTranslations)
              {
                if (kvp.Key.Abbriviation.Equals(_language.Abbriviation))
                {
                  series.SeriesTranslations[kvp.Key].Episodes = epList;
                  series.SeriesTranslations[kvp.Key].EpisodesLoaded = true;
                  series.SetLanguage(_language);
                  break;
                }
              }
            }

              }

              //also load actors
              if (_loadActors)
              {
            List<TvdbActor> actors = DownloadActors(_seriesId);
            if (actors != null)
            {
              series.TvdbActorsLoaded = true;
              series.TvdbActors = actors;
            }
              }

              //also load banner paths
              if (_loadBanners)
              {
            List<TvdbBanner> banners = DownloadBanners(_seriesId);
            if (banners != null)
            {
              series.Banners = banners;
              series.BannersLoaded = true;
            }
              }
              return series;
            }
            else
            {
              Log.Warn("More than one series returned when trying to retrieve series " + _seriesId);
              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");
            }
              }
        }
コード例 #19
0
ファイル: TvdbDownloader.cs プロジェクト: svn2github/tvdblib
        /// <summary>
        /// Download the series in the given language
        /// </summary>
        /// <param name="_seriesId">id of series</param>
        /// <param name="_language">language of series</param>
        /// <exception cref="TvdbInvalidXmlException"><para>Exception is thrown when there was an error parsing the xml files. </para>
        ///                                           <para>Feel free to post a detailed description of this issue on http://code.google.com/p/tvdblib 
        ///                                           or http://forums.thetvdb.com/</para></exception>  
        /// <exception cref="TvdbInvalidApiKeyException">The stored api key is invalid</exception>
        /// <exception cref="TvdbNotAvailableException">The tvdb database is unavailable</exception>
        /// <returns>the series object</returns>
        public TvdbSeries DownloadSeriesZipped(int _seriesId, TvdbLanguage _language)
        {
            //download the xml data from this request
              byte[] xml = null;
              String link = "";
              try
              {
            link = TvdbLinkCreator.CreateSeriesLinkZipped(m_apiKey, _seriesId, _language);
            xml = m_webClient.DownloadData(link);

            ZipInputStream zip = new ZipInputStream(new MemoryStream(xml));

            ZipEntry entry = zip.GetNextEntry();
            String seriesString = null;
            String actorsString = null;
            String bannersString = null;
            while (entry != null)
            {
              Log.Debug("Extracting " + entry.Name);
              byte[] buffer = new byte[zip.Length];
              int count = zip.Read(buffer, 0, (int)zip.Length);
              if (entry.Name.Equals(_language.Abbriviation + ".xml"))
              {
            seriesString = Encoding.UTF8.GetString(buffer);
              }
              else if (entry.Name.Equals("banners.xml"))
              {
            bannersString = Encoding.UTF8.GetString(buffer);
              }
              else if (entry.Name.Equals("actors.xml"))
              {
            actorsString = Encoding.UTF8.GetString(buffer);
              }
              entry = zip.GetNextEntry();
            }
            zip.Close();

            //extract all series the xml file contains
            List<TvdbSeries> seriesList = m_xmlHandler.ExtractSeries(seriesString);

            //if a request is made on a series id, one and only one result
            //should be returned, otherwise there obviously was an error
            if (seriesList != null && seriesList.Count == 1)
            {
              TvdbSeries series = seriesList[0];
              //add episode info to series
              List<TvdbEpisode> epList = m_xmlHandler.ExtractEpisodes(seriesString);
              if (epList != null)
              {
            foreach (KeyValuePair<TvdbLanguage, TvdbSeriesFields> kvp in series.SeriesTranslations)
            {
              if (kvp.Key.Abbriviation.Equals(_language.Abbriviation))
              {
                series.SeriesTranslations[kvp.Key].Episodes = epList;
                series.SeriesTranslations[kvp.Key].EpisodesLoaded = true;
                series.SetLanguage(_language);
                break;
              }
            }
              }

              //also load actors
              List<TvdbActor> actors = m_xmlHandler.ExtractActors(actorsString);
              if (actors != null)
              {
            series.TvdbActorsLoaded = true;
            series.TvdbActors = actors;
              }

              //also load banner paths
              List<TvdbBanner> banners = m_xmlHandler.ExtractBanners(bannersString);
              if (banners != null)
              {
            series.BannersLoaded = true;
            series.Banners = banners;
              }

              return series;
            }
            else
            {
              Log.Warn("More than one series returned when trying to retrieve series " + _seriesId);
              return null;
            }
              }
              catch (XmlException ex)
              {
            Log.Error("Error parsing the xml file " + link + "\n\n" + Encoding.Unicode.GetString(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 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");
            }
              }
        }
コード例 #20
0
ファイル: TvdbHandler.cs プロジェクト: svn2github/tvdblib
 /// <summary>
 /// Gets the basic series (without episode information and actors) with the given id either from cache 
 /// (if it has already been loaded) or from the selected tvdb mirror.
 /// 
 /// To check if this series has already been cached, please use the Method IsCached(TvdbSeries _series)
 /// </summary>
 /// <exception cref="TvdbNotAvailableException">Tvdb is not available</exception>
 /// <exception cref="TvdbInvalidApiKeyException">The given api key is not valid</exception>
 /// <param name="_seriesId">id of series</param>
 /// <param name="_language">language that should be retrieved</param>
 /// <param name="_loadBanners">if true also loads the paths to the banners</param>
 /// <returns>Instance of TvdbSeries containing all gained information</returns>
 public TvdbSeries GetBasicSeries(int _seriesId, TvdbLanguage _language, bool _loadBanners)
 {
     return GetSeries(_seriesId, _language, false, false, _loadBanners);
 }
コード例 #21
0
ファイル: TvdbLinkCreator.cs プロジェクト: svn2github/tvdblib
 internal static String CreateEpisodeLink(string _apiKey, int _episodeId, TvdbLanguage _lang, bool p)
 {
     return CreateEpisodeLink(_apiKey, _episodeId, (_lang != null ? _lang.Abbriviation : "en"), p);
 }
コード例 #22
0
ファイル: TvdbHandler.cs プロジェクト: svn2github/tvdblib
        /// <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;
        }
コード例 #23
0
ファイル: TvdbLinkCreator.cs プロジェクト: svn2github/tvdblib
 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;
 }
コード例 #24
0
ファイル: TvdbHandler.cs プロジェクト: svn2github/tvdblib
 /// <summary>
 /// Gets the full series (including episode information and actors) with the given id either from cache 
 /// (if it has already been loaded) or from the selected tvdb mirror.
 /// 
 /// To check if this series has already been cached, pleas use the Method IsCached(TvdbSeries _series)
 /// </summary>
 /// <exception cref="TvdbNotAvailableException">Tvdb is not available</exception>
 /// <exception cref="TvdbInvalidApiKeyException">The given api key is not valid</exception>
 /// <param name="_seriesId">id of series</param>
 /// <param name="_language">language that should be retrieved</param>
 /// <param name="_loadBanners">if true also loads the paths to the banners</param>
 /// <returns>Instance of TvdbSeries containing all gained information</returns>
 public TvdbSeries GetFullSeries(int _seriesId, TvdbLanguage _language, bool _loadBanners)
 {
     return GetSeries(_seriesId, _language, true, true, _loadBanners);
 }
コード例 #25
0
ファイル: TvdbLinkCreator.cs プロジェクト: svn2github/tvdblib
 internal static string CreateEpisodeLink(string _apiKey, int _seriesId, DateTime _airDate, TvdbLanguage _language)
 {
     String link = String.Format("{0}/api/GetEpisodeByAirDate.php?apikey={1}&seriesid={2}&airdate={3}&language={4}",
                           BASE_SERVER, _apiKey, _seriesId, _airDate.ToShortDateString(),
                           _language.Abbriviation);
       return link;
 }
コード例 #26
0
ファイル: TvdbHandler.cs プロジェクト: svn2github/tvdblib
        /// <summary>
        /// Gets the series with the given id either from cache (if it has already been loaded) or from 
        /// the selected tvdb mirror. If you use zip the request automatically downloads the episodes, the actors and the banners, so you should also select those features.
        /// 
        /// To check if this series has already been cached, use the Method IsCached(TvdbSeries _series)
        /// </summary>
        /// <exception cref="TvdbNotAvailableException">Tvdb is not available</exception>
        /// <exception cref="TvdbInvalidApiKeyException">The given api key is not valid</exception>
        /// <param name="_seriesId">id of series</param>
        /// <param name="_language">language abbriviation of the series that should be retrieved</param>
        /// <param name="_loadEpisodes">if true, the full series record will be loaded (series + all episodes), otherwise only the base record will be loaded which contains only series information</param>
        /// <param name="_loadBanners">if true also loads the paths to the banners</param>
        /// <param name="_loadActors">if true also loads the extended actor information</param>
        /// <param name="_useZip">If this series is not already cached and the series has to be downloaded, the zipped version will be downloaded</param>
        /// <returns>Instance of TvdbSeries containing all gained information</returns>
        public TvdbSeries GetSeries(int _seriesId, TvdbLanguage _language, bool _loadEpisodes,
            bool _loadActors, bool _loadBanners, bool _useZip)
        {
            Stopwatch watch = new Stopwatch();
              watch.Start();
              TvdbSeries series = GetSeriesFromCache(_seriesId);
              //Did I get the series completely from cache or did I have to make an additional online request
              bool loadedAdditionalInfo = false;

              if (series == null || //series not yet cached
              (_useZip && (!series.EpisodesLoaded && !series.TvdbActorsLoaded && !series.BannersLoaded)))//only the basic series info has been loaded -> zip is still faster than fetching the missing informations without using zip
              {//load complete series from tvdb
            if (_useZip)
            {
              series = m_downloader.DownloadSeriesZipped(_seriesId, _language);
            }
            else
            {
              series = m_downloader.DownloadSeries(_seriesId, _language, _loadEpisodes, _loadActors, _loadBanners);
            }

            if (series == null)
            {
              return null;
            }
            watch.Stop();
            loadedAdditionalInfo = true;
            Log.Info("Loaded series " + _seriesId + " in " + watch.ElapsedMilliseconds + " milliseconds");
            series.IsFavorite = m_userInfo == null ? false : CheckIfSeriesFavorite(_seriesId, m_userInfo.UserFavorites);
              }
              else
              {//some (if not all) information has already been loaded from tvdb at some point -> fill the missing details and return the series

            if (!_language.Abbriviation.Equals(series.Language.Abbriviation))
            {//user wants a different language than the one that has been loaded
              if (series.GetAvailableLanguages().Contains(_language))
              {
            series.SetLanguage(_language);
              }
              else
              {
            TvdbSeriesFields newFields = m_downloader.DownloadSeriesFields(_seriesId, _language);
            loadedAdditionalInfo = true;
            if (_loadEpisodes)
            {
              List<TvdbEpisode> epList = m_downloader.DownloadEpisodes(_seriesId, _language);
              if (epList != null)
              {
                newFields.Episodes = epList;
              }
            }
            if (newFields != null)
            {
              series.AddLanguage(newFields);
              series.SetLanguage(_language);
            }
            else
            {
              Log.Warn("Couldn't load new language " + _language.Abbriviation + " for series " + _seriesId);
              return null;
            }
              }
            }

            if (_loadActors && !series.TvdbActorsLoaded)
            {//user wants actors loaded
              Log.Debug("Additionally loading actors");
              List<TvdbActor> actorList = m_downloader.DownloadActors(_seriesId);
              loadedAdditionalInfo = true;
              if (actorList != null)
              {
            series.TvdbActorsLoaded = true;
            series.TvdbActors = actorList;
              }
            }

            if (_loadEpisodes && !series.EpisodesLoaded)
            {//user wants the full version but only the basic has been loaded (without episodes
              Log.Debug("Additionally loading episodes");
              List<TvdbEpisode> epList = m_downloader.DownloadEpisodes(_seriesId, _language);
              loadedAdditionalInfo = true;
              if (epList != null)
              {
            series.EpisodesLoaded = true;
            series.Episodes = epList;
              }
            }

            if (_loadBanners && !series.BannersLoaded)
            {//user wants banners loaded but current series hasn't -> Do it baby
              Log.Debug("Additionally loading banners");
              List<TvdbBanner> bannerList = m_downloader.DownloadBanners(_seriesId);
              loadedAdditionalInfo = true;
              if (bannerList != null)
              {
            series.BannersLoaded = true;
            series.Banners = bannerList;
              }
            }

            watch.Stop();
            Log.Info("Loaded series " + _seriesId + " in " + watch.ElapsedMilliseconds + " milliseconds");
              }

              if (m_cacheProvider != null)
              {//we're using a cache provider
            //if we've loaded data from online source -> save to cache
            if (m_cacheProvider.Initialised && loadedAdditionalInfo)
            {
              Log.Info("Store series " + _seriesId + " with " + m_cacheProvider.ToString());
              m_cacheProvider.SaveToCache(series);
            }

            //Store a ref to the cacheprovider and series id in each banner, so the banners
            //can be stored/loaded to/from cache
            #region add cache provider/series id
            if (series.Banners != null)
            {
              series.Banners.ForEach(delegate(TvdbBanner b)
              {
            b.CacheProvider = m_cacheProvider;
            b.SeriesId = series.Id;
              });
            }

            if (series.Episodes != null)
            {
              series.Episodes.ForEach(delegate(TvdbEpisode e)
              {
            e.Banner.CacheProvider = m_cacheProvider;
            e.Banner.SeriesId = series.Id;
              });
            }

            if (series.TvdbActors != null)
            {
              series.TvdbActors.ForEach(delegate(TvdbActor a)
              {
            a.ActorImage.CacheProvider = m_cacheProvider;
            a.ActorImage.SeriesId = series.Id;
              });
            }
            #endregion

              }
              return series;
        }
コード例 #27
0
ファイル: TvdbLinkCreator.cs プロジェクト: svn2github/tvdblib
 internal static String CreateSearchLink(String _searchString, TvdbLanguage _language)
 {
     String link = String.Format("{0}/api/GetSeries.php?seriesname={1}&language={2}", BASE_SERVER.Trim('/'), _searchString, _language.Abbriviation);
       return link;
 }
コード例 #28
0
ファイル: TvdbHandler.cs プロジェクト: svn2github/tvdblib
 /// <summary>
 /// Returns if the series is locally cached
 /// </summary>
 /// <param name="_seriesId">Id of the series</param>
 /// <param name="_language">Language</param>
 /// <param name="_loadEpisodes">Load Episodes</param>
 /// <param name="_loadActors">Load Actors</param>
 /// <param name="_loadBanners">Load Banners</param>
 /// <returns>True if the series is cached in the given configuration</returns>
 public bool IsCached(int _seriesId, TvdbLanguage _language, bool _loadEpisodes,
     bool _loadActors, bool _loadBanners)
 {
     if (m_cacheProvider != null && m_cacheProvider.Initialised)
       {
     return m_cacheProvider.IsCached(_seriesId, _language,
                                 _loadEpisodes, _loadBanners, _loadActors);
       }
       return false;
 }
コード例 #29
0
ファイル: TvdbLinkCreator.cs プロジェクト: svn2github/tvdblib
 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;
 }
コード例 #30
0
ファイル: TvdbXmlReader.cs プロジェクト: jcbarton/MUMS
        /// <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;
        }
コード例 #31
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)
        {
            String fName = m_rootFolder + Path.DirectorySeparatorChar + _seriesId +
                     Path.DirectorySeparatorChar + "series_" + _seriesId + ".cfg";
              if (File.Exists(fName))
              {
            try
            {
              FileStream fs = new FileStream(fName, FileMode.Open);
              SeriesConfiguration config = (SeriesConfiguration)m_formatter.Deserialize(fs);
              fs.Close();

              if (config.EpisodesLoaded || !_episodesLoaded &&
             config.BannersLoaded || !_bannersLoaded &&
             config.ActorsLoaded || !_actorsLoaded)
              {
            return true;
              }
              else
              {
            return false;
              }
            }
            catch (SerializationException)
            {
              Log.Warn("Cannot deserialize SeriesConfiguration object");
              return false;
            }
              }
              else
              {
            return false;
              }
        }