/// <summary> /// 解析新浪视频视频文件源地址 /// </summary> public ParseResult Parse(ParseRequest request) { ParseResult pr = new ParseResult(); //合并完整url string url = @"http://v.iask.com/v_play.php?vid=" + request.Id; string source = Network.GetHtmlSource(url, Encoding.UTF8, request.Proxy); //视频总长度 string totallength = Regex.Match(source, @"<timelength>(?<timelength>\d+)</timelength>").Groups["timelength"].Value; //Framecount string framecount = Regex.Match(source, @"<framecount>(?<framecount>\d+)</framecount>").Groups["framecount"].Value; //src string src = Regex.Match(source, @"<src>(?<src>\d+)</src>").Groups["src"].Value; pr.SpecificResult.Add("totallength", totallength); pr.SpecificResult.Add("framecount", framecount); pr.SpecificResult.Add("src", src); //vstr string vstr = Regex.Match(source, @"(?<=<vstr><!\[CDATA\[)\w+").Value; //视频信息 Regex r = new Regex(@"<durl>.+?<order>(?<order>\d+)</order>.+?<length>(?<length>\d+)</length>.+?<url><!\[CDATA\[(?<url>.+?)\]\]></url>.+?</durl>", RegexOptions.Singleline); MatchCollection matches = r.Matches(source); foreach (Match item in matches) { var pri = new ParseResultItem(); pri.RealAddress = new Uri(item.Groups["url"].Value + (string.IsNullOrEmpty(vstr) ? "" : "?vstr=" + vstr)); pri.Information.Add("order", item.Groups["order"].Value); pri.Information.Add("length", item.Groups["length"].Value); pr.Items.Add(pri); } //返回结果 return pr; }
/// <summary> /// 通过Bilibili接口解析视频文件源地址 /// </summary> public ParseResult Parse(ParseRequest request) { ParseResult pr = new ParseResult(); //合并完整url //这里使用标准方法调用Bilibili API var ts = Convert.ToInt64((DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0)).TotalMilliseconds); string url = string.Format(@"http://interface.bilibili.com/playurl?appkey={0}&cid={1}&ts={2}&sign={3}", BilibiliPlugin.AppKey, request.Id, ts, Tools.GetStringHash("appkey=" + BilibiliPlugin.AppKey + "&cid=" + request.Id + "&ts=" + ts + BilibiliPlugin.AppSecret)); var httpRequest = (HttpWebRequest)WebRequest.Create(url); httpRequest.Proxy = request.Proxy; httpRequest.CookieContainer = request.CookieContainer; string source = Network.GetHtmlSource(httpRequest, Encoding.UTF8); Video videoInfo; var serializer = new XmlSerializer(typeof(Video)); using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(source))) { videoInfo = (Video)serializer.Deserialize(ms); } //视频总长度 var totallength = videoInfo.Timelength; if (totallength != null) { pr.SpecificResult.Add("totallength", totallength); } //src var src = videoInfo.Src; if (src != null) { pr.SpecificResult.Add("src", src); } //视频信息 foreach (var durl in videoInfo.Durl) { var pri = new ParseResultItem() { RealAddress = durl.Url }; pri.Information.Add("order", durl.Order); pri.Information.Add("length", durl.Length); pr.Items.Add(pri); } //返回结果 return(pr); }
protected virtual Price ToPrice(ParseResultItem itemDto, Item item) { var price = new Price { Item = item, CurrentPrice = itemDto.Price, Date = DateTime.Now }; return(price); }
public ParseResult Parse(string type, string vid, WebProxy proxy) { ParseResult pr = new ParseResult(); //合并完整url string url = string.Format(@"http://www.tucao.cc/api/videourl.php?type={0}&vid={1}", type, vid); string source = Network.GetHtmlSource(url, Encoding.UTF8, proxy).Trim(); VideoDetails videoInfo; var serializer = new XmlSerializer(typeof(VideoDetails)); using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(source))) { videoInfo = (VideoDetails)serializer.Deserialize(ms); } //视频总长度 var totallength = videoInfo.Timelength; if (totallength != null) { pr.SpecificResult.Add("totallength", totallength); } //src var src = videoInfo.Src; if (src != null) { pr.SpecificResult.Add("src", src); } //视频信息 foreach (var durl in videoInfo.Durl) { var pri = new ParseResultItem() { RealAddress = durl.Url }; pri.Information.Add("order", durl.Order); pri.Information.Add("length", durl.Length); pr.Items.Add(pri); } pr.Items.Sort((p1, p2) => int.Parse(p1.Information["order"]) - int.Parse(p2.Information["order"])); //返回结果 return(pr); }