客至汲泉烹茶, 抚琴听者知音

使用aria2+ariaNG+onedrive搭建离线下载/在线播放程序

以前都是用一键脚本安装的,但是一键脚本限制条件也挺多,所以想学一下手动安装。另外我用的pyone虽然有离线下载功能,但是体验并不好,经常下不来,所以干脆手动装一个得了,用ariaNG面板下载自动上传,这里记录一下安装过程,所有教程均基于萌鼠大佬

介绍

aria2

aria2 is a lightweight multi-protocol & multi-source command-line download utility. It supports HTTP/HTTPS, FTP, SFTP,BitTorrent and Metalink. aria2 can be manipulated via built-in JSON-RPC and XML-RPC interfaces.(Aria2是一个命令行下轻量级、多协议、多来源的下载工具(支持 HTTP/HTTPS、FTP、BitTorrent、Metalink),内建 XML-RPC 和 JSON-RPC 用户界面。)

官网:https://aria2.github.io/

aria2NG

aria2NG是一个aria2的webUI程序,有友好的界面交互。

官网:http://ariang.mayswind.net/

一键脚本

注:本脚本是Aria2+Aria2Ng+OneIndex,且只适用于Debian 8、9纯净环境,需要有个提前解析到服务器的域名。

wget https://www.moerats.com/usr/shell/Aria2_OneIndex.sh && bash Aria2_OneIndex.sh

按要求输入以下选项:

请输入你的OneIndex域名信息(如:pan.yanshu.live):
请输入你的Aria2密钥:
请输入你OneDrive中的一个文件夹(格式:yanshu,此后所有文件都会上传到该文件夹):

然后输入域名,按提示绑定onedrive账号。

Aria2Ng访问地址:http://IP:8080OneIndex后台地址:https://xx.com/?/admin,默认密码:oneindex

相关目录

OneIndex及域名根目录:/home/wwwroot/xx.com
Aria2Ng根目录:/home/wwwroot/aria2ng
域名证书目录:/home/wwwroot/ssl
Aria2配置文件夹:/root/.aria2
Aria2下载目录:/root/Download

手动安装

安装Aria2

这里用的逗比的脚本,使用命令:

wget -N --no-check-certificate https://raw.githubusercontent.com/ToyoDAdoubiBackup/doubi/master/aria2.sh && chmod +x aria2.sh && bash aria2.sh
#备用地址
wget -N --no-check-certificate https://www.moerats.com/usr/shell/Aria2/aria2.sh && chmod +x aria2.sh && bash aria2.sh

安装完成后,如果我们想修改密码、下载文件位置、端口的话,可以使用命令bash aria2.sh,再选择修改配置即可,这里建议使用该脚本配置自动更新BT-Tracker服务器,对下载BT有加成。

默认下载目录:/usr/local/caddy/www/aria2/Download,可修改为/root/down

安装AriaNg

这一步和安装OneIndex差不多,先添加一个域名,不想用域名的可以在添加域名那里填上IP或者IP:端口,然后将AriaNg程序上传到对应的根目录,可以使用命令:

#这里以添加IP为例
#Debian/Ubuntu系统
apt-get install unzip -y
#CentOS系统
yum install unzip -y

cd /www/wwwroot/11.22.33.44
wget https://www.moerats.com/usr/down/aria-ng-0.2.0.zip && unzip aria-ng-0.2.0.zip

这时候我们就可以使用IP访问AriaNg界面了,或者IP:端口,这取决于你添加域名的时候填的什么了。

安装VPS上传脚本

1、安装脚本

安装curl,用于访问API:

#Ubuntu和Debian系统
apt-get install -y curl

#Centos系统
yum install curl -y

运行命令安装脚本:

wget --no-check-certificate -qO- "https://raw.githubusercontent.com/0oVicero0/On

2、运行账号认证程序

运行命令onedrive -a,将返回的网址复制到浏览器打开,再登陆你的OneDrive for Business账号,登陆成功后复制地址栏中的地址(复制包括localhost的所有链接地址),粘贴到SSH客户端里,敲回车键即可。

如果返回以下字段:It seems like we have a refresh token, so we are ready to go,则表明设置成功。

提示:如果你遇到bash: onedrive: command not found错误,则需要找到/usr/local/etc/OneDrive文件夹,修改onedrive和onedrive-d脚本,在第二行都加上export PATH=/usr/local/bin:$PATH代码,再保存就行了。

配置自动上传

root文件夹下新建脚本文件rcloneupload.sh,并复制下面代码:

#!/bin/bash

GID="$1";
FileNum="$2";
File="$3";
MaxSize="15728640"
RemoteDIR="";  #上传到Onedrive的路径,默认为根目录,如果要上传到指定目录,方法看文章最后面。
LocalDIR="/usr/local/caddy/www/aria2/Download/";  #Aria2下载目录,最后面保留/

if [[ -z $(echo "$FileNum" |grep -o '[0-9]*' |head -n1) ]]; then FileNum='0'; fi
if [[ "$FileNum" -le '0' ]]; then exit 0; fi
if [[ "$#" != '3' ]]; then exit 0; fi

function LoadFile(){
  IFS_BAK=$IFS
  IFS=$'\n'
  if [[ ! -d "$LocalDIR" ]]; then return; fi
  if [[ -e "$File" ]]; then
    if [[ $(dirname "$File") == $(readlink -f $LocalDIR) ]]; then
      ONEDRIVE="onedrive";
    else
      ONEDRIVE="onedrive-d";
    fi
    FileLoad="${File/#$LocalDIR}"
    while true
      do
        if [[ "$FileLoad" == '/' ]]; then return; fi
        echo "$FileLoad" |grep -q '/';
        if [[ "$?" == "0" ]]; then
          FileLoad=$(dirname "$FileLoad");
        else
          break;
        fi;
      done;
    if [[ "$FileLoad" == "$LocalDIR" ]]; then return; fi
    if [[ -n "$RemoteDIR" ]]; then
      Option=" -f $RemoteDIR";
    else
      Option="";
    fi
    EXEC="$(command -v $ONEDRIVE)";
    if [[ -z "$EXEC" ]]; then return; fi
    cd "$LocalDIR";
    if [[ -e "$FileLoad" ]]; then
      ItemSize=$(du -s "$FileLoad" |cut -f1 |grep -o '[0-9]*' |head -n1)
      if [[ -z "$ItemSize" ]]; then return; fi
      if [[ "$ItemSize" -ge "$MaxSize" ]]; then
        echo -ne "\033[33m$File \033[0mtoo large to spik.\n";
        return;
      fi
      eval "${EXEC}${Option}" \'"${FileLoad}"\';
      if [[ $? == '0' ]]; then
        rm -rf "$FileLoad";
      fi
    fi
  fi
  IFS=$IFS_BAK
}
LoadFile;

如果你想上传到指定的文件夹,修改如下:

#上传到Onedrive里的Yanshu目录,参数改为:RemoteDIR="Yanshu"; 
#上传到Onedrive里的Yanshu目录里的movie目录,参数改为:RemoteDIR="Yanshu/movie";

如果你觉得上传速度较慢,可以编辑/usr/local/etc/OneDrive/onedrive.cfg,修改threads线程数,默认2

授权chmod +x rcloneupload.sh,然后再到Aria2配置文件(在/root/.aria2中)中加上一行on-download-complete=/root/rcloneupload.sh即可,后面为脚本的路径。最后输入bash aria2.sh,重启Aria2生效。

安装onedrive列表程序

这类程序也挺多的,比如oneindexolaindexpyone,均提供了详细的安装教程,在此不再赘述。

问题

有些文件上传不了

出现这种情况的话,大概是文件虽然下载完成了,但一直卡在做种阶段,导致参数传不到自动上传脚本,从而文件夹也上传不了。

解决方法1:在配置文件里加入seed-time=0参数(意思是停止做种),再重启Aria2即可。

解决方法2:手动删除aria2NG的任务,它就会自动上传。

添加新评论