コード例 #1
0
        private async Task GetMovieInfoAsync(IMovieBuilder builder, Uri uri)
        {
            var html = await WebHttp.GetHtmlDocument(uri);

            var coverImage = html.DocumentNode.SelectSingleNode("//div[@class='single_port']/img")
                             .ThrowExceptionIfCoverImageNotExists()
                             .GetAttributeValue("src", null);
            var descriptionInput = HttpUtility.HtmlDecode(html.DocumentNode.SelectSingleNode("//div[@class='single_entry']")
                                                          .ThrowExceptionIfMovieInfoNotExists().InnerText);
            var movieInfo = builder.MovieInfo;

            using (var sr = new StringReader(descriptionInput))
            {
                for (int i = 0; i < 3; i++)
                {
                    sr.ReadLine();
                }
                movieInfo.Description = sr.ReadToEnd();
            }

            var regexInput = HttpUtility.HtmlDecode(html.DocumentNode.SelectSingleNode("//div[@class='single_date_box']")
                                                    .ThrowExceptionIfMovieInfoNotExists().InnerText);
            var match = MovieInfoRegex.Match(regexInput);

            if (match.Success)
            {
                movieInfo.LoadGenresFrom(match.Groups[1].Value);
            }

            foreach (var video in html.DocumentNode.SelectNodes("//div[@class='block-container']/center/div/iframe")
                     .ThrowExceptionIfNotExists("Unable to find the movie root"))
            {
                builder.Enqueue(this, HtmlHelpers.GetEmbededUri(video));
            }
        }
コード例 #2
0
        private async Task Build(IMovieBuilder builder, Uri uri)
        {
            var html = await WebHttp.GetHtmlDocument(uri);

            var entryContent = html.DocumentNode.SelectSingleNode("//div[@class='entry entry-content']")
                               .ThrowExceptionIfNotExists("Unable to find the movie details element");
            var img        = entryContent.SelectSingleNode("a[@class='entry-thumb']/img").ThrowExceptionIfNotExists("Movie thumbnail element");
            var categories = entryContent.SelectNodes("a[@rel='category tag']/text()")
                             .ThrowExceptionIfNotExists("Unable to find the categories element")
                             .Select(li => HttpUtility.HtmlDecode(li.InnerText));

            var movieInfo = builder.MovieInfo;

            movieInfo.LoadGenresFrom(categories);
            movieInfo.CoverImage = new Uri(img.GetAttributeValue("src", null));

            var description = entryContent.SelectSingleNode("p").ThrowExceptionIfNotExists("Unable to find description element");

            movieInfo.Description = HttpUtility.HtmlDecode(description.InnerText);

            foreach (var entry in html.DocumentNode.SelectNodes("//div[@class='entry-embed']/iframe")
                     .ThrowExceptionIfNotExists("Unable to find the movie streams"))
            {
                builder.Enqueue(this, HtmlHelpers.GetEmbededUri(entry));
            }
        }