diff --git a/grpoppro b/grpoppro index f142d71..b25c96f 100755 --- a/grpoppro +++ b/grpoppro @@ -23,19 +23,22 @@ MPV_OPTS='--vo=gpu \ --fs' ## End of definitions +# Print usage information 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 } +# Ensure fzf is installed for Termux function getFzfForTermux { - if command -v fzf >/dev/null 2>&1; then - echo -e "\n" - else + if ! command -v fzf >/dev/null 2>&1; then apt install -y fzf fi } +# Display a message function message { if [[ "$INTERACTIVE" == "on" ]]; then notify-send -t 2000 "$1" @@ -44,6 +47,7 @@ function message { fi } +# Retrieve IMDb ID function getIMDBID { 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" \ @@ -57,13 +61,15 @@ function getIMDBID { fi } -function basics() { +# Prepare basic steps for a request +function basics { title="$1" title="${title// /%20}" getIMDBID "$title" simpleurl="$apiurl/embed/$imdbid/" } +# Retrieve internal ID function getInternalID { 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" \ @@ -80,6 +86,7 @@ function getInternalID { internalid="$(echo "$response" | grep news_id | awk '{print $5}' | awk -F\' '{print $2}')" } +# Retrieve movie stream URL function getMovieStreamUrl { 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 \ @@ -104,6 +111,7 @@ function getMovieStreamUrl { )" } +# Stream the video function play { if [[ "$player" == "mpv" ]]; then MPVPID="$(pidof mpv | cut -d' ' -f1)" @@ -115,6 +123,7 @@ function play { eval "$player" "$streamurl" } +# Dump data to files function dumpData { echo "$title" > "$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" } +# Source data from files function sourceData { if [[ -f "$GRPOPPRO_DATA_FILE" ]]; then lastSeriesPlayed="$(sed -n 1p "$GRPOPPRO_DATA_FILE")" @@ -132,6 +142,7 @@ function sourceData { fi } +# Perform menu search function menuSearch { # Two requests to the api [[ "$INTERACTIVE" == "on" ]] && title=$(echo "" | wofi --dmenu --insensitive --prompt="Search Series" --width=300 --height=50) @@ -166,6 +177,7 @@ function menuSearch { resume } +# Resume last watched series function resume { # Zero requests to the api if [[ ! -f "$GRPOPPRO_DATA_FILE" ]]; then @@ -188,6 +200,7 @@ function resume { done } +# Select which series to resume function resumeSeries { if [[ ! -f "$GRPOPPRO_HISTORY_FILE" ]]; then message "No history found" @@ -230,6 +243,7 @@ function resumeSeries { resume } +# Resume last watched unfinished episode function resumeUnfinishedEpisode { # Zero requests to the api if [[ ! -f "$GRPOPPRO_DATA_FILE" ]]; then @@ -250,6 +264,7 @@ function resumeUnfinishedEpisode { resume } +# Open in browser to watch function openInBrowser { # One request to the api basics "$2" @@ -260,8 +275,10 @@ function openInBrowser { ### Program starts here ### +# Make sure the data directory exists mkdir -p "$GRPOPPRO_DATA_DIR" +# Exit if a VPN connection is active if [[ "$OSTYPE" == "linux-gnu" ]]; then if nmcli connection show --active | grep -i -q wireguard; then echo "Exiting because a vpn connection is active" @@ -269,6 +286,7 @@ if [[ "$OSTYPE" == "linux-gnu" ]]; then 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 [[ "$#" -lt 1 ]] && usage