Aria2 一键添加任务到下载列表~

· 杂货 · 2459字

还不都是因为懒得复制粘贴地址进去~

Development environment

<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>

Step

Request URL:http://localhost:6800/jsonrpc
Request Parameters:

{
"jsonrpc":"2.0",
"method":"aria2.addUri", 
"id":1536032059123, 
"params": [
    ["http://rrd.me/dnsBP"], 
    { "out":"小倩_2018-09-04_r6qECA3BVRh2Rl.flv" }
    ]
}

jsonnrpc":"2.0", is Fixed value;
"method":"aria2.addUri", is Fixed value;
"id":1536032059123, use Current Timestamp;
"params", the first array is Download URL, the second parameters 'out' is output file name, and then add header, cookie to "out" after if you need to use the information.

eg: BaiduNetdiskDownload_Export.

{
"jsonrpc":"2.0",
"method":"aria2.addUri",
"id":1536031030284,
"params":[
["https://d.pcs.baidu.com/file/3d2f2f50a06e068b647215dcd5316bc5?fid=4080388407-250528-357417400965199&dstime=1536031030&rt=sh&sign=FDtAERV-DCb740ccc5511e5e8fedcff06b081203-RgjqVV1Oc%2BV8f%2FoSAl9ZNtiYB%2Fw%3D&expires=8h&chkv=1&chkbd=0&chkpc=&dp-logid=5716341099166834504&dp-callid=0&r=143454502"],
{"out":"RrxoeYm.mp4",
"header":["User-Agent: netdisk;6.0.0.12;PC;PC-Windows;10.0.16299;WindowsBaiduYunGuanJia",
"Referer: https://pan.baidu.com/disk/home",
"Cookie: BDUSS=NNNUp6SWViUlhySGR1SUpwQVZwR1BqcDI4Smd6WWpqVWs0SEJUUVhib1JkYlZiQVFBQUFBJCQAAAAAAAAAAAEAAACH8-gxX1NvdWzYvGtpc3MAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABHojVsR6I1bcF; pcsett=1536117416-7b74edc5cb0713fde4aa92a818c72cae"]}]
}

like this.

So, using jQuery's ajax to send this data, you can add it to the aria2 download list.

...

var downloadID = new Date().getTime();
var data = '{"jsonrpc":"2.0", "method":"aria2.addUri", "id":'+downloadID+', "params": [["'+downloadURL+'"], { "out":"'+outputFileName+'" }]}';
var self = this;
$.ajax({ 
    url: 'http://localhost:6800/jsonrpc', 
    type: 'post', 
    dataType: 'json', 
    data: data,
    success: function (res) {
        if (res.error != null) {
            // send failed.
            console.log('the file adding failed to aria2 download list.');
        } else {
            // send success.
            console.log('the file added to aria2 download list.');
        }
    }
});

Warning: Safari can't load cross-domain requests, chrome is OK.

Done.

最后一次编辑于 2018 09 04 19:56:46
如果你有任何疑问,这个邮箱可以联系到我:aS4xMjE0QHlhaG9vLmNvbQ==