private bool ProcessVisualSection(MovieInfo movieInfo, string id) { bool _result = false; // first posters string _page = Helpers.GetPage(string.Format("http://www.kinopoisk.ru/level/17/film/{0}", id), null, Encoding.GetEncoding("Windows-1251"), "", true, true); if (!string.IsNullOrEmpty(_page)) { if (_page.Contains("<title>Архив постеров на КиноПоиск.ru</title>")) { // movie has no posters return(_result); } Regex _reg = new Regex(PostersRegex, RegexOptions.IgnoreCase | RegexOptions.Multiline); if (_reg.IsMatch(_page)) { for (int _i = 0; _i <= (_reg.Matches(_page).Count - 1); _i++) { string _imageUrl = string.Format("{0}", _reg.Matches(_page)[_i].Groups["Cover"].Value.Replace("sm_", "")); ResultMovieItem _movieItem = new ResultMovieItem(id, movieInfo.Name, _imageUrl, this.CollectorName); _movieItem.CollectorMovieUrl = string.Format("http://www.kinopoisk.ru/level/1/film/{0}/sr/1/", id); _movieItem.MovieInfo = movieInfo; ResultsList.Add(_movieItem); _result = true; } } } //then backdrops _page = Helpers.GetPage(string.Format("http://www.kinopoisk.ru/level/13/film/{0}", id), null, Encoding.GetEncoding("Windows-1251"), "", true, true); if (!string.IsNullOrEmpty(_page)) { Regex _reg = new Regex(BackdropsRegex, RegexOptions.IgnoreCase | RegexOptions.Singleline); if (_reg.IsMatch(_page)) { foreach (Match _m2 in _reg.Matches(_page)) { string _thumbUrl = string.Format("http://www.kinopoisk.ru/{0}", _m2.Groups["Backdrop"].Value); string _originalUrl = _thumbUrl.Replace("sm_", ""); if (!string.IsNullOrEmpty(movieInfo.Name) && !string.IsNullOrEmpty(_thumbUrl) && !string.IsNullOrEmpty(_originalUrl)) { string _width = _m2.Groups["Width"].Value; string _height = _m2.Groups["Height"].Value; BackdropItem _bi = new BackdropItem(id, movieInfo.IMDBID, this.CollectorName, _thumbUrl, _originalUrl); _bi.SetSize(_width, _height); BackdropsList.Add(_bi); } } } } return(_result); }
private bool GetResults(IEnumerable <TmdbMovie> searchResults) { foreach (var item in searchResults) { if (item == null) { continue; } if (FileManager.CancellationPending) { return(ResultsList.Count != 0); } // get movie info MovieInfo movieInfo = GetMovieInfo(item); if (string.IsNullOrEmpty(movieInfo.IMDBID) && !IsValidYear(movieInfo.Year)) { continue; } // having the tmdbid, call getimages var imagesData = api.GetMovieImages(item.id, "ALL"); // posters if (imagesData.posters.Any()) { foreach (var poster in imagesData.posters.OrderByDescending(x => x.vote_average)) { var imageUrl = string.Format("{0}{1}{2}", configuration.images.base_url, "original", poster.file_path); AddResultItem(item.id.ToString(CultureInfo.InvariantCulture), movieInfo, imageUrl); } } else { // no poster found, add anyway the movie without image if (!string.IsNullOrEmpty(movieInfo.Name)) { AddResultItem(item.id.ToString(CultureInfo.InvariantCulture), movieInfo, null); } } // backdrops if (imagesData.backdrops.Any()) { foreach (var backdrop in imagesData.backdrops.OrderByDescending(x => x.vote_average)) { var thumbUrl = string.Format("{0}{1}{2}", configuration.images.base_url, configuration.images.backdrop_sizes.First(), backdrop.file_path); var originalUrl = string.Format("{0}{1}{2}", configuration.images.base_url, "original", backdrop.file_path); var bi = new BackdropItem(item.id.ToString(CultureInfo.InvariantCulture), item.imdb_id, CollectorName, thumbUrl, originalUrl); bi.SetSize(backdrop.width.ToString(CultureInfo.InvariantCulture), backdrop.height.ToString(CultureInfo.InvariantCulture)); BackdropsList.Add(bi); } } } return(ResultsList.Count != 0); }
protected override bool ProcessVisualSection(string relLink, MovieInfo movieInfo, string id) { bool _result = false; List <string> _cache = new List <string>(); // process backdrops here //string _backdropsLink = relLink.Insert(relLink.LastIndexOf('/'), "-Screenshots"); string _backdropsLink = relLink + "#Screenshots"; string _backdropPage = Helpers.GetPage(_backdropsLink, Encoding.UTF8, true); if (!string.IsNullOrEmpty(_backdropPage)) { Regex _reg = new Regex(VisualSectionRegex, RegexOptions.IgnoreCase); foreach (Match _m2 in _reg.Matches(_backdropPage)) { string _originalUrl = null; string _thumbUrl = _m2.Groups["Link"].Value; if (!string.IsNullOrEmpty(_thumbUrl)) { _originalUrl = _thumbUrl.Insert(_thumbUrl.LastIndexOf('.'), "_large"); } // avoid duplicates returned by regex if (!_cache.Contains(_thumbUrl)) { if (!string.IsNullOrEmpty(movieInfo.Name) && !string.IsNullOrEmpty(_thumbUrl) && !string.IsNullOrEmpty(_originalUrl)) { BackdropItem _bi = new BackdropItem(id, null, this.CollectorName, _thumbUrl, _originalUrl); _bi.SetSize("1280", "720"); BackdropsList.Add(_bi); _result = true; _cache.Add(_thumbUrl); } } } } return(_result); }
private bool GetMovieDetails(string movieId, bool onlyInfo, out MovieInfo movieInfo) { bool _result = false; movieInfo = null; if (!string.IsNullOrEmpty(movieId)) { XmlDocument _docDetails = new XmlDocument(); try { _docDetails.Load(this.GetInfoUrl(movieId)); } catch { } XmlNode _movie = _docDetails.SelectSingleNode("//movie"); if (_movie != null) { MovieInfo _movieInfo = GetMovieInfo(_movie); movieInfo = _movieInfo; if (!onlyInfo) { // get posters if (_movie != null) { XmlNodeList _images = _movie.SelectNodes("//image[@type='Poster' and @size='original']"); if (_images.Count != 0) { foreach (XmlNode _image in _images) { string _imageUrl = Helpers.GetAttributeFromXmlNode(_image, "url"); ResultMovieItem _movieItem = new ResultMovieItem(movieId, _movieInfo.Name, _imageUrl, this.CollectorName); _movieItem.CollectorMovieUrl = Helpers.GetValueFromXmlNode(_movie, "url"); _movieItem.MovieInfo = _movieInfo; ResultsList.Add(_movieItem); _result = true; } } else { ResultMovieItem _movieItem = new ResultMovieItem(movieId, _movieInfo.Name, null, this.CollectorName); _movieItem.CollectorMovieUrl = Helpers.GetValueFromXmlNode(_movie, "url"); _movieItem.MovieInfo = _movieInfo; ResultsList.Add(_movieItem); _result = true; } // get fanart/backdrops XmlNodeList _fanarts = _movie.SelectNodes("//image[@type='Fanart' and @size='preview']"); if (_fanarts.Count != 0) { foreach (XmlNode _fanart in _fanarts) { string _fanartId = Helpers.GetAttributeFromXmlNode(_fanart, "id"); if (!string.IsNullOrEmpty(_fanartId)) { string _thumbUrl = Helpers.GetAttributeFromXmlNode(_movie.SelectSingleNode(string.Format("//image[@id='{0}' and @size='preview']", _fanartId)), "url"); XmlNode _originalNode = _movie.SelectSingleNode(string.Format("//image[@id='{0}' and @size='original']", _fanartId)); string _originalUrl = Helpers.GetAttributeFromXmlNode(_originalNode, "url"); string _width = _originalNode != null ? _originalNode.Attributes["width"].Value : null; string _height = _originalNode != null ? _originalNode.Attributes["height"].Value : null; if (!string.IsNullOrEmpty(_thumbUrl) && !string.IsNullOrEmpty(_originalUrl)) { BackdropItem _bi = new BackdropItem(movieId, _movieInfo.IMDBID, this.CollectorName, _thumbUrl, _originalUrl); _bi.SetSize(_width, _height); this.BackdropsList.Add(_bi); } } } } } } } } return(_result); }
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); } } } } }