Example #1
0
        public async Task DownloadBook(BookSeriesItem bookSeries, string Savepath, Action <DownloadService, DownloadProgressChangedEventArgs> TotalProgressChanged = null, Action <DownloadService, AsyncCompletedEventArgs> FileDownloadFinished = null)
        {
            string IpTemp = "145.213.{0}.{1}";
            Random ra     = new Random();
            string Ip     = string.Format(IpTemp, ra.Next(1, 255), ra.Next(1, 255));
            string html   = _downLoadHtml(bookSeries.BookId, bookSeries.Url, Ip);

            if (!string.IsNullOrWhiteSpace(html))
            {
                Match match = Regex.Match(html, "<source src=\"(?<url>.+?)\"");

                if (match.Success && match.Groups["url"].Success)
                {
                    string url       = match.Groups["url"].Value;
                    string extension = Path.GetExtension(url);
                    await _downLoadMp3(url, bookSeries.Name + extension, Savepath, Ip, TotalProgressChanged, FileDownloadFinished);

                    //byte[] bytes = _downLoadMp3(url, Ip);
                    //if (bytes != null)
                    //{
                    //    SaveMp3(bytes, index);
                    //}
                    //else
                    //{
                    //    throw new Exception("下载地址获取失败");
                    //}
                }
            }
        }
Example #2
0
        public BookSeries GetBookinfo(string BookId)
        {
            BookSeries bookSeries = new BookSeries();

            bookSeries.BookId = BookId;
            List <BookSeriesItem> list = new List <BookSeriesItem>();
            HttpItem item = new HttpItem();

            item.Method = "GET";
            item.URL    = $"http://m.ixinmo.com/shu/{BookId}.html";
            HttpHelper http   = new HttpHelper();
            HttpResult result = http.GetHtml(item);

            if (result.StatusCode == System.Net.HttpStatusCode.OK)
            {
                HtmlDocument document = new HtmlDocument();
                document.LoadHtml(result.Html);
                HtmlNode body = document.DocumentNode;

                HtmlNode nameNode = body.SelectSingleNode("//span[@class=\"bt\"]");
                bookSeries.BookName = nameNode.InnerText;

                HtmlNodeCollection listNode = body.SelectNodes("//*[@id=\"playlist\"]/ul/li");
                foreach (HtmlNode seriesNode in listNode)
                {
                    HtmlNode       node   = seriesNode.SelectSingleNode(".//a");
                    BookSeriesItem series = new BookSeriesItem();
                    series.BookId = BookId;
                    series.Name   = node.InnerText;
                    series.Url    = node.GetAttributeValue("href", "");
                    list.Add(series);
                }
                bookSeries.SeriesList = list;
            }

            return(bookSeries);
        }