Ric*_*ard 4 windows linux batch shell-script qbittorrent
如何编写批处理/脚本文件来查询qBittorrent以查明它是否正在下载某些内容?
根据结果,我想执行进一步的命令。
下面是两段代码(一段适用于 Windows,一段适用于 Linux),它们使用qBittorrent v4.1(或更高版本)API根据是否正在下载内容返回一条消息。
@echo off
rem Remove existing cookie jar
del /F %temp%\cookies.txt 2>nul
rem Login to qBittorrent
curl -s -b %temp%\cookies.txt -c %temp%\cookies.txt --header "Referer: http://localhost:8080" --data "username=admin&password=secret" http://localhost:8080/api/v2/auth/login >nul
rem Get list of downloading torrents
curl -s -b %temp%\cookies.txt -c %temp%\cookies.txt --header "Referer: http://localhost:8080" "http://localhost:8080/api/v2/torrents/info" | jq | findstr """state""" | findstr /R "stalledDL downloading metaDL" >nul
if errorlevel 0 (
echo Something downloading
) else (
echo Nothing downloading
)
rem Remove used cookie jar
del /F %temp%\cookies.txt 2>nul
Run Code Online (Sandbox Code Playgroud)
#!/bin/bash
# Remove existing cookie jar
rm -f ~/.cookies.txt
# Login to qbittorrent
curl -s -b ~/.cookies.txt -c ~/.cookies.txt --header "Referer: http://localhost:8080" --data "username=admin&password=secret" http://localhost:8080/api/v2/auth/login >/dev/null 2>&1
# Get list of downloading torrents
if [[ $(curl -s -b ~/.cookies.txt -c ~/.cookies.txt --header "Referer: http://localhost:8080" "http://localhost:8080/api/v2/torrents/info" | jq . | grep "state" | egrep "(stalledDL|downloading|metaDL)") ]]; then
echo "Something downloading"
else
echo "Nothing downloading"
fi
# Remove used cookie jar
rm -f ~/.cookies.txt
Run Code Online (Sandbox Code Playgroud)
admin和密码secret,您需要更改这些localhost:8080,您需要将其所有实例更改为正确的计算机名称/IP 和端口号cookies.txt)来保存 SID。这是在成功登录后提供给我们的,并且在执行进一步命令时必须发送。一旦我们完成它,cookie jar 就会被删除。stalledDL此代码考虑、downloading和的状态metaDL为正在下载。您可以通过查看此处记录的各种状态来更改此设置。jq从 qBittorrent API 获取 JSON 输出,并以更易于阅读/解析的方式对其进行格式化。jq.exe并将其放在与此脚本相同的文件夹中 - 我个人将其放入,C:\Windows\System32以便它可以在任何文件夹中使用jq这是至关重要的,因为 qBittorrent 的输出可能包含极长的行,findstr无法处理(并引发错误)。sudo apt-get install curljq它才能工作,并且它在大多数存储库中都可用。在 Debian 上这是sudo apt-get install jq jq技术上不需要,egrep可以修改以过滤状态和值| 归档时间: |
|
| 查看次数: |
901 次 |
| 最近记录: |