Exemplo n.º 1
0
        public async Task <bool> GetExtraDetails(Book book)
        {
            string response = await HTMLHelpers.CreateHttpRequest(new Uri($"{book.ProductPage}"));

            try
            {
                var htmlDoc = new HtmlDocument();
                htmlDoc.LoadHtml(response);

                var synopsisNode = htmlDoc.DocumentNode.Descendants("div").FirstOrDefaultWithAttribute("class", "description");
                book.Synopsis = synopsisNode?.InnerHtml;

                var      releaseNode     = htmlDoc.DocumentNode.Descendants("div").FirstOrDefaultWithAttribute("class", "product-releasedate");
                string   fullReleaseDate = releaseNode?.InnerHtml;
                string   releaseDate     = fullReleaseDate.Replace("<label>Release Date:</label>", string.Empty).Trim();
                DateTime date;
                if (DateTime.TryParse(releaseDate, out date))
                {
                    book.PublishDate = date;
                }

                return(true);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error fetching extra book details of {book}, {ex.Message}");
            }

            return(false);
        }
Exemplo n.º 2
0
        public async Task <bool> GetExtraDetails(Book book)
        {
            if (book == null ||
                string.IsNullOrEmpty(book.ProductPage))
            {
                return(false);
            }

            Console.WriteLine($"Scraping for Extra Details for {book.ProductPage}");

            string bookPage = $"{AudibleConsts.BaseURL}{book.ProductPage}";
            string bookHTML = await HTMLHelpers.CreateHttpRequest(new Uri(bookPage));

            var htmlDoc = new HtmlDocument();

            htmlDoc.LoadHtml(bookHTML);

            try
            {
                var summaryRoot = htmlDoc.DocumentNode.Descendants("div").FirstOrDefaultWithAttribute("class", "bc-container", "productPublisherSummary");
                var summary     = summaryRoot.Descendants("div").FirstOrDefaultWithAttribute("class", "bc-section", "bc-spacing-medium");
                book.Synopsis = summary?.InnerHtml;
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error fetching extra details for {book} - {ex.Message}");
                return(false);
            }

            Console.WriteLine($"Done!");
            return(true);
        }
        public async Task <bool> GetExtraDetails(Book book)
        {
            if (!string.IsNullOrEmpty(book.ThumbnailURL) &&
                !string.IsNullOrEmpty(book.Synopsis))
            {
                return(true);
            }

            string productURL = $"{book.ProductPage}";

            try
            {
                string response = await HTMLHelpers.CreateHttpRequest(new Uri(productURL));

                var bk = ParseProductHTML(response);
                if (bk != null)
                {
                    book.ImageURL = bk.ImageURL;
                    book.Synopsis = bk.Synopsis;
                }

                return(bk != null);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error parsing product page for {book}, {ex.Message}");
            }

            return(false);
        }
        public async Task <List <Book> > Search(string search)
        {
            //Page index is &cpndx=1
            List <Book> books    = new List <Book>();
            string      query    = $"/search.aspx?Category=0&SearchManufacturer0&Keyword={HTMLHelpers.EncodeSearch(search)}&TypeId=&SearchOption=0";
            var         response = await HTMLHelpers.CreateHttpRequest(new Uri($"{AudiobookstoreConsts.BaseURL}{query}"));

            var htmlDoc = new HtmlDocument();

            htmlDoc.LoadHtml(response);

            // Get all books (Figure with class span4-cat slide
            var products = htmlDoc.DocumentNode.Descendants("figure").WithAttribute("class", "span4-cat slide");

            foreach (var prod in products)
            {
                Book book = new Book();
                book.Engine = SearchType.Audiobookstore;

                var productNode = prod.Descendants("a").FirstOrDefaultWithAttribute("id", "trigger");

                book.ProductPage  = productNode?.SafeAttribute("href")?.Value;
                book.Title        = productNode?.SafeAttribute("dataProductName")?.Value;
                book.Author       = SplitOwners(productNode?.SafeAttribute("dataAuthorName")?.Value);
                book.Narrator     = SplitOwners(productNode?.SafeAttribute("dataNarratorName")?.Value);
                book.ThumbnailURL = productNode?.SafeAttribute("dataImage")?.Value;
                decimal rating;
                if (decimal.TryParse(productNode?.SafeAttribute("dataRating")?.Value, out rating))
                {
                    book.Rating = rating;
                }

                // Try new extra loading
                if (string.IsNullOrEmpty(book.ThumbnailURL))
                {
                    var imageNode = prod.Descendants("img").FirstOrDefaultWithAttribute("class", "pro-img");
                    book.ThumbnailURL = imageNode?.SafeAttribute("src")?.Value;
                }

                if (string.IsNullOrEmpty(book.Author))
                {
                    var authorNode = prod.Descendants("span").FirstOrDefaultWithAttribute("class", "authorName");
                    book.Author = authorNode?.InnerText;
                }

                books.Add(book);
            }

            // IF books are still empty, try parsing the search result likeits a product page...
            if (books.Count == 0)
            {
                var singleResult = ParseProductHTML(response);
                if (singleResult != null)
                {
                    books.Add(singleResult);
                }
            }

            return(books);
        }
Exemplo n.º 5
0
        public ActionResult Test(HTMLHelpers data)
        {
            try
            {
                // TODO: Add insert logic here

                // Assign the given data to our storage
                OneItem = data;

                if (LBTransfer.Count() > 0)
                {
                    LBTransfer.Clear();
                }
                if (data.ListBox != null)
                {
                    // Listbox Preparation
                    foreach (string x in data.ListBox)
                    {
                        LBTransfer.Add(x);
                    }
                }

                return(RedirectToAction("TestOutput"));
            }
            catch
            {
                return(View());
            }
        }
Exemplo n.º 6
0
        public async Task <List <Book> > Search(string search)
        {
            List <Book> books    = new List <Book>();
            string      query    = $"/catalogsearch/result/?q={HTMLHelpers.EncodeSearch(search)}";
            string      response = await HTMLHelpers.CreateHttpRequest(new Uri($"{GraphicAudioConsts.BaseURL}{query}"));

            var htmlDoc = new HtmlDocument();

            htmlDoc.LoadHtml(response);

            // Get all books (Figure with class span4-cat slide
            var products = htmlDoc.DocumentNode.Descendants("li").WithAttribute("class", "item col-md-3 col-smh-4");

            foreach (var prod in products)
            {
                try
                {
                    Book book = new Book();
                    book.Engine = SearchType.GraphicAudio;

                    var productNode = prod.Descendants("a").FirstOrDefaultWithAttribute("class", "product-image");
                    book.ProductPage = productNode?.Attributes["href"].Value;
                    book.Title       = productNode?.Attributes["title"].Value;

                    var imageNode = prod.Descendants("img").FirstOrDefaultWithAttribute("class", "myitems-product-image");
                    book.ThumbnailURL = imageNode?.Attributes["src"].Value;
                    book.ImageURL     = book.ThumbnailURL.Replace("small_image/265", "image/458");
                    book.Author       = "GraphicAudio";

                    var seriesNode = prod.Descendants("div").FirstOrDefaultWithAttribute("class", "series-name");
                    book.Series = seriesNode?.InnerText;

                    books.Add(book);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error parsing Product " + ex.Message);
                }
            }

            return(books);
        }
Exemplo n.º 7
0
        public async Task <bool> GetExtraDetails(Book book)
        {
            string productURL = $"{BigFinishConsts.BaseURL}{book.ProductPage}";

            try
            {
                string response = await HTMLHelpers.CreateHttpRequest(new Uri(productURL));

                var htmlDoc = new HtmlDocument();
                htmlDoc.LoadHtml(response);

                var synopsis = htmlDoc.DocumentNode.Descendants("div").FirstOrDefaultWithAttribute("class", "releaseContent");
                book.Synopsis = synopsis?.InnerHtml;
                return(true);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error parsing product page for {book}, {ex.Message}");
            }

            return(false);
        }
Exemplo n.º 8
0
        public async Task <List <Book> > Search(string search)
        {
            string query    = $"/search_results?txtSearch={HTMLHelpers.EncodeSearch(search)}";
            string response = await HTMLHelpers.CreateHttpRequest(new Uri($"{BigFinishConsts.BaseURL}{query}"));

            List <Book> books   = new List <Book>();
            var         htmlDoc = new HtmlDocument();

            htmlDoc.LoadHtml(response);

            // Get all books
            var products = htmlDoc.DocumentNode.Descendants("div").WithAttribute("class", "releaseListing with-bottom-border");

            foreach (var prod in products)
            {
                try
                {
                    Book book = new Book();
                    book.Engine = SearchType.BigFinish;

                    // Product Link
                    var prodLinkNode = prod.Descendants("div").FirstOrDefaultWithAttribute("class", "coverRelease");

                    // Covers
                    var imgLinkNode = prodLinkNode.Descendants("img").FirstOrDefault();
                    book.ThumbnailURL = $"{BigFinishConsts.BaseURL}{imgLinkNode?.Attributes["src"].Value}";
                    book.ImageURL     = book.ThumbnailURL.Replace("medium", "large");

                    // Release Date
                    var pLinkNode = prodLinkNode.Descendants("p").FirstOrDefault();
                    //Remove the annoying formatting
                    var releaseString = pLinkNode.InnerHtml.Trim();
                    releaseString = releaseString.Replace("Released ", string.Empty);
                    DateTime releaseDate;
                    if (DateTime.TryParse(releaseString, out releaseDate))
                    {
                        book.PublishDate = releaseDate;
                    }

                    // Series Name
                    var    seriesNode  = prod.Descendants("span").FirstOrDefaultWithAttribute("class", "rangeName");
                    var    aSeriesNode = seriesNode?.Descendants("a").FirstOrDefault();
                    string seriesName  = aSeriesNode?.InnerText.Trim().
                                         Replace("\r", string.Empty).
                                         Replace("\n", string.Empty).
                                         Replace("\t", string.Empty);
                    book.Series     = seriesName;
                    book.SeriesPage = aSeriesNode?.Attributes["href"].Value;

                    // Book name
                    var    bookNode  = prod.Descendants("h3").FirstOrDefaultWithAttribute("class", "releaseHeader");
                    var    aBookNode = bookNode?.Descendants("a").FirstOrDefault();
                    string bookName  = aBookNode?.InnerText.Trim().
                                       Replace("\r", string.Empty).
                                       Replace("\n", string.Empty).
                                       Replace("\t", string.Empty);
                    book.Title       = bookName;
                    book.ProductPage = aBookNode?.Attributes["href"].Value;

                    books.Add(book);
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Error parsing search for {search}, {ex.Message}");
                }
            }
            return(books);
        }
Exemplo n.º 9
0
        public async Task <List <Book> > Search(string search)
        {
            List <Book> books    = new List <Book>();
            var         query    = $"{AudibleConsts.BaseURL}/search?keywords={HTMLHelpers.EncodeSearch(search)}";
            string      response = await HTMLHelpers.CreateHttpRequest(new Uri(query));

            var htmlDoc = new HtmlDocument();

            htmlDoc.LoadHtml(response);

            // Get all books (Figure with class span4-cat slide
            var products = htmlDoc.DocumentNode.Descendants("li").WithAttribute("class", "bc-list-item", "productListItem");

            foreach (var prod in products)
            {
                try
                {
                    Book book = new Book();
                    book.Engine = SearchType.Audible;

                    var productNode = prod.Descendants("img").FirstOrDefaultWithAttribute("class", "bc-pub-block", "bc-image-inset-border");
                    // Get the ID with regex
                    string regex = "(?<=/I/)(.*?)(?=._S)";
                    Match  id    = Regex.Match(productNode?.Attributes["src"].Value, regex, RegexOptions.Singleline);

                    book.ThumbnailURL = string.Format(AudibleCoverURL, id.Value, 128);
                    book.ImageURL     = string.Format(AudibleCoverURL, id.Value, 512);


                    var titleRootNode = prod.Descendants("h3").FirstOrDefaultWithAttribute("class", "bc-size-medium");
                    var titleNode     = titleRootNode.Descendants("a").FirstOrDefaultWithAttribute("class", "bc-link", "bc-color-link");
                    book.Title = titleNode.InnerText;

                    var authorRootNode = prod.Descendants("li").FirstOrDefaultWithAttribute("class", "bc-list-item", "authorLabel");
                    var authorNode     = authorRootNode.Descendants("a").FirstOrDefaultWithAttribute("class", "bc-link", "bc-color-link");
                    book.Author = authorNode.InnerText;

                    var narratorRootNode = prod.Descendants("li").FirstOrDefaultWithAttribute("class", "bc-list-item", "narratorLabel");
                    var narratorNode     = narratorRootNode.Descendants("a").FirstOrDefaultWithAttribute("class", "bc-link", "bc-color-link");
                    book.Narrator = narratorNode.InnerText;

                    var ratingRootNode = prod.Descendants("li").FirstOrDefaultWithAttribute("class", "bc-list-item", "ratingsLabel");
                    var ratingNode     = ratingRootNode.Descendants("span").FirstOrDefaultWithAttribute("class", "bc-text", "bc-pub-offscreen");

                    var      dateRootNode = prod.Descendants("li").FirstOrDefaultWithAttribute("class", "bc-list-item", "releaseDateLabel");
                    var      dateNode     = dateRootNode.Descendants("span").FirstOrDefaultWithAttribute("class", "bc-text", "bc-size-small", "bc-color-secondary");
                    var      datestr      = dateNode.InnerText.Replace("Release date:", string.Empty).Trim();
                    DateTime date;
                    if (DateTime.TryParseExact(datestr, "dd-MM-yy", CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal, out date))
                    {
                        book.PublishDate = date;
                    }

                    string page       = titleNode.Attributes["href"].Value;
                    int    queryIndex = page.IndexOf('?');
                    book.ProductPage = page.Substring(0, queryIndex);

                    books.Add(book);
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Error fetching search - {ex.Message}");
                }
            }

            return(books);
        }