nintendo switch

Playing with Raspberry Pi 02 - Building a Download Machine

Please Google for information about Aria2, this article only covers its usage.


Install Aria2 using Docker:

git clone --depth=1 https://github.com/LJason77/docker-aria2-with-webui.git
cd docker-aria2-with-webui/
docker build -t aria2 .
docker run -d --name aria2 --restart always --network host -v /mnt/downloads:/data aria2

For detailed usage, please refer to the project: docker-aria2-with-webui

Old Blog#

Install Aria#

Since the version of aria2 in the repository is too old, I will manually compile and install it:

First, get the source code:

git clone --depth=1 https://github.com/aria2/aria2.git

Then install the necessary dependencies:

apt-get install -y libgnutls-deb0-28 nettle-dev libgmp-dev libssh2-1-dev libc-ares-dev libxml2-dev zlib1g-dev libsqlite3-dev pkg-config libgpg-error-dev libgcrypt20-dev libssl-dev libexpat1-dev libcppunit-dev autoconf automake autotools-dev autopoint libtool

Generate the necessary configuration scripts and other files for building the program:

autoreconf -i

Then start configuring aria2:


After the configuration is complete, start compiling aria2:


After the compilation is complete, the executable file is located at src/aria2c. Then run the unit tests:

make check

After the tests are finished, you can install aria2:

sudo make install

Configure aria2#

Create the configuration folder for Aria2:

sudo mkdir /etc/aria2

Create session and configuration files:

sudo touch /etc/aria2/aria2.session
sudo touch /etc/aria2/aria2.conf

Edit /etc/aria2/aria2.conf:

## File saving related

# File saving directory
# Enable disk cache, 0 to disable cache, requires version 1.16 or above, default: 16M
# Resume download

# File allocation method, can effectively reduce disk fragmentation, default: prealloc
# Pre-allocation time: none < falloc ? trunc < prealloc
# falloc and trunc require file system and kernel support
# NTFS recommends using falloc, EXT3/4 recommends trunc, MAC needs to comment out this item

## Download connection related

# Maximum number of concurrent downloads, can be modified at runtime, default: 5
# Number of connections to the same server, can be specified when adding, default: 1
# Overall download speed limit, can be modified at runtime, default: 0 (unlimited)
# Individual task download speed limit, default: 0 (unlimited)
# Overall upload speed limit, can be modified at runtime, default: 0 (unlimited)
# Individual task upload speed limit, default: 0 (unlimited)
# Disable IPv6, default: false

# Minimum file chunk size, can be specified when adding, range: 1M -1024M, default: 20M
# Assuming size=10M, for a 20MiB file, two sources will be used for download; for a 15MiB file, one source will be used for download
# Maximum number of threads for a single task, can be specified when adding, default: 5

## Progress saving related

# Read download tasks from session file
# Save erroneous and unfinished download tasks to session file when Aria2 exits
# Save session at regular intervals, 0 to save only when exiting, requires version 1.16.1 or above, default: 0

## RPC related settings

# Enable RPC, default: false
# Allow all sources, default: false
# Allow external access, default: false
# RPC port, only modify when the default port is occupied
# rpc-listen-port=6800
# Set RPC authorization token, new feature added in v1.18.4, replaces --rpc-user and --rpc-passwd options

## BT/PT download related

# Automatically start BT tasks when downloading a torrent (ending with .torrent), default: true
# Client disguise, required for PT
# Force save session, even if the task is already completed, default: false
# Newer versions will keep the .aria2 file after the task is completed when this is enabled
# When continuing previous BT tasks, no need to verify again, default: false
# Save magnet link metadata as a torrent file (.torrent file), default: false

Then execute:

aria2c --conf-path=/etc/aria2/aria2.conf -D

If there is no prompt, it means success. Next, add it to startup:

sudo touch /etc/init.d/aria2c


# Provides: aria2c
# Required-Start:    $network $local_fs $remote_fs
# Required-Stop:     $network $local_fs $remote_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: aria2c RPC init script.
# Description: Starts and stops aria2 RPC services.
case "$1" in
        echo "Starting service Aria2..."
        aria2c --conf-path=/etc/aria2/aria2.conf -D
        echo "Start service done."
        echo "Stoping service Aria2..."
        killall aria2c
        echo "Stop service done."
exit $RETVAL


sudo chmod +x /etc/init.d/aria2c
sudo apt-get -y install chkconfig
sudo chkconfig --add aria2c

Install nginx#

Nginx is a very lightweight HTTP server, which is very suitable for use on Raspberry Pi as the web management for Aria2. Install Nginx:

sudo apt-get -y install nginx

Download the third-party program:

sudo rm -rf /var/www/html
sudo git clone --depth=1 https://github.com/ziahamza/webui-aria2.git /var/www/html

Start nginx:

sudo /etc/init.d/nginx start

Add it to startup, edit /etc/rc.local, and add a line:

/etc/init.d/nginx start

You can now use Aria2 for downloading by entering the IP address of the Raspberry Pi in a browser.

Now you can just throw in links and torrents before going to school, before going to work, and before going to bed, and they will be downloaded when you come back.

If you are downloading large files, you don't have to keep your computer on all day like before.

Think about it, how powerful is your computer? According to RaspberryPi, the rated power of the third-generation Raspberry Pi is only 4.0W, very energy efficient.

I'm really tired of the speed limit on downloading Baidu Cloud resources without paying. I wanted to apply for PCS to get an API port for unlimited speed downloads.

Unfortunately, they have long seen through your intentions. Baidu has closed the registration for PCS since 2013, but old users are not affected (the reason given in the announcement is a bunch of words, but the real reason is that everyone was using it for unlimited speed and Baidu couldn't make money from it).

But there is always a way. Because old users are not affected, I finally found a PCS after some searching.

Baidu Cloud Direct Link System

Log in to Baidu Cloud, then put the file in the "hgf_blog" folder under "Cloud Disk"-"My App Data", and a list will appear on the page. Click on the file to get the direct link, and then use Aria2 to download it.

Download Baidu Cloud resources using Tampermonkey#

First, install the Tampermonkey plugin in the Chrome browser, and then install the Baidu Cloud Direct Download Helper. That's it, you can refer to the instructions inside for the tutorial.

Open Baidu Cloud, select a file, and a "Download Helper" will appear. Select "Direct Link Download"-"Show Link"-"Edit"-"Single Line", then select all and copy the link, paste it into Aria2 for downloading.

Note: If the file name is in Chinese, it will be garbled when downloading in Aria2. You can rename it in Baidu Cloud or add --out=filename after the link. The Aria2 download interface has instructions on this.

Scheduled Speed Limit#

I am at school during the day and only return home at night. In order not to affect the internet speed, I want to download at full speed during the day and limit the speed at night. Edit /var/spool/cron/crontabs/root and add:

0 19 * * * curl -H "Content-Type: application/json" -H "Accept: application/json" --data '{"jsonrpc":"2.0","id":1,"method":"aria2.changeGlobalOption","params":[{"max-overall-download-limit":"300K","max-overall-upload-limit":"10K"}]}'
30 23 * * * curl -H "Content-Type: application/json" -H "Accept: application/json" --data '{"jsonrpc":"2.0","id":1,"method":"aria2.changeGlobalOption","params":[{"max-overall-download-limit":"0","max-overall-upload-limit":"0"}]}'

The first line means that at 19:00, the download speed is limited to 300K and the upload speed is limited to 10K; the second line means that at 23:30, both the download and upload speeds are set to 0 (0 means unlimited).

Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.