-
-
Save leopku/99a8e29eec92e51851d830ba77c9ada7 to your computer and use it in GitHub Desktop.
aria2c scripts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#用户名 | |
#rpc-user=user | |
#密码 | |
#rpc-passwd=passwd | |
#上面的认证方式不建议使用,建议使用下面的token方式 | |
#设置加密的密钥 | |
#rpc-secret=token | |
#允许rpc | |
enable-rpc=true | |
#允许所有来源, web界面跨域权限需要 | |
rpc-allow-origin-all=true | |
#允许外部访问,false的话只监听本地端口 | |
rpc-listen-all=true | |
#RPC端口, 仅当默认端口被占用时修改 | |
#rpc-listen-port=6800 | |
#最大同时下载数(任务数), 路由建议值: 3 | |
max-concurrent-downloads=5 | |
#断点续传 | |
continue=true | |
#同服务器连接数 | |
max-connection-per-server=5 | |
#最小文件分片大小, 下载线程数上限取决于能分出多少片, 对于小文件重要 | |
min-split-size=10M | |
#单文件最大线程数, 路由建议值: 5 | |
split=10 | |
#下载速度限制 | |
max-overall-download-limit=0 | |
#单文件速度限制 | |
max-download-limit=0 | |
#上传速度限制 | |
max-overall-upload-limit=0 | |
#单文件速度限制 | |
max-upload-limit=0 | |
#断开速度过慢的连接 | |
#lowest-speed-limit=0 | |
#验证用,需要1.16.1之后的release版本 | |
#referer=* | |
#文件保存路径, 默认为当前启动位置 | |
dir=/Users/zfz/Downloads | |
#文件缓存, 使用内置的文件缓存, 如果你不相信Linux内核文件缓存和磁盘内置缓存时使用, 需要1.16及以上版本 | |
#disk-cache=0 | |
#另一种Linux文件缓存方式, 使用前确保您使用的内核支持此选项, 需要1.15及以上版本(?) | |
#enable-mmap=true | |
#文件预分配, 能有效降低文件碎片, 提高磁盘性能. 缺点是预分配时间较长 | |
#所需时间 none < falloc ? trunc « prealloc, falloc和trunc需要文件系统和内核支持 | |
file-allocation=prealloc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
aria2c --conf-path="aria2.conf" -D |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python2 | |
import json, urllib2, sys | |
from argparse import ArgumentParser | |
parser = ArgumentParser() | |
parser.add_argument('-c', '--cookie', help='use cookies', type=str, | |
default='', metavar='COOKIES', dest='cookies') | |
parser.add_argument('-o', '--out', help='output name', type=str, | |
default='', metavar='NAME', dest='out') | |
parser.add_argument('-d', '--dir', help='dest dir', type=str, | |
default='', metavar='DIR', dest='dir') | |
parser.add_argument('-r', '--rpc', help='aria2 rpc (http://localhost:6800/jsonroc)', | |
type=str, default='http://127.0.0.1:6800/jsonrpc', | |
metavar='URL', dest='rpc') | |
parser.add_argument('URIs', nargs='+', help='URIs', type=str, | |
default='', metavar='URI') | |
opts = parser.parse_args() | |
jsondict = {'jsonrpc':'2.0', 'id':'qwer', | |
'method':'aria2.addUri','params':[opts.URIs]} | |
aria2optsDefault={ | |
'continue' :'true', | |
'enable-http-pipeline' :'true', | |
'file-allocation' :'falloc', | |
'max-connection-per-server' :'15', | |
'split' :'15', | |
'min-split-size' :'10M'} | |
aria2opts = {} | |
aria2opts.update(aria2optsDefault) | |
if opts.out: | |
aria2opts['out'] = opts.out | |
if opts.dir: | |
aria2opts['dir'] = opts.dir | |
if opts.cookies: | |
aria2opts['header'] = ['Cookie: {0}'.format(opts.cookies)] | |
jsondict['params'].append(aria2opts) | |
jsonreq = json.dumps(jsondict) | |
print jsonreq | |
print aria2opts | |
r = urllib2.urlopen(opts.rpc, jsonreq) | |
print r.read() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
usage='Usage: aria2rpc.sh [-c COOKIE] [-d DIR] [-o NAME] URL [URL..]' | |
while [[ -n "$1" ]];do | |
case "$1" in | |
-c|--cookie) shift; cookie="$1" ;; | |
-d|--dir) shift; dir="$1" ;; | |
-o|--out) shift; output="$1" ;; | |
-r|--rpc) shift; rpc="$1" ;; | |
-h|--help) echo "$usage"; exit ;; | |
*) uris[$((i++))]="$1" ;; | |
esac | |
shift | |
done | |
if ((${#uris[@]}==0));then | |
echo "$usage" | |
exit | |
fi | |
URIs=$(IFS=, ;echo "${uris[*]}"|sed 's/,/","/g;s/^/"/;s/$/"/') | |
if [[ -z "$rpc" ]];then | |
rpc='http://127.0.0.1:6800/jsonrpc' | |
fi | |
Options="{" | |
if [[ -n "$cookie" ]];then | |
Options="$Options"'"header":["Cookie: '"$cookie"'"],' | |
fi | |
if [[ -n "$dir" ]];then | |
Options="$Options"'"dir":"'"$dir"'",' | |
fi | |
if [[ -n "$output" ]];then | |
Options="$Options"'"out":"'"$output"'",' | |
fi | |
Options="${Options%,}" | |
Options="$Options""}" | |
jsonTemplate='{"jsonrpc":"2.0","id":"qwer","method":"aria2.addUri","params":[['"$URIs"'],'"$Options"']}' | |
curl -X POST -d "$jsonTemplate" --header "Content-Type:application/json" "$rpc" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[--cookie COOKIE] [--dir FOLDER] [--output FNAME] --rpc http://localhost:6800/jsonrpc [URL] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment