forked from jensbin/init7tv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtv7
executable file
·52 lines (42 loc) · 1.34 KB
/
tv7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env bash
#
set -uo pipefail
PROXY="http://192.168.178.11:4022"
PLAYLIST="https://api.init7.net/tvchannels.xspf"
PLFILE="/tmp/tvchannels.xspf"
TMPFILE="/tmp/$$_list.tmp"
CHANNEL="$*"
if [ -f $PLFILE ]; then
currentdate=$(date +%s)
filedate=$(stat -c %Y $PLFILE)
fileage=$(echo $currentdate - $filedate | bc)
maxage=$(echo "60*60*24*7" | bc)
if [ $fileage -ge $maxage ]; then
rm $PLFILE
fi
fi
[[ -f $PLFILE ]] || curl -sLo $PLFILE $PLAYLIST
cat $PLFILE | awk '/<trackList>/{y=1;next}y' | grep "<title>" | awk '{gsub(/<[^>]*>/,"")};1' | awk '{$1=$1}1' > $TMPFILE
if [ -z ${CHANNEL+x} ]; then
cat $TMPFILE
else
numberresults=$(cat $TMPFILE | grep -i "$CHANNEL" | wc -l)
if [ $numberresults -eq 1 ]; then
thematch=$(cat $TMPFILE | grep -i "$CHANNEL" | sed "s/[!+@#$%^&*()-]/\\\&/g")
elif [ $numberresults -gt 1 ]; then
echo "Multiple matches"
echo "================"
cat $TMPFILE | grep -i "$CHANNEL"
else
echo "No match"
echo "========"
cat $TMPFILE
fi
fi
rm $TMPFILE
if [ ! -z ${thematch+x} ]; then
echo "Playing: ${thematch}"
multicastaddress=$(cat $PLFILE | awk "/$thematch/{y=1;next}y" | grep "<location>" | awk '{gsub(/<[^>]*>/,"")};1' | awk '{$1=$1}1' | head -1)
playurl="${PROXY}/udp/$(echo $multicastaddress | awk -F'@' '{ print $2 }')"
fi
[ ! -z ${playurl+x} ] && vlc "$playurl#$thematch"