Python版Linux 下的迅雷

Linux 下该不该有迅雷,这个问题一直存在分歧,在此也不予讨论。不过,迅雷抗死链的作用是巨大的,这点是不容置疑的,很多人确实用得着。
 
 
 
 

有需求就有市场,可可熊大侠不是写过一个
 
pythunder 么?干嘛不用这个下载呢?于是就有了下面的程序……
#!/usr/bin/env python

import os, sys, urllib

def usage():
    print """Usage: python tharia2.py [OPTIONS] URL

OPTIONS: As same as options of aria2c"""

def get_url_list(url, listpath):
    if not os.path.exists(listpath):
        print "Getting URL list, please wait..."
        f = urllib.urlopen("http://cocobear.info/demo/pythunder/?url=%s" % url)
        lst = open(listpath, "w+")
        lst.writelines(f.readlines())
        f.close
        lst.seek(0)
    else:
        print "Found existing url list: ", listpath
        lst = open(listpath)

    url_list = [line[:-1] for line in lst]
    lst.close()
    print "Recieved %d url(s)." % len(url_list)
    return " ".join(url_list)

def download(url):
    for prefix in (r"http://", r"https://", r"ftp://"):
        if url.startswith(prefix):
            break
    else:
        print "Invalid URL: %s" % url
        exit()

    listdir = os.path.expanduser("~/.tharia2/list/")
    listfile = os.path.split(url)[-1] + ".list"
    if not os.path.exists(listdir):
        os.makedirs(listdir)
    listpath = os.path.join(listdir, listfile)

    url_list = get_url_list(url, listpath)
    cmd = " ".join(("aria2c -c", " ".join(sys.argv[1:-1]), url_list))
    print "Executing command: %s" % cmd
    if not os.system(cmd):
        os.remove(listpath)

if __name__ == "__main__":
    if len(sys.argv) > 1:
        download(sys.argv[-1])
    else:
        usage()

 
 

很简单的一个脚本,呵呵,参数和 aria2 是一样的,区别只在于对于 url 的处理(暂时 url 只能放在命令行的最后)。
比如下载 http://www.dmato.com/DownloadFile/FishDesk2009Beta4.exe,就运行:
python tharia2.py http://www.dmato.com/DownloadFile/FishDesk2009Beta4.exe
默认 aria2 可以支持 5 线程,如果你想改为 10 线程,那么:
python tharia2.py -s 10 http://www.dmato.com/DownloadFile/FishDesk2009Beta4.exe
指定下载目录,用 -d:
python tharia2.py -d "/home/iven" -s 10 http://www.dmato.com/DownloadFile/FishDesk2009Beta4.exe
更多用法详见:
aria2c --help
目前的主要问题是,可可熊大侠的网站相应速度太慢了,过半分钟才会返回候选列表,汗……不知道是不是我的网速问题,大家可以试一下。另外,就是没有解迅雷的 thunder:// 协议了,还有快车什么的,这个貌似不难,有时间研究一下。
现在还没有开源版本的迅雷候选地址搜索工具,主要大家怕流传太广,遭到迅雷封锁。但是还是好想看看代码是怎么写的啊……
最后,项目的地址:http://github.com/iven/tharia2/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值