跳至主要內容
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?

4563博客

全新的繁體中文 WordPress 網站
  • 首頁
  • qbit自动rclone上传脚本- with tag 打标签的自动上传
未分類
1 2 月 2020

qbit自动rclone上传脚本- with tag 打标签的自动上传

千牛 大佬有话说 :

qbit自动rclone上传脚本- with tag 打标签的自动上传

本帖最后由 千牛 于 2020-2-1 00:35 编辑

翻了下论坛,确实暂时没有找到我想要的这个脚本。因此就自己diy了一个
感谢论坛前辈们做出的贡献,特别是@xcy1020 的脚本,我的是基于他的脚本内容改出来的
效果是这样的:
1. 手动对某个种子进行特殊标记。
https://img.tujidu.com/image/5e34507b7fe5c
2. 标记过后不用管它
脚本定时执行,会在执行时将其设置为上传中。上传结束后会保持在结束的标签中
https://img.tujidu.com/image/5e345569e6a9c
这样你就可以在不影响pt的情况下,随心所欲的上传到gd或者是onedrive上了

使用方法:
计划任务,定时1-3-5分钟随意时间一次执行该sh文件。怎么怎么定时你自己去研究
*/1 * * * * bash /home/用户名/data/qb_auto_rclone.sh
使用之前你得要在你的qbittorrent中建立一个种子tag
https://img.tujidu.com/image/5e344f969945a
内容是:【待上传云端】
之后使用的具体脚本代码如下
/home/用户名/data/qb_auto_rclone.sh:

#!/bin/sh

qb_version="4.2.1"
qb_username="用户名"
qb_password="密码"
qb_web_url="http://127.0.0.1:2017"
log_dir="/home/tujidu/data/qbauto"
rclone_dest="BG:" #rclone destination关键字 运行rclone config查看name字段即可
rclone_parallel="32" #rclone上传线程 默认4
from_dc_tag="/Upload" # 上传后的相对根目录,可为空

# 下面的也可以自定义,但是推荐不改动
unfinished_tag="【待上传云端】" # 这个是手动设置某些tag,因为有用才上传
uploading_tag="【正在上传】"
finished_tag="【结束】"
noupload_tag="无效-不上传"

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

version=$(echo ${qb_version} | grep -P -o "(.){2}" | 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
}

# 先移除指定tag,后增加自己的tag
function qb_change_hash_tag(){
    file_hash=$1
    fromTag=$2
    toTag=$3
    if [ ${qb_v} == "1" ]
    then # 这里是添加某些tag的方法
                curl -s -X POST -d "hashes=${file_hash}&tags=${fromTag}" "${qb_web_url}/api/v2/torrents/removeTags" –cookie "${cookie}"
      curl -s -X POST -d "hashes=${file_hash}&tags=${toTag}" "${qb_web_url}/api/v2/torrents/addTags" –cookie "${cookie}"
    elif [ ${qb_v} == "2" ]
    then
      curl -s -X POST -d "hashes=${file_hash}&category=${fromTag}" "${qb_web_url}/command/removeCategories" –cookie ${cookie}
      curl -s -X POST -d "hashes=${file_hash}&category=${toTag}" "${qb_web_url}/command/setCategory" –cookie ${cookie}
    else
      echo "qb_v=${qb_v}"
    fi
}

function rclone_copy(){
    torrent_name=$1
    torrent_hash=$2
    torrent_path=$3

    # tag = 待上传
    # 这里执行上传程序
    if [ -f "${torrent_path}" ]
    then
       echo "[$(date ‘+%Y-%m-%d %H:%M:%S’)] 类型:文件"
       echo "[$(date ‘+%Y-%m-%d %H:%M:%S’)] 类型:文件" >> ${log_dir}/qb.log
       type="file"
    elif [ -d "${torrent_path}" ]
    then
       echo "[$(date ‘+%Y-%m-%d %H:%M:%S’)] 类型:目录"
       echo "[$(date ‘+%Y-%m-%d %H:%M:%S’)] 类型:目录" >> ${log_dir}/qb.log
       type="dir"
    else
       echo "[$(date ‘+%Y-%m-%d %H:%M:%S’)] 未知类型,取消上传"
       echo "[$(date ‘+%Y-%m-%d %H:%M:%S’)] 未知类型,取消上传" >> ${log_dir}/qb.log
       # tag = 不上传
       qb_change_hash_tag ${torrent_hash} ${unfinished_tag} ${noupload_tag}
       return
    fi
    # tag = 上传中
    qb_change_hash_tag ${torrent_hash} ${unfinished_tag} ${uploading_tag}
    # 执行上传
    if [ ${type} == "file" ]
    then # 这里是rclone上传的方法
      rclone_copy_cmd=$(rclone -v copy –transfers ${rclone_parallel} –log-file${log_dir}/qbauto_copy.log "${torrent_path}" ${rclone_dest}/${from_dc_tag})
    elif [ ${type} == "dir" ]
    then
                rclone_copy_cmd=$(rclone -v copy –transfers ${rclone_parallel} –log-file ${log_dir}/qbauto_copy.log "${torrent_path}"/ ${rclone_dest}/${from_dc_tag}/"${torrent_name}")
    fi

    # tag = 已上传
    qb_change_hash_tag ${torrent_hash} ${uploading_tag} ${finished_tag}
}

function file_lock(){
    $(touch qbup.lock)
}
function can_go_lock(){
    lockStatus=$(ls | grep qbup.lock)
    if [ -z "${lockStatus}" ]
    then
      noLock="1"
      return
    fi
    noLock="0"
}
function file_unlock(){
    $(rm -rf qbup.lock)
}

function doUpload(){
    torrentInfo=$1
    i=$2
    echo $2
    echo ${i}

    torrent_name=$(echo ${torrentInfo} | jq ".[$i] | .name" | sed s/"//g)
    torrent_hash=$(echo ${torrentInfo} | jq ".[$i] | .hash" | sed s/"//g)
    save_path=$(echo ${torrentInfo} | jq ".[$i] | .save_path" | sed s/"//g)
    torrent_path="${save_path}${torrent_name}" # 这里就是他的本地实际路径,尝试将这里上传上去

    can_go_lock
    if [[ ${noLock} == "1" ]] # 厕所门能开
    then
      file_lock # 锁上厕所门
      echo ‘执行上传没事的~~~’;
      echo ${torrent_name}
      echo ${torrent_hash}
      echo ${torrent_path}
      rclone_copy ${torrent_name} ${torrent_hash} ${torrent_path}
    else
      echo ‘已有程序在上传,退出’
      return # 打不开门,换个时间来
    fi
    file_unlock # 打开厕所门,出去
}

# 每次只查询一条数据,!!上传一条数据!!
function qb_get_status(){
        qb_login
        if [ ${qb_v} == "1" ]
        then
                completed_torrents_num=$(curl -s "${qb_web_url}/api/v2/torrents/info?filter=completed" –cookie "${cookie}" | jq ‘.[] | length’ | wc -l)
                echo "任务数:".${completed_torrents_num}
                for((i=0;i<${completed_torrents_num};i++));
                do
                        curtag=$(curl -s "${qb_web_url}/api/v2/torrents/info?filter=completed" –cookie "${cookie}" | jq ".[$i] | .tags" | sed s/"//g | grep -P -o "${unfinished_tag}")
                        if [ -z "${curtag}" ]
                        then
                                curtag="null"
                        fi
                        if [ ${curtag} == "${unfinished_tag}" ]
                        then
                          torrentInfo=$(curl -s "${qb_web_url}/api/v2/torrents/info?filter=completed" –cookie "${cookie}")

                                doUpload "${torrentInfo}" ${i}
                # 每次只上传一个数据,否则的话,可能会导致多线程的争用问题
                return
                        fi
                done
        elif [ ${qb_v} == "2" ]
        then
                completed_torrents_num=$(curl -s "${qb_web_url}/query/torrents?filter=completed" –cookie "${cookie}" | jq ‘.[] | length’ | wc -l)
                for((i=0;i<${completed_torrents_num};i++));
                do
                        curtag=$(curl -s "${qb_web_url}/query/torrents?filter=completed" –cookie "${cookie}" | jq ".[$i] | .category" | sed s/"//g)
                        if [ -z "${curtag}" ]
                        then
                                curtag="null"
                        fi
                        if [ ${curtag} == "${unfinished_tag}" ]
                        then
                                torrentInfo=$(curl -s "${qb_web_url}/query/torrents?filter=completed" –cookie "${cookie}")

                doUpload "${torrentInfo}" ${i}
                # 每次只上传一个数据,否则的话,可能会导致多线程的争用问题
                return
                        fi
                done
                echo "啥事都不干";
        else
                echo "获取错误"
                echo "qb_v=${qb_v}"
        fi
}

qb_get_status

最后附图一张,表明成功了
https://img.tujidu.com/image/5e34572f73ed9

Reves 大佬有话说 :

我搞了个文件夹,归档上传用,再用crontab写个命令每天凌晨3点rclone上传该文件夹的全部文件

千牛 大佬有话说 :

Reves 大佬有话说 : 2020-2-1 00:33
我搞了个文件夹,归档上传用,再用crontab写个命令每天凌晨3点rclone上传该文件夹的全部文件 …

yc022t 有时候就是想要看个电影什么的听蛋疼的

riwsh 大佬有话说 :

马克留名

wenwei7532 大佬有话说 :

感谢分享

前排

紫薯布丁

文章導覽

上一篇文章
下一篇文章

AD

其他操作

  • 登入
  • 訂閱網站內容的資訊提供
  • 訂閱留言的資訊提供
  • WordPress.org 台灣繁體中文

51la

4563博客

全新的繁體中文 WordPress 網站
返回頂端
本站採用 WordPress 建置 | 佈景主題採用 GretaThemes 所設計的 Memory
4563博客
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?
在這裡新增小工具