131 lines
5.0 KiB
Bash
Executable File
131 lines
5.0 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
function streamChannel {
|
|
|
|
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
|
|
|
|
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
|
|
|
|
}
|
|
|
|
function getSchedule {
|
|
|
|
BASEURL="https://thetvapp.to/tv"
|
|
RESULTS="$(curl -s "$BASEURL")"
|
|
CHANNELS="$(printf "%s" "$RESULTS" | pup 'ol json{}' | jq -r '.[].children.[].text' | sed 's/amp;//g')"
|
|
CHANNEL="$(printf "%s" "$CHANNELS" | cat -n | tofi --include "$HOME"/.config/tofi/tofiColors --num-results 10 --prompt-text Channels: | sed 's/^ *//g' | awk '{print $1}')"
|
|
CHANNELURL="$(printf "%s" "$RESULTS" | pup 'ol json{}' | jq -r '.[].children.[].href' | sed "${CHANNEL}q;d")"
|
|
CHANNELID="$(curl -s "https://thetvapp.to$CHANNELURL" | grep jsonUrl | cut -d'+' -f3 | head -n1 | sed 's/^ *//g' | cut -d'"' -f2)"
|
|
CHANNELJSONURL="https://thetvapp.to/json/$CHANNELID.json"
|
|
|
|
GETSCHEDULE=$(cat <<EOF
|
|
#!/usr/bin/env node
|
|
const axios = require('axios');
|
|
let jsonUrl = "$CHANNELJSONURL"
|
|
axios.get(jsonUrl)
|
|
.then(function(response) {
|
|
let mydata = response.data;
|
|
let index = 0;
|
|
for (let i = 0; i < mydata.length; i++) {
|
|
let now = new Date();
|
|
let startTime = new Date(mydata[i]["startTime"] * 1000);
|
|
let endTime = new Date(mydata[i]["endTime"] * 1000);
|
|
if (startTime >= now && now <= endTime) {
|
|
index = i - 1;
|
|
break;
|
|
}
|
|
}
|
|
|
|
for (let i = index; i < mydata.length; i++) {
|
|
let title = mydata[i]["title"];
|
|
if (mydata[i]["episodeTitle"] != null) {
|
|
title = title + " - " + mydata[i]["episodeTitle"];
|
|
}
|
|
let airTime = new Date(mydata[i]["startTime"] * 1000);
|
|
console.log(
|
|
airTime.toLocaleString('en-US', {
|
|
hour: 'numeric',
|
|
minute: 'numeric',
|
|
hour12: true
|
|
}) +
|
|
": " + title
|
|
);
|
|
}
|
|
})
|
|
.catch(function(error) {
|
|
console.log(error);
|
|
});
|
|
EOF
|
|
)
|
|
|
|
printf "%s" "$GETSCHEDULE" > /tmp/getSchedule.js
|
|
chmod +x /tmp/getSchedule.js
|
|
export NODE_PATH="$HOME/.local/share/npm/lib/node_modules"
|
|
node /tmp/getSchedule.js
|
|
rm /tmp/getSchedule.js
|
|
exit 0
|
|
|
|
}
|
|
|
|
[[ -z "$1" ]] && printf "Usage: tv.sh [stream|schedule]\n" && exit 1
|
|
[[ "$1" != "stream" && "$1" != "schedule" ]] && printf "Usage: tv.sh [stream|schedule]\n" && exit 1
|
|
[[ -z "$(command -v tofi)" ]] && printf "tofi is not installed\n" && exit 1
|
|
[[ -z "$(command -v pup)" ]] && printf "pup is not installed\n" && exit 1
|
|
[[ -z "$(command -v jq)" ]] && printf "jq is not installed\n" && exit 1
|
|
[[ -z "$(command -v notify-send)" ]] && printf "notify-send is not installed\n" && exit 1
|
|
[[ -z "$(command -v mpv)" ]] && printf "mpv is not installed\n" && exit 1
|
|
[[ -z "$(command -v node)" ]] && printf "node is not installed\n" && exit 1
|
|
[[ -z "$(command -v npm)" ]] && printf "npm is not installed\n" && exit 1
|
|
[[ -z "$(command -v curl)" ]] && printf "curl is not installed\n" && exit 1
|
|
[[ -z "$(command -v git)" ]] && printf "git is not installed\n" && exit 1
|
|
[[ -z "$(command -v sed)" ]] && printf "sed is not installed\n" && exit 1
|
|
[[ -z "$(command -v awk)" ]] && printf "awk is not installed\n" && exit 1
|
|
[[ -z "$(command -v cat)" ]] && printf "cat is not installed\n" && exit 1
|
|
[[ -z "$(command -v printf)" ]] && printf "printf is not installed\n" && exit 1
|
|
[[ -z "$(command -v xargs)" ]] && printf "xargs is not installed\n" && exit 1
|
|
[[ -z "$(command -v basename)" ]] && printf "basename is not installed\n" && exit 1
|
|
[[ -z "$(command -v pgrep)" ]] && printf "pgrep is not installed\n" && exit 1
|
|
[[ -z "$(command -v setsid)" ]] && printf "setsid is not installed\n" && exit 1
|
|
[[ -z "$(command -v sleep)" ]] && printf "sleep is not installed\n" && exit 1
|
|
[[ "$1" == "stream" ]] && streamChannel
|
|
[[ "$1" == "schedule" ]] && getSchedule
|