This program uses the technique of multithreading and the technology of DataGridView Cell expansion.
1. Get the Download list
private void Getdownlist () {//system.web.httputility.urldecode (Decrypt try { list<model.novel> list = new list<model.novel> (); WebResponse response = null; StreamReader reader = null; String Result = ""; Uri uri = new Uri ("requested address of the audiobook"); HttpWebRequest request = (HttpWebRequest) webrequest.create (URI. Absoluteuri); Request. Method = "GET"; Response = Request. GetResponse (); reader = new StreamReader (response. GetResponseStream (), encoding.default); Result = reader. ReadToEnd (); var htmldocument = new Htmlagilitypack.htmldocument (); Htmldocument.loadhtml (Result); var html = Htmldocument.documentnode; var title = html. Cssselect ("title"); foreach (var item in title) {//messagebox.show (iTem. Innerhtml.tostring ()); } int i = 0; int m = 1; var ul = html. Cssselect ("ul"); foreach (var item in ul) {if (i = = 8) {Forea CH (var item1 in item. Cssselect ("Li")) {string no = M < 10? "XX" + m:m < 100? "0" + m:m.tostring (); Model.novel novel = new Model.novel (); Novel. Title = "Mortal Monk" + no;//item1. Cssselect ("a"). ToArray () [0]. InnerText; Novel. Downdesc = "I want to download"; Novel. Playfile = "Play"; Novel. Downpath = "/Mortal biography/Mortal repair of the Immortals" + No + ". mp3";//item1. Cssselect ("a"). ToArray () [0]. attributes["href"]. Value; List. Add (novel); m++; }} i++; } dgvfilelist.datasource = list; } catch (Exception ex) {Writeerror (ex. Message); Application.exit (); } }
2. Download the file's code
public void DownloadFile (object RowIndex) {int index = rowindex.getdbnullvalue (0); String url = Dgvfilelist.rows[index]. cells["Downpath"]. Value.tostring (); string filename = lblpath.text + "\ \" + Dgvfilelist.rows[index]. cells["Title"]. Value.tostring () + ". mp3"; float percent = 0; try {System.Net.HttpWebRequest Myrq = (System.Net.HttpWebRequest) System.Net.HttpWebRequest.Crea Te (URL); System.Net.HttpWebResponse MYRP = (System.Net.HttpWebResponse) myrq.getresponse (); Long totalbytes = Myrp. ContentLength; System.IO.Stream st = Myrp. GetResponseStream (); System.IO.Stream so = new System.IO.FileStream (filename, System.IO.FileMode.Create); Long totaldownloadedbyte = 0; Byte[] by = new byte[1024]; DateTime StartTime = DateTime.Now; int osize = St. Read (by, 0, (int.) by. Length); while (Osize > 0) {totaldownloadedbyte = osize + totaldownloadedbyte; System.Windows.Forms.Application.DoEvents (); So. Write (by, 0, osize); Osize = St. Read (by, 0, (int.) by. Length); DateTime EndTime = DateTime.Now; TimeSpan ts = endtime.subtract (StartTime); Double ispeed = totaldownloadedbyte/ts. TotalSeconds; Dgvfilelist[3, index]. Value = Model.FileOperate.GetAutoSizeString (Ispeed, 2) + "/S"; Percent = (float) totaldownloadedbyte/(float) totalbytes * 100; Dgvfilelist[2, index]. Value = percent. Getdbnullvalue (0); } dgvfilelist[3, index]. Value = "Download complete, time consuming" + Math.Round (DateTime.Now.Subtract (StartTime). TotalSeconds, 2) + "s"; So. Close (); St. Close (); } catch (System.Exception ex) {WriteeRror (ex. Message); }}
WinForm Audio Player (sound fiction [Mortal biography])