Ubuntu18.04和OpenWrt 18.06.0 下使用aria2和BaiduExport處理百度盤下載


Ubuntu下沒有可用的百度盤客戶端, 下載大文件如果通過瀏覽器就會特別不可靠. 可以使用Chrome插件 BaiduExport 得到下載鏈接和參數后, 通過aria2進行下載.

Aria2安裝

直接通過apt install 就可以了

$ sudo apt install aria2
[sudo] password for milton: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libaec0 libfreexl1 libgeos-3.6.2 libgeos-c1v5 libgeotiff2 libhdf4-0-alt
  libhdf5-100 libkmlbase1 libkmldom1 libkmlengine1 libminizip1
  libmysqlclient20 libnetcdf13 libogdi3.2 libpq5 libproj12 libsz2
  liburiparser1 libxerces-c3.2 proj-data python-asn1crypto python-cffi-backend
  python-cryptography python-enum34 python-idna python-ipaddress
  python-paramiko python-pyasn1 python-six
Use 'sudo apt autoremove' to remove them.
The following NEW packages will be installed:
  aria2
0 upgraded, 1 newly installed, 0 to remove and 17 not upgraded.
Need to get 1,236 kB of archives.
After this operation, 4,819 kB of additional disk space will be used.
Get:1 http://cn.archive.ubuntu.com/ubuntu bionic/universe amd64 aria2 amd64 1.33.1-1 [1,236 kB]
Fetched 1,236 kB in 5s (258 kB/s)  
Selecting previously unselected package aria2.
(Reading database ... 206284 files and directories currently installed.)
Preparing to unpack .../aria2_1.33.1-1_amd64.deb ...
Unpacking aria2 (1.33.1-1) ...
Setting up aria2 (1.33.1-1) ...
Processing triggers for man-db (2.8.3-2) ...

運行aria2

可以直接通過命令行啟動, 例如: 

aria2c -c -s10 -k1M -x16 -o "output.file" -d /home/milton/Downloads/ "http://some.where.com/some/file"

各參數含義可以通過aria2c --help 查看, 或者在線手冊 https://aria2.github.io/manual/en/html/aria2c.html

也可以使用配置文件, 使用配置文件啟動的命令如下, 你也可以把conf文件放到其他目錄, 如果使用-D參數則進入后台運行

aria2c --conf-path=/home/milton/.config/aria2/aria2.conf

配置文件例子

## 文件保存相關 ##

# 文件的保存路徑(可使用絕對路徑或相對路徑), 默認: 當前啟動位置
dir=~/downloads
# 啟用磁盤緩存, 0為禁用緩存, 需1.16以上版本, 默認:16M
#disk-cache=32M
# 文件預分配方式, 能有效降低磁盤碎片, 默認:prealloc
# 預分配所需時間: none < falloc ? trunc < prealloc
# falloc和trunc則需要文件系統和內核支持
# NTFS建議使用falloc, EXT3/4建議trunc, MAC 下需要注釋此項
#file-allocation=none
# 斷點續傳
continue=true

## 下載連接相關 ##

# 最大同時下載任務數, 運行時可修改, 默認:5
#max-concurrent-downloads=5
# 同一服務器連接數, 添加時可指定, 默認:1
max-connection-per-server=5
# 最小文件分片大小, 添加時可指定, 取值范圍1M -1024M, 默認:20M
# 假定size=10M, 文件為20MiB 則使用兩個來源下載; 文件為15MiB 則使用一個來源下載
min-split-size=2M
# 單個任務最大線程數, 添加時可指定, 默認:5
#split=5
# 整體下載速度限制, 運行時可修改, 默認:0
#max-overall-download-limit=0
# 單個任務下載速度限制, 默認:0
#max-download-limit=0
# 整體上傳速度限制, 運行時可修改, 默認:0
#max-overall-upload-limit=0
# 單個任務上傳速度限制, 默認:0
#max-upload-limit=0
# 禁用IPv6, 默認:false
#disable-ipv6=true
# 連接超時時間, 默認:60
#timeout=60
# 最大重試次數, 設置為0表示不限制重試次數, 默認:5
#max-tries=5
# 設置重試等待的秒數, 默認:0
#retry-wait=0

## 進度保存相關 ##

# 從會話文件中讀取下載任務
input-file=/home/milton/.config/aria2/aria2.session
# 在Aria2退出時保存`錯誤/未完成`的下載任務到會話文件
save-session=/home/milton/.config/aria2/aria2.session
# 定時保存會話, 0為退出時才保存, 需1.16.1以上版本, 默認:0
#save-session-interval=60

## RPC相關設置 ##

# 啟用RPC, 默認:false
enable-rpc=true
# 允許所有來源, 默認:false
rpc-allow-origin-all=true
# 允許非外部訪問, 默認:false
rpc-listen-all=true
# 事件輪詢方式, 取值:[epoll, kqueue, port, poll, select], 不同系統默認值不同
#event-poll=select
# RPC監聽端口, 端口被占用時可以修改, 默認:6800
#rpc-listen-port=6800
# 設置的RPC授權令牌, v1.18.4新增功能, 取代 --rpc-user 和 --rpc-passwd 選項
rpc-secret=123123
# 設置的RPC訪問用戶名, 此選項新版已廢棄, 建議改用 --rpc-secret 選項
#rpc-user=<USER>
# 設置的RPC訪問密碼, 此選項新版已廢棄, 建議改用 --rpc-secret 選項
#rpc-passwd=<PASSWD>
# 是否啟用 RPC 服務的 SSL/TLS 加密,
# 啟用加密后 RPC 服務需要使用 https 或者 wss 協議連接
#rpc-secure=true
# 在 RPC 服務中啟用 SSL/TLS 加密時的證書文件,
# 使用 PEM 格式時,您必須通過 --rpc-private-key 指定私鑰
#rpc-certificate=/path/to/certificate.pem
# 在 RPC 服務中啟用 SSL/TLS 加密時的私鑰文件
#rpc-private-key=/path/to/certificate.key

## BT/PT下載相關 ##

# 當下載的是一個種子(以.torrent結尾)時, 自動開始BT任務, 默認:true
#follow-torrent=true
# BT監聽端口, 當端口被屏蔽時使用, 默認:6881-6999
listen-port=51413
# 單個種子最大連接數, 默認:55
#bt-max-peers=55
# 打開DHT功能, PT需要禁用, 默認:true
enable-dht=false
# 打開IPv6 DHT功能, PT需要禁用
#enable-dht6=false
# DHT網絡監聽端口, 默認:6881-6999
#dht-listen-port=6881-6999
# 本地節點查找, PT需要禁用, 默認:false
#bt-enable-lpd=false
# 種子交換, PT需要禁用, 默認:true
enable-peer-exchange=false
# 每個種子限速, 對少種的PT很有用, 默認:50K
#bt-request-peer-speed-limit=50K
# 客戶端偽裝, PT需要
peer-id-prefix=-TR2770-
user-agent=Transmission/2.77
# 當種子的分享率達到這個數時, 自動停止做種, 0為一直做種, 默認:1.0
seed-ratio=0
# 強制保存會話, 即使任務已經完成, 默認:false
# 較新的版本開啟后會在任務完成后依然保留.aria2文件
#force-save=false
# BT校驗相關, 默認:true
#bt-hash-check-seed=true
# 繼續之前的BT任務時, 無需再次校驗, 默認:false
bt-seed-unverified=true
# 保存磁力鏈接元數據為種子文件(.torrent文件), 默認:false
bt-save-metadata=true

BaiduExport安裝

 https://github.com/acgotaku/BaiduExporter . 在Releases下找到最新的crx文件, 下載到本地后, 解壓縮至用戶home目錄下 ~/.config/google-chrome/Default/BaiduExporter . (試過放Extensions目錄下, 但是重啟后會被刪除)

打開Chrome, 菜單 More Tools -> Extensions, 打開Development Mode, 點擊Load Unpacked, 選擇剛才的目錄, 安裝就完成了

BaiduExport和Aria2使用

在Chrome中訪問百度盤的時候, 在文件列表頁會增加一項"導出下載", 如果本地已經啟動了aria2, 這里可以配置本地的aria2信息, 然后點擊Aria2 RPC將下載添加到本地Aria2, 也可以點擊導出文本, 得到一個aria2c的命令行, 這個命令行稍加修改就可以直接運行啟動下載.

安裝YAAW

這也是一個Chrome插件, 但是可以直接從Chrome中在線安裝. 配置一下就可以連接到aria2查看下載列表和進度. 如果設置了secret或用戶名密碼的, 連接URL需要修改一下, 如下

使用 --rpc-secret=xxxxxx 選項
設置為: http://token:xxxxxx@host:port/jsonrpc

使用 --rpc-user=user --rpc-passwd=pwd 選項設置為:
http://user:pwd@host:port/jsonrpc

以上 JSON-RPC Path 中的 http 可以用 ws 替代, 代表使用 WebSocket 協議

Openwrt 18.06.0下的Aria2

openwrt18.06.0下集成的aria2版本是1.33.0, 如果有配置界面的話, 直接在界面上就能進行配置, 我在路由器上的配置為

config aria2 'main'
	option user 'aria2'
	option dir '/mnt/sda1/aria2'
	option bt_enable_lpd 'true'
	option enable_dht 'true'
	option follow_torrent 'true'
	option file_allocation 'none'
	option save_session_interval '30'
	list header ''
	option rpc_auth_method 'token'
	option rpc_secret '123123'
	option config_dir '/mnt/sda1/aria2'
	option enable_log 'true'
	option log_level 'debug'
	option disk_cache '1M'
	option max_concurrent_downloads '5'
	option max_connection_per_server '16'
	option min_split_size '2M'
	option split '5'
	option enabled '1'
	option rpc_listen_port '6800'
	list extra_settings 'log=/mnt/sda1/aria2/aria2.log'
	list extra_settings 'check-certificate=false'

注意最后的兩個 extra_settings:

log=/xxx/xxx 這個配置, 是為了打開日志記錄. 因為界面上配置即使enable_log=true, 也只會在system_log中顯示極少的幾個日志, 為了檢查出錯的原因, 必須要顯示指定日志文件

check-certificate=false 這個是因為openwrt下並沒有像Ubuntu那樣的/etc/ssl/certs/ca-certificates.crt , 所以下載https文件時會報錯 SSL/TLS handshake failure: unable to get local issuer certificate, 為了能繼續下載而關閉了證書校驗. (這是不安全的做法, 不過對於下載電影之類的需求, 這個就無所謂了)

YAAW和BaiduExport與Openwrt Aria2的連接方式是一樣的.

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM