批量下载工具

一款模仿迅雷批量下载的小工具,提供同步和异步两种下载方式。

public partial class Form1 : Form
    {
        string URL = "";

        public Form1()
        {
            InitializeComponent();
        }

        private void realShow()
        {
            if (weburl.Text.Contains("*"))
            {
                string url2 = "";
                int min=0;
                int max=0;
                try { min = Int32.Parse(zmin.Text); }
                catch { };
                try{max = Int32.Parse(zmax.Text);}catch { }
                int xing = weburl.Text.IndexOf('*');
                string wildcard = wc.Text;
                string url = weburl.Text.Substring(0, xing);
                try
                {
                    url2 = weburl.Text.Substring(xing + 1, weburl.TextLength - xing - 1);
                }
                catch
                { }
                showurl.Text = url + min.ToString("d" + wildcard) + url2 + "\r\n" + "\r\n" + "…………" + "\r\n" + "\r\n" + "…………" + "\r\n\r\n" + url + max.ToString("d" + wildcard) + url2;
            }
        }

        private void downPic(string url,string fileName)
        {
            
            string myStringWebResource = null;
            fileName += ".jpg";
            // Create a new WebClient instance.
            WebClient myWebClient = new WebClient();
            // Concatenate the domain with the Web resource filename.
            myStringWebResource = url + fileName;

            // Download the Web resource and save it into the current filesystem folder.
            myWebClient.DownloadFile(myStringWebResource, fileName);
            
        }

        private void downPicAsync(string url, string fileName)
        {
            fileName += ".jpg";
            WebClient client = new WebClient();
            Uri uri = new Uri(url+fileName);

            // Specify that the DownloadFileCallback method gets called
            // when the download completes.
            //client.DownloadFileCompleted += new AsyncCompletedEventHandler(DownloadFileCallback2);
            // Specify a progress notification handler.
            //client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(DownloadProgressCallback);
            client.DownloadFileAsync(uri,fileName);

        }

        private void button1_Click(object sender, EventArgs e)
        {
            int min = int.Parse(zmin.Text);
            int max = int.Parse(zmax.Text);
            string wildchar = wc.Text;
            int xing = weburl.Text.IndexOf('*');
            string url = weburl.Text.Substring(0, xing);

            if (radioButton1.Checked == true && min<max)
            {
                for (int i = min; i < max+1; i++)
                {
                    downPic(url, i.ToString("d"+wildchar));
                    toolStripStatusLabel1.Text = "正在下载" + i.ToString();
                    Application.DoEvents();
                }
            }
            else if(radioButton2.Checked == true && min<max)
            {
                for (int i = 1; i < 30; i++)
                {
                    downPicAsync(url, i.ToString("d"+wildchar));
                    toolStripStatusLabel1.Text = "正在下载" + i.ToString();
                    Application.DoEvents();
                }
            }
            else 
            {

            }
            toolStripStatusLabel1.Text = "下载完成";

        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {
            realShow();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            toolStripStatusLabel1.Text = "批量下载";
            URL = weburl.Text;
            radioButton1.Select();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            realShow();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            string min = "1";
           // string m;
           
            label1.Text =string.Format("{0:D5}", 23);
        }

        private void wc_TextChanged(object sender, EventArgs e)
        {
            realShow();
        }

        private void zmax_TextChanged(object sender, EventArgs e)
        {
            realShow();
        }
    }

2011061618334468.jpg

下载地址:http://dl.dbank.com/c0oi9ty5tx

转载于:https://www.cnblogs.com/geekzph/archive/2011/06/16/2082986.html

zhuaxia 可以从 xiami.com 和 music.163.com 下载 MP3 文件和音频。zhuaxia 是一个基于命令行的虾米音乐 ( www.xiami.com 以下简称[虾])和网易云音乐( music.163.com 以下简称[易]) 多线程批量下载工具zhuaxia 的开发调试环境:python 2.7.6依赖requests modulemutagen modulebeautifulsoup4 module特性自动识别解析URL. 目前支持:[虾] 歌曲,专辑,精选集,用户收藏[todo], 歌手热门[易] 歌曲,专辑,歌单,歌手热门下载歌手热门歌曲:数量可配置( 海外IP下载xiami资源" 一节加入实验性-p选项,尝试解决频繁请求被服务器ban的问题中英文命令行界面. 配置项 lang=en|cn 默认中文(cn)InstallationArchlinux 用户, zhuaxia可以从AUR中获取稳定版本(master branch):稳定版本:yaourt -S zhuaxia最新git版本(bleeding branch):yaourt -S zhuaxia-git其他用户:sudo python setup.py installUsage配置文件, 第一次运行zx后, 在$HOME/.zhuaxia/ 会有配置文件 zhuaxia.conf 配置参数有中文说明使用:zhuaxia (抓虾) -- 抓取[虾米音乐]和[网易云音乐]的 mp3 音乐 [CONFIG FILE:]   $HOME/.zhuaxia/zhuaxia.conf [OPTIONS]      -H : 首选HQ质量(320kbps),          > 虾米音乐  网易音乐 <             -无需特殊要求,直接下载高音质资源     -p : (实验性选项)使用代理池下载         在下载/解析量大的情况下,目标服务器会对禁止频繁的请求,所以zhuaxia可以自动获取         代理来解析和下载资源。因为获取的代理速度/可靠性不一,下载可能会缓慢或不稳定。     -h :显示帮助     -f :从文件下载     -v :显示版本信息 [USAGE]      zx [OPTION]          : 下载指定URL资源, 抓虾自动识别链接, 支持             - [虾] 歌曲,专辑,精选集,用户收藏,艺人TopN             - [易] 歌曲,专辑,歌单,艺人TopN         例子:            zx "http://www.xiami.com/space/lib-song/u/25531126"           zx "http://music.163.com/song?id=27552647"     zx [OPTION] -f           : 多个URL在一个文件中,每个URL一行。 URLs可以是混合[虾]和[易]的不同类型音乐资源。例子:           $ cat /tmp/foo.txt             http://music.163.com/artist?id=5345             http://www.xiami.com/song/1772130322             http://music.163.com/album?id=2635059             http://www.xiami.com/album/32449           $ zx -f /tmp/foo.txtProxy setting海外IP下载xiami资源xiami.com屏蔽了海外ip的http请求。在配置文件中添加(如果不存在的话)xiami.proxy.http=ip:port 可以让zhuaxia通过代理来解析xiami资源。 例如:xiami.proxy.http=127.0.0.1:8080这里ip:port构成的http代理是国内的代理服务器。 如果你的机器已经是国内的ip,请注释或删除这个选项。获取国内代理的简单方法:到http://proxy-list.org/ 搜索China的代理就好。Screenshotsdownloading (gif animation) parse input file parse url 标签:zhuaxia
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值