aria2使用ajax调用

Posted 劣徒5520

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了aria2使用ajax调用相关的知识,希望对你有一定的参考价值。

@(文章的标题)

1. 利用ajax调用aria2后台下载

1.1. 总结:

网上很少有的教程ajax调用。

  • aria2作为后台下载服务器,接受前台(浏览器或者cmd命令端口)的命令进行下载。
  • 有了以下ajax命令就可以在网页上点击按钮直接调用aria2后台下载了。

aria2提供网页UI控制界面如Aira2Ng等,直接提供下载地址,提供相关控制下载。
我是对照的http://aria2c.com/以及Aira2Ng请求参数慢慢推敲的,大家也可以这么来获取更多命令。
像什么nodejs已经python也都可以调用,但未深入研究。只觉得ajax调用比较亲民实用,故此研究。并分享出来。

1.2. ajax调用aria2—Demo

自定义工具下载下载地址

技术图片

1.3. postMan命令测试

postMan能通过也就等于ajax可以使用了,原理一致。需要有前端知识。

1.3.1. post基本使用方法

  1. cmd启动命令可以看日志,窗口关闭失效,
    aria2c.exe --conf-path=aria2.conf
    技术图片

  2. postman请求参数设置
    技术图片

  3. 请求地址http://localhost:6800/jsonrpc

  4. 请求参数如下:(注意post 参数在 body 下 raw下面)

1.3.2. 单一文件下载


测试一:
{
    "jsonrpc": "2.0",
    "method": "aria2.addUri",
    "id": 456,
    "params": [
        ["http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe"], {
            "split": "5",
            "max-connection-per-server": "5",
            "seed-ratio": "0"
        }
    ]
}

测试二:带下载地址和重命名

{
            "jsonrpc": "2.0",
            "method": "aria2.addUri",
            "id": 1,
            "params": [["http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe"], {
                "out": "QQ1235.exe",
                "dir": "./微信文件夹",
                "pause": "false",//是否暂停下载
                "split": "5",
                "max-connection-per-server": "5",
                "seed-ratio": "0"
            }]
        }

1.3.3. 取消暂停

[{"jsonrpc":"2.0","method":"aria2.unpause","id":1,"params":["1d02656f3dbbf3a4"]}]

{"jsonrpc":"2.0","method":"aria2.unpause","id":"QXJpYU5nXzE1NzA3MDg1NDZfMC4wNjE0MzE0MTg4Nzc5NDE0Ng==","params":["1d02656f3dbbf3a4"]}

1.3.4. 停止和暂停对应的进程

[{"jsonrpc":"2.0","method":"aria2.pause","id":1,"params":["1d02656f3dbbf3a4"]}]
{"jsonrpc":"2.0","method":"aria2.unpause","id":"1","params":["d9562748f18a4f94"]}

1.3.5. 开始所有/停止所有

{"jsonrpc":"2.0","method":"aria2.pauseAll","id":1,"params":[]}
{"jsonrpc":"2.0","method":"aria2.unpauseAll","id":1,"params":[]}

1.3.6. 查询所有停止下载的信息

{"jsonrpc":"2.0","method":"aria2.tellStopped","id":1,"params":[0,1000]}

1.3.7. 删除记录

{"jsonrpc":"2.0","method":"aria2.removeDownloadResult","id":"QXJpYU5nXzE1NzA3MDk0NjRfMC44OTQ2Njc5NDY0NjQzNTc5","params":["a788bd810e9dcb31"]}

1.3.8. 在下载中强制暂停/停止

{"jsonrpc":"2.0","method":"aria2.forcePause","id":"QXJpYU5nXzE1NzA3MDk4NjdfMC43NDc1OTgzNzkzNDE4NDIx","params":["d9562748f18a4f94"]}

1.3.9. 设置网速

{"lowest-speed-limit":"1"} 1表示一字节

{"jsonrpc":"2.0","method":"aria2.changeGlobalOption","id":"QXJpYU5nXzE1NzA3MTAwMDZfMC41MzM4NjkzNjUyMDAzMDE5","params":[{"lowest-speed-limit":"1"}]}

1.3.10. 设置相关参数

{"jsonrpc":"2.0","method":"aria2.changeGlobalOption","id":1,"params":[{"max-overall-download-limit":"1 KiB","max-overall-upload-limit":"20 KiB","max-concurrent-downloads":"20","min-split-size":"10 MiB","user-agent":"Transmission/2.77","dir":"downloadData"}]}

技术图片

1.3.11. 查看所有正在下载的信息

{"jsonrpc":"2.0","method":"aria2.tellActive","id":1}

返回结果
技术图片

1.3.12. 查询所有暂时(等待下载信息 非下载完成停止信息)

{"jsonrpc":"2.0","method":"aria2.tellWaiting","id":1,"params":[0,1000]}

技术图片

1.3.13. 查询所有已经完成或者停止的信息

{"jsonrpc":"2.0","method":"aria2.tellStopped","id":1,"params":[0,1000]}

技术图片

1.3.14. 查询版本信息

{"jsonrpc":"2.0","method":"aria2.getVersion","id":1,"params":[]}

技术图片

1.3.15. 查询状态信息

{"jsonrpc":"2.0","method":"aria2.getGlobalStat","id":1,"params":[]}

技术图片

1.3.16. 获得的多个参数



{
    "jsonrpc": "2.0",
    "method": "aria2.addUri",
    "id": "QXJpYU5nXzE1NzA3MDg5MjZfMC45ODgyODc0NDcxMTE2MzI3",
    "params": [["http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe", "http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe", "http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe", "http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe", "http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe", "http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe", "http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe", "http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe", "http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe", "http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe", "http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe", "http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe", "http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe", "http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe", "http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe", "http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe", "http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe", "http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe", "http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe", "http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe", "http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe", "http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe", "http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe", "http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe", "http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe", "http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe", "http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe", "http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe", "http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe", "http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe", "http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe", "http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe", "http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe", "http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe", "http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe"], {
        "allow-overwrite": "false",
        "allow-piece-length-change": "false",
        "always-resume": "true",
        "async-dns": "true",
        "auto-file-renaming": "true",
        "bt-enable-hook-after-hash-check": "true",
        "bt-enable-lpd": "false",
        "bt-force-encryption": "false",
        "bt-hash-check-seed": "true",
        "bt-load-saved-metadata": "false",
        "bt-max-peers": "55",
        "bt-metadata-only": "false",
        "bt-min-crypto-level": "plain",
        "bt-remove-unselected-file": "false",
        "bt-request-peer-speed-limit": "51200",
        "bt-require-crypto": "false",
        "bt-save-metadata": "true",
        "bt-seed-unverified": "true",
        "bt-stop-timeout": "0",
        "bt-tracker-connect-timeout": "60",
        "bt-tracker-interval": "0",
        "bt-tracker-timeout": "60",
        "check-integrity": "false",
        "conditional-get": "false",
        "connect-timeout": "60",
        "content-disposition-default-utf8": "false",
        "continue": "true",
        "dir": "./QQ下载文件夹2",
        "dry-run": "false",
        "enable-http-keep-alive": "true",
        "enable-http-pipelining": "false",
        "enable-mmap": "false",
        "enable-peer-exchange": "false",
        "file-allocation": "falloc",
        "follow-metalink": "true",
        "follow-torrent": "true",
        "force-save": "false",
        "ftp-pasv": "true",
        "ftp-reuse-connection": "true",
        "ftp-type": "binary",
        "hash-check-only": "false",
        "http-accept-gzip": "false",
        "http-auth-challenge": "false",
        "http-no-cache": "false",
        "lowest-speed-limit": "0",
        "max-connection-per-server": "5",
        "max-download-limit": "0",
        "max-file-not-found": "0",
        "max-mmap-limit": "9223372036854775807",
        "max-resume-failure-tries": "0",
        "max-tries": "5",
        "max-upload-limit": "0",
        "metalink-enable-unique-protocol": "true",
        "metalink-preferred-protocol": "none",
        "min-split-size": "10485760",
        "no-file-allocation-limit": "5242880",
        "no-netrc": "false",
        "out": "QQ66.exe",
        "parameterized-uri": "false",
        "pause-metadata": "false",
        "piece-length": "1048576",
        "proxy-method": "get",
        "realtime-chunk-checksum": "true",
        "remote-time": "false",
        "remove-control-file": "false",
        "retry-wait": "0",
        "reuse-uri": "true",
        "rpc-save-upload-metadata": "true",
        "save-not-found": "true",
        "seed-ratio": "0",
        "split": "5",
        "stream-piece-selector": "default",
        "timeout": "60",
        "uri-selector": "feedback",
        "use-head": "false",
        "user-agent": "Transmission/2.77"
    }]
}

页面调用


<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <title></title>
        <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script>
    </head>
    <body>

    </body>
    <script>
        //https://static.zhihu.com/heifetz/vendor.7177302d6c7d65981005.js
        var url1 = "http://localhost:6800/jsonrpc?tm=1569769711558";
        var downData=[{
                "jsonrpc": "2.0",
                "method": "aria2.addUri",
                "id": 456,
                "params": [
                    ["http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe"], {
                        "split": "5",
                        "max-connection-per-server": "5",
                        "seed-ratio": "0"
                    }
                ]
            }, {
                "jsonrpc": "2.0",
                "method": "aria2.addUri",
                "id": 457,
                "params": [
                    ["https://cdn.bootcss.com/jquery/3.4.1/jquery.js"], {
                        "split": "5",
                        "max-connection-per-server": "5",
                        "seed-ratio": "0"
                    }
                ]
            }, {
                "jsonrpc": "2.0",
                "method": "aria2.addUri",
                "id": 458,
                "params": [
                    ["https://static.zhihu.com/heifetz/vendor.7177302d6c7d65981005.js"], {
                        "split": "5",
                        "max-connection-per-server": "5",
                        "seed-ratio": "0"
                    }
                ]
            }];

        $.ajax({
            url: url1,
            data: JSON.stringify(downData),
            type: "post",
            //async: false,//false为同步
            dataType: "json",
            success: function(obj) {
                console.log(obj)
            }
        });
    </script>
</html>
idid

1.4. 相关教程

Aria2 & YAAW 使用说明
下载工具系列——Aria2 (几乎全能的下载神器)

百度Google+研究=知晓一切
也欢迎讨论QQ:1092413979

以上是关于aria2使用ajax调用的主要内容,如果未能解决你的问题,请参考以下文章

html PHP代码片段: - AJAX基本示例:此代码演示了使用PHP和JavaScript实现的基本AJAX功能。

html 输入类型提交通常在单击时重新加载页面。此片段使输入不重新加载页面以便进行ajax调用

链接中的 URL 片段和 JSF 中的 ajax 重定向

采集抖音话题/音乐/用户作品/喜欢+Python调用Aria2下载+fire一键生成命令行

AJAX相关JS代码片段和部分浏览器模型

Python采集X音用户作品+调用Aria2下载+fire生成命令行+Vue界面