Uniform curl execution

This commit is contained in:
2024-12-31 03:04:54 +02:00
parent 271e03efe1
commit 132260433f

View File

@@ -41,17 +41,45 @@ function message {
# Standard curl request # Standard curl request
function curlRequest { function curlRequest {
local url="$1"
local custom_method="${2:-}"
local custom_accept="${3:-}"
local shifts=1 # Initialize shifts to account for the URL
shift # Shift out the URL
# Check for custom method and Accept header, and shift accordingly
if [[ -n "$custom_method" ]]; then
shifts=$((shifts + 1))
shift
fi
if [[ -n "$custom_accept" ]]; then
shifts=$((shifts + 1))
shift
fi
# Apply default values if not provided
custom_method="${custom_method:-GET}"
custom_accept="${custom_accept:-$ACCEPT}"
# Dynamically shift the total number of times needed
shift $((shifts - 1))
response="$(curl -s -L \ response="$(curl -s -L \
-c "$GRPOPPRO_COOKIE_FILE" \ -c "$GRPOPPRO_COOKIE_FILE" \
-b "$GRPOPPRO_COOKIE_FILE" \ -b "$GRPOPPRO_COOKIE_FILE" \
"$url" \
--compressed \
-X "$custom_method" \
-A "$USER_AGENT" \ -A "$USER_AGENT" \
-H "$ACCEPT" \ -H "$custom_accept" \
-H "$ACCEPT_LANGUAGE" \ -H "$ACCEPT_LANGUAGE" \
-H "$CONNECTION" \ -H "$CONNECTION" \
-H "$UP_IN_REQ" \ -H "$UP_IN_REQ" \
--compressed \
"$@" "$@"
)" )"
exit_code="$?" exit_code="$?"
if [[ "$exit_code" -ne 0 ]]; then if [[ "$exit_code" -ne 0 ]]; then
message "Error: Failed to execute curl request." message "Error: Failed to execute curl request."
@@ -120,30 +148,29 @@ function getInternalID {
# Retrieve movie stream URL # Retrieve movie stream URL
function getMovieStreamUrl { function getMovieStreamUrl {
PHPSESSID="$(grep 'PHPSESSID' "$GRPOPPRO_COOKIE_FILE" | awk '{print $NF}')" PHPSESSID="$(grep 'PHPSESSID' "$GRPOPPRO_COOKIE_FILE" | awk '{print $NF}')"
response="$(curl -s -L \ local headers=(
-c "$GRPOPPRO_COOKIE_FILE" \ '-H Accept-Encoding: gzip, deflate, br, zstd'
-b "$GRPOPPRO_COOKIE_FILE" \ '-H Content-Type: application/x-www-form-urlencoded; charset=UTF-8'
"$apiurl/engine/ajax/controller.php" \ '-H X-Requested-With: XMLHttpRequest'
--compressed \ "-H Origin: $apiurl"
-X POST \ '-H DNT: 1'
-A "$USER_AGENT" \ '-H Sec-GPC: 1'
-H 'Accept: application/json, text/javascript, */*; q=0.01' \ "-H Referer: $simpleurl"
-H "$ACCEPT_LANGUAGE" \ "-H Cookie: PHPSESSID=$PHPSESSID"
-H 'Accept-Encoding: gzip, deflate, br, zstd' \ '-H Sec-Fetch-Dest: empty'
-H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' \ '-H Sec-Fetch-Mode: cors'
-H 'X-Requested-With: XMLHttpRequest' \ '-H Sec-Fetch-Site: same-origin'
-H "Origin: $apiurl" \ '-H TE: trailers'
-H 'DNT: 1' \ '--data-raw'
-H 'Sec-GPC: 1' \ "mod=players&news_id=$internalid"
-H "$CONNECTION" \ )
-H "Referer: $simpleurl" \
-H "Cookie: PHPSESSID=$PHPSESSID" \ response="$(curlRequest "$apiurl/engine/ajax/controller.php" \
-H 'Sec-Fetch-Dest: empty' \ "POST" \
-H 'Sec-Fetch-Mode: cors' \ 'Accept: application/json, text/javascript, */*; q=0.01' \
-H 'Sec-Fetch-Site: same-origin' \ "${headers[@]}"
-H 'TE: trailers' \
--data-raw "mod=players&news_id=$internalid"
)" )"
streamurl="$(echo "$response" \ streamurl="$(echo "$response" \
| sed 's/\\//g' \ | sed 's/\\//g' \
| grep -oP 'file:"\K[^"]+' | grep -oP 'file:"\K[^"]+'