a380206367 发表于 2023-6-29 13:00

群晖 Download Station BT 种子下载 自动添加trackerlist

本帖最后由 a380206367 于 2023-6-29 21:24 编辑

群晖的DownloadStation(简称DS)不支持订阅trackerlist的功能,trackerlist可以让ds去连接更多的种子服务器,让下载速度加快很多;

虽然ds本身不支持订阅trackerlist,但是可以手动向每个下载的任务添加tracker列表,如下图
https://blog.js-css.com/wp-content/uploads/2023/06/image-48-1024x508.png

trackerlist可以从github上公开的仓库获取,也可以找其他的tracker列表,
比较有名的trackerlist是这个仓库 https://ngosang.github.io/trackerslist/, 该仓库会定时更新最新的trackerlist。

我在解决群晖套件另外一个问题的时候,无意间发现了一个万能cli工具 synowebapi 可以操作群晖的任意功能,所以基于该工具
写了一个脚本,该脚本可以向下载中的bt任务自动添加tracker,只需要把这个脚本配置到群晖计划任务中,该脚本就可以全自动的检测下载任务,并自动添加tracker

注意:脚本是基于 DSM 7.2 版本的,6x版本没有验证过,如果有需要的话可以回帖,我做个兼容

#!/bin/bash

DISABLE_COLOR=false

BLACK="\e[30m"
RED="\e[31m"
GREEN="\e[32m"
YELLOW="\e[33m"
BLUE="\e[34m"
MAGENTA="\e[35m"
CYAN="\e[36m"
LIGHT_GRAY="\e[37m"
DARK_GRAY="\e[90m"
LIGHT_RED="\e[91m"
LIGHT_GREEN="\e[92m"
LIGHT_YELLOW="\e[93m"
LIGHT_BLUE="\e[94m"
LIGHT_MAGENTA="\e[95m"
LIGHT_CYAN="\e[96m"
WHITE="\e[97m"
END="\e[0m"

if [ $DISABLE_COLOR == true ]; then
BLACK=""
RED=""
GREEN=""
YELLOW=""
BLUE=""
MAGENTA=""
CYAN=""
LIGHT_GRAY=""
DARK_GRAY=""
LIGHT_RED=""
LIGHT_GREEN=""
LIGHT_YELLOW=""
LIGHT_BLUE=""
LIGHT_MAGENTA=""
LIGHT_CYAN=""
WHITE=""
END=""
fi


# 群晖DS 任务状态定义
TASK_STATUS_WAITING=1
TASK_STATUS_DOWNLOADING=2
TASK_STATUS_PAUSED=3
TASK_STATUS_FINISHING=4
TASK_STATUS_FINISHED=5
TASK_STATUS_HASH_CHECKING=6
TASK_STATUS_SEEDING=7
TASK_STATUS_FILEHOSTING_WAITING=8
TASK_STATUS_EXTRACTING=9
TASK_STATUS_ERROR=10
TASK_STATUS_BROKEN_LINK=11
TASK_STATUS_DESTINATION_NOT_EXIST=12
TASK_STATUS_DESTINATION_DENIED=13
TASK_STATUS_DISK_FULL=14
TASK_STATUS_QUOTA_REACHED=15
TASK_STATUS_TIMEOUT=16
TASK_STATUS_EXCEED_MAX_FILE_SYSTEM_SIZE=17
TASK_STATUS_EXCEED_MAX_DESTINATION_SIZE=18
TASK_STATUS_EXCEED_MAX_TEMP_SIZE=19
TASK_STATUS_ENCRYPTED_NAME_TOO_LONG=20
TASK_STATUS_NAME_TOO_LONG=21
TASK_STATUS_TORRENT_DUPLICATE=22
TASK_STATUS_FILE_NOT_EXIST=23
TASK_STATUS_REQUIRED_PREMIUM_ACCOUNT=24
TASK_STATUS_NOT_SUPPORTED_TYPE=25
TASK_STATUS_TRY_IT_LATER=26
TASK_STATUS_TASK_ENCRYPTION=27
TASK_STATUS_MISSING_PYTHON=28
TASK_STATUS_PRIVATE_VIDEO=29
TASK_STATUS_FTP_ENCRYPTION_NOT_SUPPORTED_TYPE=30
TASK_STATUS_EXTRACT_FAILED=31
TASK_STATUS_EXTRACT_FAILED_WRONG_PASSWORD=32
TASK_STATUS_EXTRACT_FAILED_INVALID_ARCHIVE=33
TASK_STATUS_EXTRACT_FAILED_QUOTA_REACHED=34
TASK_STATUS_EXTRACT_FAILED_DISK_FULL=35
TASK_STATUS_UNKNOWN=36

trackerlistUrl="https://cdn.jsdelivr.net/gh/ngosang/trackerslist@master/trackers_all.txt"

trackerList=$(curl -f $trackerlistUrl 2>/dev/null)
if [[ $? != 0 ]]; then
echo "Tracker list url unavailable please check url: $trackerlistUrl"
exit 1
fi
trackerList=$(echo '"'$trackerList'"' | jq -c 'split(" ")')
trackerListLength=$(jq 'length' <<<$trackerList)

if [[ $trackerListLength == 0 ]]; then
echo "No found tracker please check tracker list: $trackerlistUrl"
exit 1
fi

pakcageList=$(synowebapi --exec api=SYNO.Core.Package method=list version=2 additional='["status"]' 2>/dev/null | jq -c '.data.packages | map(select(.id == "DownloadStation"))')

isRunning=$(jq -r 'map(select(.id == "DownloadStation") | .additional.status) | .[]' <<<$pakcageList)

if [ $isRunning != "running" ]; then
echo -e "Download Station$RED not running$END exit"
exit
fi

echo "Download Station is running go next step"

downloadList=$(synowebapi --exec api=SYNO.DownloadStation2.Task method=list version=2 limit=-1 "status=[$TASK_STATUS_DOWNLOADING]" 2>/dev/null | jq -c '.data.task | map(select(.type == "bt"))')
downloadListCount=$(jq 'length' <<<$downloadList)

if [[ $downloadListCount -eq 0 ]]; then
echo "Not found bt download task"
exit
fi

echo "Download tasks count: $downloadListCount"

for idx in $(seq 0 $((downloadListCount - 1))); do
echo "----------------Task [$idx]------------------"
task=$(jq -c ".[$idx]" <<<$downloadList)
taskId=$(jq -r .id <<<$task)
taskName=$(jq -r .title <<<$task)
taskTrackerList=$(synowebapi --exec api=SYNO.DownloadStation2.Task.BT.Tracker method=list version=2 task_id="$taskId" limit=-1 2>/dev/null | jq -c '.')
taskTrackerListMap=$(jq -c '.data.items | reduce .[] as $i ({}; .[$i.url] = 1)' 2>/dev/null <<<$taskTrackerList)
if [[ $? != 0 ]]; then
    echo "Task: 【$taskName】 is busy skip task; $taskTrackerList"
    continue
fi
taskTrackerListCount=$(jq '.data.total' <<<$taskTrackerList)echo "Task:【$taskName】 has tracker count: $taskTrackerListCount"
needAddedTrackerList=$(jq -c --argjson hashMap $taskTrackerListMap 'map(select(. | in($hashMap) == false))' <<<$trackerList)
needAddedTrackerListLength=$(jq 'length' <<<$needAddedTrackerList)

if [[ $needAddedTrackerListLength == 0 ]]; then
    echo "The task does not need to add a new tracker"
    continue
fi

echo "A list of trackers that need to be added to the task: $needAddedTrackerList , count: $needAddedTrackerListLength"

result=$(synowebapi --exec api=SYNO.DownloadStation2.Task.BT.Tracker method=add version=2 task_id=$taskId tracker=$needAddedTrackerList 2>/dev/null)

if [[ $(jq '.success' <<<$result) == true ]]; then
    echo "Task: [$taskName] tracker list add success"
else
    echo "Task: [$taskName] tracker list add fail"
fi
done

echo "Automatically add tracker script to complete"





fgd888 发表于 2023-8-18 10:19

本帖最后由 fgd888 于 2023-8-18 10:21 编辑

我这里的网络连不到楼主发的82行url,自己换了另一个地址搞定了,谢谢楼主了。https://cf.trackerslist.com/all.txt

输出最后显示
Task: tracker list add success
Automatically add tracker script to complete

yukun8168 发表于 2023-7-4 11:32

您好,我在计划任务里创建计划任务设置每分钟执行,不行哦。触发任务也不行。
我的是7.1系统的。

梦与非 发表于 2023-7-12 22:17

7.1 MARK,稍后再看

joysen 发表于 2023-8-8 03:12

/bin/bash: line 100: [: !=: unary operator expected
Download Station is running go next step
Not found bt download task

这是生成的执行日志,dowsload station在运行中,但是查询不到下载任务
DSM 7.2

a380206367 发表于 2023-8-11 19:38

joysen 发表于 2023-8-8 03:12
/bin/bash: line 100: [: !=: unary operator expected
Download Station is running go next step
Not f ...

你可以尝试把脚本 保存在一个文件里 然后再执行 看看报错信息 不然不好定位是哪里错了

1107934496 发表于 2023-8-18 16:42

感谢楼主分享,目前我的下载放在6.2.1的黑裙上,7.1的黑裙拿来跑wx了,等我调整后尝试一下

camxier 发表于 2023-8-30 07:49

谢谢楼主的分享

是路人诶 发表于 2023-9-10 23:16

joysen 发表于 2023-8-8 03:12
/bin/bash: line 100: [: !=: unary operator expected
Download Station is running go next step
Not f ...

我也遇到了,创建计划的时候用root执行就解决了,然后只需要把 trackerlist 订阅链接换掉就正常使用了

wzg15071145430 发表于 2023-9-26 14:40

可以啊!!!
页: [1] 2 3
查看完整版本: 群晖 Download Station BT 种子下载 自动添加trackerlist