二维码
搬瓦工 locvps

确实暂时没有找到我想要的这个脚本。因此就自己diy了一个。
感谢论坛前辈们做出的贡献,特别是@xcy1020 的脚本,我的是基于他的脚本内容改出来的
效果是这样的:
1. 手动对某个种子进行特殊标记。

2. 标记过后不用管它
脚本定时执行,会在执行时将其设置为上传中。上传结束后会保持在结束的标签中

这样你就可以在不影响pt的情况下,随心所欲的上传到gd或者是onedrive上了.
还有个例子就是说你的djj视频,下载时搞个标签,下载完自动上传,其他的视频根本不会上传。最后可以对上传完的全部删掉 
相对于之前的下载完成自动上传的脚本有两个好处:
1. 不是所有下载完成的都上传,你可以指定某些种子上传,其余的可以挂机
2. 下载完成上传那个权限很麻烦,脚本和
rclone没权限无法运行成功的,这个直接定时任务不会有权限问题,轻松搞定。

使用方法:
计划任务,定时1分钟一次执行该sh文件。怎么怎么定时你自己去研究

  1. */1 * * * * bash /home/用户名/data/qb_auto_rclone.sh


使用之前你得要在你的qbittorrent中建立一个种子tag。

内容是:【待上传云端】 到时候脚本运行起来了会自动上传。

之后使用的具体脚本代码如下
/home/用户名/data/qb_auto_rclone.sh:


  1. #!/bin/sh


  2. qb_versiON="4.2.1"

  3. qb_username="用户名"

  4. qb_password="密码"

  5. qb_web_url="http://127.0.0.1:2017"

  6. log_dir="/home/tujidu/data/qbauto"

  7. rclone_dest="BG:" #rclone destination关键字 运行rclone config查看name字段即可

  8. rclone_parallel="32" #rclone上传线程 默认4

  9. from_dc_tag="/Upload" # 上传后的相对根目录,可为空


  10. # 下面的也可以自定义,但是推荐不改动

  11. unfinished_tag="【待上传云端】" # 这个是手动设置某些tag,因为有用才上传

  12. uploading_tag="【正在上传】"

  13. finished_tag="【结束】"

  14. noupload_tag="无效-不上传"


  15. if [ ! -d ${log_dir} ]

  16. then

  17.         mkdir -p ${log_dir}

  18. fi


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


  20. function qb_login(){

  21.         if [ ${version} -gt 404 ]

  22.         then

  23.                 qb_v="1"

  24.                 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}')

  25.                 if [ -n ${cookie} ]

  26.                 then

  27.                         echo "[$(date '+%Y-%m-%d %H:%M:%S')] 登录成功!cookie:${cookie}" >> ${log_dir}/autodel.log


  28.                 else

  29.                         echo "[$(date '+%Y-%m-%d %H:%M:%S')] 登录失败!" >> ${log_dir}/autodel.log

  30.                 fi

  31.         elif [[ ${version} -le 404 && ${version} -ge 320 ]]

  32.         then

  33.                 qb_v="2"

  34.                 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}')

  35.                 if [ -n ${cookie} ]

  36.                 then

  37.                         echo "[$(date '+%Y-%m-%d %H:%M:%S')] 登录成功!cookie:${cookie}" >> ${log_dir}/autodel.log

  38.                 else

  39.                         echo "[$(date '+%Y-%m-%d %H:%M:%S')] 登录失败" >> ${log_dir}/autodel.log

  40.                 fi

  41.         elif [[ ${version} -ge 310 && ${version} -lt 320 ]]

  42.         then

  43.                 qb_v="3"

  44.                 echo "陈年老版本,请及时升级"

  45.                 exit

  46.         else

  47.                 qb_v="0"

  48.                 exit

  49.         fi

  50. }


  51. # 先移除指定tag,后增加自己的tag

  52. function qb_change_hash_tag(){

  53.     file_hash=$1

  54.     fromTag=$2

  55.     toTag=$3

  56.     if [ ${qb_v} == "1" ]

  57.     then # 这里是添加某些tag的方法

  58.                 curl -s -X POST -d "hashes=${file_hash}&tags=${fromTag}" "${qb_web_url}/api/v2/torrents/removeTags" --cookie "${cookie}"

  59.         curl -s -X POST -d "hashes=${file_hash}&tags=${toTag}" "${qb_web_url}/api/v2/torrents/addTags" --cookie "${cookie}"

  60.     elif [ ${qb_v} == "2" ]

  61.     then

  62.         curl -s -X POST -d "hashes=${file_hash}&category=${fromTag}" "${qb_web_url}/command/removeCategories" --cookie ${cookie}

  63.         curl -s -X POST -d "hashes=${file_hash}&category=${toTag}" "${qb_web_url}/command/setCategory" --cookie ${cookie}

  64.     else

  65.         echo "qb_v=${qb_v}"

  66.     fi

  67. }


  68. function rclone_copy(){

  69.     torrent_name=$1

  70.     torrent_hash=$2

  71.     torrent_path=$3


  72.     # tag = 待上传

  73.     # 这里执行上传程序

  74.     if [ -f "${torrent_path}" ]

  75.     then

  76.        echo "[$(date '+%Y-%m-%d %H:%M:%S')] 类型:文件"

  77.        echo "[$(date '+%Y-%m-%d %H:%M:%S')] 类型:文件" >> ${log_dir}/qb.log

  78.        type="file"

  79.     elif [ -d "${torrent_path}" ]

  80.     then

  81.        echo "[$(date '+%Y-%m-%d %H:%M:%S')] 类型:目录"

  82.        echo "[$(date '+%Y-%m-%d %H:%M:%S')] 类型:目录" >> ${log_dir}/qb.log

  83.        type="dir"

  84.     else

  85.        echo "[$(date '+%Y-%m-%d %H:%M:%S')] 未知类型,取消上传"

  86.        echo "[$(date '+%Y-%m-%d %H:%M:%S')] 未知类型,取消上传" >> ${log_dir}/qb.log

  87.        # tag = 不上传

  88.        qb_change_hash_tag ${torrent_hash} ${unfinished_tag} ${noupload_tag}

  89.        return

  90.     fi

  91.     # tag = 上传中

  92.     qb_change_hash_tag ${torrent_hash} ${unfinished_tag} ${uploading_tag}

  93.     # 执行上传

  94.     if [ ${type} == "file" ]

  95.     then # 这里是rclone上传的方法

  96.         rclone_copy_cmd=$(rclone -v copy --transfers ${rclone_parallel} --log-file  ${log_dir}/qbauto_copy.log "${torrent_path}" ${rclone_dest}/${from_dc_tag})

  97.     elif [ ${type} == "dir" ]

  98.     then

  99.                 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}")

  100.     fi


  101.     # tag = 已上传

  102.     qb_change_hash_tag ${torrent_hash} ${uploading_tag} ${finished_tag}

  103. }


  104. function file_lock(){

  105.     $(touch qbup.lock)

  106. }

  107. function can_go_lock(){

  108.     lockStatus=$(ls | grep qbup.lock)

  109.     if [ -z "${lockStatus}" ]

  110.     then

  111.         noLock="1"

  112.         return

  113.     fi

  114.     noLock="0"

  115. }

  116. function file_unlock(){

  117.     $(rm -rf qbup.lock)

  118. }


  119. function doUpload(){

  120.     torrentInfo=$1

  121.     i=$2

  122.     echo $2

  123.     echo ${i}


  124.     torrent_name=$(echo ${torrentInfo} | jq ".[$i] | .name" | sed s/"//g)

  125.     torrent_hash=$(echo ${torrentInfo} | jq ".[$i] | .hash" | sed s/"//g)

  126.     save_path=$(echo ${torrentInfo} | jq ".[$i] | .save_path" | sed s/"//g)

  127.     torrent_path="${save_path}${torrent_name}" # 这里就是他的本地实际路径,尝试将这里上传上去


  128.     can_go_lock

  129.     if [[ ${noLock} == "1" ]] # 厕所门能开

  130.     then

  131.         file_lock # 锁上厕所门

  132.         echo '执行上传没事的~~~';

  133.         echo ${torrent_name}

  134.         echo ${torrent_hash}

  135.         echo ${torrent_path}

  136.         rclone_copy ${torrent_name} ${torrent_hash} ${torrent_path}

  137.     else

  138.         echo '已有程序在上传,退出'

  139.         return # 打不开门,换个时间来

  140.     fi

  141.     file_unlock # 打开厕所门,出去

  142. }


  143. # 每次只查询一条数据,!!上传一条数据!!

  144. function qb_get_status(){

  145.         qb_login

  146.         if [ ${qb_v} == "1" ]

  147.         then

  148.                 completed_torrents_num=$(curl -s "${qb_web_url}/api/v2/torrents/info?filter=completed" --cookie "${cookie}" | jq '.[] | length' | wc -l)

  149.                 echo "任务数:".${completed_torrents_num}

  150.                 for((i=0;i<${completed_torrents_num};i++));

  151.                 do

  152.                         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}")

  153.                         if [ -z "${curtag}" ]

  154.                         then

  155.                                 curtag="null"

  156.                         fi

  157.                         if [ ${curtag} == "${unfinished_tag}" ]

  158.                         then

  159.                             torrentInfo=$(curl -s "${qb_web_url}/api/v2/torrents/info?filter=completed" --cookie "${cookie}")


  160.                                 doUpload "${torrentInfo}" ${i}

  161.                 # 每次只上传一个数据,否则的话,可能会导致多线程的争用问题

  162.                 return

  163.                         fi

  164.                 done

  165.         elif [ ${qb_v} == "2" ]

  166.         then

  167.                 completed_torrents_num=$(curl -s "${qb_web_url}/query/torrents?filter=completed" --cookie "${cookie}" | jq '.[] | length' | wc -l)

  168.                 for((i=0;i<${completed_torrents_num};i++));

  169.                 do

  170.                         curtag=$(curl -s "${qb_web_url}/query/torrents?filter=completed" --cookie "${cookie}" | jq ".[$i] | .category" | sed s/"//g)

  171.                         if [ -z "${curtag}" ]

  172.                         then

  173.                                 curtag="null"

  174.                         fi

  175.                         if [ ${curtag} == "${unfinished_tag}" ]

  176.                         then

  177.                                 torrentInfo=$(curl -s "${qb_web_url}/query/torrents?filter=completed" --cookie "${cookie}")


  178.                 doUpload "${torrentInfo}" ${i}

  179.                 # 每次只上传一个数据,否则的话,可能会导致多线程的争用问题

  180.                 return

  181.                         fi

  182.                 done

  183.                 echo "啥事都不干";

  184.         else

  185.                 echo "获取错误"

  186.                 echo "qb_v=${qb_v}"

  187.         fi

  188. }


  189. qb_get_status



最后附图一张,表明成功了 

--------
如果过程中出现了你的奇怪操作未上传完就重启电脑或者kill rclone,可能脚本会挂掉什么的,此时需要删除同目录下的一个.lock文件。


locvps
评论专区
  • 昵 称必填
  • 邮 箱必填
  • 网 址选填
◎已有 0 人评论
BudgetVM
作者介绍
总干事

总干事

总干事作为本站编辑,主要负责VPS优惠、域名优惠和站长百科三个栏目。
80vps henghost
budgetvm sugarhosts
二维码

分享:

支付宝

微信