Ejemplo n.º 1
0
		public bool Download()
		{
			//开始下载
			delegates.TipText(new ParaTipText(this.Info, "正在分析動畫下載位址"));

            Regex regChapter = new Regex("http://.+/v/[^-]+-(?<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.dm530.com/show/(?<value>[^.]+).html");
                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("class=\"on\"");
                while (chapter_start > 0)
                {
                    int chapter_end = src.IndexOf("class=\"on\"", chapter_start+1);
                    if (chapter_end < 0)
                        break;

                    string sub_src = src.Substring(chapter_start, chapter_end - chapter_start);

                    regChapter = new Regex("class=\"on\">(?<source_name>[^<]+)</li>");
                    Match item = regChapter.Match(sub_src);
                    if (item.Success == false)
                        break;

                    string souce_name = item.Groups["source_name"].Value;

                    string chapter = "title='(?<chapter_name>[^']+)' href='(?<link_url>[^']+)'";
                    regChapter = new Regex(chapter);
                    item = regChapter.Match(sub_src);

                    while (item.Success)
                    {
                        string url = "http://www.dm530.com" + 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 = chapter_end;
                }

                if (dict.Count <= 0)
                    return false;

                //选择下载哪部漫画
                subUrls = ToolForm.CreateMultiSelectForm(dict, Info.AutoAnswer, "dm530");
                //如果用户没有选择任何章节
                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://.+/[^-]+-(?<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);

                string title_name = "NoName";
                regChapter = new Regex("<meta name=\"title\" content=\"(?<title_name>[^\"]+)\">");
                Match item = regChapter.Match(chaper_src);
                if (item.Success) {
                    title_name = item.Groups["title_name"].Value;
                }
                regChapter = new Regex("/playdata/(?<js_name>[^\"]+)");
                item = regChapter.Match(chaper_src);
                if (item.Success == false)
                    continue;

                string js_url = "http://www.dm530.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:\dm530.txt", js_src);

                //取得视频信息
                List <Dm530Video> chapterinfo = new List<Dm530Video>();

                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)
                        {
                            Dm530Video video = new Dm530Video();
                            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], title_name);
            }
			return true;
		}
Ejemplo n.º 2
0
        public bool Download()
        {
            //开始下载
            delegates.TipText(new ParaTipText(this.Info, "正在分析動畫下載位址"));

            Regex regChapter = new Regex("http://.+/v/[^-]+-(?<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.dm530.com/show/(?<value>[^.]+).html");
                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("class=\"on\"");
                while (chapter_start > 0)
                {
                    int chapter_end = src.IndexOf("class=\"on\"", chapter_start + 1);
                    if (chapter_end < 0)
                    {
                        break;
                    }

                    string sub_src = src.Substring(chapter_start, chapter_end - chapter_start);

                    regChapter = new Regex("class=\"on\">(?<source_name>[^<]+)</li>");
                    Match item = regChapter.Match(sub_src);
                    if (item.Success == false)
                    {
                        break;
                    }

                    string souce_name = item.Groups["source_name"].Value;

                    string chapter = "title='(?<chapter_name>[^']+)' href='(?<link_url>[^']+)'";
                    regChapter = new Regex(chapter);
                    item       = regChapter.Match(sub_src);

                    while (item.Success)
                    {
                        string url          = "http://www.dm530.com" + 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 = chapter_end;
                }

                if (dict.Count <= 0)
                {
                    return(false);
                }

                //选择下载哪部漫画
                subUrls = ToolForm.CreateMultiSelectForm(dict, Info.AutoAnswer, "dm530");
                //如果用户没有选择任何章节
                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://.+/[^-]+-(?<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);

                string title_name = "NoName";
                regChapter = new Regex("<meta name=\"title\" content=\"(?<title_name>[^\"]+)\">");
                Match item = regChapter.Match(chaper_src);
                if (item.Success)
                {
                    title_name = item.Groups["title_name"].Value;
                }
                regChapter = new Regex("/playdata/(?<js_name>[^\"]+)");
                item       = regChapter.Match(chaper_src);
                if (item.Success == false)
                {
                    continue;
                }

                string js_url = "http://www.dm530.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:\dm530.txt", js_src);

                //取得视频信息
                List <Dm530Video> chapterinfo = new List <Dm530Video>();

                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)
                        {
                            Dm530Video video = new Dm530Video();
                            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], title_name);
            }
            return(true);
        }