离线下载网盘——aria2下载自动上传阿里云盘等等国内外各种网盘

还是得益于alist和rclone,国内网盘基本上不能用rclone挂载,不过支持webdav。刚好alist支持挂载国内各种网盘,支持webdav,rclone就可以挂载了。挂载之后配合aria2,就可以当离线网盘了。

1、alsit安装参考:https://zsxwz.com/2022/03/29/

2、rclone配置webdav

apt install rclone

rclone config

#配置
#输入n,新健配置
e/n/d/r/c/s/q> n

#名称随意,但是后面aria2上传脚本需要一致
name>aliyun

#选择webdav编号,不同版本编号可能不同,自己看仔细一点
Storage>41

#挂载目录
url>http://你服务器ip:5244/dav

#其他类型
vendor>5

#用户名和密码,根据alist后台修改,输入密码是看不见的,但其实已经输入了
user>admin
password:

#其他的默认回车即可。

#配置好之后q,退出

配置好之后可以查看一下是否挂载成功。

rclone lsd aliyun:/
#如果可以正常返回你网盘目录,就挂载成功了。

3、aria2离线下载:

apt install aria2

#添加aria2配置文件
mkdir -p ~/.config/aria2
vim  ~/.config/aria2/aria2.conf

#添加以下内容
dir=/root/Downloads
disk-cache=32M
continue=true
max-connection-per-server=16
min-split-size=10M
split=32
event-poll=select
rpc-listen-port=6800
listen-port=51413
bt-max-peers=100
enable-dht=true
#enable-dht6=false
dht-listen-port=6881-6999
bt-enable-lpd=true
enable-peer-exchange=true
seed-time=0
on-download-complete=/root/.config/aria2/up.sh
bt-tracker=

下载完之后,自动上传脚本:vim ~/.config/aria2/up.sh,添加,以下内容,记得修改一下rclone挂载网盘的名称,和上传的路径,根目录就是/

#!/usr/bin/env bash

DOWNLOAD_PATH='/root/Downloads'

DRIVE_NAME='挂载名称记得修改'

DRIVE_PATH='/上传目录'

export RCLONE_RETRIES_SLEEP=10s

RETRY_NUM=3

FILE_PATH=$3
RELATIVE_PATH=${FILE_PATH#${DOWNLOAD_PATH}/}
TOP_PATH=${DOWNLOAD_PATH}/${RELATIVE_PATH%%/*}
RED_FONT_PREFIX="\033[31m"
LIGHT_GREEN_FONT_PREFIX="\033[1;32m"
YELLOW_FONT_PREFIX="\033[1;33m"
LIGHT_PURPLE_FONT_PREFIX="\033[1;35m"
FONT_COLOR_SUFFIX="\033[0m"
INFO="[${LIGHT_GREEN_FONT_PREFIX}INFO${FONT_COLOR_SUFFIX}]"
ERROR="[${RED_FONT_PREFIX}ERROR${FONT_COLOR_SUFFIX}]"
WARRING="[${YELLOW_FONT_PREFIX}WARRING${FONT_COLOR_SUFFIX}]"

TASK_INFO() {
    echo -e "
-------------------------- [${YELLOW_FONT_PREFIX}TASK INFO${FONT_COLOR_SUFFIX}] --------------------------
${LIGHT_PURPLE_FONT_PREFIX}Download path:${FONT_COLOR_SUFFIX} ${DOWNLOAD_PATH}
${LIGHT_PURPLE_FONT_PREFIX}File path:${FONT_COLOR_SUFFIX} ${FILE_PATH}
${LIGHT_PURPLE_FONT_PREFIX}Upload path:${FONT_COLOR_SUFFIX} ${UPLOAD_PATH}
${LIGHT_PURPLE_FONT_PREFIX}Remote path:${FONT_COLOR_SUFFIX} ${REMOTE_PATH}
-------------------------- [${YELLOW_FONT_PREFIX}TASK INFO${FONT_COLOR_SUFFIX}] --------------------------
"
}

CLEAN_UP() {
    [[ -n ${MIN_SIZE} || -n ${INCLUDE_FILE} || -n ${EXCLUDE_FILE} ]] && echo -e "${INFO} Clean up excluded files ..."
    [[ -n ${MIN_SIZE} ]] && rclone delete -v "${UPLOAD_PATH}" --max-size ${MIN_SIZE}
    [[ -n ${INCLUDE_FILE} ]] && rclone delete -v "${UPLOAD_PATH}" --exclude "*.{${INCLUDE_FILE}}"
    [[ -n ${EXCLUDE_FILE} ]] && rclone delete -v "${UPLOAD_PATH}" --include "*.{${EXCLUDE_FILE}}"
}

UPLOAD_FILE() {
    RETRY=0
    while [ ${RETRY} -le ${RETRY_NUM} ]; do
        [ ${RETRY} != 0 ] && (
            echo
            echo -e "$(date +"%m/%d %H:%M:%S") ${ERROR} Upload failed! Retry ${RETRY}/${RETRY_NUM} ..."
            echo
        )
        rclone move -v "${UPLOAD_PATH}" "${REMOTE_PATH}"
        RCLONE_EXIT_CODE=$?
        if [ ${RCLONE_EXIT_CODE} -eq 0 ]; then
            [ -e "${DOT_ARIA2_FILE}" ] && rm -vf "${DOT_ARIA2_FILE}"
            rclone rmdirs -v "${DOWNLOAD_PATH}" --leave-root
            echo -e "$(date +"%m/%d %H:%M:%S") ${INFO} Upload done: ${UPLOAD_PATH} -> ${REMOTE_PATH}"
            [ $LOG_PATH ] && echo -e "$(date +"%m/%d %H:%M:%S") [INFO] Upload done: ${UPLOAD_PATH} -> ${REMOTE_PATH}" >>${LOG_PATH}
            break
        else
            RETRY=$((${RETRY} + 1))
            [ ${RETRY} -gt ${RETRY_NUM} ] && (
                echo
                echo -e "$(date +"%m/%d %H:%M:%S") ${ERROR} Upload failed: ${UPLOAD_PATH}"
                [ $LOG_PATH ] && echo -e "$(date +"%m/%d %H:%M:%S") [ERROR] Upload failed: ${UPLOAD_PATH}" >>${LOG_PATH}
                echo
            )
            sleep 3
        fi
    done
}

UPLOAD() {
    echo -e "$(date +"%m/%d %H:%M:%S") ${INFO} Start upload..."
    TASK_INFO
    UPLOAD_FILE
}

if [ -z $2 ]; then
    echo && echo -e "${ERROR} This script can only be used by passing parameters through Aria2."
    echo && echo -e "${WARRING} 直接运行此脚本可能导致无法开机!"
    exit 1
elif [ $2 -eq 0 ]; then
    exit 0
fi

if [ -e "${FILE_PATH}.aria2" ]; then
    DOT_ARIA2_FILE="${FILE_PATH}.aria2"
elif [ -e "${TOP_PATH}.aria2" ]; then
    DOT_ARIA2_FILE="${TOP_PATH}.aria2"
fi

if [ "${TOP_PATH}" = "${FILE_PATH}" ] && [ $2 -eq 1 ]; then # 普通单文件下载,移动文件到设定的网盘文件夹。
    UPLOAD_PATH="${FILE_PATH}"
    REMOTE_PATH="${DRIVE_NAME}:${DRIVE_PATH}"
    UPLOAD
    exit 0
elif [ "${TOP_PATH}" != "${FILE_PATH}" ] && [ $2 -gt 1 ]; then # BT下载(文件夹内文件数大于1),移动整个文件夹到设定的网盘文件夹。
    UPLOAD_PATH="${TOP_PATH}"
    REMOTE_PATH="${DRIVE_NAME}:${DRIVE_PATH}/${RELATIVE_PATH%%/*}"
    CLEAN_UP
    UPLOAD
    exit 0
elif [ "${TOP_PATH}" != "${FILE_PATH}" ] && [ $2 -eq 1 ]; then # 第三方度盘工具下载(子文件夹或多级目录等情况下的单文件下载)、BT下载(文件夹内文件数等于1),移动文件到设定的网盘文件夹下的相同路径文件夹。
    UPLOAD_PATH="${FILE_PATH}"
    REMOTE_PATH="${DRIVE_NAME}:${DRIVE_PATH}/${RELATIVE_PATH%/*}"
    UPLOAD
    exit 0
fi

echo -e "${ERROR} Unknown error."
TASK_INFO
exit 1

设置一下权限:chmod +x ~/.config/aria2/up.sh

如果下载磁力之类的,可以设置自动更新tracker:

vim ~/.config/aria2/tracker.sh

#添加以下内容
#!/bin/bash
list=`wget -qO- https://raw.githubusercontent.com/ngosang/trackerslist/master/trackers_all.txt|awk NF|sed ":a;N;s/\n/,/g;ta"`
sed -i "s@bt-tracker.*@bt-tracker=$list@g" ~/.config/aria2/aria2.conf

#更新tracker
bash ~/.config/aria2/tracker.sh
#更新完需要重启一下aria2.

后台运行可以使用systemd

vim /etc/systemd/system/aria2.service

#添加以下内容
[Unit]
Description=aria2c
After=network.target
[Service]
ExecStart=/usr/bin/aria2c --enable-rpc --rpc-listen-all --conf-path=/root/.config/aria2/aria2.conf
[Install]
WantedBy=multi-user.target

#管理aria2
启动: systemctl start aria2
关闭: systemctl stop aria2
自启: systemctl enable aria2
状态: systemctl status aria2
重启: systemctl restart aria2

4、离线下载,如果在终端里使用:

aria2c https://你需要下载的文件链接

#下载完自动上传,也可以检查一下是否上传成功
rcloe ls aliyun:/

离线下载,浏览器可以使用aria2管理面板,电脑chrome和安卓kiwi就可以使用扩展:

https://chrome.google.com/webstore/detail/aria2-for-chrome/mpkodccbngfoacfalldjimigbofkhgjn

rpc地址:http://你服务ip:6800/jsonrpc

然后网页上看到你想下载的,右键发送到aria2即可,然后就可以自动离线到阿里云盘等等网盘了。

安卓手机也可以直接使用ariang:https://github.com/mayswind/AriaNg/releases

使用via或者chrome浏览器打开,配置也是一样的,只是协议需要修改成websocket协议,否则连不上。

最后视频教程:

油管:https://youtu.be/pwyVzR460Q8

b站:https://www.bilibili.com/video/BV1PL4y1E7jw/

视频号:

留言

* - 必填