Last active
March 22, 2020 18:36
-
-
Save EnorMOZ/d3d38704dc8b3411f6ea493f7e787b7e to your computer and use it in GitHub Desktop.
Radarr Script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh -e | |
ApiKey=12345 | |
DBP="/opt/radarr4k/app/radarr.db" | |
RUL="http://localhost:17878" | |
DEBUG="True" | |
SQL="/usr/bin/sqlite3" | |
#IF it fails you can start it where it left off by using the Id where it failed | |
#MID=$($SQL $DBP "select Id from Movies where MovieFileID > 0 and Id > 2375 ORDER BY Id;") | |
MID=$($SQL $DBP "select Id from Movies where MovieFileID > 0 ORDER BY Id;") | |
prog() { | |
local w=50 p=$1 | |
shift | |
printf -v dots "%*s" "$(($p * $w / 100))" "" | |
dots=${dots// /#} | |
printf "\r\e[K|%-*s| %3d %% %s" "$w" "$dots" "$p" "$*" | |
} | |
UpdateSchema() { | |
echo -e "Changing schemaRevision to 2 for $mID to force mediaInfo scan on next refresh" | |
$SQL $DBP <<EOF | |
.timeout 2000 | |
UPDATE MovieFiles SET MediaInfo = replace(MediaInfo, '"schemaRevision": 5', '"schemaRevision": 2') WHERE MovieId = $mID; | |
EOF | |
} | |
RefreshMovie() { | |
echo -e "\nRefreshing Movie $mID" | |
if [ $DEBUG == "True" ]; then | |
curl -s "$RUL/api/v3/command?apikey=$ApiKey" \ | |
-H 'content-type: application/x-www-form-urlencoded; charset=UTF-8' \ | |
--data "{\"name\":\"RefreshMovie\",\"movieId\":$mID}" --compressed >/dev/null | |
else | |
curl -s "$RUL/api/v3/command?apikey=$ApiKey" \ | |
-H 'content-type: application/x-www-form-urlencoded; charset=UTF-8' \ | |
--data "{\"name\":\"RefreshMovie\",\"movieId\":$mID}" | |
fi | |
} | |
RenameMovie() { | |
echo -e "\nRenaming Movie $mID" | |
if [ $DEBUG == "True" ]; then | |
curl -s "$RUL/api/v3/command?apikey=$ApiKey" \ | |
-H 'content-type: application/x-www-form-urlencoded; charset=UTF-8' \ | |
--data "{\"name\":\"RenameMovie\",\"movieIds\":[$mID]}" --compressed >/dev/null | |
else | |
curl -s "$RUL/api/v3/command?apikey=$ApiKey" \ | |
-H 'content-type: application/x-www-form-urlencoded; charset=UTF-8' \ | |
--data "{\"name\":\"RenameMovie\",\"movieIds\":[$mID]}" | |
fi | |
} | |
UpdateCF() { | |
echo -e "\nUpdating CF for $mID" | |
for QID in $($SQL $DBP "select Id from MovieFiles where MovieID = $mID;"); do | |
if [ $DEBUG == "True" ]; then | |
curl -s "$RUL/api/v3/command?apikey=$ApiKey" \ | |
--data "{name: \"updateMovieFileQuality\", movieFileIds: [$QID]}" \ | |
-H "Content-Type: application/json" >/dev/null | |
else | |
curl -s "$RUL/api/v3/command?apikey=$ApiKey" \ | |
--data "{name: \"updateMovieFileQuality\", movieFileIds: [$QID]}" \ | |
-H "Content-Type: application/json" | |
fi | |
done | |
} | |
TOTAL() { | |
TOTALITEMS=$(echo $MID | wc -w) | |
i=0 | |
echo -e "\nProcessing $total results:" | |
} | |
usage() { | |
echo "usage: $0 [pick from one: [--refreshmovies|-refresh] | [--updatecfs|-update] | [--renamemovie | -rename] | [--all| -all]| [-h]" | |
} | |
if [[ $# == 0 ]]; then | |
usage | |
exit 1 | |
fi | |
while [ "$1" != "" ]; do | |
case $1 in | |
--refreshmovies | -refreshmovies | -refresh) | |
TOTAL | |
for mID in $(echo "${MID}"); do | |
i=$((i + 1)) | |
taskpercent=$((i * 100 / $TOTALITEMS)) | |
prog "$taskpercent" $i of $TOTALITEMS...Id $mID | |
RefreshMovie | |
sleep 4 | |
done | |
;; | |
--updatecfs | -updatecfs | -update) | |
TOTAL | |
for mID in $(echo "${MID}"); do | |
i=$((i + 1)) | |
taskpercent=$((i * 100 / $TOTALITEMS)) | |
prog "$taskpercent" $i of $TOTALITEMS...Id $mID | |
UpdateCF | |
sleep .25 | |
RefreshMovie | |
done | |
;; | |
--renamemovie | -renamemovie | -rename) | |
TOTAL | |
for mID in $(echo "${MID}"); do | |
i=$((i + 1)) | |
taskpercent=$((i * 100 / $TOTALITEMS)) | |
prog "$taskpercent" $i of $TOTALITEMS...Id $mID | |
RenameMovie | |
sleep .25 | |
done | |
;; | |
--all | -all) | |
TOTAL | |
for mID in $(echo "${MID}"); do | |
i=$((i + 1)) | |
taskpercent=$((i * 100 / $TOTALITEMS)) | |
prog "$taskpercent" $i of $TOTALITEMS...Id $mID | |
UpdateSchema | |
RefreshMovie | |
sleep 4 | |
UpdateCF | |
RefreshMovie | |
sleep .25 | |
done | |
;; | |
-h | --help) | |
usage | |
exit | |
;; | |
*) | |
usage | |
exit 1 | |
;; | |
esac | |
shift | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment