예제 #1
0
        internal static String CreateUpdateLink(string _apiKey, Util.UpdateInterval _interval, bool _zipped)
        {
            String link = String.Format("{0}/api/{1}/updates/updates_{2}{3}", BASE_SERVER, _apiKey,
                                        _interval, (_zipped ? ".zip" : ".xml"));

            return(link);
        }
예제 #2
0
        internal static String CreateUpdateLink(string _apiKey, Util.UpdateInterval _interval, bool _zipped)
        {
            String link = String.Format("{0}/api/{1}/updates/updates_{2}{3}", ActiveMirror.MirrorPath.ToString().Trim('/'), _apiKey,
                                        _interval, (_zipped ? ".zip" : ".xml"));

            return(link);
        }
예제 #3
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 = TvdbLinkCreator.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 +
                                                         ", you may 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");
                }
            }
        }
예제 #4
0
        private bool MakeUpdate(Util.UpdateInterval _interval)
        {
            //update all flagged series
            List <TvdbSeries>  updateSeries;
            List <TvdbEpisode> updateEpisodes;
            DateTime           updateTime   = m_downloader.DownloadUpdate(out updateSeries, out updateEpisodes, _interval);
            List <int>         cachedSeries = m_cacheProvider.GetCachedSeries();

            List <TvdbSeries> seriesToSave = new List <TvdbSeries>();

            foreach (TvdbSeries us in updateSeries)
            {
                foreach (TvdbSeries s in m_loadedData.SeriesList)
                {
                    if (us.Id == s.Id)
                    {
                        if (s.LastUpdated < us.LastUpdated)
                        {//changes occured in series
                            UpdateSeries(s, us.LastUpdated);
                        }
                        break;
                    }
                }

                //Update series that have been already cached but are not in memory
                foreach (int s in cachedSeries)
                {
                    if (us.Id == s)
                    {//changes occured in series
                        TvdbSeries series = m_cacheProvider.LoadSeriesFromCache(us.Id);
                        if (series.LastUpdated < us.LastUpdated)
                        {
                            UpdateSeries(series, us.LastUpdated);
                            AddSeriesToCache(series);
                            seriesToSave.Add(series);
                        }
                        break;
                    }
                }
            }

            //update all flagged episodes
            foreach (TvdbEpisode ue in updateEpisodes)
            {
                foreach (TvdbSeries s in m_loadedData.SeriesList)
                {
                    if (ue.SeriesId == s.Id)
                    {
                        UpdateEpisode(s, ue);
                        break;
                    }
                }

                foreach (int s in cachedSeries)
                {
                    if (ue.SeriesId == s)
                    {//changes occured in series
                        TvdbSeries series = m_cacheProvider.LoadSeriesFromCache(ue.SeriesId);
                        UpdateEpisode(series, ue);
                        break;
                    }
                }
            }

            //todo: update banner information here -> ask in forum if fanart doesn't contain all fields on purpose...

            //set the last updated time to time of this update
            m_loadedData.LastUpdated = updateTime;

            return(true);
        }
예제 #5
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));
        }
예제 #6
0
        private bool MakeUpdate(Util.UpdateInterval _interval, bool _zipped)
        {
            Log.Info("Started update (" + _interval.ToString() + ")");
            Stopwatch watch = new Stopwatch();

            watch.Start();
            //update all flagged series
            List <TvdbSeries>  updateSeries;
            List <TvdbEpisode> updateEpisodes;
            List <TvdbBanner>  updateBanners;
            DateTime           updateTime   = m_downloader.DownloadUpdate(out updateSeries, out updateEpisodes, out updateBanners, _interval, _zipped);
            List <int>         cachedSeries = m_cacheProvider.GetCachedSeries();

            List <TvdbSeries> seriesToSave = new List <TvdbSeries>();

            foreach (TvdbSeries us in updateSeries)
            {
                foreach (TvdbSeries s in m_loadedData.SeriesList)
                {
                    if (us.Id == s.Id)
                    {
                        if (s.LastUpdated < us.LastUpdated)
                        {//changes occured in series
                            UpdateSeries(s, us.LastUpdated);
                        }
                        break;
                    }
                }

                //Update series that have been already cached but are not in memory
                foreach (int s in cachedSeries)
                {
                    if (us.Id == s)
                    {//changes occured in series
                        TvdbSeries series = m_cacheProvider.LoadSeriesFromCache(us.Id);
                        if (series.LastUpdated < us.LastUpdated)
                        {
                            UpdateSeries(series, us.LastUpdated);
                            AddSeriesToCache(series);
                            seriesToSave.Add(series);
                        }
                        break;
                    }
                }
            }

            //update all flagged episodes
            foreach (TvdbEpisode ue in updateEpisodes)
            {
                foreach (TvdbSeries s in m_loadedData.SeriesList)
                {
                    if (ue.SeriesId == s.Id)
                    {
                        UpdateEpisode(s, ue);
                        break;
                    }
                }

                foreach (int s in cachedSeries)
                {
                    if (ue.SeriesId == s)
                    {//changes occured in series
                        TvdbSeries series = m_cacheProvider.LoadSeriesFromCache(ue.SeriesId);
                        UpdateEpisode(series, ue);
                        break;
                    }
                }
            }

            //todo: update banner information here -> wait for forum response regarding missing
            foreach (TvdbBanner b in updateBanners)
            {
                foreach (TvdbSeries s in m_loadedData.SeriesList)
                {
                    if (s.Id == b.SeriesId)
                    {
                        UpdateBanner(s, b);
                        break;
                    }
                }

                foreach (int s in cachedSeries)
                {
                    if (b.SeriesId == s)
                    {//changes occured in series
                        TvdbSeries series = m_cacheProvider.LoadSeriesFromCache(s);
                        UpdateBanner(series, b);
                        break;
                    }
                }
            }
            //set the last updated time to time of this update
            m_loadedData.LastUpdated = updateTime;
            watch.Stop();
            Log.Info("Finished update (" + _interval.ToString() + ") in " + watch.ElapsedMilliseconds + " milliseconds");
            return(true);
        }