Fixed unnecessary bug.
This commit is contained in:
40
README.md
40
README.md
@@ -1,50 +1,44 @@
|
|||||||
# tv.sh
|
# tv.sh
|
||||||
|
|
||||||
A small script to offer a selection menu of channels in ustvgo.tv using rofi (or dmenu if you change the code) and start playing in mpv.
|
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.
|
||||||
|
|
||||||
Intended for those who like the selection but don't necessarily want to add the m3u file to a program like vlc.
|
Intended for those who like the selection but don't necessarily want to add the m3u file to a program like vlc.
|
||||||
|
|
||||||
You should first go get [ustvgo_to_m3u](https://github.com/benmoose39/ustvgo_to_m3u) which actually does everything for this to be useful and then change the path to the ustvgo.m3u file in the script
|
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.
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
git clone https://git.konsthol.eu/konsthol/UsTvGo_Menu
|
git clone https://git.konsthol.eu/konsthol/TheTvApp_Menu
|
||||||
cd UsTvGo_Menu
|
cd TheTvApp_Menu
|
||||||
sudo cp tv.sh /usr/bin/
|
sudo cp tv.sh /usr/bin/
|
||||||
(Or cp tv.sh anywhere in your $PATH)
|
(Or cp tv.sh anywhere in your $PATH)
|
||||||
```
|
```
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
Simply run `tv.sh` or even better assign it to run with a keybinding
|
Simply run `tv.sh stream` or `tv.sh schedule` or even better assign those two functions to run with a keybinding.
|
||||||
|
|
||||||
Also as benmoose39 says in his repo the playlist url changes every 4 hours so if you don't hate setting up cron jobs you should do the following
|
|
||||||
|
|
||||||
```sh
|
|
||||||
crontab -e (to open the cronjobs file)
|
|
||||||
0 */4 * * * ~/PATH_UP_TO/ustvgo_to_m3u/autorun.sh
|
|
||||||
```
|
|
||||||
|
|
||||||
If you want it to renew before 4 hours have passed or after, you can change the cron parameters according to [crontab.guru](https://crontab.guru/)
|
|
||||||
|
|
||||||
## Dependencies
|
## Dependencies
|
||||||
|
|
||||||
* grep
|
* git
|
||||||
* awk
|
* curl
|
||||||
* sed
|
* sed
|
||||||
* rofi (or dmenu)
|
* tofi (or dmenu if you change the code)
|
||||||
* mpv
|
* mpv
|
||||||
* tail
|
* grep
|
||||||
|
* npm
|
||||||
|
* node
|
||||||
|
* pup
|
||||||
|
* jq
|
||||||
* notify-send (Optional)
|
* notify-send (Optional)
|
||||||
|
|
||||||
## Credits go to
|
## Credits go to
|
||||||
|
|
||||||
* [benmoose39](https://github.com/benmoose39)
|
* [habitual69](https://github.com/habitual69)
|
||||||
|
|
||||||
As this script uses his [ustvgo_to_m3u](https://github.com/benmoose39/ustvgo_to_m3u) script
|
As this script uses his [thetvappstream](https://github.com/habitual69/thetvappstream) script.
|
||||||
|
|
||||||
* [USTVGO](https://ustvgo.tv/)
|
* [THETVAPP](https://thetvapp.to/)
|
||||||
|
|
||||||
As they provide the channel streams
|
|
||||||
|
|
||||||
|
As they provide the channel streams.
|
||||||
|
|||||||
135
tv.sh
135
tv.sh
@@ -1,15 +1,130 @@
|
|||||||
#!/bin/sh
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
PLAYLIST_FILE="/home/konsthol/Gits/ustvgo_to_m3u/ustvgo.m3u"
|
function streamChannel {
|
||||||
|
|
||||||
channel="$(grep tvg-id "$PLAYLIST_FILE" | awk '{print $2}' | sed 's/[^"]*"\([^"]*\)".*/\1/' | rofi -dmenu -i -l 20 -p 'Channels')"
|
if [[ ! -d "$HOME/Gits/thetvappstream/" ]]; then
|
||||||
|
mkdir -p "$HOME/Gits"
|
||||||
if [[ -n $channel ]]
|
notify-send -t 2000 "Cloning necessary repositories"
|
||||||
then
|
git clone https://github.com/habitual69/thetvappstream "$HOME/Gits/thetvappstream"
|
||||||
notify-send -t 2000 "Playing "$channel
|
cd "$HOME/Gits/thetvappstream/" || exit
|
||||||
mpv "$(grep "$channel" "$PLAYLIST_FILE" | tail -n 1)"
|
notify-send -t 2000 "Copying .env_example to .env"
|
||||||
else
|
cp .env_example .env
|
||||||
notify-send "Nothing was chosen"
|
notify-send -t 2000 "Installing necessary dependencies"
|
||||||
|
npm -g install
|
||||||
fi
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user