Esempio n. 1
0
        /// <summary>
        /// Download the episodes
        /// </summary>
        /// <param name="_seriesId"></param>
        /// <param name="_language"></param>
        /// <returns></returns>
        internal List <TvdbEpisode> DownloadEpisodes(int _seriesId, TvdbLanguage _language)
        {
            String             xml    = m_webClient.DownloadString(TvdbLinks.CreateSeriesEpisodesLink(m_apiKey, _seriesId, _language));
            List <TvdbEpisode> epList = m_xmlHandler.ExtractEpisodes(xml);

            return(epList);
        }
Esempio n. 2
0
        /// <summary>
        /// Download the given episode from tvdb
        /// </summary>
        /// <param name="_episodeId"></param>
        /// <param name="_language"></param>
        /// <returns></returns>
        internal TvdbEpisode DownloadEpisode(int _episodeId, TvdbLanguage _language)
        {
            String data;

            try
            {
                data = m_webClient.DownloadString(TvdbLinks.CreateEpisodeLink(m_apiKey, _episodeId, _language, false));
            }
            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 episode " + _episodeId +
                                                         ", it seems like you have an invalid api key (" + m_apiKey + ")");
                }
                else
                {
                    throw new TvdbNotAvailableException("Couldn't connect to Thetvdb.com to retrieve " + _episodeId +
                                                        ", check your internet connection and the status of http://thetvdb.com");
                }
            }
            List <TvdbEpisode> epList = m_xmlHandler.ExtractEpisodes(data);

            if (epList.Count == 1)
            {
                return(epList[0]);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 3
0
        internal TvdbSeriesFields DownloadSeriesFields(int _seriesId, TvdbLanguage _language)
        {
            String data;

            try
            {
                data = m_webClient.DownloadString(TvdbLinks.CreateSeriesLink(m_apiKey, _seriesId, _language, false, false));
            }
            catch (Exception ex)
            {
                Log.Warn("Request not successfull", ex);
                return(null);
            }
            //extract all series the xml file contains
            List <TvdbSeriesFields> seriesList = m_xmlHandler.ExtractSeriesFields(data);

            if (seriesList != null && seriesList.Count == 1)
            {
                return(seriesList[0]);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Download the episodes
        /// </summary>
        /// <param name="_seriesId"></param>
        /// <param name="_language"></param>
        /// <returns></returns>
        internal List <TvdbEpisode> DownloadEpisodes(int _seriesId, TvdbLanguage _language)
        {
            String xml  = "";
            String link = "";

            try
            {
                link = TvdbLinks.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 +
                                                         ", it seems like you have an invalid api key");
                }
                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");
                }
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Download series from tvdb
        /// </summary>
        /// <param name="series"></param>
        /// <returns></returns>
        internal TvdbSeries DownloadSeries(int _seriesId, TvdbLanguage _language, bool _loadEpisodes, bool _loadActors, bool _loadBanners)
        {
            //download the xml data from this request
            String data;

            try
            {
                data = m_webClient.DownloadString(TvdbLinks.CreateSeriesLink(m_apiKey, _seriesId, _language, _loadEpisodes, false));
            }
            catch (Exception ex)
            {
                Log.Warn("Request not successfull", ex);
                return(null);
            }
            //extract all series the xml file contains
            List <TvdbSeries> seriesList = m_xmlHandler.ExtractSeries(data);

            //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(data);
                    foreach (TvdbEpisode e in epList)
                    {
                        Util.AddEpisodeToSeries(e, series);
                    }
                }

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

                //also load banner paths
                if (_loadBanners)
                {
                    List <TvdbBanner> banners = DownloadBanners(_seriesId);
                    if (banners != null)
                    {
                        series.Banners = banners;
                    }
                }
                return(series);
            }
            else
            {
                Log.Warn("More than one series returned when trying to retrieve series " + _seriesId);
                return(null);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Initialise the form
        /// </summary>
        /// <param name="_userId"></param>
        public void InitialiseForm(String _userId, ICacheProvider _provider)
        {
            //m_tvdbHandler = new Tvdb(new BinaryCacheProvider(@"cachefile.bin"), Resources.API_KEY);new XmlCacheProvider("XmlCache")

              m_tvdbHandler = new Tvdb(_provider, Resources.API_KEY);
              m_tvdbHandler.InitCache();

              List<TvdbLanguage> m_languages = m_tvdbHandler.Languages;

              foreach (TvdbLanguage l in m_languages)
              {
            if (l.Abbriviation.Equals("en")) m_currentLanguage = l;
            cbLanguage.Items.Add(l);
              }
              lblCurrentLanguage.Text = "[" + m_currentLanguage.ToString() + "]";

              //enable/disable community features
              if (_userId != null)
              {
            TvdbUser user = new TvdbUser("user", _userId);
            m_tvdbHandler.UserInfo = user;
            List<TvdbSeries> favList = null;
            try
            {
              user.UserPreferredLanguage = m_tvdbHandler.GetPreferredLanguage();
              favList = m_tvdbHandler.GetUserFavorites(user.UserPreferredLanguage);
            }
            catch (TvdbInvalidApiKeyException ex)
            {
              MessageBox.Show(ex.Message);
            }
            catch (TvdbNotAvailableException ex)
            {
              MessageBox.Show(ex.Message);
            }

            if (favList != null)
            {
              foreach (TvdbSeries s in favList)
              {
            cbUserFavourites.Items.Add(s);
              }
            }
              }
              else
              {
            cbUserFavourites.Text = "No userinfo set";
            cbUserFavourites.Enabled = false;
              }

              cmdAddRemoveFavorites.Enabled = false;
              cmdSendSeriesRating.Enabled = false;
              raterSeriesYourRating.Enabled = false;
        }
Esempio n. 7
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>
        internal TvdbEpisode DownloadEpisode(int _seriesId, DateTime _airDate, TvdbLanguage _language)
        {
            String xml  = "";
            String link = "";

            try
            {
                link = TvdbLinks.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.Count == 1)
                    {
                        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");
                }
            }
        }
Esempio n. 8
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)
        {
            if (m_seriesTranslations.Keys.Contains(_language))
            {
                if (this.Language != null)
                {
                    if (m_seriesTranslations.Keys.Contains(this.Language))
                    {//the current language is not added to the dictionary -> add it
                        m_seriesTranslations.Remove(this.Language);
                    }


                    TvdbSeriesFields f = new TvdbSeriesFields();
                    f.Id             = this.Id;
                    f.Actors         = this.Actors;
                    f.AirsDayOfWeek  = this.AirsDayOfWeek;
                    f.AirsTime       = this.AirsTime;
                    f.ContentRating  = this.ContentRating;
                    f.FirstAired     = this.FirstAired;
                    f.Genre          = this.Genre;
                    f.ImdbId         = this.ImdbId;
                    f.Language       = this.Language;
                    f.Network        = this.Network;
                    f.Overview       = this.Overview;
                    f.Rating         = this.Rating;
                    f.Runtime        = this.Runtime;
                    f.TvDotComId     = this.TvDotComId;
                    f.SeriesName     = this.SeriesName;
                    f.Status         = this.Status;
                    f.BannerPath     = this.BannerPath;
                    f.FanartPath     = this.FanartPath;
                    f.LastUpdated    = this.LastUpdated;
                    f.Zap2itId       = this.Zap2itId;
                    f.Episodes       = this.Episodes;
                    f.EpisodesLoaded = this.EpisodesLoaded;

                    m_seriesTranslations.Add(this.Language, f);
                }
                this.UpdateTvdbFields(m_seriesTranslations[_language]);
                return(true);
            }
            else
            {//the translation hasn't been loaded yet
                return(false);
            }
        }
Esempio n. 9
0
        internal TvdbSeriesFields DownloadSeriesFields(int _seriesId, TvdbLanguage _language)
        {
            String xml  = "";
            String link = "";

            try
            {
                link = TvdbLinks.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 +
                                                         ", it seems like you have an invalid api key");
                }
                else
                {
                    throw new TvdbNotAvailableException("Couldn't connect to Thetvdb.com to retrieve " + _seriesId +
                                                        ", check your internet connection and the status of http://thetvdb.com");
                }
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Download the given episode from tvdb
        /// </summary>
        /// <param name="_episodeId"></param>
        /// <param name="_language"></param>
        /// <returns></returns>
        internal TvdbEpisode DownloadEpisode(int _episodeId, TvdbLanguage _language)
        {
            String xml  = "";
            String link = "";

            try
            {
                link = TvdbLinks.CreateEpisodeLink(m_apiKey, _episodeId, _language, false);
                xml  = m_webClient.DownloadString(link);
                List <TvdbEpisode> epList = m_xmlHandler.ExtractEpisodes(xml);

                if (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.Abbriviation +
                                                           "), 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");
                }
            }
        }
Esempio n. 11
0
        /// <summary>
        /// Set the language of the series to one of the languages that have
        /// already been loaded
        /// </summary>
        /// <param name="_language"></param>
        /// <returns></returns>
        public bool SetLanguage(TvdbLanguage _language)
        {
            if (m_seriesTranslations.Keys.Contains(_language))
            {
                if (!m_seriesTranslations.Keys.Contains(Language))
                {
                    TvdbSeriesFields f = new TvdbSeriesFields();
                    f.Id            = this.Id;
                    f.Actors        = this.Actors;
                    f.AirsDayOfWeek = this.AirsDayOfWeek;
                    f.AirsTime      = this.AirsTime;
                    f.ContentRating = this.ContentRating;
                    f.FirstAired    = this.FirstAired;
                    f.Genre         = this.Genre;
                    f.ImdbId        = this.ImdbId;
                    f.Language      = this.Language;
                    f.Network       = this.Network;
                    f.Overview      = this.Overview;
                    f.Rating        = this.Rating;
                    f.Runtime       = this.Runtime;
                    f.TvDotComId    = this.TvDotComId;
                    f.SeriesName    = this.SeriesName;
                    f.Status        = this.Status;
                    f.BannerPath    = this.BannerPath;
                    f.FanartPath    = this.FanartPath;
                    f.LastUpdated   = this.LastUpdated;
                    f.Zap2itId      = this.Zap2itId;
                }
                m_seriesTranslations[Language].Episodes = this.Episodes;

                this.UpdateTvdbFields(m_seriesTranslations[_language]);
                return(true);
            }
            else
            {//the translation hasn't been loaded yet
                return(false);
            }
        }
Esempio n. 12
0
        /// <summary>
        /// Download the given episode from tvdb
        /// </summary>
        /// <param name="_episodeId"></param>
        /// <param name="_language"></param>
        /// <returns></returns>
        internal TvdbEpisode DownloadEpisode(int _episodeId, TvdbLanguage _language)
        {
            String data;
              try
              {
            data = m_webClient.DownloadString(TvdbLinks.CreateEpisodeLink(m_apiKey, _episodeId, _language, false));
              }
              catch (Exception ex)
              {
            Log.Warn("Request not successfull", ex);
            return null;
              }
              List<TvdbEpisode> epList = m_xmlHandler.ExtractEpisodes(data);

              if (epList.Count == 1)
              {
            return epList[0];
              }
              else
              {
            return null;
              }
        }
Esempio n. 13
0
        /// <summary>
        /// Download the given episode from tvdb
        /// </summary>
        /// <param name="_episodeId"></param>
        /// <param name="_language"></param>
        /// <returns></returns>
        internal TvdbEpisode DownloadEpisode(int _episodeId, TvdbLanguage _language)
        {
            String data;

            try
            {
                data = m_webClient.DownloadString(TvdbLinks.CreateEpisodeLink(m_apiKey, _episodeId, _language, false));
            }
            catch (Exception ex)
            {
                Log.Warn("Request not successfull", ex);
                return(null);
            }
            List <TvdbEpisode> epList = m_xmlHandler.ExtractEpisodes(data);

            if (epList.Count == 1)
            {
                return(epList[0]);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 14
0
        internal TvdbSeries DownloadSeriesZipped(int _seriesId, TvdbLanguage _language)
        {
            //download the xml data from this request
            byte[] xml  = null;
            String link = "";

            try
            {
                link = TvdbLinks.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];
                    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);
                }
            }
            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 +
                                                         ", it seems like you have an invalid api key");
                }
                else
                {
                    throw new TvdbNotAvailableException("Couldn't connect to Thetvdb.com to retrieve " + _seriesId +
                                                        ", check your internet connection and the status of http://thetvdb.com");
                }
            }
        }
Esempio n. 15
0
        /// <summary>
        /// Download series from tvdb
        /// </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></returns>
        internal 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 = TvdbLinks.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);
                        foreach (TvdbEpisode e in epList)
                        {
                            Util.AddEpisodeToSeries(e, series);
                        }
                    }

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

                    //also load banner paths
                    if (_loadBanners)
                    {
                        List <TvdbBanner> banners = DownloadBanners(_seriesId);
                        if (banners != null)
                        {
                            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" + 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 +
                                                         ", it seems like you have an invalid api key");
                }
                else
                {
                    throw new TvdbNotAvailableException("Couldn't connect to Thetvdb.com to retrieve " + _seriesId +
                                                        ", check your internet connection and the status of http://thetvdb.com");
                }
            }
        }
Esempio n. 16
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>
 public TvdbEpisode GetEpisode(int _seriesId, DateTime _airDate, TvdbLanguage _language)
 {
     TvdbEpisode ep = m_downloader.DownloadEpisode(_seriesId, _airDate, _language);
       return ep;
 }
Esempio n. 17
0
 internal static String CreateSeriesLinkZipped(String _apiKey, int _seriesId, TvdbLanguage _lang)
 {
     return TvdbLinks.ActiveMirror.MirrorPath + "/api/" + _apiKey + "/series/" + _seriesId +
                             "/all/" + (_lang != null ? _lang.Abbriviation : "en") + ".zip";
 }
Esempio n. 18
0
        /// <summary>
        /// Download series from tvdb
        /// </summary>
        /// <param name="series"></param>
        /// <returns></returns>
        internal TvdbSeries DownloadSeries(int _seriesId, TvdbLanguage _language, bool _loadEpisodes, bool _loadActors, bool _loadBanners)
        {
            //download the xml data from this request
              String data;
              try
              {
            data = m_webClient.DownloadString(TvdbLinks.CreateSeriesLink(m_apiKey, _seriesId, _language, _loadEpisodes, false));
              }
              catch (Exception ex)
              {
            Log.Warn("Request not successfull", ex);
            return null;
              }
              //extract all series the xml file contains
              List<TvdbSeries> seriesList = m_xmlHandler.ExtractSeries(data);

              //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(data);
              foreach (TvdbEpisode e in epList)
              {
            Util.AddEpisodeToSeries(e, series);
              }
            }

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

            //also load banner paths
            if (_loadBanners)
            {
              List<TvdbBanner> banners = DownloadBanners(_seriesId);
              if (banners != null)
              {
            series.Banners = banners;
              }
            }
            return series;
              }
              else
              {
            Log.Warn("More than one series returned when trying to retrieve series " + _seriesId);
            return null;
              }
        }
Esempio n. 19
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>
 public TvdbSeries GetFullSeries(int _seriesId, TvdbLanguage _language, bool _loadBanners)
 {
     return GetSeries(_seriesId, _language, true, true, _loadBanners);
 }
Esempio n. 20
0
        /// <summary>
        /// Retrieve the episode with the given id in the given language
        /// </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)
        {
            TvdbEpisode episode = GetEpisodeFromCache(_episodeId, _language);

              if (episode != null)
              {
            return episode;
              }
              else
              {
            episode = m_downloader.DownloadEpisode(_episodeId, _language);
            AddEpisodeToCache(episode);
            return episode;
              }
        }
Esempio n. 21
0
        internal TvdbSeriesFields DownloadSeriesFields(int _seriesId, TvdbLanguage _language)
        {
            String data;
              try
              {
            data = m_webClient.DownloadString(TvdbLinks.CreateSeriesLink(m_apiKey, _seriesId, _language, false, false));
              }
              catch (Exception ex)
              {
            Log.Warn("Request not successfull", ex);
            return null;
              }
              //extract all series the xml file contains
              List<TvdbSeriesFields> seriesList = m_xmlHandler.ExtractSeriesFields(data);

              if (seriesList != null && seriesList.Count == 1)
              {
            return seriesList[0];
              }
              else
              {
            return null;
              }
        }
Esempio n. 22
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 (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;
        }
Esempio n. 23
0
        /// <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;
        }
Esempio n. 24
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>
 internal TvdbEpisode DownloadEpisode(int _seriesId, DateTime _airDate, TvdbLanguage _language)
 {
     String xml = "";
       String link = "";
       try
       {
     link = TvdbLinks.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.Count == 1)
       {
     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");
     }
       }
 }
Esempio n. 25
0
 /// <summary>
 /// Download the episode specified from http://thetvdb.com
 /// </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></returns>
 internal TvdbEpisode DownloadEpisode(int _seriesId, int _seasonNr, int _episodeNr, String _order, TvdbLanguage _language)
 {
     String xml = "";
       String link = "";
       try
       {
     link = TvdbLinks.CreateEpisodeLink(m_apiKey, _seriesId, _seasonNr, _episodeNr, _order, _language);
     xml = m_webClient.DownloadString(link);
     List<TvdbEpisode> epList = m_xmlHandler.ExtractEpisodes(xml);
     if (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 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");
     }
       }
 }
Esempio n. 26
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 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);

              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();
            Log.Info("Loaded series in " + watch.ElapsedMilliseconds + " milliseconds");
            series.IsFavorite = m_userInfo == null ? false : CheckIfSeriesFavorite(_seriesId, m_userInfo.UserFavorites);
            AddSeriesToCache(series);
            return series;
              }
              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);
            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
              List<TvdbActor> actorList = m_downloader.DownloadActors(_seriesId);
              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
              List<TvdbEpisode> epList = m_downloader.DownloadEpisodes(_seriesId, _language);
              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
              List<TvdbBanner> bannerList = m_downloader.DownloadBanners(_seriesId);
              if (bannerList != null)
              {
            series.BannersLoaded = true;
            series.Banners = bannerList;
              }
            }

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

            return series;
              }
        }
Esempio n. 27
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)
        {
            foreach (TvdbSeries s in m_loadedData.SeriesList)
              {
            if (s.Id == _seriesId && s.Language.Abbriviation.Equals(_language.Abbriviation))
            {
              if ((s.BannersLoaded || !_loadActors) &&
             (s.TvdbActorsLoaded || !_loadActors) &&
             (s.EpisodesLoaded || !_loadEpisodes))
              {
            return true;
              }
            }
              }

              if (m_cacheProvider != null)
              {
            return m_cacheProvider.IsCached(_seriesId, _loadEpisodes, _loadBanners, _loadActors);
              }
              return false;
        }
Esempio n. 28
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>
 public TvdbSeries GetBasicSeries(int _seriesId, TvdbLanguage _language, bool _loadBanners)
 {
     return GetSeries(_seriesId, _language, false, false, _loadBanners);
 }
Esempio n. 29
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="_episodeId"></param>
 /// <param name="_language"></param>
 /// <returns></returns>
 private TvdbEpisode GetEpisodeFromCache(int _episodeId, TvdbLanguage _language)
 {
     foreach (TvdbSeries s in m_loadedData.SeriesList)
       {
     foreach (TvdbEpisode e in s.Episodes)
     {
       if (e.Id == _episodeId)
       {
     return e;
       }
     }
       }
       return null;
 }
Esempio n. 30
0
        /// <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;
        }
Esempio n. 31
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
       return TvdbLinks.ActiveMirror.MirrorPath + "/api/" + _apiKey + "/series/" + _seriesId + "/all/" +
     (_lang != null ? _lang.Abbriviation : "en") + ".xml";
 }
Esempio n. 32
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);
 }
Esempio n. 33
0
        /// <summary>
        /// Download the episodes
        /// </summary>
        /// <param name="_seriesId"></param>
        /// <param name="_language"></param>
        /// <returns></returns>
        internal List<TvdbEpisode> DownloadEpisodes(int _seriesId, TvdbLanguage _language)
        {
            String xml = m_webClient.DownloadString(TvdbLinks.CreateSeriesEpisodesLink(m_apiKey, _seriesId, _language));
              List<TvdbEpisode> epList = m_xmlHandler.ExtractEpisodes(xml);

              return epList;
        }
Esempio n. 34
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>
        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);
              }
              AddSeriesToCache(series);
            }
              }
              HandleUserFavoriteRetrieved(idList);
              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");
              }
        }
Esempio n. 35
0
 /// <summary>
 /// Download the episode specified from http://thetvdb.com
 /// </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></returns>
 internal TvdbEpisode DownloadEpisode(int _seriesId, int _seasonNr, int _episodeNr, String _order, TvdbLanguage _language)
 {
     try
       {
     String xml = m_webClient.DownloadString(TvdbLinks.CreateEpisodeLink(m_apiKey, _seriesId, _seasonNr, _episodeNr, _order, _language));
     List<TvdbEpisode> epList = m_xmlHandler.ExtractEpisodes(xml);
     if (epList.Count == 1)
     {
       return epList[0];
     }
     else
     {
       return null;
     }
       }
       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 + "/" +
                                        _order + "/" + _seasonNr + "/" + _episodeNr + "/" + _language.Abbriviation +
                                        ", it seems like you have an invalid api key (" + m_apiKey + ")");
     }
     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");
     }
       }
 }
Esempio n. 36
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);
 }
Esempio n. 37
0
        /// <summary>
        /// Download the episodes
        /// </summary>
        /// <param name="_seriesId"></param>
        /// <param name="_language"></param>
        /// <returns></returns>
        internal List<TvdbEpisode> DownloadEpisodes(int _seriesId, TvdbLanguage _language)
        {
            String xml;
              try
              {
            xml = m_webClient.DownloadString(TvdbLinks.CreateSeriesEpisodesLink(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 episodes fo " + _seriesId +
                                               ", it seems like you have an invalid api key (" + m_apiKey + ")");
            }
            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");
            }
              }
              List<TvdbEpisode> epList = m_xmlHandler.ExtractEpisodes(xml);

              return epList;
        }
Esempio n. 38
0
 internal static string CreateEpisodeLink(string _apiKey, int _seriesId, int _seasonNr, 
     int _episodeNr, string _order, TvdbLanguage _lang)
 {
     return TvdbLinks.ActiveMirror.MirrorPath + "/api/" + _apiKey + "/series/" + _seriesId + "/" + _order + "/" + _seasonNr + "/"
                                        + "/" + _episodeNr + "/" + (_lang != null ? _lang.Abbriviation : "en") + ".xml";
 }
Esempio n. 39
0
        /// <summary>
        /// Download series from tvdb
        /// </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></returns>
        internal TvdbSeries DownloadSeries(int _seriesId, TvdbLanguage _language, bool _loadEpisodes, bool _loadActors, bool _loadBanners)
        {
            //download the xml data from this request
              String data;
              try
              {
            data = m_webClient.DownloadString(TvdbLinks.CreateSeriesLink(m_apiKey, _seriesId, _language, _loadEpisodes, false));
              }
              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");
            }
              }
              //extract all series the xml file contains
              List<TvdbSeries> seriesList = m_xmlHandler.ExtractSeries(data);

              //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(data);
              foreach (TvdbEpisode e in epList)
              {
            Util.AddEpisodeToSeries(e, series);
              }
            }

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

            //also load banner paths
            if (_loadBanners)
            {
              List<TvdbBanner> banners = DownloadBanners(_seriesId);
              if (banners != null)
              {
            series.Banners = banners;
              }
            }
            return series;
              }
              else
              {
            Log.Warn("More than one series returned when trying to retrieve series " + _seriesId);
            return null;
              }
        }
Esempio n. 40
0
 internal static String CreateSeriesLink(String _apiKey, int _seriesId, TvdbLanguage _lang, bool _full, bool _zipped)
 {
     return TvdbLinks.ActiveMirror.MirrorPath + "/api/" + _apiKey + "/series/" + _seriesId +
      (_full ? "/all/" : "/") + (_lang != null ? _lang.Abbriviation : "en") + ".xml";
 }
Esempio n. 41
0
        internal TvdbSeriesFields DownloadSeriesFields(int _seriesId, TvdbLanguage _language)
        {
            String data;
              try
              {
            data = m_webClient.DownloadString(TvdbLinks.CreateSeriesLink(m_apiKey, _seriesId, _language, false, false));
              }
              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");
            }
              }
              //extract all series the xml file contains
              List<TvdbSeriesFields> seriesList = m_xmlHandler.ExtractSeriesFields(data);

              if (seriesList != null && seriesList.Count == 1)
              {
            return seriesList[0];
              }
              else
              {
            return null;
              }
        }
Esempio n. 42
0
 internal static String CreateEpisodeLink(string _apiKey, int _episodeId, TvdbLanguage _lang, bool p)
 {
     return TvdbLinks.ActiveMirror.MirrorPath + "/api/" + _apiKey + "/episodes/"
     + _episodeId + "/" + (_lang != null ? _lang.Abbriviation : "en") + ".xml";
 }
Esempio n. 43
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;
              }
        }