public bool Download() { //开始下载 delegates.TipText(new ParaTipText(this.Info, "正在分析動畫下載位址")); Regex regChapter = new Regex("http://.+/video-(?<param1>[0-9])-(?<param2>[0-9][0-9]?).html"); Match linkname = regChapter.Match (Info.Url); //要下载的Url列表 var subUrls = new Collection<string>(); if (linkname.Success == false) { //尼玛是整部 regChapter = new Regex("http://www.jiyingdm.com/(?<value>.+)"); linkname = regChapter.Match(Info.Url); //取得Url源文件 string src = Network.GetHtmlSource(Info.Url, Encoding.GetEncoding("GBK"), Info.Proxy); //填充字典 var dict = new Dictionary<string, string>(); int chapter_start = src.IndexOf("listTip.get"); while (chapter_start > 0) { int chapter_end = src.IndexOf("var playLen", chapter_start); if (chapter_end < 0) return false; string sub_src = src.Substring(chapter_start, chapter_end - chapter_start); regChapter = new Regex("listTip.get\\('(?<source_name>[^']+)'"); Match item = regChapter.Match(sub_src); if (item.Success == false) return false; string souce_name = item.Groups["source_name"].Value; string chapter = "title='(?<chapter_name>[^']+)' href='/" + linkname.Groups["value"].Value + "(?<link_url>[^']+)'"; regChapter = new Regex(chapter); item = regChapter.Match(sub_src); while (item.Success) { string url = "http://www.jiyingdm.com/" + linkname.Groups["value"].Value + item.Groups["link_url"].Value; string chapter_name = souce_name + "-" + item.Groups["chapter_name"].Value; dict.Add(url.Trim(), chapter_name); // first match is "hello world"!! but this turns out to be an infinite loop item = item.NextMatch(); } chapter_start = src.IndexOf("listTip.get", chapter_end); } //选择下载哪部漫画 subUrls = ToolForm.CreateMultiSelectForm(dict, Info.AutoAnswer, "jiyingdm"); //如果用户没有选择任何章节 if (subUrls.Count == 0) { return false; } } else { subUrls.Add(Info.Url); } Info.PartCount = subUrls.Count; Info.CurrentPart = 0; foreach (string url in subUrls) { //提示更换新Part delegates.NewPart(new ParaNewPart(this.Info, Info.CurrentPart)); regChapter = new Regex("http://.+/video-(?<param1>[0-9])-(?<param2>[0-9][0-9]?).html"); Match urlname = regChapter.Match (url); string chaper_src = Network.GetHtmlSource(url, Encoding.GetEncoding("GBK"), Info.Proxy); regChapter = new Regex("/playdata/(?<js_name>[^\"]+)"); Match item = regChapter.Match(chaper_src); if (item.Success == false) continue; string js_url = "http://www.jiyingdm.com/playdata/" + item.Groups["js_name"].Value; string js_src = Network.GetHtmlSource(js_url, Encoding.GetEncoding("GBK"), Info.Proxy); int json_start = js_src.IndexOf("["); int json_end = js_src.LastIndexOf("]"); js_src = js_src.Substring(json_start, json_end - json_start + 1); System.IO.File.WriteAllText(@"d:\jiyingdm.txt", js_src); //取得视频信息 List <JiyingDmVideo> chapterinfo = new List<JiyingDmVideo>(); JArray jarr = JArray.Parse(js_src); int videoidx = -1; foreach (var jitem in jarr.Children()) { foreach (var jsubitem in jitem.Children()) { if (jsubitem.Type == JTokenType.String) { JiyingDmVideo video = new JiyingDmVideo(); video.souce = jsubitem.ToString(); videoidx++; chapterinfo.Add(video); } else if (jsubitem.Type == JTokenType.Array) { chapterinfo [videoidx].info = jsubitem.ToObject<List<string>>(); } } } int param1 = int.Parse(urlname.Groups["param1"].Value); int param2 = int.Parse(urlname.Groups["param2"].Value); DownloadChapter(chapterinfo[param1].info[param2]); } return true; }
public bool Download() { //开始下载 delegates.TipText(new ParaTipText(this.Info, "正在分析動畫下載位址")); Regex regChapter = new Regex("http://.+/video-(?<param1>[0-9])-(?<param2>[0-9][0-9]?).html"); Match linkname = regChapter.Match(Info.Url); //要下载的Url列表 var subUrls = new Collection <string>(); if (linkname.Success == false) { //尼玛是整部 regChapter = new Regex("http://www.jiyingdm.com/(?<value>.+)"); linkname = regChapter.Match(Info.Url); //取得Url源文件 string src = Network.GetHtmlSource(Info.Url, Encoding.GetEncoding("GBK"), Info.Proxy); //填充字典 var dict = new Dictionary <string, string>(); int chapter_start = src.IndexOf("listTip.get"); while (chapter_start > 0) { int chapter_end = src.IndexOf("var playLen", chapter_start); if (chapter_end < 0) { return(false); } string sub_src = src.Substring(chapter_start, chapter_end - chapter_start); regChapter = new Regex("listTip.get\\('(?<source_name>[^']+)'"); Match item = regChapter.Match(sub_src); if (item.Success == false) { return(false); } string souce_name = item.Groups["source_name"].Value; string chapter = "title='(?<chapter_name>[^']+)' href='/" + linkname.Groups["value"].Value + "(?<link_url>[^']+)'"; regChapter = new Regex(chapter); item = regChapter.Match(sub_src); while (item.Success) { string url = "http://www.jiyingdm.com/" + linkname.Groups["value"].Value + item.Groups["link_url"].Value; string chapter_name = souce_name + "-" + item.Groups["chapter_name"].Value; dict.Add(url.Trim(), chapter_name); // first match is "hello world"!! but this turns out to be an infinite loop item = item.NextMatch(); } chapter_start = src.IndexOf("listTip.get", chapter_end); } //选择下载哪部漫画 subUrls = ToolForm.CreateMultiSelectForm(dict, Info.AutoAnswer, "jiyingdm"); //如果用户没有选择任何章节 if (subUrls.Count == 0) { return(false); } } else { subUrls.Add(Info.Url); } Info.PartCount = subUrls.Count; Info.CurrentPart = 0; foreach (string url in subUrls) { //提示更换新Part delegates.NewPart(new ParaNewPart(this.Info, Info.CurrentPart)); regChapter = new Regex("http://.+/video-(?<param1>[0-9])-(?<param2>[0-9][0-9]?).html"); Match urlname = regChapter.Match(url); string chaper_src = Network.GetHtmlSource(url, Encoding.GetEncoding("GBK"), Info.Proxy); regChapter = new Regex("/playdata/(?<js_name>[^\"]+)"); Match item = regChapter.Match(chaper_src); if (item.Success == false) { continue; } string js_url = "http://www.jiyingdm.com/playdata/" + item.Groups["js_name"].Value; string js_src = Network.GetHtmlSource(js_url, Encoding.GetEncoding("GBK"), Info.Proxy); int json_start = js_src.IndexOf("["); int json_end = js_src.LastIndexOf("]"); js_src = js_src.Substring(json_start, json_end - json_start + 1); System.IO.File.WriteAllText(@"d:\jiyingdm.txt", js_src); //取得视频信息 List <JiyingDmVideo> chapterinfo = new List <JiyingDmVideo>(); JArray jarr = JArray.Parse(js_src); int videoidx = -1; foreach (var jitem in jarr.Children()) { foreach (var jsubitem in jitem.Children()) { if (jsubitem.Type == JTokenType.String) { JiyingDmVideo video = new JiyingDmVideo(); video.souce = jsubitem.ToString(); videoidx++; chapterinfo.Add(video); } else if (jsubitem.Type == JTokenType.Array) { chapterinfo [videoidx].info = jsubitem.ToObject <List <string> >(); } } } int param1 = int.Parse(urlname.Groups["param1"].Value); int param2 = int.Parse(urlname.Groups["param2"].Value); DownloadChapter(chapterinfo[param1].info[param2]); } return(true); }