aria2p  light weight dowload helper on teminal

**注意：以下の記事を参考にされ、問題が生じた場合、責任は負いかねます。**
I am a Manjaro linux user (one of Arch linux clone). So I use Arch tools, following setup. 

# aria2p : download helper.  CLI tool using python.

>Command-line tool and Python library to interact with an aria2c daemon process through JSON-RPC.

Aria2を利用した軽量なdownload toolです。
Aria2の利用者で、vimmerのような人たちに興味を持って頂けそうな気がします。

開発は最近なのか、関心が薄いのか、netであまり取り上げられいません。:sob:

## 1. まずAria2から

>aria2 は軽量なマルチプロトコル&マルチソースのコマンドラインダウンロードユーティリティです。HTTP/HTTPS, FTP, BitTorrent, Metalink をサポートしています。aria2 はビルトインの JSON-RPC と XML-RPC インターフェイスで操作することができます。
https://wiki.archlinux.jp/index.php/Aria2#.E5.8F.82.E7.85.A7

Aria2 is one of **best download utility**. It can download files not only from web, but also from torrent or metalink and etc. 

If you use Aria2 as daemon, you can **download files on background** and also **use it from remote PCs**.


## 2. aria2p　sample screen shot

[There are many download helpers usig aria2](https://wiki.archlinux.jp/index.php/Aria2#.E3.82.B5.E3.83.B3.E3.83.97.E3.83.AB_aria2.daemon). But most of them use GUI.

But aria2p runs on terminal as CLI tools and very light. I love it. :heart:
Here is a sample gif movie  of aria2p from its git page.  

![gif movie](https://user-images.githubusercontent.com/3999221/72664104-41658180-39fa-11ea-838e-022ed29d8c0b.gif)

## 3. Aria2.  install & setup
I am a Manjaro linux user (one of Arch linux clone). So I use Arch tools, following setup. 

### 3-1. install Aria2

```
yay -S aria aria2c-daemon
```

### 3-2. Aria2 run as daemon

Create download directory & **permission 777**, because Aria-daemon can save files there.
**Aria-daemon runs as user=aria2c, group=aria2c.**

```
## create a directory somewhere. Here is sample.
mkdir -p aria_dw
chmod 777 aira_dw
```
### 3-3. Edit config.

```
sudo vim /etc/conf.d/aria2c.conf

.....
## download dirctory
## set permission 777
dir=aria_dw

## set RPC token
rpc-secret=hoge  # exchange "hoge" to others, for security.

....
## set proxy, if needed.
#all-proxy=http://127.0.0.1:3128

## other setting, if needed.
....
```

### 3-4. run Aria2 as daemon using systemctl

```
sudo systemctl enable --now aria2cd
```

#### confirm
```
sudo systemctl status aria2cd

● aria2cd.service - aria2c Service
     Loaded: loaded (/etc/systemd/system/aria2cd.service; disabled; preset: disabled)
     Active: active (running) since .......
 Invocation: fed87108916a4e95a3b546ee6d2bc1d5
    Process: 16556 ExecStart=/usr/bin/aria2c -D --conf-path=${ARIA2C_CONF} --save-session-interval=180 >
   Main PID: 16557 (aria2c)
      Tasks: 1 (limit: 76947)
     Memory: 10.7M
        CPU: 804ms
     CGroup: /system.slice/aria2cd.service
             └─16557 /usr/bin/aria2c -D --conf-path=/etc/conf.d/aria2c.conf --save-session-interval=180>

....  systemd[1]: Starting aria2c Service...
....  systemd[1]: Started aria2c Service.
```

#### for test, aria2c run as daemon from user.

[if you need an aria2c instance quickly, run the following command:](https://stackoverflow.com/questions/62101819/how-to-use-aria2c-rpc-server-as-a-daemon)

```
aria2c --enable-rpc --rpc-listen-all --rpc-secret=hoge
```

## 4. aria2p. install & set up

### 4-1. set up python local environmnet, using pyenv.
aria2p pkg exists in Arch's AUR, but not work...
So I have to use python local environment.

You can use other utils, not pyenv. But I do not know it works or not.

```
## install pyenv.
yay -S pyenv

pyenv install 3.7.6  # aria2p may work on 3.8.10 not 3.7.6.
```

### 4-2. install aria2p

use 3.7.6 here, but newer python version might be OK.
```
pyenv local 3.7.6

pip install aria2p[tui]
```

### 4-3. find path of aria2p & create alias
```
which aria2p

$HOME/.pyenv/versions/3.7.6/bin/aria2p 
```

#### create alias

[options are explained at git page](https://github.com/pawamoy/aria2p?tab=readme-ov-file)
```
alias aria2p=' $HOME/.pyenv/versions/3.7.6/bin/aria2p -s hoge
alais aa0=' aria2p'

## connect Aria2c running on remote PC (192.168.1.254)
aaa(){ $HOME/.pyenv/versions/3.7.6/bin/aria2p -H http://192.168.1.254 -s hoge}

## add download file links to aria-daemon.
aab() { echo "aria2p add\n" ;
        $HOME/.pyenv/versions/3.7.6/bin/aria2p -H http://192.168.1.254 -s hoge add "$@" 
        && aaa}
```

### 4-4. sample for usage

add dowload link to Aria2c & start download using aria2c.
```
$HOME/.pyenv/versions/3.7.6/bin/aria2p -H http://192.168.1.254 -s hoge add\
http://host.robots.ox.ac.uk/pascal/VOC/voc2012/VOCtrainval_11-May-2012.tar

## or use alias
aab http://host.robots.ox.ac.uk/pascal/VOC/voc2012/VOCtrainval_11-May-2012.tar 
```

#### sample screen shot

##### type F6, sort menu shows up at left.

![aria2p_03-06-2025_01.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3786524/59977ea4-188a-4475-8973-29bc4c0aa609.png)

### 5. menu screen

#### escape : cancel the menu and move top menu

#### F1, ? : help

![aria2p_help_03-06-2025_01.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3786524/db985605-c922-4cd7-a6ef-c4dea3a456f7.png)

#### space : toggle pause/ resume download

become "paused/active" inside the orage window.

![aria2p_pause_03-06-2025_01.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3786524/0c823bd8-0dd1-4bdf-8786-45685de2e427.png)

#### F9, del : remove download, and choose delete files or not from this menu.

Links are removed, but saving files is not deleted on my PC, I should delete files later.

![aria2p_remove_03-06-2025_01.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3786524/e700f373-ebd4-4065-ba16-f40c37293a3a.png)


## 6. command options
https://github.com/pawamoy/aria2p?tab=readme-ov-file

```
aria2p -h

Global options:
  -h, --help            Show this help message and exit. Commands also accept
                        the -h/--help option.
  -p PORT, --port PORT  Port to use to connect to the remote server.
  -H HOST, --host HOST  Host address for the remote server.
  -s SECRET, --secret SECRET
                        Secret token to use to connect to the remote server.
  -L {TRACE,DEBUG,INFO,SUCCESS,WARNING,ERROR,CRITICAL}, --log-level {TRACE,DEBUG,INFO,SUCCESS,WARNING,ERROR,CRITICAL}
                        Log level to use
  -P LOG_PATH, --log-path LOG_PATH
                        Log path to use. Can be a directory or a file.
  -T CLIENT_TIMEOUT, --client-timeout CLIENT_TIMEOUT
                        Timeout in seconds for requests to the remote server.
                        Floats supported. Default: 60.0.

Commands:

    add                 Add downloads with URIs/Magnets/torrents/Metalinks.
    add-magnets (add-magnet)
                        Add downloads with Magnet URIs.
    add-metalinks (add-metalink)
                        Add downloads with Metalink files.
    add-torrents (add-torrent)
                        Add downloads with torrent files.
    autopurge (autoclear)
                        Automatically purge completed/removed/failed
                        downloads.
    call                Call a remote method through the JSON-RPC client.
    pause (stop)        Pause downloads.
    remove (rm, del, delete)
                        Remove downloads.
    resume (start)      Resume downloads.
    show                Show the download progression.
    top                 Launch the top-like interactive interface.
    listen              Listen to notifications.
```


# reference
[aria2p git](https://github.com/pawamoy/aria2p?tab=readme-ov-file#add)
[aria2 manuual page](https://aria2.github.io/manual/en/html/index.html)
[Aria2 from Arch page](https://wiki.archlinux.jp/index.php/Aria2#.E3.82.B5.E3.83.B3.E3.83.97.E3.83.AB_aria2.daemon)
[aria2c-daemon from AUR](https://aur.archlinux.org/packages/aria2c-daemon)
[aria2p AUR but not work](https://aur.archlinux.org/packages/aria2p)
[b1337xyz's cofigs](https://github.com/b1337xyz/config/tree/main/aria2)
[b1337xyz's script](https://github.com/b1337xyz/scripts/blob/main/shell/autostart/aria2rpc.sh)