forked from std4453/mikanarr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauto_qb_rename.sh
52 lines (38 loc) · 1.87 KB
/
auto_qb_rename.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/bash
# Description:
#
# Author: Sage
# Email: [email protected]
# Version: 1.0
# CreateTime: 2022-6-10 15:47:45
if [[ "${sonarr_eventtype}" != "Grab" ]]; then
echo "[Auto_QB_Rename] Sonarr Event Type is NOT Grab, exiting."
exit
fi
QB_URL=http://
QB_USERNAME=
QB_PASSWORD=
COOKIE=$(curl -i -s --header "Referer: ${QB_URL}" --data-urlencode "username=${QB_USERNAME}" --data-urlencode "password=${QB_PASSWORD}" ${QB_URL}/api/v2/auth/login | grep "set-cookie:" | cut -d';' -f1 | cut -d':' -f2)
if [ -n ${COOKIE} ]; then
echo "[$(date '+%Y-%m-%d %H:%M:%S')] 登录成功! cookie:${COOKIE}" > /dev/stdout
else
echo "[$(date '+%Y-%m-%d %H:%M:%S')] 登录失败!" > /dev/stderr
exit
fi
# Get filename of the torrent.
OLD_PATH=`curl -s ${QB_URL}/api/v2/torrents/info?hashes=${sonarr_download_id} --cookie ${COOKIE} | jq '.[].name' | sed 's/"//g' | sed "s/\'//g"`
# Get file type of the job.
MEDIA_TYPE=`curl -s ${QB_URL}/api/v2/torrents/info?hashes=${sonarr_download_id} --cookie ${COOKIE} | jq '.[].name' | sed 's/"//g' | sed "s/\'//g" | awk -F. '{print $NF}'`
# Will be modified to name.
#NEW_PATH="["${sonarr_release_releasegroup}"] "${sonarr_release_title}"."${MEDIA_TYPE}
NEW_PATH=${sonarr_release_title}"."${MEDIA_TYPE}
# Log.
echo "oldPath: ""${OLD_PATH} ""\n""newPath: " "${NEW_PATH}" > /dev/stderr
ENCODED_OLD_PATH=$(echo ${OLD_PATH} | tr -d '\n' | od -An -tx1 | tr ' ' % | tr -d '\n')
ENCODED_NEW_PATH=$(echo ${NEW_PATH} | tr -d '\n' | od -An -tx1 | tr ' ' % | tr -d '\n')
CURL_DATA=\'"hash="${sonarr_download_id}"&oldPath="${ENCODED_OLD_PATH}"&newPath="${ENCODED_NEW_PATH}\'
echo "curlData: ""${CURL_DATA}" > /dev/stdout
# Call QB Rename API
echo "#!/bin/bash" > /tmp/tmpscripts.sh
echo "sleep 10 && /usr/bin/curl -s ${QB_URL}/api/v2/torrents/renameFile --data-raw ${CURL_DATA} --cookie ${COOKIE}" >> /tmp/tmpscripts.sh
/bin/bash /tmp/tmpscripts.sh > /dev/stdout &