This commit is contained in:
2024-12-30 19:33:34 +02:00
parent f909fbb39b
commit bc5376caf1

View File

@@ -23,19 +23,22 @@ MPV_OPTS='--vo=gpu \
--fs' --fs'
## End of definitions ## End of definitions
# Print usage information
function usage { function usage {
echo -e "\n\tUsage:\n\n\t$(basename "$0") \"name of film or show\" [season] [episode(ex 01 02 .. 10 11)]\n\tOr $(basename "$0") [--menu|--resume|--select|--finish]\n\tOr $(basename "$0") --open \"name of film or show\"" echo -e "\n\tUsage:\n\n\t$(basename "$0") \"name of film or show\" [season] [episode(ex 01 02 .. 10 11)]"
echo -e "\tOr $(basename "$0") [--menu|--resume|--select|--finish]"
echo -e "\tOr $(basename "$0") --open \"name of film or show\""
exit 0 exit 0
} }
# Ensure fzf is installed for Termux
function getFzfForTermux { function getFzfForTermux {
if command -v fzf >/dev/null 2>&1; then if ! command -v fzf >/dev/null 2>&1; then
echo -e "\n"
else
apt install -y fzf apt install -y fzf
fi fi
} }
# Display a message
function message { function message {
if [[ "$INTERACTIVE" == "on" ]]; then if [[ "$INTERACTIVE" == "on" ]]; then
notify-send -t 2000 "$1" notify-send -t 2000 "$1"
@@ -44,6 +47,7 @@ function message {
fi fi
} }
# Retrieve IMDb ID
function getIMDBID { function getIMDBID {
imdbid="$(curl -s -L -c "$GRPOPPRO_COOKIE_FILE" -b "$GRPOPPRO_COOKIE_FILE" \ imdbid="$(curl -s -L -c "$GRPOPPRO_COOKIE_FILE" -b "$GRPOPPRO_COOKIE_FILE" \
-A "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:133.0) Gecko/20100101 Firefox/133.0" \ -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:133.0) Gecko/20100101 Firefox/133.0" \
@@ -57,13 +61,15 @@ function getIMDBID {
fi fi
} }
function basics() { # Prepare basic steps for a request
function basics {
title="$1" title="$1"
title="${title// /%20}" title="${title// /%20}"
getIMDBID "$title" getIMDBID "$title"
simpleurl="$apiurl/embed/$imdbid/" simpleurl="$apiurl/embed/$imdbid/"
} }
# Retrieve internal ID
function getInternalID { function getInternalID {
response="$(curl -s -L -c "$GRPOPPRO_COOKIE_FILE" -b "$GRPOPPRO_COOKIE_FILE" \ response="$(curl -s -L -c "$GRPOPPRO_COOKIE_FILE" -b "$GRPOPPRO_COOKIE_FILE" \
-A "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:133.0) Gecko/20100101 Firefox/133.0" \ -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:133.0) Gecko/20100101 Firefox/133.0" \
@@ -80,6 +86,7 @@ function getInternalID {
internalid="$(echo "$response" | grep news_id | awk '{print $5}' | awk -F\' '{print $2}')" internalid="$(echo "$response" | grep news_id | awk '{print $5}' | awk -F\' '{print $2}')"
} }
# 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}')"
streamurl="$(curl -s -L -c "$GRPOPPRO_COOKIE_FILE" -b "$GRPOPPRO_COOKIE_FILE" "$apiurl/engine/ajax/controller.php" --compressed -X POST \ streamurl="$(curl -s -L -c "$GRPOPPRO_COOKIE_FILE" -b "$GRPOPPRO_COOKIE_FILE" "$apiurl/engine/ajax/controller.php" --compressed -X POST \
@@ -104,6 +111,7 @@ function getMovieStreamUrl {
)" )"
} }
# Stream the video
function play { function play {
if [[ "$player" == "mpv" ]]; then if [[ "$player" == "mpv" ]]; then
MPVPID="$(pidof mpv | cut -d' ' -f1)" MPVPID="$(pidof mpv | cut -d' ' -f1)"
@@ -115,6 +123,7 @@ function play {
eval "$player" "$streamurl" eval "$player" "$streamurl"
} }
# Dump data to files
function dumpData { function dumpData {
echo "$title" > "$GRPOPPRO_DATA_FILE" echo "$title" > "$GRPOPPRO_DATA_FILE"
echo "$seasonEpisode" >> "$GRPOPPRO_DATA_FILE" echo "$seasonEpisode" >> "$GRPOPPRO_DATA_FILE"
@@ -124,6 +133,7 @@ function dumpData {
tac "$GRPOPPRO_HISTORY_FILE" | awk -F'|' '!seen[$1]++' | tac > "${GRPOPPRO_DATA_DIR}/temp.txt" && mv "${GRPOPPRO_DATA_DIR}/temp.txt" "$GRPOPPRO_HISTORY_FILE" tac "$GRPOPPRO_HISTORY_FILE" | awk -F'|' '!seen[$1]++' | tac > "${GRPOPPRO_DATA_DIR}/temp.txt" && mv "${GRPOPPRO_DATA_DIR}/temp.txt" "$GRPOPPRO_HISTORY_FILE"
} }
# Source data from files
function sourceData { function sourceData {
if [[ -f "$GRPOPPRO_DATA_FILE" ]]; then if [[ -f "$GRPOPPRO_DATA_FILE" ]]; then
lastSeriesPlayed="$(sed -n 1p "$GRPOPPRO_DATA_FILE")" lastSeriesPlayed="$(sed -n 1p "$GRPOPPRO_DATA_FILE")"
@@ -132,6 +142,7 @@ function sourceData {
fi fi
} }
# Perform menu search
function menuSearch { function menuSearch {
# Two requests to the api # Two requests to the api
[[ "$INTERACTIVE" == "on" ]] && title=$(echo "" | wofi --dmenu --insensitive --prompt="Search Series" --width=300 --height=50) [[ "$INTERACTIVE" == "on" ]] && title=$(echo "" | wofi --dmenu --insensitive --prompt="Search Series" --width=300 --height=50)
@@ -166,6 +177,7 @@ function menuSearch {
resume resume
} }
# Resume last watched series
function resume { function resume {
# Zero requests to the api # Zero requests to the api
if [[ ! -f "$GRPOPPRO_DATA_FILE" ]]; then if [[ ! -f "$GRPOPPRO_DATA_FILE" ]]; then
@@ -188,6 +200,7 @@ function resume {
done done
} }
# Select which series to resume
function resumeSeries { function resumeSeries {
if [[ ! -f "$GRPOPPRO_HISTORY_FILE" ]]; then if [[ ! -f "$GRPOPPRO_HISTORY_FILE" ]]; then
message "No history found" message "No history found"
@@ -230,6 +243,7 @@ function resumeSeries {
resume resume
} }
# Resume last watched unfinished episode
function resumeUnfinishedEpisode { function resumeUnfinishedEpisode {
# Zero requests to the api # Zero requests to the api
if [[ ! -f "$GRPOPPRO_DATA_FILE" ]]; then if [[ ! -f "$GRPOPPRO_DATA_FILE" ]]; then
@@ -250,6 +264,7 @@ function resumeUnfinishedEpisode {
resume resume
} }
# Open in browser to watch
function openInBrowser { function openInBrowser {
# One request to the api # One request to the api
basics "$2" basics "$2"
@@ -260,8 +275,10 @@ function openInBrowser {
### Program starts here ### ### Program starts here ###
# Make sure the data directory exists
mkdir -p "$GRPOPPRO_DATA_DIR" mkdir -p "$GRPOPPRO_DATA_DIR"
# Exit if a VPN connection is active
if [[ "$OSTYPE" == "linux-gnu" ]]; then if [[ "$OSTYPE" == "linux-gnu" ]]; then
if nmcli connection show --active | grep -i -q wireguard; then if nmcli connection show --active | grep -i -q wireguard; then
echo "Exiting because a vpn connection is active" echo "Exiting because a vpn connection is active"
@@ -269,6 +286,7 @@ if [[ "$OSTYPE" == "linux-gnu" ]]; then
fi fi
fi fi
# Prepare the necessary steps for Termux environment
[[ "$OSTYPE" != "linux-gnu" ]] && INTERACTIVE="off" && menu="fzf -i --prompt=seasonXepisode" && player="am start -n is.xyz.mpv/.MPVActivity -a android.intent.action.VIEW -d" && getFzfForTermux [[ "$OSTYPE" != "linux-gnu" ]] && INTERACTIVE="off" && menu="fzf -i --prompt=seasonXepisode" && player="am start -n is.xyz.mpv/.MPVActivity -a android.intent.action.VIEW -d" && getFzfForTermux
[[ "$#" -lt 1 ]] && usage [[ "$#" -lt 1 ]] && usage