Esempio n. 1
0
        /// <summary>
        /// Download an Update
        /// </summary>
        /// <param name="updateSeries"></param>
        /// <param name="updateEpisodes"></param>
        /// <param name="_interval"></param>
        /// <returns></returns>
        internal DateTime DownloadUpdate(out List <TvdbSeries> updateSeries, out List <TvdbEpisode> updateEpisodes, Util.UpdateInterval _interval)
        {
            String xml = m_webClient.DownloadString(TvdbLinks.CreateUpdateLink(m_apiKey, Util.UpdateInterval.day));

            updateEpisodes = m_xmlHandler.ExtractEpisodeUpdates(xml);
            updateSeries   = m_xmlHandler.ExtractSeriesUpdates(xml);

            return(m_xmlHandler.ExtractUpdateTime(xml));
        }
Esempio n. 2
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  = "";
            String link = "";

            try
            {
                link = TvdbLinks.CreateUpdateLink(m_apiKey, _interval, _zipped);
                if (_zipped)
                {
                    byte[]         data = m_webClient.DownloadData(link);
                    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(link);
                }

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

                return(m_xmlHandler.ExtractUpdateTime(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 (ZipException ex)
            {
                Log.Error("Error unzipping the xml file " + link, ex);
                throw new TvdbInvalidXmlException("Error unzipping the xml file " + link);
            }
            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");
                }
                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");
                }
            }
        }