예제 #1
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;
    }
예제 #2
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;
    }
예제 #3
0
 /// <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.Empty;
   String link = string.Empty;
   try
   {
     link = TvdbLinkCreator.CreateSeriesEpisodesLink(_apiKey, seriesId, language);
     xml = DownloadString(link);
     List<TvdbEpisode> epList = _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)
   {
     throw HandleWebException("retrieve episodes for series " + seriesId, ex);
   }
 }
예제 #4
0
    /// <summary>
    /// Retrieve the episode with the given parameters. This function will find
    /// episodes that are already cached.
    /// </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>
    /// <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 GetEpisode(int seriesId, int seasonNr, int episodeNr, TvdbEpisode.EpisodeOrdering order, TvdbLanguage language)
    {
      TvdbEpisode episode = null;
      if (_cacheProvider != null && _cacheProvider.Initialised)
      {
        if (_cacheProvider.IsCached(seriesId, language, true, false, false))
        {
          TvdbSeries series = _cacheProvider.LoadSeriesFromCache(seriesId);
          if (series.Language != language)
          {
            series.SetLanguage(language);
          }

          if (series.Episodes != null)
          {
            foreach (TvdbEpisode e in series.Episodes)
            {
              if (e.EpisodeNumber == episodeNr && e.SeasonNumber == seasonNr && order == TvdbEpisode.EpisodeOrdering.DefaultOrder ||
                  e.DvdEpisodeNumber == episodeNr && e.SeasonNumber == seasonNr && order == TvdbEpisode.EpisodeOrdering.DvdOrder ||
                  e.AbsoluteNumber == episodeNr && order == TvdbEpisode.EpisodeOrdering.AbsoluteOrder)
              {//We found the episode that matches the episode number according to the given ordering
                episode = e;
                break;
              }
            }
          }
        }
      }

      return episode ?? _downloader.DownloadEpisode(seriesId, seasonNr, episodeNr, order, language);
    }
예제 #5
0
 /// <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 (_cacheProvider != null && _cacheProvider.Initialised)
     return _cacheProvider.IsCached(seriesId, language, loadEpisodes, loadBanners, loadActors);
   return false;
 }
예제 #6
0
 /// <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>
 /// <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 GetFullSeries(int seriesId, TvdbLanguage language, bool loadBanners)
 {
   return GetSeries(seriesId, language, true, true, loadBanners);
 }
예제 #7
0
 /// <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
 /// <summary>
 /// Search for a seris on tvdb using the name of the series
 /// </summary>
 /// <param name="name">Name of series</param>
 /// <param name="language">Language to search in</param>
 /// <returns>List of possible hits (containing only very basic information (id, name,....)</returns>
 public List<TvdbSearchResult> SearchSeries(String name, TvdbLanguage language)
 {
   List<TvdbSearchResult> retSeries = _downloader.DownloadSearchResults(name, language);
   return retSeries;
 }
예제 #9
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>
 /// <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.Empty;
   String link = string.Empty;
   try
   {
     link = TvdbLinkCreator.CreateEpisodeLink(_apiKey, seriesId, airDate, language);
     xml = DownloadString(link);
     if (!xml.Contains("No Results from SP"))
     {
       List<TvdbEpisode> epList = _xmlHandler.ExtractEpisodes(xml);
       if (epList != null && epList.Count == 1)
       {
         epList[0].Banner.SeriesId = seriesId;
         return epList[0];
       }
     }
     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)
   {
     throw HandleContentWebException(
       string.Format("Couldn't download episode  for series {0} from {1}({2}), maybe the episode doesn't exist", seriesId, airDate.ToShortDateString(), language.Abbriviation), 
       ex);
   }
 }
예제 #10
0
    /// <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 orderString = null;
      switch (order)
      {
        case TvdbEpisode.EpisodeOrdering.AbsoluteOrder:
          orderString = "absolute";
          break;
        case TvdbEpisode.EpisodeOrdering.DefaultOrder:
          orderString = "default";
          break;
        case TvdbEpisode.EpisodeOrdering.DvdOrder:
          orderString = "dvd";
          break;
      }

      try
      {
        link = TvdbLinkCreator.CreateEpisodeLink(_apiKey, seriesId, seasonNr, episodeNr, orderString, language);
        xml = DownloadString(link);
        List<TvdbEpisode> epList = _xmlHandler.ExtractEpisodes(xml);
        return epList != null && epList.Count == 1 ? epList[0] : 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)
      {
        throw HandleContentWebException(
          string.Format("Couldn't download episode {0}/{1}/{2}/{3}/{4}, maybe the episode or the ordering doesn't exist", seriesId, order, seasonNr, episodeNr, language.Abbriviation),
          ex);
      }
    }
예제 #11
0
 /// <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(_apiKey, episodeId, language, false);
     xml = DownloadString(link);
     List<TvdbEpisode> epList = _xmlHandler.ExtractEpisodes(xml);
     return epList != null && epList.Count == 1 ? epList[0] : 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)
   {
     throw HandleContentWebException("Couldn't download episode " + episodeId + "(" + language + "), maybe the episode doesn't exist", ex);
   }
 }
예제 #12
0
    internal TvdbSeriesFields DownloadSeriesFields(int seriesId, TvdbLanguage language)
    {
      String xml = string.Empty;
      String link = string.Empty;
      try
      {
        link = TvdbLinkCreator.CreateSeriesLink(_apiKey, seriesId, language, false, false);
        xml = DownloadString(link);

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

        return seriesList != null && seriesList.Count == 1 ? seriesList[0] : 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)
      {
        throw HandleWebException("retrieve fields for series " + seriesId, ex);
      }
    }
예제 #13
0
    /// <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 = string.Empty;
      try
      {
        link = TvdbLinkCreator.CreateSeriesLinkZipped(_apiKey, seriesId, language);
        xml = 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 = _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 = _xmlHandler.ExtractEpisodes(seriesString);
          if (epList != null)
          {
            foreach (KeyValuePair<TvdbLanguage, TvdbSeriesFields> kvp in series.SeriesTranslations.Where(kvp => 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 = _xmlHandler.ExtractActors(actorsString);
          if (actors != null)
          {
            series.TvdbActorsLoaded = true;
            series.TvdbActors = actors;
          }

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

          return series;
        }
        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)
      {
        throw HandleWebException("retrieve zipped series details for " + seriesId, ex);
      }
    }
예제 #14
0
    /// <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.Empty;
      String link = string.Empty;
      try
      {
        link = TvdbLinkCreator.CreateSeriesLink(_apiKey, seriesId, language, loadEpisodes, false);
        xml = DownloadString(link);

        //extract all series the xml file contains
        List<TvdbSeries> seriesList = _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 = _xmlHandler.ExtractEpisodes(xml);
            if (epList != null)
            {
              foreach (KeyValuePair<TvdbLanguage, TvdbSeriesFields> kvp in series.SeriesTranslations.Where(kvp => 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;
        }
        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)
      {
        throw HandleWebException("retrieve series details for " + seriesId, ex);
      }
    }
예제 #15
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;
    }
예제 #16
0
 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
 /// <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.Empty;
   String link = string.Empty;
   try
   {
     link = TvdbLinkCreator.CreateSearchLink(name, language);
     xml = DownloadString(link);
     return _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)
   {
     throw HandleWebException("retrieve search results for " + name, ex);
   }
 }
예제 #18
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;
 }
예제 #19
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);
 }
예제 #20
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>
    /// <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="TvdbUserNotFoundException">The user doesn't exist</exception>
    /// <exception cref="TvdbNotAvailableException">The tvdb database is unavailable</exception>
    public List<TvdbSeries> GetUserFavorites(TvdbLanguage lang)
    {
      if (_userInfo == null)
        throw new TvdbUserNotFoundException("You can't get the favourites when no user is defined");
      if (lang == null)
        throw new Exception("you have to define a language");
      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 = _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 (_cacheProvider != null && _cacheProvider.Initialised)
            _cacheProvider.SaveToCache(series);
        }
      }
      return retList;
    }
예제 #21
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));
 }
예제 #22
0
 /// <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);
 }
예제 #23
0
 internal static String CreateEpisodeLink(string apiKey, int episodeId, TvdbLanguage lang, bool p)
 {
   return CreateEpisodeLink(apiKey, episodeId, (lang != null ? lang.Abbriviation : "en"), p);
 }
예제 #24
0
    /// <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>
    /// <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 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
        series = useZip ?
          _downloader.DownloadSeriesZipped(seriesId, language) :
          _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 = _userInfo != null && CheckIfSeriesFavorite(seriesId, _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 != series.Language)
        {//user wants a different language than the one that has been loaded
          if (series.GetAvailableLanguages().Contains(language))
            series.SetLanguage(language);
          else
          {
            TvdbSeriesFields newFields = _downloader.DownloadSeriesFields(seriesId, language);
            loadedAdditionalInfo = true;
            if (loadEpisodes)
            {
              List<TvdbEpisode> epList = _downloader.DownloadEpisodes(seriesId, language);
              if (epList != null)
              {
                newFields.Episodes = epList;
                newFields.EpisodesLoaded = true;
              }
            }
            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 = _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 = _downloader.DownloadEpisodes(seriesId, language);
          loadedAdditionalInfo = true;
          if (epList != null)
            series.SetEpisodes(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 = _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 (_cacheProvider != null)
      {//we're using a cache provider
        //if we've loaded data from online source -> save to cache
        if (_cacheProvider.Initialised && loadedAdditionalInfo)
        {
          Log.Info("Store series " + seriesId + " with " + _cacheProvider);
          _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(b =>
                                   {
                                     b.CacheProvider = _cacheProvider;
                                     b.SeriesId = series.Id;
                                   });
        }

        if (series.Episodes != null)
        {
          series.Episodes.ForEach(e =>
                                    {
                                      e.Banner.CacheProvider = _cacheProvider;
                                      e.Banner.SeriesId = series.Id;
                                    });
        }

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


      }
      return series;
    }
예제 #25
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;
 }
예제 #26
0
 /// <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>
 /// <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 GetBasicSeries(int seriesId, TvdbLanguage language, bool loadBanners)
 {
   return GetSeries(seriesId, language, false, false, loadBanners);
 }
예제 #27
0
 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;
 }
예제 #28
0
 /// <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>
 /// <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 GetEpisode(int episodeId, TvdbLanguage language)
 {
   return _downloader.DownloadEpisode(episodeId, language);
 }
예제 #29
0
 internal static String CreateSearchLink(String searchString, TvdbLanguage language)
 {
   String link = String.Format("{0}/api/GetSeries.php?seriesname={1}&language={2}", BASE_SERVER.Trim('/'), HttpUtility.UrlEncode(searchString), language.Abbriviation);
   return link;
 }
예제 #30
0
    /// <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>
    /// <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 GetEpisode(int seriesId, DateTime airDate, TvdbLanguage language)
    {
      TvdbEpisode episode = null;
      if (_cacheProvider != null && _cacheProvider.Initialised)
      {
        if (_cacheProvider.IsCached(seriesId, language, true, false, false))
        {
          TvdbSeries series = _cacheProvider.LoadSeriesFromCache(seriesId);
          if (series.Language != language)
            series.SetLanguage(language);

          foreach (TvdbEpisode e in series.Episodes)
          {
            if (e.FirstAired.Year == airDate.Year && e.FirstAired.Month == airDate.Month && e.FirstAired.Day == airDate.Day)
            {//We found the episode that first aired at the given day
              episode = e;
              break;
            }
          }
        }
      }
      return episode ?? (_downloader.DownloadEpisode(seriesId, airDate, language));
    }
예제 #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="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)
    {
      bool actorsLoaded = false;
      bool bannersLoaded = false;

      String seriesRoot = _rootFolder + Path.DirectorySeparatorChar + seriesId;
      if (!Directory.Exists(seriesRoot))
        return false;

      bool episodesLoaded;
      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;

      return episodesLoaded || !checkEpisodesLoaded &&
             bannersLoaded || !checkBannersLoaded &&
             actorsLoaded || !checkActorsLoaded;
    }