예제 #1
0
        /// <summary>
        /// Download an Update
        /// </summary>
        /// <param name="_updateSeries">updated series to return</param>
        /// <param name="_updateEpisodes">updated episodes to return</param>
        /// <param name="_updateBanners">updated banners to return</param>
        /// <param name="_interval">interval to download</param>
        /// <param name="_zipped">use zip</param>
        /// <returns>Time of the update</returns>
        internal DateTime DownloadUpdate(out List<TvdbSeries> _updateSeries, out List<TvdbEpisode> _updateEpisodes,
            out List<TvdbBanner> _updateBanners, Util.UpdateInterval _interval, bool _zipped)
        {
            String xml = null;
              try
              {
            if (_zipped)
            {
              byte[] data = m_webClient.DownloadData(TvdbLinks.CreateUpdateLink(m_apiKey, _interval, _zipped));
              ZipInputStream zip = new ZipInputStream(new MemoryStream(data));
              zip.GetNextEntry();
              byte[] buffer = new byte[zip.Length];
              int count = zip.Read(buffer, 0, (int)zip.Length);
              xml = Encoding.UTF8.GetString(buffer);
            }
            else
            {
              xml = m_webClient.DownloadString(TvdbLinks.CreateUpdateLink(m_apiKey, _interval, _zipped));
            }
              }
              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 updates for " + _interval +
                                               ", it seems like you use an invalid api key (" + m_apiKey + ")");
            }
            else
            {
              throw new TvdbNotAvailableException("Couldn't connect to Thetvdb.com to retrieve updates for " + _interval +
                                              ", check your internet connection and the status of http://thetvdb.com");
            }
              }

              _updateEpisodes = m_xmlHandler.ExtractEpisodeUpdates(xml);
              _updateSeries = m_xmlHandler.ExtractSeriesUpdates(xml);
              _updateBanners = m_xmlHandler.ExtractBannerUpdates(xml);

              return m_xmlHandler.ExtractUpdateTime(xml);
        }
예제 #2
0
        internal TvdbSeries DownloadSeriesZipped(int _seriesId, TvdbLanguage _language)
        {
            //download the xml data from this request
              byte[] data;
              try
              {
            data = m_webClient.DownloadData(TvdbLinks.CreateSeriesLinkZipped(m_apiKey, _seriesId, _language));
              }
              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 +
                                               ", it seems like you have an invalid api key (" + m_apiKey + ")");
            }
            else
            {
              throw new TvdbNotAvailableException("Couldn't connect to Thetvdb.com to retrieve " + _seriesId +
                                              ", check your internet connection and the status of http://thetvdb.com");
            }
              }

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

              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];
            series.EpisodesLoaded = true;
            series.Episodes = new List<TvdbEpisode>();
            //add episode info to series
            List<TvdbEpisode> epList = m_xmlHandler.ExtractEpisodes(seriesString);
            foreach (TvdbEpisode e in epList)
            {
              Util.AddEpisodeToSeries(e, series);
            }

            //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;
              }
        }