Compare commits

...

10 Commits

Author SHA1 Message Date
e9aba9ecc8 I'm sorry. 2025-02-11 19:03:04 +02:00
72e04ddce1 [skip ci] I'll fix the build monday 2025-02-03 21:38:55 +02:00
74755a8cf3 Well, it's doing something. 2025-01-25 06:41:24 +02:00
aac3ab50b0 Minor updates 2025-01-15 16:58:59 +02:00
0cdca31be9 At times like this I wish I was a Garbage Man. 2025-01-05 14:18:34 +02:00
8542fd1607 GIT :/ 2025-01-05 13:38:40 +02:00
4ffc2ffef6 Fix hard-coded [object Object] string (thanks!) 2025-01-05 13:30:05 +02:00
37d3bf2df3 Is there an achievement for this? 2025-01-05 13:25:30 +02:00
68f9a4cece Now reading a config file using fallback values 2025-01-05 02:03:18 +02:00
a4cd17f597 Local variables instead of global ones 2025-01-05 01:02:20 +02:00

249
grpoppro
View File

@@ -2,15 +2,12 @@
## Definitions
GRPOPPRO_DATA_DIR="${XDG_DATA_HOME:-$HOME/.local/share}/grpoppro"
GRPOPPRO_CONFIG_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/grpoppro"
GRPOPPRO_CONFIG_FILE="$GRPOPPRO_CONFIG_DIR/grpopprorc"
GRPOPPRO_DATA_FILE="$GRPOPPRO_DATA_DIR/lastPlayedSeries"
GRPOPPRO_PLAYLIST_FILE="$GRPOPPRO_DATA_DIR/lastPlaylistPlayed"
GRPOPPRO_COOKIE_FILE="$GRPOPPRO_DATA_DIR/cookies.txt"
GRPOPPRO_HISTORY_FILE="$GRPOPPRO_DATA_DIR/history"
INTERACTIVE="on"
DEBUG="on"
menu="fuzzel -d -p "
#menu="fzf -i --prompt="
apiurl="https://coverapi.store"
### Curl constants
USER_AGENT="Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/117.0"
ACCEPT="Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"
@@ -18,7 +15,6 @@ ACCEPT_LANGUAGE="Accept-Language: en-US,en;q=0.5"
CONNECTION="Connection: keep-alive"
UP_IN_REQ="Upgrade-Insecure-Requests: 1"
### End of curl constants
player="mpv"
MPV_OPTS='--vo=gpu \
--gpu-api=opengl \
--opengl-es=yes \
@@ -32,10 +28,12 @@ MPV_OPTS='--vo=gpu \
# Display a message
function message {
if [[ "$INTERACTIVE" == "on" ]]; then
notify-send -t 2000 "$1"
local interactive="$GRPOPPRO_INTERACTIVE"
local msg="$1"
if [[ "$interactive" == "on" ]]; then
notify-send -t 2000 "$msg"
else
echo -e "\n\t$1"
echo -e "\n\t$msg"
fi
}
@@ -66,10 +64,10 @@ function curlRequest {
# Dynamically shift the total number of times needed
shift $((shifts - 1))
if [[ "$DEBUG" == "off" ]]; then
if [[ "$GRPOPPRO_DEBUG" == "off" ]]; then
if [[ "$OSTYPE" == "linux-gnu" ]]; then
response="$(curl_ff117 -s -L \
response="$(curl_chrome131 -s -L \
-c"$GRPOPPRO_COOKIE_FILE" \
-b"$GRPOPPRO_COOKIE_FILE" \
"$url" \
@@ -103,7 +101,7 @@ function curlRequest {
if [[ "$OSTYPE" == "linux-gnu" ]]; then
LOG_FILE="/tmp/grpoppro_curl_commands.log"
local curl_command=(
"curl_ff117"
"curl_chrome131"
"-s"
"-L"
"-c$GRPOPPRO_COOKIE_FILE"
@@ -173,6 +171,11 @@ function getFzfForTermux {
# Retrieve IMDb ID
function getIMDBID {
local title="$1"
local response
local imdbid
response="$(curlRequest "https://www.imdb.com/find/?q=$title")"
imdbid="$(echo "$response" \
| grep -io ' href=['"'"'"][^"'"'"']*['"'"'"]' \
@@ -189,18 +192,31 @@ function getIMDBID {
message "Film or show not found in imdb"
exit 0
fi
echo "$imdbid"
}
# Prepare basic steps for a request
function basics {
title="$1"
local title="$1"
local imdbid
local simpleurl
title="${title// /%20}"
getIMDBID "$title"
imdbid="$(getIMDBID "$title")"
simpleurl="$apiurl/embed/$imdbid/"
echo "$simpleurl"
}
# Retrieve internal ID
function getInternalID {
local simpleurl="$1"
local response
local internalid
response="$(curlRequest "$simpleurl")"
if echo "$response" | grep -q "404 Not Found"; then
message "Non valid response"
@@ -215,11 +231,19 @@ function getInternalID {
| awk '{print $5}' \
| awk -F\' '{print $2}'
)"
echo "$internalid"
}
# Retrieve movie stream URL
function getMovieStreamUrl {
local internalid="$1"
local PHPSESSID
PHPSESSID="$(grep 'PHPSESSID' "$GRPOPPRO_COOKIE_FILE" | awk '{print $NF}')"
local response
local streamurl
local headers=(
'-H Accept-Encoding: gzip, deflate, br, zstd'
'-H Content-Type: application/x-www-form-urlencoded; charset=UTF-8'
@@ -247,22 +271,30 @@ function getMovieStreamUrl {
| sed 's/\\//g' \
| grep -oP 'file:"\K[^"]+'
)"
echo "$streamurl"
}
# Stream the video
function play {
local streamurl="$1"
if [[ "$player" == "mpv" ]]; then
MPVPID="$(pidof mpv | cut -d' ' -f1)"
[[ -n "$MPVPID" ]] && kill -s SIGTERM "$MPVPID"
player="mpv --save-position-on-quit ${MPV_OPTS}"
fi
[[ "$OSTYPE" != "linux-gnu" ]] && INTERACTIVE="off" && streamurl="${streamurl//https/http}"
[[ "$OSTYPE" != "linux-gnu" ]] && GRPOPPRO_INTERACTIVE="off" && streamurl="${streamurl//https/http}"
# No setsid -f here because we need to wait for mpv to finish
eval "$player" "$streamurl"
}
# Dump data to files
function dumpData {
local title="$1"
local seasonEpisode="$2"
local streamurl="$3"
echo "$title" > "$GRPOPPRO_DATA_FILE"
echo "$seasonEpisode" >> "$GRPOPPRO_DATA_FILE"
echo "$streamurl" >> "$GRPOPPRO_DATA_FILE"
@@ -273,17 +305,31 @@ function dumpData {
# Source data from files
function sourceData {
local lastSeriesPlayed
local lastSeasonEpisodePlayed
local lastEpisodePlayedURL
if [[ -f "$GRPOPPRO_DATA_FILE" ]]; then
lastSeriesPlayed="$(sed -n 1p "$GRPOPPRO_DATA_FILE")"
lastSeasonEpisodePlayed="$(sed -n 2p "$GRPOPPRO_DATA_FILE")"
lastEpisodePlayedURL="$(sed -n 3p "$GRPOPPRO_DATA_FILE")"
fi
echo "$lastSeriesPlayed|$lastSeasonEpisodePlayed|$lastEpisodePlayedURL"
}
# Perform menu search
function menuSearch {
local title
local imdbid
local simpleurl
local internalid
local response
local seasonEpisode
local streamurl
# Two requests to the api
if [[ "$INTERACTIVE" == "on" ]]; then
if [[ "$GRPOPPRO_INTERACTIVE" == "on" ]]; then
title=$(echo "" | wofi --dmenu --insensitive --prompt="Search Series" --width=300 --height=50)
else
read -r -p "Search Series: " title
@@ -293,9 +339,9 @@ function menuSearch {
exit 0
fi
title="${title// /%20}"
getIMDBID "$title"
imdbid="$(getIMDBID "$title")"
simpleurl="$apiurl/embed/$imdbid/"
getInternalID "$simpleurl"
internalid="$(getInternalID "$simpleurl")"
response="$(curlRequest "$apiurl/uploads/playlists/$internalid.txt")"
echo "$response" > "$GRPOPPRO_PLAYLIST_FILE"
title="$(grep "mp4" "$GRPOPPRO_PLAYLIST_FILE" \
@@ -320,8 +366,8 @@ function menuSearch {
| head -n1 \
| awk -F\" '{print $4}'
)"
dumpData "$title" "$seasonEpisode"
play
dumpData "$title" "$seasonEpisode" "$streamurl"
play "$streamurl"
resume
}
@@ -332,29 +378,39 @@ function resume {
message "Nothing to resume"
exit 0
fi
sourceData
title=$lastSeriesPlayed
local data
local title
data="$(sourceData)"
title="$(echo "$data" | cut -d '|' -f1)"
while true
do
sourceData
seasonEpisode="$(jq '.[]' "$GRPOPPRO_PLAYLIST_FILE" \
data="$(sourceData)"
local seasonEpisode
local lastSeasonEpisodePlayed
lastSeasonEpisodePlayed="$(echo "$data" | cut -d '|' -f2)"
episodes_left="$(jq '.[]' "$GRPOPPRO_PLAYLIST_FILE" \
| grep "mp4" \
| awk -F/ '{print $NF}' \
| awk -F. '{print $1}' \
| sed -n -e "0,/$lastSeasonEpisodePlayed/!p" \
| eval "$menu"\""$title" \"
| sed -n -e "0,/$lastSeasonEpisodePlayed/!p"
)"
if [[ -z "$episodes_left" ]]; then
message "You finished $title"
exit 0
fi
seasonEpisode="$(printf "%s" "$episodes_left" | eval "$menu"\""$title" \")"
if [[ -z "$seasonEpisode" ]]; then
message "Nothing Selected"
exit 0
fi
local streamurl
streamurl="$(jq '.[]' "$GRPOPPRO_PLAYLIST_FILE" \
| grep "${seasonEpisode}" \
| head -n1 \
| awk -F\" '{print $4}'
)"
dumpData "$title" "$seasonEpisode"
play
dumpData "$title" "$seasonEpisode" "$streamurl"
play "$streamurl"
done
}
@@ -367,6 +423,7 @@ function resumeSeries {
exit 0
fi
local resume_series
resume_series="$(awk -F'|' '{print $1}' "$GRPOPPRO_HISTORY_FILE" \
| sort \
| uniq \
@@ -377,29 +434,32 @@ function resumeSeries {
exit 0
fi
local resume_episode
resume_episode="$(grep "^$resume_series|" "$GRPOPPRO_HISTORY_FILE" | awk -F'|' '{print $2}')"
if [[ -n "$resume_episode" ]]; then
message "Continuing $resume_series from $resume_episode"
fi
local resume_streamurl
resume_streamurl=$(grep "^$resume_series|$resume_episode|" "$GRPOPPRO_HISTORY_FILE" | awk -F'|' '{print $3}')
title="$resume_series"
local title="$resume_series"
local lastTitle
lastTitle="$(sed -n 1p "$GRPOPPRO_DATA_FILE")"
if [[ ! "$title" == "$lastTitle" ]]; then
title="${title// /%20}"
getIMDBID "$title"
imdbid="$(getIMDBID "$title")"
simpleurl="$apiurl/embed/$imdbid/"
getInternalID "$simpleurl"
internalid="$(getInternalID "$simpleurl")"
response="$(curlRequest "$apiurl/uploads/playlists/$internalid.txt")"
echo "$response" > "$GRPOPPRO_PLAYLIST_FILE"
fi
title="$(grep "mp4" "$GRPOPPRO_PLAYLIST_FILE" | head -n1 | awk -F/ '{print $(NF-1)}')"
title="${title//_/ }"
title="${title//-/ }"
seasonEpisode="$resume_episode"
streamurl="$resume_streamurl"
dumpData "$title" "$seasonEpisode"
play
local seasonEpisode="$resume_episode"
local streamurl="$resume_streamurl"
dumpData "$title" "$seasonEpisode" "$streamurl"
play "$streamurl"
resume
}
@@ -410,15 +470,22 @@ function resumeUnfinishedEpisode {
message "Nothing to resume"
exit 0
fi
sourceData
local data
local lastSeriesPlayed
local lastSeasonEpisodePlayed
local lastEpisodePlayedURL
data="$(sourceData)"
lastSeriesPlayed="$(echo "$data" | cut -d '|' -f1)"
lastSeasonEpisodePlayed="$(echo "$data" | cut -d '|' -f2)"
lastEpisodePlayedURL="$(echo "$data" | cut -d '|' -f3)"
message "Continuing $lastSeriesPlayed from $lastSeasonEpisodePlayed"
streamurl="$lastEpisodePlayedURL"
local streamurl="$lastEpisodePlayedURL"
if [[ "$player" == "mpv" ]]; then
MPVPID="$(pidof mpv | cut -d' ' -f1)"
[[ -n "$MPVPID" ]] && kill -s SIGTERM "$MPVPID"
player="mpv --resume-playback ${MPV_OPTS}"
fi
[[ "$OSTYPE" != "linux-gnu" ]] && INTERACTIVE="off" && streamurl="${streamurl//https/http}"
[[ "$OSTYPE" != "linux-gnu" ]] && GRPOPPRO_INTERACTIVE="off" && streamurl="${streamurl//https/http}"
# No setsid -f here because we need to wait for mpv to finish
eval "$player" "$streamurl"
resume
@@ -426,9 +493,13 @@ function resumeUnfinishedEpisode {
# Open in browser to watch
function openInBrowser {
local title="$2"
local simpleurl
# One request to the api
basics "$2"
getInternalID "$simpleurl"
simpleurl="$(basics "$title")"
local internalid
internalid="$(getInternalID "$simpleurl")"
xdg-open "$simpleurl"
exit 0
}
@@ -439,6 +510,7 @@ function getHistory {
exit 0
fi
local history
history="$(awk -F'|' '{print $1,":<=> At =>",$2}' "$GRPOPPRO_HISTORY_FILE" | column -t -s':')"
message "$history"
@@ -446,12 +518,18 @@ function getHistory {
}
function getSeries {
local title="$1"
local season="$2"
local episode="$3"
local simpleurl
simpleurl="$(basics "$title")"
local internalid
internalid="$(getInternalID "$simpleurl")"
local response
# Two requests to the api
basics "$1"
getInternalID "$simpleurl"
season="$2"
episode="$3"
response="$(curlRequest "$apiurl/uploads/playlists/$internalid.txt")"
local streamurl
streamurl="$(echo "$response" \
| jq '.[]' \
| grep "mp4" \
@@ -460,34 +538,94 @@ function getSeries {
| awk -F\" '{print $4}'
)"
title="${title//%20/ }"
local capitalized_title
capitalized_title="$(echo "$title" | awk '{for(i=1;i<=NF;i++) $i=toupper(substr($i,1,1)) substr($i,2)}1')"
message "Loading $capitalized_title at season $season on episode $episode"
play
play "$streamurl"
exit 0
}
function getMovie {
local simpleurl
# Two requests to the api
if [[ "$1" == *"tt"* ]]; then
simpleurl="$1"
else
basics "$1" # Gets the title, performs one request to imdb and gets the complete url
simpleurl="$(basics "$1")" # Gets the title, performs one request to imdb and gets the complete url
fi
getInternalID "$simpleurl" # Gets the complete url and performs one request to get the internal id or inform us it does not exist
getMovieStreamUrl "$internalid" # Gets the internal id and performs one request to get the stream url
title="${title//%20/ }"
local internalid
internalid="$(getInternalID "$simpleurl")" # Gets the complete url and performs one request to get the internal id or inform us it does not exist
local streamurl
streamurl="$(getMovieStreamUrl "$internalid")" # Gets the internal id and performs one request to get the stream url
local title="${title//%20/ }"
local capitalized_title
capitalized_title="$(echo "$title" | awk '{for(i=1;i<=NF;i++) $i=toupper(substr($i,1,1)) substr($i,2)}1')"
message "Loading $capitalized_title"
play # It uses mpv to stream the file
play "$streamurl" # It uses mpv to stream the file
exit 0
}
### Program starts here ###
# Prepare the necessary steps for Termux environment
if [[ "$OSTYPE" != "linux-gnu" ]]; then
GRPOPPRO_INTERACTIVE="off"
menu="fzf -i --prompt=seasonXepisode"
player="am start -n is.xyz.mpv/.MPVActivity -a android.intent.action.VIEW -d"
getFzfForTermux
fi
if [[ -f "$GRPOPPRO_CONFIG_FILE" ]]; then
while IFS='=' read -r key value; do
# Ignore lines starting with #
if [[ "$key" =~ ^#.* ]]; then
continue
fi
# Check if value starts and ends with quotes
if [[ $value =~ ^\".*\"$ ]]; then
# Remove surrounding quotes, but preserve internal spaces
value="${value%\"}" # Remove trailing quote
value="${value#\"}" # Remove leading quote
else
# Wont appear for empty config file
# But will appear for empty lines
echo "Invalid value found"
exit 1
fi
export "$key=$value"
done < "$GRPOPPRO_CONFIG_FILE"
else
echo "Configuration file not found!"
echo "Creating one at $GRPOPPRO_CONFIG_FILE"
mkdir -p "$GRPOPPRO_CONFIG_DIR"
# touch "$GRPOPPRO_CONFIG_FILE"
DEFAULTS=$(cat <<EOF
GRPOPPRO_INTERACTIVE="on"
GRPOPPRO_DEBUG="on"
apiurl="https://coverapi.store"
menu="fuzzel -d -p "
# menu="fzf -i --prompt="
player="mpv"
EOF
)
echo "$DEFAULTS" > "$GRPOPPRO_CONFIG_FILE"
echo "Try again"
exit 1
fi
# Set default values if not set in config
: "${GRPOPPRO_INTERACTIVE:=on}"
: "${GRPOPPRO_DEBUG:=on}"
: "${apiurl:=https://coverapi.store}"
: "${player:=mpv}"
: "${menu:=fuzzel -d -p }"
# Ensure curl-impersonate is installed
if ! command -v curl-impersonate-ff >/dev/null 2>&1; then
message "You should get curl-impersonate to make it seem less obvious you use curl"
exit 0
if [[ "$OSTYPE" == "linux-gnu" ]]; then
if ! command -v curl-impersonate-chrome >/dev/null 2>&1; then
message "You should get curl-impersonate to make it seem less obvious you use curl"
exit 0
fi
fi
# Make sure the data directory exists
@@ -496,14 +634,11 @@ 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"
message "Exiting because a vpn connection is active"
exit 0
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
[[ "$#" -gt 3 ]] && usage
[[ "$#" -eq 3 ]] && getSeries "$@"