From 132260433fc19eb08fcb9b2d6beb0ddfe200e0ef Mon Sep 17 00:00:00 2001 From: konsthol Date: Tue, 31 Dec 2024 03:04:54 +0200 Subject: [PATCH] Uniform curl execution --- grpoppro | 77 ++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 52 insertions(+), 25 deletions(-) diff --git a/grpoppro b/grpoppro index 00144af..f2a197d 100755 --- a/grpoppro +++ b/grpoppro @@ -41,17 +41,45 @@ function message { # Standard curl request 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 \ -c "$GRPOPPRO_COOKIE_FILE" \ -b "$GRPOPPRO_COOKIE_FILE" \ + "$url" \ + --compressed \ + -X "$custom_method" \ -A "$USER_AGENT" \ - -H "$ACCEPT" \ + -H "$custom_accept" \ -H "$ACCEPT_LANGUAGE" \ -H "$CONNECTION" \ -H "$UP_IN_REQ" \ - --compressed \ "$@" )" + exit_code="$?" if [[ "$exit_code" -ne 0 ]]; then message "Error: Failed to execute curl request." @@ -120,30 +148,29 @@ function getInternalID { # Retrieve movie stream URL function getMovieStreamUrl { PHPSESSID="$(grep 'PHPSESSID' "$GRPOPPRO_COOKIE_FILE" | awk '{print $NF}')" - response="$(curl -s -L \ - -c "$GRPOPPRO_COOKIE_FILE" \ - -b "$GRPOPPRO_COOKIE_FILE" \ - "$apiurl/engine/ajax/controller.php" \ - --compressed \ - -X POST \ - -A "$USER_AGENT" \ - -H 'Accept: application/json, text/javascript, */*; q=0.01' \ - -H "$ACCEPT_LANGUAGE" \ - -H 'Accept-Encoding: gzip, deflate, br, zstd' \ - -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' \ - -H 'X-Requested-With: XMLHttpRequest' \ - -H "Origin: $apiurl" \ - -H 'DNT: 1' \ - -H 'Sec-GPC: 1' \ - -H "$CONNECTION" \ - -H "Referer: $simpleurl" \ - -H "Cookie: PHPSESSID=$PHPSESSID" \ - -H 'Sec-Fetch-Dest: empty' \ - -H 'Sec-Fetch-Mode: cors' \ - -H 'Sec-Fetch-Site: same-origin' \ - -H 'TE: trailers' \ - --data-raw "mod=players&news_id=$internalid" + local headers=( + '-H Accept-Encoding: gzip, deflate, br, zstd' + '-H Content-Type: application/x-www-form-urlencoded; charset=UTF-8' + '-H X-Requested-With: XMLHttpRequest' + "-H Origin: $apiurl" + '-H DNT: 1' + '-H Sec-GPC: 1' + "-H Referer: $simpleurl" + "-H Cookie: PHPSESSID=$PHPSESSID" + '-H Sec-Fetch-Dest: empty' + '-H Sec-Fetch-Mode: cors' + '-H Sec-Fetch-Site: same-origin' + '-H TE: trailers' + '--data-raw' + "mod=players&news_id=$internalid" + ) + + response="$(curlRequest "$apiurl/engine/ajax/controller.php" \ + "POST" \ + 'Accept: application/json, text/javascript, */*; q=0.01' \ + "${headers[@]}" )" + streamurl="$(echo "$response" \ | sed 's/\\//g' \ | grep -oP 'file:"\K[^"]+'