コード例 #1
0
        public List <DetailVideoInfo> GetVideoChoices(VideoInfo video)
        {
            List <DetailVideoInfo> clips = new List <DetailVideoInfo>();

            TitleDetails title = IMDbAPI.GetTitle(apiSession, video.VideoUrl as string);

            video.Other       = title;
            video.Title       = title.Title;
            video.Description = title.Plot;
            if (!string.IsNullOrEmpty(title.Image))
            {
                video.Thumb = getResizedImage(title.Image);
            }

            List <VideoReference> videos = title.GetVideos();

            if (videos != null)
            {
                foreach (VideoReference clip in videos)
                {
                    if (clip.Description == null)
                    {
                        clip.Description = video.Description;
                    }

                    DetailVideoInfo vid = new DetailVideoInfo();
                    vid.Other       = clip;
                    vid.Title       = title.Title + " - " + clip.Title;
                    vid.Title2      = clip.Title;
                    vid.Description = clip.Description;

                    vid.Thumb    = clip.Image;
                    vid.VideoUrl = clip.ID;
                    vid.Length   = clip.Duration.ToString();
                    clips.Add(vid);
                }
            }

            return(clips);
        }
コード例 #2
0
        public override List <SearchResultItem> Search(string query, string category = null)
        {
            var videos = new List <SearchResultItem>();

            // check if we have an IMDb in the search query
            string id = IMDbAPI.ParseTitleConst(query);

            if (id != null)
            {
                // we found an IMDb id so we do a details request
                TitleDetails title = IMDbAPI.GetTitle(apiSession, id);
                VideoInfo    video = new VideoInfo();
                video.Other       = title;
                video.Title       = title.Title;
                video.Description = title.Plot;
                video.Thumb       = getResizedImage(title.Image);
                video.VideoUrl    = title.ID;

                videos.Add(video);

                // return the result
                return(videos);
            }

            SearchResults results = IMDbAPI.Search(apiSession, query);

            foreach (ResultType key in results.Titles.Keys)
            {
                var titles = results.Titles[key];
                foreach (TitleReference title in titles)
                {
                    VideoInfo video = createVideoInfoFromTitleReference(title);
                    videos.Add(video);
                }
            }

            return(videos);
        }
コード例 #3
0
        /// <summary>
        /// Gets the IMDb title
        /// </summary>
        /// <param name="session">a session instance.</param>
        /// <param name="imdbID">IMDb ID</param>
        /// <returns></returns>
        public static TitleDetails GetTitle(Session session, string imdbID)
        {
            string uri = string.Format(session.Settings.BaseUriMobile, session.Settings.TitleDetailsMobile, "/" + imdbID + "/");

            HtmlNode root = GetResponseFromSite(session, uri);

            TitleDetails title = new TitleDetails();

            title.session = session;
            title.ID      = imdbID;

            // Main Details
            HtmlNode node      = root.SelectSingleNode("//div[@class='media-body']");
            string   titleInfo = node.SelectSingleNode("h1").InnerText;

            ParseDisplayStringToTitleBase(title, HttpUtility.HtmlDecode(titleInfo));

            // Tagline
            node = node.SelectSingleNode("p");
            if (node != null)
            {
                title.Tagline = HttpUtility.HtmlDecode(node.InnerText);
            }

            // Release date
            node = root.SelectSingleNode("//section[h3='Release Date:']/span");
            if (node != null)
            {
                DateTime value;
                if (DateTime.TryParse(node.InnerText, out value))
                {
                    title.ReleaseDate = value;
                }
            }

            // Summary
            node = root.SelectSingleNode("//p[@itemprop='description']");
            if (node != null)
            {
                node = node.FirstChild;
                if (node != null)
                {
                    title.Plot = HttpUtility.HtmlDecode(node.InnerText).Trim();
                }
            }

            // Genres
            title.Genres = root.SelectNodes("//span[@itemprop='genre']").Select(s => HttpUtility.HtmlDecode(s.InnerText)).ToList();


            // Ratings / Votes
            // todo: fix this
            node = root.SelectSingleNode("//p[@class='votes']/strong");
            if (node != null)
            {
                title.Rating = Convert.ToDouble(node.InnerText, CultureInfo.InvariantCulture.NumberFormat);

                // Votes
                string votes = node.NextSibling.InnerText;
                if (votes.Contains("votes"))
                {
                    votes       = Regex.Replace(votes, @".+?([\d\,]+) votes.+", "$1", RegexOptions.Singleline);
                    title.Votes = Convert.ToInt32(votes.Replace(",", ""));
                }
            }

            // Certification
            node = root.SelectSingleNode("//span[@itemprop='contentRating']");
            if (node != null)
            {
                title.Certificate = HttpUtility.HtmlDecode(node.GetAttributeValue("content", "?"));
            }

            //Poster
            node = root.SelectSingleNode("//div[@class='poster']/a");
            if (node != null)
            {
                Match match = imdbImageExpression.Match(node.Attributes["href"].Value);
                if (match.Success)
                {
                    title.Image = HttpUtility.UrlDecode(match.Groups["filename"].Value + match.Groups["ext"].Value);
                }
            }

            // Cast
            HtmlNodeCollection nodes = root.SelectNodes("//div[@id='cast-and-crew']/div/ul/li");

            if (nodes != null)
            {
                foreach (HtmlNode n in nodes)
                {
                    HtmlNode infoNode = n.SelectSingleNode("div[@class='text-center']/div[@class='ellipse']");
                    if (infoNode == null)
                    {
                        continue;
                    }

                    // Character info
                    Character character = new Character();
                    character.Actor         = new NameReference();
                    character.Actor.session = session;
                    character.Actor.Name    = HttpUtility.HtmlDecode(infoNode.InnerText).Trim();

                    infoNode = n.SelectSingleNode("a");
                    if (infoNode != null)
                    {
                        character.Actor.ID = infoNode.Attributes["href"].Value.Replace("http://m.imdb.com/name/", "").Replace("/", "");
                    }

                    infoNode = n.Descendants("small").Last();
                    if (infoNode != null)
                    {
                        character.Name = HttpUtility.HtmlDecode(infoNode.InnerText).Trim();
                    }

                    infoNode = n.SelectSingleNode("a/img");
                    if (infoNode != null)
                    {
                        Match match = imdbImageExpression.Match(infoNode.Attributes["src"].Value);
                        if (match.Success)
                        {
                            character.Actor.Image = HttpUtility.UrlDecode(match.Groups["filename"].Value + match.Groups["ext"].Value);
                        }
                    }

                    // add character object to the title
                    title.Cast.Add(character);
                }
            }

            nodes = root.SelectNodes("//div[@id='cast-and-crew']");
            if (nodes != null)
            {
                foreach (HtmlNode n in nodes.Elements("a"))
                {
                    var itemprop = n.GetAttributeValue("itemprop", "");
                    if (itemprop == "director" || itemprop == "creator")
                    {
                        NameReference person = new NameReference();
                        person.session = session;
                        person.ID      = n.Attributes["href"].Value.Replace("//m.imdb.com/name/", "").Replace("/", "");
                        person.ID      = person.ID.Substring(0, person.ID.IndexOf("?"));
                        person.Name    = HttpUtility.HtmlDecode(n.Descendants("span").First().InnerText).Trim();

                        if (itemprop == "director")
                        {
                            title.Directors.Add(person);
                        }
                        else if (itemprop == "creator")
                        {
                            title.Writers.Add(person);
                        }
                    }
                }
            }

            HtmlNode trailerNode = root.SelectSingleNode("//span[@data-trailer-id]");

            if (trailerNode != null)
            {
                string videoId = trailerNode.GetAttributeValue("data-trailer-id", string.Empty);
                if (videoId != string.Empty)
                {
                    title.trailer = videoId;
                }
            }

            return(title);
        }