public override List <VideoReference> GetVideos() { List <VideoReference> list = IMDbAPI.GetVideos(this.session, this.ID); if (this.Trailer != null) { // replace the reference with a details version int i = list.FindIndex(x => x.ID == this.Trailer.ID); if (i > -1) { list.RemoveAt(i); } // put the main trailer on top list.Insert(0, this.Trailer); } else if (this.trailer != null) { int i = list.FindIndex(x => x.ID == this.trailer); if (i > -1) { // move the video on top and rename the title VideoReference video = list[i]; video.Title = "Main Trailer"; list.RemoveAt(i); list.Insert(0, video); } } return(list); }
/// <summary> /// Gets the videos associated with this title (video gallery). /// </summary> /// <param name="session">The session.</param> /// <param name="imdbID">The imdb ID.</param> /// <remarks>uses web scraping</remarks> /// <returns></returns> public static List<VideoReference> GetVideos(Session session, string imdbID) { List<VideoReference> videos = new List<VideoReference>(); string data = session.MakeRequest(string.Format(session.Settings.VideoGallery, imdbID)); HtmlNode root = Utility.ToHtmlNode(data); if (root != null) { var nodes = root.SelectNodes("//div[contains(@class, 'results-item')]"); string movieTitle = root.SelectSingleNode("//h3/a").InnerText; if (nodes != null) { foreach (HtmlNode node in nodes) { HtmlNode imgNode = node.SelectSingleNode("a/img"); if (imgNode == null) continue; string href = node.SelectSingleNode("h2/a").GetAttributeValue("href", ""); if (href.Contains("/imdblink/")) continue; // link to an external trailer string videoTitle = node.SelectSingleNode("h2/a").InnerText; if (videoTitle.ToLower().Trim() == movieTitle.ToLower().Trim()) { // if the title is the same as the movie title try the image's title var title2 = imgNode.GetAttributeValue("title", ""); if (title2 != "") videoTitle = title2; } // clean up the video title int i = videoTitle.IndexOf(" -- "); if (i >= 0) { videoTitle = videoTitle.Substring(i + 4); } videoTitle = videoTitle.Replace(movieTitle + ":", string.Empty).Trim(); VideoReference video = new VideoReference(); video.session = session; video.Image = imgNode.GetAttributeValue("src", ""); video.ID = imgNode.Attributes["viconst"].Value; video.Title = HttpUtility.HtmlDecode(videoTitle); videos.Add(video); } } } return videos; }