@@ -980,49 +980,60 @@ function call_api {
980980 local message=" $2 " # Message to log
981981 local method=" $3 " # HTTP method to use (GET, POST, PUT, DELETE)
982982 local endpoint=" $4 " # API endpoint to call
983- local data # Data to send with the request. All subsequent arguments are treated as data.
983+ local -a curl_data_args=() # Use array instead of string for safer argument passing (see issue #118)
984984
985985 # Process remaining data values
986986 shift 4
987987 while (( "$# " )) ; do
988- # Escape double quotes in data parameter
989- local param=" ${1// \" / \\\" } "
990- case " $param " in
988+ case " $1 " in
991989 " {" * |" [" * )
992- data+= " --json \" $param \" "
990+ curl_data_args+=( --json " $1 " )
993991 shift
994992 ;;
995993 * =* )
996- data+= " --data-urlencode \" $param \" "
994+ curl_data_args+=( --data-urlencode " $1 " )
997995 shift
998996 ;;
999997 * )
1000- data+= " --data-raw \" $param \" "
998+ curl_data_args+=( --data-raw " $1 " )
1001999 shift
10021000 ;;
10031001 esac
10041002 done
10051003
1004+ local -a curl_args=(
1005+ -s
1006+ --fail-with-body
1007+ -H " X-Api-Key: $striptracks_apikey "
1008+ -H " Content-Type: application/json"
1009+ -H " Accept: application/json"
1010+ )
1011+
10061012 local url=" $striptracks_api_url /$endpoint "
1007- [ $striptracks_debug -ge 1 ] && echo " Debug|$message Calling ${striptracks_type^} API using $method and URL '$url '${data: + with$data } " | log
1013+ local data_info=" "
1014+ [ ${# curl_data_args[@]} -gt 0 ] && data_info=" with data: ${curl_data_args[*]} "
1015+ [ $striptracks_debug -ge 1 ] && echo " Debug|$message Calling ${striptracks_type^} API using $method and URL '$url '$data_info " | log
10081016 if [ " $method " = " GET" ]; then
1009- method= " -G "
1017+ curl_args+=(-G)
10101018 else
1011- method= " -X $method "
1019+ curl_args+=( -X " $method " )
10121020 fi
1013- local curl_cmd=" curl -s --fail-with-body -H \" X-Api-Key: $striptracks_apikey \" -H \" Content-Type: application/json\" -H \" Accept: application/json\" ${data: +$data } $method \" $url \" "
1014- [ $striptracks_debug -ge 2 ] && echo " Debug|Executing: $curl_cmd " | sed -E ' s/(X-Api-Key: )[^"]+/\1[REDACTED]/' | log
1021+ # Add data arguments and url to curl arguments array
1022+ curl_args+=(" ${curl_data_args[@]} " )
1023+ curl_args+=(--url " $url " )
1024+ [ $striptracks_debug -ge 2 ] && echo " Debug|Executing: curl ${curl_args[*]} " | sed -E ' s/(X-Api-Key: )[^ ]+/\1[REDACTED]/' | log
10151025 unset striptracks_result
10161026 # (See issue #104)
10171027 declare -g striptracks_result
10181028
10191029 # Retry up to five times if database is locked
10201030 local i=0
10211031 for (( i= 1 ; i <= 5 ; i++ )) ; do
1022- striptracks_result=$( eval " $curl_cmd " )
1032+ striptracks_result=$( curl " ${curl_args[@]} " )
10231033 local curl_return=$?
10241034 if [ $curl_return -ne 0 ]; then
1025- local message=$( echo -e " [$curl_return ] curl error when calling: \" $url \" ${data: + with$data } \nWeb server returned: $( echo $striptracks_result | jq -jcM ' if type=="array" then map(.errorMessage) | join(", ") else (if has("title") then "[HTTP \(.status?)] \(.title?) \(.errors?)" elif has("message") then .message else "Unknown JSON format." end) end' ) " | awk ' {print "Error|"$0}' )
1035+ local error_message=" $( echo $striptracks_result | jq -jcM ' if type=="array" then map(.errorMessage) | join(", ") else (if has("title") then "[HTTP \(.status?)] \(.title) \(.errors?)" elif has("message") then .message else "Unknown JSON format." end) end' ) "
1036+ local message=$( echo -e " [$curl_return ] curl error when calling: \" $url \" $data_info \nWeb server returned: $error_message " | awk ' {print "Error|"$0}' )
10261037 echo " $message " | log
10271038 echo " $message " >&2
10281039 break
@@ -1133,7 +1144,8 @@ function check_video {
11331144 # Create temporary filename
11341145 local basename=" $( basename -- " ${striptracks_video} " ) "
11351146 local fileroot=" ${basename% .* } "
1136- export striptracks_tempvideo=" $( dirname -- " ${striptracks_video} " ) /$( mktemp -u -- " ${fileroot: 0: 5} .tmp.XXXXXX" ) "
1147+ # ._ prefixed files are ignored by Radarr/Sonarr (see issues #65 and #115)
1148+ export striptracks_tempvideo=" $( dirname -- " ${striptracks_video} " ) /$( mktemp -u -- " ._${fileroot: 0: 5} .tmp.XXXXXX" ) "
11371149 [ $striptracks_debug -ge 1 ] && echo " Debug|Using temporary file \" $striptracks_tempvideo \" " | log
11381150}
11391151function detect_languages {
@@ -1260,7 +1272,6 @@ function detect_languages {
12601272 local message=" Warn|No languages found in any profile or custom format. Unable to use automatic language detection."
12611273 echo " $message " | log
12621274 echo " $message " >&2
1263- change_exit_status 20
12641275 else
12651276 # Final determination of configured languages in profiles or custom formats
12661277 local profileLangNames=" $( echo $profileLanguages | jq -crM ' [.[].name]' ) "
0 commit comments