Exemple #1
0
        private void GetPosters(TheTVDBSerieItem serieItem)
        {
            XmlDocument  _doc    = new XmlDocument();
            MemoryStream _stream = null;

            SetCurrentEpisodeRelatedInfo(serieItem.ID, serieItem.MovieInfo);

            // check if cache has the current series XML
            if (CurrentSeriesHelper.GetPostersData.ContainsKey(serieItem.ID))
            {
                _doc.LoadXml(CurrentSeriesHelper.GetPostersData[serieItem.ID]);
            }
            else
            {
                string _postersUrl = string.Format("{0}{1}/banners.xml", BaseUrl, serieItem.ID);
                _stream = SendRequest(_postersUrl);
                if (_stream != null && _stream.Length > 0)
                {
                    //SetCurrentEpisodeRelatedInfo(serieItem.ID, serieItem.MovieInfo);

                    _stream.Position = 0;

                    try
                    {
                        _doc.Load(_stream);
                        _stream.Dispose();
                        _stream = null;

                        // update cache
                        if (!CurrentSeriesHelper.GetPostersData.ContainsKey(serieItem.ID))
                        {
                            CurrentSeriesHelper.GetPostersData.Add(serieItem.ID, _doc.OuterXml.ToString());
                        }
                        else
                        {
                            CurrentSeriesHelper.GetPostersData[serieItem.ID] = _doc.OuterXml.ToString();
                        }
                    }
                    catch { }
                }
            }
            // take just poster and season that is not seasonwide
            //XmlNodeList _images = _doc.SelectNodes("//Banner[BannerType='poster' or (BannerType='season' and BannerType2='season')]");
            //XmlNodeList _images = _doc.SelectNodes("//Banner[BannerType='poster' or (BannerType='season' ) or BannerType='fanart' or BannerType='series']");
            XmlNodeList _images = null;

            if (FileManager.Configuration.Options.RetrieveBannersAsBackdrops)
            {
                _images = _doc.SelectNodes("//Banner");
            }
            else
            {
                _images = _doc.SelectNodes("//Banner[BannerType='poster' or (BannerType='season' and BannerType2='season') or BannerType='fanart']");
            }
            if (_images.Count != 0)
            {
                foreach (XmlNode _item in _images)
                {
                    // process posters
                    string _type  = Helpers.GetValueFromXmlNode(_item, "BannerType");
                    string _type2 = Helpers.GetValueFromXmlNode(_item, "BannerType2");
                    if ((string.Compare(_type, "poster") == 0) || ((string.Compare(_type, "season") == 0) && (string.Compare(_type2, "seasonwide") != 0)))
                    {
                        string _relPath      = Helpers.GetValueFromXmlNode(_item.SelectSingleNode("BannerPath"));
                        string _imageUrl     = string.Format("{0}/banners/{1}", m_MirrorPath, _relPath);
                        string _seasonNumber = Helpers.GetValueFromXmlNode(_item.SelectSingleNode("Season"));
                        if (!IsSameSeason(_seasonNumber, m_EpisodeData.Season))
                        {
                            continue;
                        }

                        string _id        = serieItem.ID.ToString();
                        string _title     = serieItem.Title;
                        string _extraText = !string.IsNullOrEmpty(_seasonNumber) ? string.Format(" [Season {0}]", _seasonNumber) : string.Empty;
                        int    _seasonNr  = 0;
                        try
                        {
                            _seasonNr = !string.IsNullOrEmpty(_seasonNumber) ? Int32.Parse(_seasonNumber) : 0;
                        }
                        catch { }

                        if (!string.IsNullOrEmpty(_title) && !string.IsNullOrEmpty(_relPath))
                        {
                            ResultMovieItem _movieItem = new ResultMovieItem(_id, _title, _imageUrl, CollectorName);
                            _movieItem.ExtraText         = _extraText;
                            _movieItem.IsSeasonCover     = !string.IsNullOrEmpty(_movieItem.ExtraText);
                            _movieItem.Season            = _seasonNr;
                            _movieItem.MovieInfo         = serieItem.MovieInfo;
                            _movieItem.CollectorMovieUrl = _id != null?string.Format("http://thetvdb.com/index.php?tab=series&id={0}", _id) : null;

                            ResultsList.Insert(Math.Max(0, ResultsList.Count - 1), _movieItem);
                        }
                    }
                    else // must be a fanart
                    {
                        string _relPath      = Helpers.GetValueFromXmlNode(_item.SelectSingleNode("ThumbnailPath"));
                        string _thumbUrl     = string.Format("{0}/banners/{1}", m_MirrorPath, _relPath);
                        string _relPath2     = Helpers.GetValueFromXmlNode(_item.SelectSingleNode("BannerPath"));
                        string _originalUrl  = string.Format("{0}/banners/{1}", m_MirrorPath, _relPath2);
                        bool   _isWideBanner = Helpers.GetValueFromXmlNode(_item, "BannerType2") == "graphical" || Helpers.GetValueFromXmlNode(_item, "BannerType2") == "blank";
                        if (string.IsNullOrEmpty(_relPath))
                        {
                            _relPath  = _relPath2;
                            _thumbUrl = _originalUrl;
                        }

                        string _width  = null;
                        string _height = null;
                        string _s      = Helpers.GetValueFromXmlNode(_item, "BannerType2");
                        if (!string.IsNullOrEmpty(_s))
                        {
                            Match _m = Regex.Match(_s, "(?<Width>[0-9]+?)x(?<Height>([0-9]*)?)", RegexOptions.Singleline | RegexOptions.IgnoreCase);
                            _width  = _m.Success ? _m.Groups["Width"].Value : null;
                            _height = _m.Success ? _m.Groups["Height"].Value : null;
                        }

                        if (!string.IsNullOrEmpty(_relPath) && !string.IsNullOrEmpty(_relPath2))
                        {
                            BackdropItem _bi = new BackdropItem(serieItem.ID.ToString(), (serieItem != null ? serieItem.IMDBId : string.Empty), this.CollectorName, _thumbUrl, _originalUrl);
                            _bi.Season   = m_EpisodeData.Season;
                            _bi.Episode  = m_EpisodeData.Episode;
                            _bi.IsBanner = _isWideBanner;
                            _bi.SetSize(_width, _height);
                            this.BackdropsList.Add(_bi);
                        }
                    }
                }
            }
        }
Exemple #2
0
        private void GetEpisodes(TheTVDBSerieItem serieItem)
        {
            XmlDocument  _doc    = new XmlDocument();
            MemoryStream _stream = null;

            // check if cache has the current series XML
            if (CurrentSeriesHelper.GetEpisodesData.ContainsKey(serieItem.ID))
            {
                _doc.LoadXml(CurrentSeriesHelper.GetEpisodesData[serieItem.ID]);
            }
            else
            {
                string _episodesUrl = string.Format("{0}{1}/all/{2}.xml", BaseUrl, serieItem.ID, FileManager.Configuration.Options.MovieSheetsOptions.TVShowsLanguage);
                _stream = SendRequest(_episodesUrl);
                if (_stream == null || _stream.Length == 0)
                {
                    _episodesUrl = string.Format("{0}{1}/all/", BaseUrl, serieItem.ID);
                    _stream      = SendRequest(_episodesUrl);
                }
                if (_stream != null && _stream.Length > 0)
                {
                    try
                    {
                        _doc.Load(_stream);
                        _stream.Dispose();
                        _stream = null;

                        // update cache
                        if (!CurrentSeriesHelper.GetEpisodesData.ContainsKey(serieItem.ID))
                        {
                            CurrentSeriesHelper.GetEpisodesData.Add(serieItem.ID, _doc.OuterXml.ToString());
                        }
                        else
                        {
                            CurrentSeriesHelper.GetEpisodesData[serieItem.ID] = _doc.OuterXml.ToString();
                        }
                    }
                    catch { }
                }
            }

            // take just poster and season that is not seasonwide
            XmlNodeList _episodes = _doc.SelectNodes("//Episode");

            if (_episodes.Count != 0)
            {
                string _episodeField = null;
                string _seasonField  = null;
                switch (m_EpisodeData.Type)
                {
                default:
                case EpisodeType.AiredOrder:
                    _episodeField = "EpisodeNumber";
                    _seasonField  = "SeasonNumber";
                    break;

                case EpisodeType.DVDOrder:
                    _episodeField = "DVD_episodenumber";
                    _seasonField  = "DVD_season";
                    break;

                case EpisodeType.Absolute:
                    _episodeField = "absolute_number";
                    _seasonField  = string.Empty;
                    break;
                }

                foreach (XmlNode _item in _episodes)
                {
                    string _relPath  = Helpers.GetValueFromXmlNode(_item.SelectSingleNode("filename"));
                    string _imageUrl = string.Format("{0}/banners/{1}", m_MirrorPath, _relPath);

                    string _seasonNumber  = string.IsNullOrEmpty(_seasonField) ? string.Empty : Helpers.GetValueFromXmlNode(_item.SelectSingleNode(_seasonField));
                    string _episodeNumber = Helpers.GetValueFromXmlNode(_item.SelectSingleNode(_episodeField));
                    // remove trailing numbers like 2.0 -> 2
                    _seasonNumber  = TrimValue(_seasonNumber);
                    _episodeNumber = TrimValue(_episodeNumber);

                    // if same episode and (if defined) same season
                    if ((_episodeNumber == m_EpisodeData.Episode) &&
                        ((!string.IsNullOrEmpty(_seasonNumber) && (_seasonNumber == m_EpisodeData.Season)) || string.IsNullOrEmpty(_seasonNumber))
                        )
                    {
                        string _episodeName = Helpers.GetValueFromXmlNode(_item.SelectSingleNode("EpisodeName"));
                        _episodeName = string.IsNullOrEmpty(_episodeName) ? string.Empty : string.Format(" - {0}", _episodeName);
                        string _id        = serieItem.ID.ToString();
                        string _title     = serieItem.Title;
                        string _extraText = _seasonNumber != null?string.Format(" [Season {0}]", _seasonNumber) : string.Empty;

                        //_extraText = _episodeNumber != null && _episodeNumber != "0" ? string.Format("{0} [Episode {1}{2}] (screenshot)", _extraText, _episodeNumber, _episodeName) : _extraText;
                        _extraText = _episodeNumber != null && _episodeNumber != "0" ? string.Format("{0} [Episode {1}]", _extraText, _episodeNumber) : _extraText;

                        if (!string.IsNullOrEmpty(_title) /*&& !string.IsNullOrEmpty(_relPath)*/)
                        {
                            ResultMovieItem _movieItem = new ResultMovieItem(_id, _title, _imageUrl, CollectorName);
                            _movieItem.ExtraText         = _extraText;
                            _movieItem.MovieInfo         = serieItem.MovieInfo;
                            _movieItem.CollectorMovieUrl = _id != null?string.Format("http://thetvdb.com/index.php?tab=series&id={0}", _id) : null;

                            ResultsList.Add(_movieItem);

                            if (!string.IsNullOrEmpty(_relPath))
                            {
                                BackdropItem _bi = new BackdropItem(serieItem.ID.ToString(), (serieItem != null ? serieItem.IMDBId : string.Empty), this.CollectorName, _imageUrl, _imageUrl);
                                _bi.Episode      = m_EpisodeData.Episode;
                                _bi.Season       = m_EpisodeData.Season;
                                _bi.IsScreenshot = true;
                                this.BackdropsList.Insert(0, _bi);
                            }
                        }
                    }
                }
            }
        }
Exemple #3
0
        private bool GetSeries(string keywords)
        {
            m_Series.Clear();

            MemoryStream _stream = null;

            XmlDocument _doc = new XmlDocument();

            // if we are processing same series then use cache
            if (IsSameSeriesBeingProcessed())
            {
                try
                {
                    _doc.LoadXml(CurrentSeriesHelper.GetSeriesDataXML);
                }
                catch { }
            }
            else
            {
                // if u have imdbid then USE IT!!
                if (!string.IsNullOrEmpty(m_IMDbId))
                {
                    // sample:  http://thetvdb.com/api/GetSeriesByRemoteID.php?imdbid=tt0411008
                    string _seriesUrl = string.Format("{0}/api/GetSeriesByRemoteID.php?imdbid={1}&language={2}", m_MirrorPath, m_IMDbId, FileManager.Configuration.Options.MovieSheetsOptions.TVShowsLanguage);
                    _stream = SendRequest(_seriesUrl);
                    if (_stream == null || _stream.Length == 0)
                    {
                        _seriesUrl = string.Format("{0}/api/GetSeriesByRemoteID.php?imdbid={1}", m_MirrorPath, m_IMDbId);
                        _stream    = SendRequest(_seriesUrl);
                    }
                }
                else // no imdbid, use keywords
                {
                    string _seriesUrl = string.Format("{0}/api/GetSeries.php?seriesname={1}&language={2}", m_MirrorPath, keywords, FileManager.Configuration.Options.MovieSheetsOptions.TVShowsLanguage);
                    _stream = SendRequest(_seriesUrl);
                    if (_stream == null || _stream.Length == 0)
                    {
                        _seriesUrl = string.Format("{0}/api/GetSeries.php?seriesname={1}", m_MirrorPath, keywords);
                        _stream    = SendRequest(_seriesUrl);
                    }
                }

                if (_stream != null && _stream.Length > 0)
                {
                    _stream.Position = 0;
                    try
                    {
                        _doc.Load(_stream);
                        _stream.Dispose();
                        _stream = null;
                    }
                    catch { }
                }
            }


            XmlNodeList _series = _doc.SelectNodes("//Series");

            if (_series.Count != 0)
            {
                foreach (XmlNode _item in _series)
                {
                    int    _id    = Convert.ToInt32(Helpers.GetValueFromXmlNode(_item, "seriesid"));
                    string _title = HttpUtility.HtmlDecode(Helpers.GetValueFromXmlNode(_item, "SeriesName"));
                    string _imdb  = Helpers.GetValueFromXmlNode(_item, "IMDB_ID");
                    string _year  = GetSeriesYear(_item);

                    if (string.IsNullOrEmpty(_imdb) && !IsValidYear(_year))
                    {
                        continue;
                    }

                    // if I have an imdbid and it is not matching the found one, skip this series
                    if (!string.IsNullOrEmpty(m_IMDbId) /*&& !string.IsNullOrEmpty(_imdb)*/ &&
                        m_IMDbId.ToLowerInvariant() != _imdb.ToLowerInvariant())
                    {
                        // this series does not match the provided imdbid
                        continue;
                    }

                    bool _addIt = true;

                    if (IsSameSeriesBeingProcessed())
                    {
                        // if we have series data, we use it for filtering
                        if (!string.IsNullOrEmpty(CurrentSeriesHelper.SeriesID) && (string.Compare(CurrentSeriesHelper.SeriesID, _id.ToString(), true) != 0))
                        {
                            // different ID do not add it
                            _addIt = false;
                        }
                    }
                    else
                    {
                        // we are not anymore in the same series RootFolder, reset CurrentSeriesHelper data
                        CurrentSeriesHelper.Reset();
                        // remember the new series root
                        CurrentSeriesHelper.SeriesRootFolder = GetCurrentSeriesRootFolder();
                        // cache result of the current GetSeriesData
                        CurrentSeriesHelper.GetSeriesDataXML = _doc.OuterXml.ToString();
                    }

                    if (_addIt)
                    {
                        MovieInfo _movieInfo = GetMovieInfo(_item, _id.ToString());

                        if (!m_Series.ContainsKey(_id))
                        {
                            TheTVDBSerieItem _new = new TheTVDBSerieItem(_id, _title, _imdb);
                            _new.MovieInfo = _movieInfo;
                            m_Series.Add(_id, _new);
                        }
                    }
                }
            }

            return(m_Series.Count != 0);
        }