qBittorrent + Rclone 自动上传脚本

2020年05月12日

载自hostloc社区,ID:xcy1020
通过添加标签或者分类,再添加定时任务,可以指定种子分享率达到期望值再删除数据,避免吸血请自行安装jq

确保两个脚本的auto_del_flag变量一致,否则没办法删除分享率达标的种子只吸血的同学只需要将qu_auto.sh的leeching_mode设为true即可需要控制分享率的需要两个脚本并添加监控任务

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
*/1 * * * * bash /root/ratio_mon.sh
*/1 * * * * bash /root/ratio_mon.sh
*/1 * * * * bash /root/ratio_mon.sh

 

支持qBittorrent v3.2.0+ 不支持v3.1.x
实测v4.2.0Beta1功能可用 其他版本未测

使用方法:qB WEB UI 勾选“Torrent 完成时运行外部程序” 填上

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
bash /root/qb_auto.sh "%N" "%F" "%R" "%D" "%C" "%Z" "%I"
bash /root/qb_auto.sh "%N" "%F" "%R" "%D" "%C" "%Z" "%I"
bash /root/qb_auto.sh  "%N" "%F" "%R" "%D" "%C" "%Z" "%I"

 

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
chmod +x qb_auto.sh
chmod +x qb_auto.sh
chmod +x qb_auto.sh

 
qb_auto.sh内容

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
#!/bin/sh
torrent_name=$1
content_dir=$2
root_dir=$3
save_dir=$4
files_num=$5
torrent_size=$6
file_hash=$7
qb_version="4.2.0" #如4.0.4、4.1.9.1、4.2.0等,不支持3.1.X
qb_username="hostloc" #qb用户名
qb_password="hostloc.com" #qb密码
qb_web_url="https://hostloc.com" #QB web路径,可以填写本地https://localhost:8080
leeching_mode="true" #吸血模式 设为true 上传完后自动删除种子及数据 否则不删除,继续做种
log_dir="/root/qbauto" #日志目录
rclone_dest="gdrive" #rclone destination关键字 运行rclone config查看name字段即可
rclone_parallel="32" #rclone上传线程 默认4
auto_del_flag="rclone"#添加标签或者分类来标识已上传的种子 v4.0.4+版本添加标签“rclone”,低版本通过添加分类“rclone”标识
if [ ! -d ${log_dir} ]
then
mkdir -p ${log_dir}
fi
version=$(echo $qb_version | grep -P -o "([0-9]\.){2}[0-9]" | sed s/\\.//g)
function qb_login(){
if [ ${version} -gt 404 ]
then
qb_v="1"
cookie=$(curl -i --header "Referer: ${qb_web_url}" --data "username=${qb_username}&password=${qb_password}" "${qb_web_url}/api/v2/auth/login" | grep -P -o 'SID=\S{32}')
if [ -n ${cookie} ]
then
echo "[$(date '+%Y-%m-%d %H:%M:%S')] 登录成功!cookie:${cookie}" >> ${log_dir}/autodel.log
else
echo "[$(date '+%Y-%m-%d %H:%M:%S')] 登录失败!" >> ${log_dir}/autodel.log
fi
elif [[ ${version} -le 404 && ${version} -ge 320 ]]
then
qb_v="2"
cookie=$(curl -i --header "Referer: ${qb_web_url}" --data "username=${qb_username}&password=${qb_password}" "${qb_web_url}/login" | grep -P -o 'SID=\S{32}')
if [ -n ${cookie} ]
then
echo "[$(date '+%Y-%m-%d %H:%M:%S')] 登录成功!cookie:${cookie}" >> ${log_dir}/autodel.log
else
echo "[$(date '+%Y-%m-%d %H:%M:%S')] 登录失败" >> ${log_dir}/autodel.log
fi
elif [[ ${version} -ge 310 && ${version} -lt 320 ]]
then
qb_v="3"
echo "陈年老版本,请及时升级"
exit
else
qb_v="0"
exit
fi
}
function qb_del(){
if [ ${leeching_mode} == "true" ]
then
if [ ${qb_v} == "1" ]
then
curl "${qb_web_url}/api/v2/torrents/delete?hashes=${file_hash}&deleteFiles=true" --cookie ${cookie}
echo "[$(date '+%Y-%m-%d %H:%M:%S')] 删除成功!种子名称:${torrent_name}" >> ${log_dir}/qb.log
elif [ ${qb_v} == "2" ]
then
curl -X POST -d "hashes=${file_hash}" "${qb_web_url}/command/deletePerm" --cookie ${cookie}
else
echo "[$(date '+%Y-%m-%d %H:%M:%S')] 删除成功!种子文件:${torrent_name}" >> ${log_dir}/qb.log
echo "qb_v=${qb_v}" >> ${log_dir}/qb.log
fi
else
echo "[$(date '+%Y-%m-%d %H:%M:%S')] 不自动删除已上传种子" >> ${log_dir}/qb.log
fi
}
function rclone_copy(){
if [ ${type} == "file" ]
then
rclone_copy_cmd=$(rclone -v copy --transfers ${rclone_parallel} --log-file ${log_dir}/qbauto_copy.log "${content_dir}" ${rclone_dest}:qbauto/)
elif [ ${type} == "dir" ]
then
rclone_copy_cmd=$(rclone -v copy --transfers ${rclone_parallel} --log-file ${log_dir}/qbauto_copy.log "${content_dir}"/ ${rclone_dest}:qbauto/"${torrent_name}")
fi
}
function qb_add_auto_del_tags(){
if [ ${qb_v} == "1" ]
then
curl -X POST -d "hashes=${file_hash}&tags=${auto_del_flag}" "${qb_web_url}/api/v2/torrents/addTags" --cookie "${cookie}"
elif [ ${qb_v} == "2" ]
then
curl -X POST -d "hashes=${file_hash}&category=${auto_del_flag}" "${qb_web_url}/command/setCategory" --cookie ${cookie}
else
echo "qb_v=${qb_v}" >> ${log_dir}/qb.log
fi
}
if [ -f "${content_dir}" ]
then
echo "[$(date '+%Y-%m-%d %H:%M:%S')] 类型:文件" >> ${log_dir}/qb.log
type="file"
rclone_copy
qb_login
qb_add_auto_del_tags
qb_del
elif [ -d "${content_dir}" ]
then
echo "[$(date '+%Y-%m-%d %H:%M:%S')] 类型:目录" >> ${log_dir}/qb.log
type="dir"
rclone_copy
qb_login
qb_add_auto_del_tags
qb_del
else
echo "[$(date '+%Y-%m-%d %H:%M:%S')] 未知类型,取消上传" >> ${log_dir}/qb.log
fi
echo "种子名称:${torrent_name}" >> ${log_dir}/qb.log
echo "内容路径:${content_dir}" >> ${log_dir}/qb.log
echo "根目录:${root_dir}" >> ${log_dir}/qb.log
echo "保存路径:${save_dir}" >> ${log_dir}/qb.log
echo "文件数:${files_num}" >> ${log_dir}/qb.log
echo "文件大小:${torrent_size}Bytes" >> ${log_dir}/qb.log
echo "HASH:${file_hash}" >> ${log_dir}/qb.log
echo "Cookie:${cookie}" >> ${log_dir}/qb.log
echo -e "-------------------------------------------------------------\n" >> ${log_dir}/qb.log
#!/bin/sh torrent_name=$1 content_dir=$2 root_dir=$3 save_dir=$4 files_num=$5 torrent_size=$6 file_hash=$7 qb_version="4.2.0" #如4.0.4、4.1.9.1、4.2.0等,不支持3.1.X qb_username="hostloc" #qb用户名 qb_password="hostloc.com" #qb密码 qb_web_url="https://hostloc.com" #QB web路径,可以填写本地https://localhost:8080 leeching_mode="true" #吸血模式 设为true 上传完后自动删除种子及数据 否则不删除,继续做种 log_dir="/root/qbauto" #日志目录 rclone_dest="gdrive" #rclone destination关键字 运行rclone config查看name字段即可 rclone_parallel="32" #rclone上传线程 默认4 auto_del_flag="rclone"#添加标签或者分类来标识已上传的种子 v4.0.4+版本添加标签“rclone”,低版本通过添加分类“rclone”标识 if [ ! -d ${log_dir} ] then mkdir -p ${log_dir} fi version=$(echo $qb_version | grep -P -o "([0-9]\.){2}[0-9]" | sed s/\\.//g) function qb_login(){ if [ ${version} -gt 404 ] then qb_v="1" cookie=$(curl -i --header "Referer: ${qb_web_url}" --data "username=${qb_username}&password=${qb_password}" "${qb_web_url}/api/v2/auth/login" | grep -P -o 'SID=\S{32}') if [ -n ${cookie} ] then echo "[$(date '+%Y-%m-%d %H:%M:%S')] 登录成功!cookie:${cookie}" >> ${log_dir}/autodel.log else echo "[$(date '+%Y-%m-%d %H:%M:%S')] 登录失败!" >> ${log_dir}/autodel.log fi elif [[ ${version} -le 404 && ${version} -ge 320 ]] then qb_v="2" cookie=$(curl -i --header "Referer: ${qb_web_url}" --data "username=${qb_username}&password=${qb_password}" "${qb_web_url}/login" | grep -P -o 'SID=\S{32}') if [ -n ${cookie} ] then echo "[$(date '+%Y-%m-%d %H:%M:%S')] 登录成功!cookie:${cookie}" >> ${log_dir}/autodel.log else echo "[$(date '+%Y-%m-%d %H:%M:%S')] 登录失败" >> ${log_dir}/autodel.log fi elif [[ ${version} -ge 310 && ${version} -lt 320 ]] then qb_v="3" echo "陈年老版本,请及时升级" exit else qb_v="0" exit fi } function qb_del(){ if [ ${leeching_mode} == "true" ] then if [ ${qb_v} == "1" ] then curl "${qb_web_url}/api/v2/torrents/delete?hashes=${file_hash}&deleteFiles=true" --cookie ${cookie} echo "[$(date '+%Y-%m-%d %H:%M:%S')] 删除成功!种子名称:${torrent_name}" >> ${log_dir}/qb.log elif [ ${qb_v} == "2" ] then curl -X POST -d "hashes=${file_hash}" "${qb_web_url}/command/deletePerm" --cookie ${cookie} else echo "[$(date '+%Y-%m-%d %H:%M:%S')] 删除成功!种子文件:${torrent_name}" >> ${log_dir}/qb.log echo "qb_v=${qb_v}" >> ${log_dir}/qb.log fi else echo "[$(date '+%Y-%m-%d %H:%M:%S')] 不自动删除已上传种子" >> ${log_dir}/qb.log fi } function rclone_copy(){ if [ ${type} == "file" ] then rclone_copy_cmd=$(rclone -v copy --transfers ${rclone_parallel} --log-file ${log_dir}/qbauto_copy.log "${content_dir}" ${rclone_dest}:qbauto/) elif [ ${type} == "dir" ] then rclone_copy_cmd=$(rclone -v copy --transfers ${rclone_parallel} --log-file ${log_dir}/qbauto_copy.log "${content_dir}"/ ${rclone_dest}:qbauto/"${torrent_name}") fi } function qb_add_auto_del_tags(){ if [ ${qb_v} == "1" ] then curl -X POST -d "hashes=${file_hash}&tags=${auto_del_flag}" "${qb_web_url}/api/v2/torrents/addTags" --cookie "${cookie}" elif [ ${qb_v} == "2" ] then curl -X POST -d "hashes=${file_hash}&category=${auto_del_flag}" "${qb_web_url}/command/setCategory" --cookie ${cookie} else echo "qb_v=${qb_v}" >> ${log_dir}/qb.log fi } if [ -f "${content_dir}" ] then echo "[$(date '+%Y-%m-%d %H:%M:%S')] 类型:文件" >> ${log_dir}/qb.log type="file" rclone_copy qb_login qb_add_auto_del_tags qb_del elif [ -d "${content_dir}" ] then echo "[$(date '+%Y-%m-%d %H:%M:%S')] 类型:目录" >> ${log_dir}/qb.log type="dir" rclone_copy qb_login qb_add_auto_del_tags qb_del else echo "[$(date '+%Y-%m-%d %H:%M:%S')] 未知类型,取消上传" >> ${log_dir}/qb.log fi echo "种子名称:${torrent_name}" >> ${log_dir}/qb.log echo "内容路径:${content_dir}" >> ${log_dir}/qb.log echo "根目录:${root_dir}" >> ${log_dir}/qb.log echo "保存路径:${save_dir}" >> ${log_dir}/qb.log echo "文件数:${files_num}" >> ${log_dir}/qb.log echo "文件大小:${torrent_size}Bytes" >> ${log_dir}/qb.log echo "HASH:${file_hash}" >> ${log_dir}/qb.log echo "Cookie:${cookie}" >> ${log_dir}/qb.log echo -e "-------------------------------------------------------------\n" >> ${log_dir}/qb.log
#!/bin/sh
torrent_name=$1
content_dir=$2
root_dir=$3
save_dir=$4
files_num=$5
torrent_size=$6
file_hash=$7

qb_version="4.2.0" #如4.0.4、4.1.9.1、4.2.0等,不支持3.1.X
qb_username="hostloc" #qb用户名
qb_password="hostloc.com" #qb密码
qb_web_url="https://hostloc.com" #QB web路径,可以填写本地https://localhost:8080
leeching_mode="true" #吸血模式 设为true 上传完后自动删除种子及数据 否则不删除,继续做种
log_dir="/root/qbauto" #日志目录
rclone_dest="gdrive" #rclone destination关键字 运行rclone config查看name字段即可
rclone_parallel="32" #rclone上传线程 默认4
auto_del_flag="rclone"#添加标签或者分类来标识已上传的种子 v4.0.4+版本添加标签“rclone”,低版本通过添加分类“rclone”标识

if [ ! -d ${log_dir} ]
then
        mkdir -p ${log_dir}
fi

version=$(echo $qb_version | grep -P -o "([0-9]\.){2}[0-9]" | sed s/\\.//g)

function qb_login(){
        if [ ${version} -gt 404 ]
        then
                qb_v="1"
                cookie=$(curl -i --header "Referer: ${qb_web_url}" --data "username=${qb_username}&password=${qb_password}" "${qb_web_url}/api/v2/auth/login" | grep -P -o 'SID=\S{32}')
                if [ -n ${cookie} ]
                then
                        echo "[$(date '+%Y-%m-%d %H:%M:%S')] 登录成功!cookie:${cookie}" >> ${log_dir}/autodel.log

                else
                        echo "[$(date '+%Y-%m-%d %H:%M:%S')] 登录失败!" >> ${log_dir}/autodel.log
                fi
        elif [[ ${version} -le 404 && ${version} -ge 320 ]]
        then
                qb_v="2"
                cookie=$(curl -i --header "Referer: ${qb_web_url}" --data "username=${qb_username}&password=${qb_password}" "${qb_web_url}/login" | grep -P -o 'SID=\S{32}')
                if [ -n ${cookie} ]
                then
                        echo "[$(date '+%Y-%m-%d %H:%M:%S')] 登录成功!cookie:${cookie}" >> ${log_dir}/autodel.log
                else
                        echo "[$(date '+%Y-%m-%d %H:%M:%S')] 登录失败" >> ${log_dir}/autodel.log
                fi
        elif [[ ${version} -ge 310 && ${version} -lt 320 ]]
        then
                qb_v="3"
                echo "陈年老版本,请及时升级"
                exit
        else
                qb_v="0"
                exit
        fi
}

function qb_del(){
        if [ ${leeching_mode} == "true" ]
        then
                if [ ${qb_v} == "1" ]
                then
                        curl "${qb_web_url}/api/v2/torrents/delete?hashes=${file_hash}&deleteFiles=true" --cookie ${cookie}
                        echo "[$(date '+%Y-%m-%d %H:%M:%S')] 删除成功!种子名称:${torrent_name}" >> ${log_dir}/qb.log
                elif [ ${qb_v} == "2" ]
                then
                        curl -X POST -d "hashes=${file_hash}" "${qb_web_url}/command/deletePerm" --cookie ${cookie}
                else
                        echo "[$(date '+%Y-%m-%d %H:%M:%S')] 删除成功!种子文件:${torrent_name}" >> ${log_dir}/qb.log
                        echo "qb_v=${qb_v}" >> ${log_dir}/qb.log
                fi
        else
                echo "[$(date '+%Y-%m-%d %H:%M:%S')] 不自动删除已上传种子" >> ${log_dir}/qb.log
        fi
}

function rclone_copy(){
        if [ ${type} == "file" ]
        then
                rclone_copy_cmd=$(rclone -v copy --transfers ${rclone_parallel} --log-file  ${log_dir}/qbauto_copy.log "${content_dir}" ${rclone_dest}:qbauto/)
        elif [ ${type} == "dir" ]
        then
                rclone_copy_cmd=$(rclone -v copy --transfers ${rclone_parallel} --log-file ${log_dir}/qbauto_copy.log "${content_dir}"/ ${rclone_dest}:qbauto/"${torrent_name}")
        fi
}

function qb_add_auto_del_tags(){
        if [ ${qb_v} == "1" ]
        then
                curl -X POST -d "hashes=${file_hash}&tags=${auto_del_flag}" "${qb_web_url}/api/v2/torrents/addTags" --cookie "${cookie}"
        elif [ ${qb_v} == "2" ]
        then
                curl -X POST -d "hashes=${file_hash}&category=${auto_del_flag}" "${qb_web_url}/command/setCategory" --cookie ${cookie}
        else
                echo "qb_v=${qb_v}" >> ${log_dir}/qb.log
        fi
}

if [ -f "${content_dir}" ]
then
   echo "[$(date '+%Y-%m-%d %H:%M:%S')] 类型:文件" >> ${log_dir}/qb.log
   type="file"
   rclone_copy
   qb_login
   qb_add_auto_del_tags
   qb_del
elif [ -d "${content_dir}" ]
then
   echo "[$(date '+%Y-%m-%d %H:%M:%S')] 类型:目录" >> ${log_dir}/qb.log
   type="dir"
   rclone_copy
   qb_login
   qb_add_auto_del_tags
   qb_del
else
   echo "[$(date '+%Y-%m-%d %H:%M:%S')] 未知类型,取消上传" >> ${log_dir}/qb.log
fi

echo "种子名称:${torrent_name}" >> ${log_dir}/qb.log
echo "内容路径:${content_dir}" >> ${log_dir}/qb.log
echo "根目录:${root_dir}" >> ${log_dir}/qb.log
echo "保存路径:${save_dir}" >> ${log_dir}/qb.log
echo "文件数:${files_num}" >> ${log_dir}/qb.log
echo "文件大小:${torrent_size}Bytes" >> ${log_dir}/qb.log
echo "HASH:${file_hash}" >> ${log_dir}/qb.log
echo "Cookie:${cookie}" >> ${log_dir}/qb.log
echo -e "-------------------------------------------------------------\n" >> ${log_dir}/qb.log

 

简单版本,只管上传:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
/home/qbtuser/up.sh "%F" "%N"
/home/qbtuser/up.sh "%F" "%N"
/home/qbtuser/up.sh "%F" "%N"

 

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
#!/bin/bash
file=$1
if [ -d "$file" ];then
rclone copy "$1" gd:/Downloads/"$2"
elif [ -f "$file" ]; then
rclone copy "$1" gd:/Downloads/
fi
#!/bin/bash file=$1 if [ -d "$file" ];then rclone copy "$1" gd:/Downloads/"$2" elif [ -f "$file" ]; then rclone copy "$1" gd:/Downloads/ fi
#!/bin/bash
file=$1
if [ -d "$file" ];then
rclone copy "$1" gd:/Downloads/"$2"
elif [ -f "$file" ]; then
rclone copy "$1" gd:/Downloads/
fi

 

脚本下载:链接:https://pan.baidu.com/s/1CWZMSxfG-yrutFnpnGdeFA 提取码:trmk


sicnature ---------------------------------------------------------------------
I P 地 址: 3.17.62.86
区 域 位 置: 美国俄亥俄
系 统 信 息: 美国
Original content, please indicate the source:
同福客栈论坛 | 蟒蛇科普海南乡情论坛 | JiaYu Blog
sicnature ---------------------------------------------------------------------
Welcome to reprint. Please indicate the source https://myzhenai.com/post/3329.html

没有评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注