public void SendHtml() { jfYuRequest jfYu = new jfYuRequest("https://b2b.10086.cn/b2b/main/listVendorNotice.html?noticeType=2") { Method = jfYuRequestMethod.Get }; jfYu.RequestHeader.Host = "https://b2b.10086.cn"; var x = jfYu.GetHtml(); var y = jfYu.GetHtmlAsync().Result; Assert.IsTrue(x.Length > 100); Assert.AreEqual(x.Substring(x.Length - 100, 99), y.Substring(y.Length - 100, 99)); }
private async Task <List <VideoPagedInfo> > GetVideoInfo(string bvid) { var videos = new List <VideoPagedInfo>(); try { var jfYu = new jfYuRequest($"https://api.bilibili.com/x/web-interface/view?bvid={bvid}") { Timeout = 30000 }; jfYu.RequestHeader.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"; jfYu.RequestHeader.AcceptEncoding = "gzip, deflate, br"; jfYu.RequestHeader.AcceptLanguage = "zh-CN,zh;q=0.9,en;q=0.8"; jfYu.RequestHeader.CacheControl = "max-age=0"; jfYu.RequestHeader.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36"; var html = await jfYu.GetHtmlAsync(); var data = (dynamic)Serializer.Deserialize <object>(html); if (jfYu.StatusCode == System.Net.HttpStatusCode.OK && data.code == "0") { //获取视频信息 string title = data.data.title; string reg = @"\:" + @"|du\;" + @"|\/" + @"|\\" + @"|\|" + @"|\," + @"|\*" + @"|\?" + @"|\""" + @"|\<" + @"|\>"; Regex r = new Regex(reg); var Sections = Serializer.Deserialize <List <VideoPagedInfo> >(data.data.pages.ToString()); var Aid = data.data.aid.ToString(); var Mid = data.data.owner.mid.ToString(); var Name = data.data.owner.name.ToString(); foreach (var item in Sections) { item.AID = Aid; item.BVID = bvid; item.Mid = Mid; item.Name = Name; item.Title = r.Replace(title, ""); item.SavePath = FilePath.Text; videos.Add(item); } } } catch (Exception ex) { } return(videos); }
private async Task DownLoadVideo(VideoPagedInfo data, ManualResetEvent resetEvent) { try { var video = DownList.FirstOrDefault(q => q.cid.Equals(data.cid)); if (video != null) { var SavePath = video.SavePath + "\\" + video.Title + "\\"; if (!Directory.Exists(SavePath)) { Directory.CreateDirectory(SavePath); } var fileName = $"P{data.page}{data.part}"; //三次重试 for (int j = 0; j < 4; j++) { var urlReq = new jfYuRequest($"https://api.bilibili.com/x/player/playurl?avid={data.AID}&cid={data.cid}&ptype=json&qn=112") { Encoding = Encoding.UTF8, Timeout = 30000 }; var urlReqhtml = await urlReq.GetHtmlAsync(); var urlReqData = Serializer.Deserialize <dynamic>(urlReqhtml); string url = urlReqData.data.durl[0].url; data.size = urlReqData.data.durl[0].size; data.Size = ((decimal)data.size / 1024 / 1024).ToString("0.00") + "MB"; var dfreq = new jfYuRequest(url); dfreq.RequestHeader.Referer = $"https://www.bilibili.com/video/{video.BVID}"; try { bool result = await dfreq.GetFileAsync($"{SavePath}\\{fileName}.flv", (q, e, t) => { resetEvent.WaitOne(); Dispatcher.Invoke(() => { var pro = double.Parse(q.ToString("0.00")); data.Process = pro + "%"; data.Speed = e > 1024 ? $"{e / 1024:0.00}MB/s" : $"{e:0.00}KB/s"; //TimeSpan time = TimeSpan.FromSeconds((double)t); VideoListView.Items.Refresh(); }); }); if (result) { Dispatcher.Invoke(() => { data.color = Color.Green; VideoListView.Items.Refresh(); }); tasks.Remove(data.cid); } return; } catch (Exception) { if (j >= 4) { data.Process = "0%"; data.Speed = "0KB/s"; data.state = "错误"; Dispatcher.Invoke(() => { VideoListView.Items.Refresh(); }); } } } } } catch (Exception) { data.Process = "0%"; data.Speed = "0KB/s"; data.state = "错误"; Dispatcher.Invoke(() => { VideoListView.Items.Refresh(); }); } }