diff --git a/README.md b/README.md index 3b43265..e139a21 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,14 @@ # tv.sh -A small script to offer a selection menu of channels in thetvapp.to using tofi (or dmenu etc if you change the code) and start playing in mpv. +A small script to offer a channel selection menu through fuzzel and pass the streaming links to mpv. -Intended for those who like the selection but don't necessarily want to add the m3u file to a program like vlc. - -It clones the repo [thetvappstream](https://github.com/habitual69/thetvappstream) which actually does everything for this to be useful. Meaning this is the program that actually provides the channels and the script is just a menu to select them. +It performs requests to epg.pw to retrieve the data. ## Installation ```sh -git clone https://git.konsthol.eu/konsthol/TheTvApp_Menu -cd TheTvApp_Menu +git clone https://git.konsthol.eu/konsthol/MPVTV +cd MPVTV sudo cp tv.sh /usr/bin/ (Or cp tv.sh anywhere in your $PATH) ``` @@ -24,21 +22,16 @@ Simply run `tv.sh stream` or `tv.sh schedule` or even better assign those two fu * git * curl * sed -* tofi (or dmenu if you change the code) +* awk +* fuzzel (or dmenu if you change the code) * mpv * grep -* npm -* node -* pup * jq +* cut * notify-send (Optional) ## Credits go to -* [habitual69](https://github.com/habitual69) +* [EPG](https://epg.pw/) -As this script uses his [thetvappstream](https://github.com/habitual69/thetvappstream) script. - -* [THETVAPP](https://thetvapp.to/) - -As they provide the channel streams. +As they provide the data. diff --git a/tv.sh b/tv.sh index 58c817d..12ba562 100755 --- a/tv.sh +++ b/tv.sh @@ -1,130 +1,214 @@ #!/usr/bin/env bash -function streamChannel { +MPVTV_DATA_DIR=${XDG_DATA_HOME:-$HOME/.local/share}/mpvtv -if [[ ! -d "$HOME/Gits/thetvappstream/" ]]; then - mkdir -p "$HOME/Gits" - notify-send -t 2000 "Cloning necessary repositories" - git clone https://github.com/habitual69/thetvappstream "$HOME/Gits/thetvappstream" - cd "$HOME/Gits/thetvappstream/" || exit - notify-send -t 2000 "Copying .env_example to .env" - cp .env_example .env - notify-send -t 2000 "Installing necessary dependencies" - npm -g install -fi +apiurl="https://epg.pw" +RESPONSE1_FILE="${MPVTV_DATA_DIR}/response1.txt" +RESPONSE2_FILE="${MPVTV_DATA_DIR}/response2.txt" +RESPONSE3_FILE="${MPVTV_DATA_DIR}/response3.txt" +COOKIES_FILE="${MPVTV_DATA_DIR}/cookies.txt" +CHANNELS_FILE="${MPVTV_DATA_DIR}/channels.txt" +SCHEDULE_FILE="${MPVTV_DATA_DIR}/schedule.json" +CORRECT_SCHEDULE_FILE="${MPVTV_DATA_DIR}/correct_schedule.json" +M3U8_FILE="${MPVTV_DATA_DIR}/m3u8.txt" -cd "$HOME/Gits/thetvappstream/" || exit - -PIDAPP="$(pgrep -f "node app.js")" -PIDMPV="$(pgrep mpv)" -IP=$(hostname -i) - -[[ -n "$PIDAPP" ]] && kill -9 "$PIDAPP" - -notify-send -t 2000 "Getting channels list" - -setsid -f node app.js -sleep 5 - -channel="$(curl -s "http://$IP:5000/channels.m3u" | grep "channel/" | xargs -L1 basename | tofi --include "$HOME"/.config/tofi/tofiColors --num-results 10 --prompt-text Channels: )" - -# channel="$(grep tvg-id "$PLAYLIST_FILE" | awk '{print $2}' | sed 's/[^"]*"\([^"]*\)".*/\1/' | rofi -dmenu -i -l 20 -p 'Channels')" - -if [[ -n "$channel" ]]; then - [[ -n "$PIDMPV" ]] && kill -9 "$PIDMPV" - notify-send -t 2000 "Playing $channel" - setsid -f mpv --vo=gpu --gpu-api=opengl --opengl-es=yes --term-osd-bar "http://$IP:5000/channel/$channel" - sleep 5 - kill -9 "$(pgrep -f "node app.js")" -else - notify-send -t 2000 "Nothing was chosen" - kill -9 "$(pgrep -f "node app.js")" -fi - -[[ -n "$PIDAPP" ]] && kill -9 "$PIDAPP" -cd ~ || exit -exit 0 +mkdir -p "${MPVTV_DATA_DIR}" +function usage { + echo "Usage: $(basename "$0") [stream|schedule]" + exit 0 } +function clearFiles { + [[ -f "$RESPONSE2_FILE" ]] && rm "$RESPONSE2_FILE" + [[ -f "$RESPONSE3_FILE" ]] && rm "$RESPONSE3_FILE" + [[ -f "$SCHEDULE_FILE" ]] && rm "$SCHEDULE_FILE" + [[ -f "$CORRECT_SCHEDULE_FILE" ]] && rm "$CORRECT_SCHEDULE_FILE" +} + +[[ "$#" -lt 1 ]] && usage +[[ "$#" -gt 1 ]] && usage +if [[ "$#" -eq 1 ]]; then + if [[ "$1" != "stream" ]] && [[ "$1" != "schedule" ]]; then + usage + fi +fi + +if [[ ! -f "$RESPONSE1_FILE" ]]; then + response="$(curl -s -L -c "$COOKIES_FILE" -b "$COOKIES_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" \ + "$apiurl/areas/gb.html?lang=en" + )" + + echo "$response" > "$RESPONSE1_FILE" +fi + +# shellcheck disable=SC1143 +if [[ ! -f "$CHANNELS_FILE" ]]; then + CHANNELS="$( + sed '1,/
/d' "$RESPONSE1_FILE" | \ + sed '/<\/table>/,$d' | \ + awk '/