Ejemplo n.º 1
0
        public XmlDocument GetSeriesBannersOnline(int seriesID)
        {
            try
            {
                Init();

                string url = string.Format(Shoko.Server.Constants.TvDBURLs.urlBannersXML, urlMirror,
                                           Shoko.Server.Constants.TvDBURLs.apiKey,
                                           seriesID);
                logger.Trace("GetSeriesBannersOnline: {0}", url);

                // Search for a series
                string xmlSeries = Utils.DownloadWebPage(url);

                XmlDocument docBanners = new XmlDocument();
                docBanners.LoadXml(xmlSeries);

                return(docBanners);
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Error in TVDBHelper.GetSeriesBannersOnline: " + ex.ToString());
            }

            return(null);
        }
Ejemplo n.º 2
0
/*
 *              public static bool ConfirmTvDBOnline()
 *              {
 *                      TvDB_Series tvser = GetSeriesInfoOnline(73255);
 *                      if (tvser == null)
 *                              return false;
 *                      else
 *                              return true;
 *              }
 */

        public static TvDB_Series GetSeriesInfoOnline(int seriesID)
        {
            try
            {
                //Init();

                string url = string.Format(Shoko.Server.Constants.TvDBURLs.urlSeriesBaseXML, URLMirror,
                                           Shoko.Server.Constants.TvDBURLs.apiKey,
                                           seriesID,
                                           ServerSettings.TvDB_Language);
                logger.Trace("GetSeriesInfo: {0}", url);

                // Search for a series
                string xmlSeries = Utils.DownloadWebPage(url);
                logger.Trace("GetSeriesInfo RESULT: {0}", xmlSeries);

                if (xmlSeries.Trim().Length == 0)
                {
                    return(null);
                }

                XmlDocument docSeries = new XmlDocument();
                docSeries.LoadXml(xmlSeries);

                TvDB_Series tvSeries = null;
                if (docSeries != null)
                {
                    tvSeries = RepoFactory.TvDB_Series.GetByTvDBID(seriesID);
                    if (tvSeries == null)
                    {
                        tvSeries = new TvDB_Series();
                    }

                    tvSeries.PopulateFromSeriesInfo(docSeries);
                    RepoFactory.TvDB_Series.Save(tvSeries);
                }

                return(tvSeries);
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Error in TVDBHelper.GetSeriesInfoOnline: " + ex.ToString());
            }

            return(null);
        }
Ejemplo n.º 3
0
        /*
         *  public List<TvDB_ImageFanart> GetFanart(int seriesID, bool forceRefresh)
         *  {
         *      List<TvDB_ImageFanart> fanarts = new List<TvDB_ImageFanart>();
         *
         *      if (forceRefresh)
         *      {
         *          fanarts = GetFanartOnline(seriesID);
         *      }
         *      else
         *      {
         *          TvDB_ImageFanartRepository repFanart = new TvDB_ImageFanartRepository();
         *          fanarts = repFanart.GetBySeriesID(seriesID);
         *          if (fanarts.Count == 0)
         *              fanarts = GetFanartOnline(seriesID);
         *      }
         *
         *      return fanarts;
         *  }
         *
         *  public List<TvDB_ImageFanart> GetFanartOnline(int seriesID)
         *  {
         *      List<TvDB_ImageFanart> fanarts = new List<TvDB_ImageFanart>();
         *
         *      XmlDocument doc = GetSeriesBannersOnline(seriesID);
         *      List<object> banners = ParseBanners(seriesID, doc);
         *
         *      foreach (object obj in banners)
         *      {
         *          if (obj.GetType() == typeof(TvDB_ImageFanart))
         *              fanarts.Add((TvDB_ImageFanart)obj);
         *      }
         *
         *      return fanarts;
         *  }
         *
         *  public List<TvDB_ImageWideBanner> GetWideBannersOnline(int seriesID)
         *  {
         *      List<TvDB_ImageWideBanner> wideBanners = new List<TvDB_ImageWideBanner>();
         *
         *      XmlDocument doc = GetSeriesBannersOnline(seriesID);
         *      List<object> banners = ParseBanners(seriesID, doc);
         *
         *      foreach (object obj in banners)
         *      {
         *          if (obj.GetType() == typeof(TvDB_ImageWideBanner))
         *              wideBanners.Add((TvDB_ImageWideBanner)obj);
         *      }
         *
         *      return wideBanners;
         *  }
         *
         *  public List<TvDB_ImagePoster> GetPostersOnline(int seriesID)
         *  {
         *      //BaseConfig.MyAnimeLog.Write("Getting posters online: {0}", seriesID);
         *      List<TvDB_ImagePoster> posters = new List<TvDB_ImagePoster>();
         *
         *      XmlDocument doc = GetSeriesBannersOnline(seriesID);
         *      List<object> banners = ParseBanners(seriesID, doc);
         *
         *      foreach (object obj in banners)
         *      {
         *          if (obj.GetType() == typeof(TvDB_ImagePoster))
         *              posters.Add((TvDB_ImagePoster)obj);
         *      }
         *
         *      return posters;
         *  }
         */

        public List <TvDB_Language> GetLanguages()
        {
            List <TvDB_Language> languages = new List <TvDB_Language>();

            try
            {
                Init();

                string url = string.Format(Shoko.Server.Constants.TvDBURLs.urlLanguagesXML, urlMirror,
                                           Shoko.Server.Constants.TvDBURLs.apiKey);
                logger.Trace("GetLanguages: {0}", url);

                // Search for a series
                string xmlSeries = Utils.DownloadWebPage(url, Encoding.UTF8);

                XmlDocument docLanguages = new XmlDocument();

                docLanguages.LoadXml(xmlSeries);

                XmlNodeList lanItems = docLanguages["Languages"].GetElementsByTagName("Language");

                //BaseConfig.MyAnimeLog.Write("Found {0} banner nodes", bannerItems.Count);

                if (lanItems.Count <= 0)
                {
                    return(languages);
                }

                foreach (XmlNode node in lanItems)
                {
                    TvDB_Language lan = new TvDB_Language();

                    lan.Name         = node["name"].InnerText.Trim();
                    lan.Abbreviation = node["abbreviation"].InnerText.Trim();
                    languages.Add(lan);
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Error in TVDBHelper.GetSeriesBannersOnline: " + ex.ToString());
            }

            return(languages);
        }
Ejemplo n.º 4
0
        private void Init()
        {
            try
            {
                if (initialised)
                {
                    return;
                }

                // 01. try and download the list of mirrors
                string xmlMirrors = Utils.DownloadWebPage(urlMirrorsList);

                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.LoadXml(xmlMirrors);

                XmlNodeList mirrorItems = xmlDoc["Mirrors"].GetElementsByTagName("Mirror");

                if (mirrorItems.Count <= 0)
                {
                    return;
                }

                string id = mirrorItems[0]["id"].InnerText;
                urlMirror = mirrorItems[0]["mirrorpath"].InnerText;
                string typemask = mirrorItems[0]["typemask"].InnerText;

                logger.Info("TVDB Mirror: {0}", urlMirror);

                // 02. get the server time
                string      xmlServerTime = Utils.DownloadWebPage(urlServerTime);
                XmlDocument docServer     = new XmlDocument();
                docServer.LoadXml(xmlServerTime);

                serverTime = docServer["Items"]["Time"].InnerText;

                logger.Info("serverTime: {0}", serverTime);

                initialised = true;
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Error in TVDBHelper.Init: " + ex.ToString());
            }
        }
Ejemplo n.º 5
0
        public List <TVDB_Series_Search_Response> SearchSeries(string criteria)
        {
            List <TVDB_Series_Search_Response> results = new List <TVDB_Series_Search_Response>();

            try
            {
                Init();

                if (!initialised)
                {
                    return(results);
                }

                // Search for a series
                string url = string.Format(Shoko.Server.Constants.TvDBURLs.urlSeriesSearch, criteria);
                logger.Trace("Search TvDB Series: {0}", url);

                string xmlSeries = Utils.DownloadWebPage(url);

                XmlDocument docSeries = new XmlDocument();
                docSeries.LoadXml(xmlSeries);

                bool hasData = docSeries["Data"].HasChildNodes;
                if (hasData)
                {
                    XmlNodeList seriesItems = docSeries["Data"].GetElementsByTagName("Series");

                    foreach (XmlNode series in seriesItems)
                    {
                        TVDB_Series_Search_Response searchResult = new TVDB_Series_Search_Response();
                        searchResult.Populate(series);

                        results.Add(searchResult);
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Error in SearchSeries: " + ex.ToString());
            }

            return(results);
        }
Ejemplo n.º 6
0
        public static List <int> GetUpdatedSeriesList(string serverTime)
        {
            List <int> seriesList = new List <int>();

            try
            {
                string url = string.Format(Shoko.Server.Constants.TvDBURLs.urlUpdatesList, URLMirror, serverTime);

                // Search for a series
                string xmlUpdateList = Utils.DownloadWebPage(url);
                //BaseConfig.MyAnimeLog.Write("GetSeriesInfo RESULT: {0}", xmlSeries);

                XmlDocument docUpdates = new XmlDocument();
                docUpdates.LoadXml(xmlUpdateList);

                XmlNodeList nodes = docUpdates["Items"].GetElementsByTagName("Series");
                foreach (XmlNode node in nodes)
                {
                    string sid = node.InnerText;
                    int    id  = -1;
                    int.TryParse(sid, out id);
                    if (id > 0)
                    {
                        seriesList.Add(id);
                    }

                    //BaseConfig.MyAnimeLog.Write("Updated series: {0}", sid);
                }

                return(seriesList);
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Error in GetUpdatedSeriesList: " + ex.ToString());
                return(seriesList);
            }
        }