All Projects → shiny → Php Aria2

shiny / Php Aria2

Licence: wtfpl
Talking with aria2 through JSON-RPC

Labels

Projects that are alternatives of or similar to Php Aria2

Kikoplay
KikoPlay - NOT ONLY A Full-Featured Danmu Player 不仅仅是全功能弹幕播放器
Stars: ✭ 313 (+439.66%)
Mutual labels:  aria2
Animetrackerlist
动漫磁性链接加速方案(animeTrackerList)
Stars: ✭ 572 (+886.21%)
Mutual labels:  aria2
Trackerslistcollection
🎈 Updated daily! A list of popular BitTorrent Trackers! / 每天更新!全网热门 BT Tracker 列表!
Stars: ✭ 9,761 (+16729.31%)
Mutual labels:  aria2
Negibox
All in one downloader 全能下载器
Stars: ✭ 335 (+477.59%)
Mutual labels:  aria2
Aria2 Static Builds
aria2 static builds for GNU/Linux & Windows (with OpenSSL).
Stars: ✭ 547 (+843.1%)
Mutual labels:  aria2
Maria
a macOS native app/widget for aria2 download tool.
Stars: ✭ 618 (+965.52%)
Mutual labels:  aria2
Aria2app
Aria2App is an advanced download manager based on aria2 that can handle remote servers too.
Stars: ✭ 294 (+406.9%)
Mutual labels:  aria2
Ariang
AriaNg, a modern web frontend making aria2 easier to use.
Stars: ✭ 8,339 (+14277.59%)
Mutual labels:  aria2
Safari2aria
safari extension for use aria2 to replace safari default download
Stars: ✭ 563 (+870.69%)
Mutual labels:  aria2
Ccaa
Linux一键安装Aria2 + AriaNg + FileBrowse实现离线下载、文件管理。
Stars: ✭ 756 (+1203.45%)
Mutual labels:  aria2
Openiothub
💖A free IoT (Internet of Things) platform and private cloud. [一个免费的物联网和私有云平台,支持内网穿透]
Stars: ✭ 371 (+539.66%)
Mutual labels:  aria2
Persepolis
Persepolis Download Manager is a GUI for aria2.
Stars: ✭ 5,218 (+8896.55%)
Mutual labels:  aria2
Motrix
A full-featured download manager.
Stars: ✭ 29,357 (+50515.52%)
Mutual labels:  aria2
Baidu Netdisk Downloaderx
⚡️ 一款图形界面的百度网盘不限速下载器,支持 Windows、Linux 和 Mac。
Stars: ✭ 17,390 (+29882.76%)
Mutual labels:  aria2
Aria2 Pro Docker
Aria2 Pro | A perfect Aria2 Docker image | 更好用的 Aria2 Docker 容器镜像
Stars: ✭ 802 (+1282.76%)
Mutual labels:  aria2
Amm
Aria2 Menubar Monitor
Stars: ✭ 312 (+437.93%)
Mutual labels:  aria2
Pixivuserbatchdownload
P站画师个人作品批量下载工具,UserScript + Aria2。可高度自定义重命名,发送到本地或远程(如路由器)下载。
Stars: ✭ 603 (+939.66%)
Mutual labels:  aria2
Aria2gui
Aria2GUI for macOS
Stars: ✭ 7,931 (+13574.14%)
Mutual labels:  aria2
Baidupcs Nodes
百度网盘节点 Nodes of BaiduPCS
Stars: ✭ 15 (-74.14%)
Mutual labels:  aria2
Aria Ng Gui
一个 Aria2 图形界面客户端 | An Aria2 GUI for Windows & Linux & MacOS
Stars: ✭ 741 (+1177.59%)
Mutual labels:  aria2

php-aria2

Talking with aria2 through JSON-RPC

  1. Install
  2. Class Aria2
    1. Usage
    2. Batch Requests
    3. System Methods
    4. Example #1: Download File
    5. Example #2: The Returned Data
      1. Can't Download
      2. Downloading (Active)
      3. Downloaded
  3. Docker Playground
  4. Updates
  5. Contributors

Install

1. Install aria2c

Make sure aria2c is running and rpc is enabled, You can add this into /etc/rc.local /usr/local/bin/aria2c --enable-rpc --rpc-allow-origin-all -c -D

Also See The Document of Aria2

2. Require Aria2.php

The codes just 82 lines but support all RPC methods. Using php's magic method __call

2.1 Install by composer

composer require daijie/aria2

2.2 Or copy Aria2.php

Class Aria2

Aria2 {
    __construct ( string $server [, string $token ] )
    __destruct ( void )
    __call(string $name, array $arg)
    public Object batch( [Callable $func ] )
    public bool inBatch( void )
    public array commit( void )
    protected string req ( array $data )
}

Usage

$aria2 = new Aria2('http://127.0.0.1:6800/jsonrpc'); 
// http://127.0.0.1:6800/jsonrpc is the default value, 
// equals to $aria2 = new Aria2
$aria2->getGlobalStat();
$aria2->tellActive();
$aria2->tellWaiting(0,1000);
$aria2->tellStopped(0,1000);
$aria2->addUri(
	['https://www.google.com.hk/images/srpr/logo3w.png'],
	['dir'=>'/tmp']
);
$aria2->tellStatus('1');
$aria2->removeDownloadResult('1');
//and more ...

Also See Manual of Aria2 RPC Interface To Get The Method List

.i.e, It's the example from Aria2 manual wrote in Python:

>>> import urllib2, json, base64
>>> metalink = base64.b64encode(open('file.meta4').read())
>>> jsonreq = json.dumps({'jsonrpc':'2.0', 'id':'qwer',
...                       'method':'aria2.addMetalink',
...                       'params':[metalink]})
>>> c = urllib2.urlopen('http://localhost:6800/jsonrpc', jsonreq)
>>> c.read()
'{"id":"qwer","jsonrpc":"2.0","result":["2089b05ecca3d829"]}'

If you are using php with php-aria2:

<?php
require 'vendor/autoload.php';
$metalink = file_get_contents('file.meta4');
$aria2 = new Aria2('http://localhost:6800/jsonrpc');
$c = $aria2->addMetalink($metalink);
#It means the method is aria2.addMetalink
print_r($c); 

Batch requests

Now php-aria2 support JSON-RPC 2.0 Specification Batch requests In v1.2.0 batch requests have been introduced.

  • Aria2::batch - Start batch mode
  • Aria2::inBatch - Detect batch mode
  • Aria2::commit - End batch mode and commit commands
$aria2 = new Aria2('http://127.0.0.1:6800/jsonrpc');
$aria2->batch()
      ->getGlobalStat()
      ->tellActive()
      ->tellWaiting(0,1000)
      ->tellStopped(0,1000)
      ->addUri(
			['https://www.google.com.hk/images/srpr/logo3w.png'],
			['dir'=>'/tmp']
		)
		->commit();

Another ways is anonymous function, it also support method chaining. Don't forget commit.

$aria2 = new Aria2('http://aria2:6800/jsonrpc', "token:e6c3778f-6361-4ed0-b126-f2cf8fca06db");
$aria2->batch(function($aria2){
    $aria2->getGlobalStat();
    $aria2->system_listMethods();
});
$status = $aria2->commit();

System methods

  • system.multicall
  • system.listMethods
  • system.listNotifications

There are some system methods, you can call it using

  • Aria2::system_multicall
  • Aria2::system_listMethods
  • Aria2::system_listNotifications

php-aria2 convert _ to . automatically. If method name without a _, php-aria2 will auto prepend a aria2.

$aria2 = new Aria2('http://127.0.0.1:6800/jsonrpc');
$aria2->system_listMethods();
$aria2->getGlobalStat();

Example #1: Download File

$aria2->addUri(
	['https://www.google.com.hk/images/srpr/logo3w.png'],
	['dir'=>'/tmp']
);

More Options Here

Example #2: The Returned Data

Case: Can't Download

Array
(
    [id] => 1
    [jsonrpc] => 2.0
    [result] => Array
        (
            [completedLength] => 0
            [connections] => 0
            [dir] => /tmp
            [downloadSpeed] => 0
            [errorCode] => 1
            [files] => Array
                (
                    [0] => Array
                        (
                            [completedLength] => 0
                            [index] => 1
                            [length] => 0
                            [path] => 
                            [selected] => true
                            [uris] => Array
                                (
                                    [0] => Array
                                        (
                                            [status] => used
                                            [uri] => https://www.google.com.hk/images/srpr/logo3w.png
                                        )

                                )

                        )

                )
            [gid] => 2
            [numPieces] => 0
            [pieceLength] => 1048576
            [status] => error
            [totalLength] => 0
            [uploadLength] => 0
            [uploadSpeed] => 0
        )

)

Case: Downloading (Active)

Array
(
    [id] => 1
    [jsonrpc] => 2.0
    [result] => Array
        (
            [bitfield] => e0000000
            [completedLength] => 3932160
            [connections] => 1
            [dir] => /data/files/lixian
            [downloadSpeed] => 75972
            [files] => Array
                (
                    [0] => Array
                        (
                            [completedLength] => 3145728
                            [index] => 1
                            [length] => 31550548
                            [path] => /data/files/lixian/茶经.陆羽.扫描版.pdf
                            [selected] => true
                            [uris] => Array
                                (
                                    [0] => Array
                                        (
                                            [status] => used
                                            [uri] => http://gdl.lixian.vip.xunlei.com/download?fid=zKHWI/O2IbQ07pi/0hPYP1OLwrBUbOEBAAAAACaqKvQbmfR7K7JcbWGT3XQBlDzs&mid=666&threshold=150&tid=3018BA81C31480902DC937770AC2734F&srcid=4&verno=1&g=26AA2AF41B99F47B2BB25C6D6193DD7401943CEC&scn=c7&i=0D2B59F64D6CCBB5A1507A03C3B685BC&t=4&ui=222151634&ti=106821253185&s=31550548&m=0&n=013A830CE1AD5D2EC2DCE21471C9A8C3E8D1D7CA2F64660000&ff=0&co=33BB9833AB0EE7AAEA94105B64C8013F&cm=1
                                        )

                                    [1] => Array
                                        (
                                            [status] => waiting
                                            [uri] => http://gdl.lixian.vip.xunlei.com/download?fid=zKHWI/O2IbQ07pi/0hPYP1OLwrBUbOEBAAAAACaqKvQbmfR7K7JcbWGT3XQBlDzs&mid=666&threshold=150&tid=3018BA81C31480902DC937770AC2734F&srcid=4&verno=1&g=26AA2AF41B99F47B2BB25C6D6193DD7401943CEC&scn=c7&i=0D2B59F64D6CCBB5A1507A03C3B685BC&t=4&ui=222151634&ti=106821253185&s=31550548&m=0&n=013A830CE1AD5D2EC2DCE21471C9A8C3E8D1D7CA2F64660000&ff=0&co=33BB9833AB0EE7AAEA94105B64C8013F&cm=1
                                        )

                                    [2] => Array
                                        (
                                            [status] => waiting
                                            [uri] => http://gdl.lixian.vip.xunlei.com/download?fid=zKHWI/O2IbQ07pi/0hPYP1OLwrBUbOEBAAAAACaqKvQbmfR7K7JcbWGT3XQBlDzs&mid=666&threshold=150&tid=3018BA81C31480902DC937770AC2734F&srcid=4&verno=1&g=26AA2AF41B99F47B2BB25C6D6193DD7401943CEC&scn=c7&i=0D2B59F64D6CCBB5A1507A03C3B685BC&t=4&ui=222151634&ti=106821253185&s=31550548&m=0&n=013A830CE1AD5D2EC2DCE21471C9A8C3E8D1D7CA2F64660000&ff=0&co=33BB9833AB0EE7AAEA94105B64C8013F&cm=1
                                        )

                                    [3] => Array
                                        (
                                            [status] => waiting
                                            [uri] => http://gdl.lixian.vip.xunlei.com/download?fid=zKHWI/O2IbQ07pi/0hPYP1OLwrBUbOEBAAAAACaqKvQbmfR7K7JcbWGT3XQBlDzs&mid=666&threshold=150&tid=3018BA81C31480902DC937770AC2734F&srcid=4&verno=1&g=26AA2AF41B99F47B2BB25C6D6193DD7401943CEC&scn=c7&i=0D2B59F64D6CCBB5A1507A03C3B685BC&t=4&ui=222151634&ti=106821253185&s=31550548&m=0&n=013A830CE1AD5D2EC2DCE21471C9A8C3E8D1D7CA2F64660000&ff=0&co=33BB9833AB0EE7AAEA94105B64C8013F&cm=1
                                        )

                                    [4] => Array
                                        (
                                            [status] => waiting
                                            [uri] => http://gdl.lixian.vip.xunlei.com/download?fid=zKHWI/O2IbQ07pi/0hPYP1OLwrBUbOEBAAAAACaqKvQbmfR7K7JcbWGT3XQBlDzs&mid=666&threshold=150&tid=3018BA81C31480902DC937770AC2734F&srcid=4&verno=1&g=26AA2AF41B99F47B2BB25C6D6193DD7401943CEC&scn=c7&i=0D2B59F64D6CCBB5A1507A03C3B685BC&t=4&ui=222151634&ti=106821253185&s=31550548&m=0&n=013A830CE1AD5D2EC2DCE21471C9A8C3E8D1D7CA2F64660000&ff=0&co=33BB9833AB0EE7AAEA94105B64C8013F&cm=1
                                        )

                                )

                        )

                )
            [gid] => 3
            [numPieces] => 31
            [pieceLength] => 1048576
            [status] => active
            [totalLength] => 31550548
            [uploadLength] => 0
            [uploadSpeed] => 0
        )

)

Case: Downloaded

Array
(
    [id] => 1
    [jsonrpc] => 2.0
    [result] => Array
        (
            [bitfield] => fffffffe
            [completedLength] => 31550548
            [connections] => 0
            [dir] => /data/files/lixian
            [downloadSpeed] => 0
            [errorCode] => 0
            [files] => Array
                (
                    [0] => Array
                        (
                            [completedLength] => 31550548
                            [index] => 1
                            [length] => 31550548
                            [path] => /data/files/lixian/茶经.陆羽.扫描版.pdf
                            [selected] => true
                            [uris] => Array
                                (
                                    [0] => Array
                                        (
                                            [status] => used
                                            [uri] => http://gdl.lixian.vip.xunlei.com/download?fid=zKHWI/O2IbQ07pi/0hPYP1OLwrBUbOEBAAAAACaqKvQbmfR7K7JcbWGT3XQBlDzs&mid=666&threshold=150&tid=3018BA81C31480902DC937770AC2734F&srcid=4&verno=1&g=26AA2AF41B99F47B2BB25C6D6193DD7401943CEC&scn=c7&i=0D2B59F64D6CCBB5A1507A03C3B685BC&t=4&ui=222151634&ti=106821253185&s=31550548&m=0&n=013A830CE1AD5D2EC2DCE21471C9A8C3E8D1D7CA2F64660000&ff=0&co=33BB9833AB0EE7AAEA94105B64C8013F&cm=1
                                        )

                                    [1] => Array
                                        (
                                            [status] => waiting
                                            [uri] => http://gdl.lixian.vip.xunlei.com/download?fid=zKHWI/O2IbQ07pi/0hPYP1OLwrBUbOEBAAAAACaqKvQbmfR7K7JcbWGT3XQBlDzs&mid=666&threshold=150&tid=3018BA81C31480902DC937770AC2734F&srcid=4&verno=1&g=26AA2AF41B99F47B2BB25C6D6193DD7401943CEC&scn=c7&i=0D2B59F64D6CCBB5A1507A03C3B685BC&t=4&ui=222151634&ti=106821253185&s=31550548&m=0&n=013A830CE1AD5D2EC2DCE21471C9A8C3E8D1D7CA2F64660000&ff=0&co=33BB9833AB0EE7AAEA94105B64C8013F&cm=1
                                        )

                                    [2] => Array
                                        (
                                            [status] => waiting
                                            [uri] => http://gdl.lixian.vip.xunlei.com/download?fid=zKHWI/O2IbQ07pi/0hPYP1OLwrBUbOEBAAAAACaqKvQbmfR7K7JcbWGT3XQBlDzs&mid=666&threshold=150&tid=3018BA81C31480902DC937770AC2734F&srcid=4&verno=1&g=26AA2AF41B99F47B2BB25C6D6193DD7401943CEC&scn=c7&i=0D2B59F64D6CCBB5A1507A03C3B685BC&t=4&ui=222151634&ti=106821253185&s=31550548&m=0&n=013A830CE1AD5D2EC2DCE21471C9A8C3E8D1D7CA2F64660000&ff=0&co=33BB9833AB0EE7AAEA94105B64C8013F&cm=1
                                        )

                                    [3] => Array
                                        (
                                            [status] => waiting
                                            [uri] => http://gdl.lixian.vip.xunlei.com/download?fid=zKHWI/O2IbQ07pi/0hPYP1OLwrBUbOEBAAAAACaqKvQbmfR7K7JcbWGT3XQBlDzs&mid=666&threshold=150&tid=3018BA81C31480902DC937770AC2734F&srcid=4&verno=1&g=26AA2AF41B99F47B2BB25C6D6193DD7401943CEC&scn=c7&i=0D2B59F64D6CCBB5A1507A03C3B685BC&t=4&ui=222151634&ti=106821253185&s=31550548&m=0&n=013A830CE1AD5D2EC2DCE21471C9A8C3E8D1D7CA2F64660000&ff=0&co=33BB9833AB0EE7AAEA94105B64C8013F&cm=1
                                        )

                                    [4] => Array
                                        (
                                            [status] => waiting
                                            [uri] => http://gdl.lixian.vip.xunlei.com/download?fid=zKHWI/O2IbQ07pi/0hPYP1OLwrBUbOEBAAAAACaqKvQbmfR7K7JcbWGT3XQBlDzs&mid=666&threshold=150&tid=3018BA81C31480902DC937770AC2734F&srcid=4&verno=1&g=26AA2AF41B99F47B2BB25C6D6193DD7401943CEC&scn=c7&i=0D2B59F64D6CCBB5A1507A03C3B685BC&t=4&ui=222151634&ti=106821253185&s=31550548&m=0&n=013A830CE1AD5D2EC2DCE21471C9A8C3E8D1D7CA2F64660000&ff=0&co=33BB9833AB0EE7AAEA94105B64C8013F&cm=1
                                        )

                                    [5] => Array
                                        (
                                            [status] => waiting
                                            [uri] => http://gdl.lixian.vip.xunlei.com/download?fid=zKHWI/O2IbQ07pi/0hPYP1OLwrBUbOEBAAAAACaqKvQbmfR7K7JcbWGT3XQBlDzs&mid=666&threshold=150&tid=3018BA81C31480902DC937770AC2734F&srcid=4&verno=1&g=26AA2AF41B99F47B2BB25C6D6193DD7401943CEC&scn=c7&i=0D2B59F64D6CCBB5A1507A03C3B685BC&t=4&ui=222151634&ti=106821253185&s=31550548&m=0&n=013A830CE1AD5D2EC2DCE21471C9A8C3E8D1D7CA2F64660000&ff=0&co=33BB9833AB0EE7AAEA94105B64C8013F&cm=1
                                        )

                                )

                        )

                )
            [gid] => 3
            [numPieces] => 31
            [pieceLength] => 1048576
            [status] => complete
            [totalLength] => 31550548
            [uploadLength] => 0
            [uploadSpeed] => 0
        )

)

Docker Playground

require docker-compose

Docker playground: nginx (17 MB) + php7-fpm (82 MB) + aria2c (6 MB)

init playground

git clone https://github.com/shiny/php-aria2/
cd php-aria2/playground
docker-compose up

then open another terminal and enter playground

docker-compose exec php composer require daijie/aria2

for China user we suggest use the phpcomposer mirror

docker-compose exec php composer config repo.packagist composer https://packagist.phpcomposer.com
docker-compose exec php composer require daijie/aria2

After that, the playground structure:

├── aria2.conf # Aria2 conf file
├── data # Store downloaded file
├── docker-compose.yml
├── nginx.conf # nginx conf
└── www # Web dir
    ├── composer.json
    ├── composer.lock
    ├── index.php
    └── vendor
        ├── autoload.php
        ├── composer
        │   ├── ClassLoader.php
        │   ├── LICENSE
        │   ├── autoload_classmap.php
        │   ├── autoload_namespaces.php
        │   ├── autoload_psr4.php
        │   ├── autoload_real.php
        │   ├── autoload_static.php
        │   └── installed.json
        └── daijie
            └── aria2
                ├── Aria2.php
                ├── LICENSE.txt
                ├── README.md
                └── composer.json

Edit www/index.php and Open Browser To Visit http://127.0.0.1:8080

Updates

v1.2.1b

  • add batch anonymous function

v1.2.0b

  • Add system methods
  • Add batch mode

v1.1

Now support default token(secret) in php-aria2, compatible with v1.0

Before

$aria2 = new Aria2('http://aria2:6800/jsonrpc');
$aria2->addUri(
    "token:e6c3778f-6361-4ed0-b126-f2cf8fca06db",
    ['https://www.docker.com/sites/default/files/moby.svg']
);
$aria2->getGlobalStat("token:e6c3778f-6361-4ed0-b126-f2cf8fca06db");

After

$aria2 = new Aria2('http://aria2:6800/jsonrpc', "token:e6c3778f-6361-4ed0-b126-f2cf8fca06db");
$aria2->addUri(
    ['https://www.docker.com/sites/default/files/moby.svg']
);
$status = $aria2->getGlobalStat();

Contributors

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].