Become a programmer, they said. It'll be fun, they said.

This commit is contained in:
2024-12-17 23:45:34 +02:00
parent a1640e804e
commit beb33b5fd8
2 changed files with 167 additions and 124 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
*.txt

290
grpoppro
View File

@@ -1,170 +1,212 @@
#!/usr/bin/env bash #!/usr/bin/env bash
GRPOPPRO_DATA_DIR=~/.local/share/grpoppro GRPOPPRO_DATA_DIR=${XDG_DATA_HOME:-$HOME/.local/share}/grpoppro
#GRPOPPRO_DATA_DIR=${XDG_DATA_HOME:-$HOME/.local/}/grpoppro GRPOPPRO_DATA_FILE=$GRPOPPRO_DATA_DIR/lastPlayedSeries
GRPOPPRO_DATA_FILE=$GRPOPPRO_DATA_DIR/lastPlayed GRPOPPRO_PLAYLIST_FILE=$GRPOPPRO_DATA_DIR/lastPlaylistPlayed
GRPOPPRO_COOKIE_FILE=$GRPOPPRO_DATA_DIR/cookies.txt
INTERACTIVE="on" INTERACTIVE="on"
menu="rofi -show -dmenu -p " menu="fuzzel -d -p "
#menu="fzf -i --prompt=" #menu="fzf -i --prompt="
#menu="dmenu -i -l 10 -p "
apiurl="https://coverapi.store" apiurl="https://coverapi.store"
player="mpv" player="mpv"
function getFzfForTermux { mkdir -p "$GRPOPPRO_DATA_DIR"
if command -v fzf >/dev/null 2>&1; then
echo -e "\n" if nmcli connection show --active | grep -i -q wireguard; then
else echo exiting because vpn is active
apt install -y fzf exit 0
fi fi
function getFzfForTermux {
if command -v fzf >/dev/null 2>&1; then
echo -e "\n"
else
apt install -y fzf
fi
} }
[[ "$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
function getMovieStreamUrl() { function getMovieStreamUrl() {
streamurl=$(curl -s 'https://coverapi.store/engine/ajax/controller.php' \ PHPSESSID="$(grep 'PHPSESSID' "$GRPOPPRO_COOKIE_FILE" | awk '{print $NF}')"
-H 'Connection: keep-alive' \ streamurl="$(curl -s -L -c "$GRPOPPRO_COOKIE_FILE" -b "$GRPOPPRO_COOKIE_FILE" "$apiurl/engine/ajax/controller.php" --compressed -X POST \
-H 'sec-ch-ua: " Not A;Brand";v="99", "Chromium";v="98"' \ -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:133.0) Gecko/20100101 Firefox/133.0' \
-H 'Accept: application/json, text/javascript, */*; q=0.01' \ -H 'Accept: application/json, text/javascript, */*; q=0.01' \
-H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' \ -H 'Accept-Language: en-US,en;q=0.5' \
-H 'X-Requested-With: XMLHttpRequest' \ -H 'Accept-Encoding: gzip, deflate, br, zstd' \
-H 'sec-ch-ua-mobile: ?0' \ -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' \
-H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.80 Safari/537.36' \ -H 'X-Requested-With: XMLHttpRequest' \
-H 'sec-ch-ua-platform: "Linux"' \ -H "Origin: $apiurl" \
-H 'Origin: https://coverapi.store' \ -H 'DNT: 1' \
-H 'Sec-Fetch-Site: same-origin' \ -H 'Sec-GPC: 1' \
-H 'Sec-Fetch-Mode: cors' \ -H 'Connection: keep-alive' \
-H 'Sec-Fetch-Dest: empty' \ -H "Referer: $simpleurl" \
-H 'Referer: '$simpleurl'' \ -H "Cookie: PHPSESSID=$PHPSESSID" \
-H 'Accept-Language: en-GB,en;q=0.9,el;q=0.8' \ -H 'Sec-Fetch-Dest: empty' \
-H 'Cookie: PHPSESSID=6be2a34628cde3aeefbfed1020a10127' \ -H 'Sec-Fetch-Mode: cors' \
--data-raw 'mod=players&news_id='$movieid'' \ -H 'Sec-Fetch-Site: same-origin' \
--compressed | awk '{print $12}' | awk -F, '{print $1}' | sed 's/\\//g' | awk -F\" '{print $2}') -H 'TE: trailers' \
--data-raw "mod=players&news_id=$internalid" \
| sed 's/\\//g' | grep -oP 'file:"\K[^"]+'
)"
} }
function getMovieID() { function getInternalID() {
movieid=$(curl -s $simpleurl | grep news_id | awk '{print $5}' | awk -F\' '{print $2}') 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" \
-H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8" \
function getSeriesID_URL { -H "Accept-Language: en-US,en;q=0.5" \
getMovieID "$simpleurl" -H "Connection: keep-alive" \
seriesid=$movieid -H "Upgrade-Insecure-Requests: 1" \
seriesurl=$(curl -s 'https://coverapi.store/uploads/playlists/'$seriesid'.txt') "$simpleurl"
)"
if echo "$response" | grep -q "id='el-content'></div>"; then
[[ "$INTERACTIVE" == "on" ]] && notify-send -t 2000 "No file found" || echo -e "\n\tNo file found" && exit
fi
internalid="$(echo "$response" | grep news_id | awk '{print $5}' | awk -F\' '{print $2}')"
} }
function getIMDBID() { function getIMDBID() {
imdbid=$(curl -s "https://www.imdb.com/find?ref_=nv_sr_fn&s=all&q=$title" | grep -io ' href=['"'"'"][^"'"'"']*['"'"'"]' | grep 'href="/title/'| head -n1 | sed -e 's/href="\/title\///' -e 's/\/?.*//' -e 's/^ //') imdbid="$(curl -s "http://imdb.konsthol.eu/find?q=$title" | grep -io ' href=['"'"'"][^"'"'"']*['"'"'"]' | grep title | head -n1 | sed -e 's/^ //' -e 's/href="\/title\///' -e 's/"//')"
if ! [[ "$imdbid" == *"tt"* ]];then if ! [[ "$imdbid" == *"tt"* ]]; then
[[ "$INTERACTIVE" == "on" ]] && notify-send -t 2000 "Film or show not found in imdb" || echo -e "\n\tFilm or show not found in imdb" [[ "$INTERACTIVE" == "on" ]] && notify-send -t 2000 "Film or show not found in imdb" || echo -e "\n\tFilm or show not found in imdb"
exit exit
fi fi
} }
function usage { function usage {
echo -e "\n\tUsage: $(basename "$0") \"name of film or show\" [season] [episode(ex 01 02 .. 10 11)]\n\tOr $(basename "$0") [--menu|--resume|--finish]" echo -e "\n\tUsage: $(basename "$0") \"name of film or show\" [season] [episode(ex 01 02 .. 10 11)]\n\tOr $(basename "$0") [--menu|--resume|--finish]"
exit exit
} }
function play {
if $(curl -s $simpleurl | grep -q "id='el-content'></div>");
then [[ "$INTERACTIVE" == "on" ]] && notify-send -t 2000 "No file found" || echo -e "\n\tNo file found" && exit
fi
[[ "$player" == "mpv" ]] && player="mpv --save-position-on-quit --fs"
[[ "$OSTYPE" != "linux-gnu" ]] && INTERACTIVE="off" && streamurl=$(echo $streamurl | sed 's/https/http/g')
$player $streamurl
}
function dumpData() {
echo $title > ~/.local/share/grpoppro/lastPlayed
echo $seasonEpisode >> ~/.local/share/grpoppro/lastPlayed
echo $streamurl >> ~/.local/share/grpoppro/lastPlayed
[[ "$INTERACTIVE" == "on" ]] && notify-send -t 2000 "Last Played -> $seasonEpisode" || echo "Last Played -> $seasonEpisode"
function play {
[[ "$player" == "mpv" ]] && player="mpv --save-position-on-quit --fs"
[[ "$OSTYPE" != "linux-gnu" ]] && INTERACTIVE="off" && streamurl="${streamurl//https/http}"
eval "$player" "$streamurl"
} }
function dumpData() {
echo "$title" > "$GRPOPPRO_DATA_FILE"
echo "$seasonEpisode" >> "$GRPOPPRO_DATA_FILE"
echo "$streamurl" >> "$GRPOPPRO_DATA_FILE"
[[ "$INTERACTIVE" == "on" ]] && notify-send -t 2000 "Last Played -> $seasonEpisode" || echo "Last Played -> $seasonEpisode"
}
function sourceData { function sourceData {
[ -f "$GRPOPPRO_DATA_FILE" ] && lastSeasonEpisodePlayed="$(sed -n 2p $GRPOPPRO_DATA_FILE)" && lastSeriesPlayed="$(sed -n 1p $GRPOPPRO_DATA_FILE)" && lastEpisodePlayedURL="$(sed -n 3p $GRPOPPRO_DATA_FILE)" [ -f "$GRPOPPRO_DATA_FILE" ] && lastSeasonEpisodePlayed="$(sed -n 2p "$GRPOPPRO_DATA_FILE")" && lastSeriesPlayed="$(sed -n 1p "$GRPOPPRO_DATA_FILE")" && lastEpisodePlayedURL="$(sed -n 3p "$GRPOPPRO_DATA_FILE")"
} }
[[ "$#" -lt 1 ]] && usage [[ "$#" -lt 1 ]] && usage
[[ "$#" -gt 3 ]] && usage [[ "$#" -gt 3 ]] && usage
[[ "$#" -eq 2 ]] && usage [[ "$#" -eq 2 ]] && usage
#Standard Stuff #Standard Stuff
function basics() { function basics() {
title=$(echo "$1" | sed 's/ /%20/g') title="$1"
getIMDBID "$title" title="${title// /%20}"
simpleurl=$apiurl/embed/$imdbid/ getIMDBID "$title"
simpleurl="$apiurl/embed/$imdbid/"
} }
function menuSearch { function menuSearch {
[[ "$INTERACTIVE" == "on" ]] && title=$(rofi -dmenu -i -no-fixed-num-lines -p "Search Series") # Two requests to the api
[[ "$INTERACTIVE" == "off" ]] && [[ -z "$title" ]] && read -p "Search Series: " title [[ "$INTERACTIVE" == "on" ]] && title=$(echo "" | wofi --dmenu --insensitive --prompt="Search Series" --width=300 --height=50)
[[ -z "$title" ]] && exit [[ "$INTERACTIVE" == "off" ]] && [[ -z "$title" ]] && read -r -p "Search Series: " title
title=$(echo $title | sed 's/ /%20/g') [[ -z "$title" ]] && exit
getIMDBID "$title" title="${title// /%20}"
simpleurl=$apiurl/embed/$imdbid/ getIMDBID "$title"
getSeriesID_URL simpleurl="$apiurl/embed/$imdbid/"
seasonEpisode=$(curl -s 'https://coverapi.store/uploads/playlists/'$seriesid'.txt' | grep "mp4" | awk -F\" '{print $8}' | awk -F/ '{print $NF}' | awk -F. '{print $1}' | $menu"$(echo $title | sed 's/%20/ /g')") getInternalID "$simpleurl"
if [[ -z "$seasonEpisode" ]]; then response="$(curl -s -L -c "$GRPOPPRO_COOKIE_FILE" -b "$GRPOPPRO_COOKIE_FILE" \
[[ "$INTERACTIVE" == "on" ]] && notify-send -t 2000 "Nothing Selected" || echo "Nothing Selected" -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:133.0) Gecko/20100101 Firefox/133.0" \
exit -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8" \
fi -H "Accept-Language: en-US,en;q=0.5" \
streamurl=$(curl -s 'https://coverapi.store/uploads/playlists/'$seriesid'.txt' | grep "mp4" | grep "${seasonEpisode}" | head -n 1 | awk -F\" '{print $8}') -H "Connection: keep-alive" \
mkdir -p ~/.local/share/grpoppro -H "Upgrade-Insecure-Requests: 1" \
dumpData "$title" "$seasonEpisode" "$apiurl/uploads/playlists/$internalid.txt"
play )"
resume echo "$response" > "$GRPOPPRO_PLAYLIST_FILE"
title="$(grep "mp4" "$GRPOPPRO_PLAYLIST_FILE" | head -n1 | awk -F/ '{print $(NF-1)}')"
title="${title//_/ }"
seasonEpisode="$(grep "mp4" "$GRPOPPRO_PLAYLIST_FILE" | awk -F\" '{print $8}' | awk -F/ '{print $NF}' | awk -F. '{print $1}' | eval "$menu"\""$title"\")"
if [[ -z "$seasonEpisode" ]]; then
[[ "$INTERACTIVE" == "on" ]] && notify-send -t 2000 "Nothing Selected" || echo "Nothing Selected"
exit
fi
streamurl="$(grep "mp4" "$GRPOPPRO_PLAYLIST_FILE" | grep "${seasonEpisode}" | head -n1 | awk -F\" '{print $8}')"
dumpData "$title" "$seasonEpisode"
play
resume
} }
function resume { function resume {
sourceData # Zero requests to the api
title=$lastSeriesPlayed [ ! -f "$GRPOPPRO_DATA_FILE" ] && echo "Nothing to resume" && exit
getIMDBID "$title" sourceData
while true title=$lastSeriesPlayed
do while true
sourceData do
simpleurl=$apiurl/embed/$imdbid/ sourceData
getSeriesID_URL seasonEpisode="$(grep "mp4" "$GRPOPPRO_PLAYLIST_FILE" | awk -F\" '{print $8}' | awk -F/ '{print $NF}' | awk -F. '{print $1}' | sed -n -e "0,/$lastSeasonEpisodePlayed/!p" | eval "$menu"\""$title"\")"
seasonEpisode=$(curl -s 'https://coverapi.store/uploads/playlists/'$seriesid'.txt' | grep "mp4" | awk -F\" '{print $8}' | awk -F/ '{print $NF}' | awk -F. '{print $1}' | sed -n -e "0,/$lastSeasonEpisodePlayed/!p" | $menu"$(echo $title | sed 's/%20/ /g')") if [[ -z "$seasonEpisode" ]]; then
if [[ -z "$seasonEpisode" ]]; then [[ "$INTERACTIVE" == "on" ]] && notify-send -t 2000 "Nothing Selected" || echo "Nothing Selected"
[[ "$INTERACTIVE" == "on" ]] && notify-send "Nothing Selected" || echo "Nothing Selected" exit
exit fi
fi streamurl="$(grep "mp4" "$GRPOPPRO_PLAYLIST_FILE" | grep "${seasonEpisode}" | head -n1 | awk -F\" '{print $8}')"
streamurl=$(curl -s 'https://coverapi.store/uploads/playlists/'$seriesid'.txt' | grep "mp4" | grep "${seasonEpisode}" | head -n 1 | awk -F\" '{print $8}') dumpData "$title" "$seasonEpisode"
dumpData "$title" "$seasonEpisode" play
play done
done
}
function resumeUnfinishedEpisode {
sourceData
streamurl=$lastEpisodePlayedURL
[[ "$OSTYPE" != "linux-gnu" ]] && INTERACTIVE="off" && streamurl=$(echo $streamurl | sed 's/https/http/g')
[[ "$player" == "mpv" ]] && player="mpv --resume-playback --fs"
$player $streamurl
resume
} }
[[ "$1" == "--menu" ]] && menuSearch function resumeUnfinishedEpisode {
[[ "$1" == "--resume" ]] && resume # Zero requests to the api
[ ! -f "$GRPOPPRO_DATA_FILE" ] && echo "Nothing to resume" && exit
sourceData
streamurl="$lastEpisodePlayedURL"
[[ "$OSTYPE" != "linux-gnu" ]] && INTERACTIVE="off" && streamurl="${streamurl//https/http}"
[[ "$player" == "mpv" ]] && player="mpv --resume-playback --fs"
eval "$player" "$streamurl"
resume
}
[[ "$1" == "--menu" ]] && menuSearch
[[ "$1" == "--resume" ]] && resume
[[ "$1" == "--finish" ]] && resumeUnfinishedEpisode [[ "$1" == "--finish" ]] && resumeUnfinishedEpisode
if [[ "$1" == *"tt"* ]] && [[ "$#" -eq 1 ]] && [[ "$1" != "--menu" ]] && [[ "$1" != "--resume" ]];then # One arguement and it contains the imdb id
simpleurl=$1 if [[ "$1" == *"tt"* ]] && [[ "$#" -eq 1 ]] && [[ "$1" != "--menu" ]] && [[ "$1" != "--resume" ]]; then
getMovieID "$simpleurl" simpleurl="$1"
getMovieStreamUrl "$movieid" getInternalID "$simpleurl"
play getMovieStreamUrl "$internalid"
exit play
exit
fi fi
# Series URL # Series URL
if [[ "$#" -eq 3 ]];then if [[ "$#" -eq 3 ]]; then
basics "$1" # Two requests to the api
getSeriesID_URL basics "$1"
season=$2 getInternalID "$simpleurl"
episode=$3 season="$2"
streamurl=$(curl -s 'https://coverapi.store/uploads/playlists/'$seriesid'.txt' | grep "mp4" | grep "${season}x${episode}" | head -n 1 | awk -F\" '{print $8}') episode="$3"
play streamurl="$(curl -s -L -c "$GRPOPPRO_COOKIE_FILE" -b "$GRPOPPRO_COOKIE_FILE" \
exit -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:133.0) Gecko/20100101 Firefox/133.0" \
-H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8" \
-H "Accept-Language: en-US,en;q=0.5" \
-H "Connection: keep-alive" \
-H "Upgrade-Insecure-Requests: 1" \
"$apiurl/uploads/playlists/$internalid.txt" | grep "mp4" | grep "${season}x${episode}" | head -n1 | awk -F\" '{print $8}')"
play
exit
fi fi
# Movies URL # Movies URL
if [[ "$#" -eq 1 ]] && [[ "$1" != "--menu" ]] && [[ "$1" != "--resume" ]];then if [[ "$#" -eq 1 ]] && [[ "$1" != "--menu" ]] && [[ "$1" != "--resume" ]]; then
basics "$1" # Two requests to the api
getMovieID "$simpleurl" basics "$1" # Gets the title, performs one request to imdb and gets the complete url
getMovieStreamUrl "$movieid" getInternalID "$simpleurl" # Gets the complete url and performs one request to get the internal id or inform us it does not exist
play getMovieStreamUrl "$internalid" # Gets the internal id and performs one request to get the stream url
exit play # It uses mpv to stream the file
exit
fi fi