-
Notifications
You must be signed in to change notification settings - Fork 1
/
stream_notify
executable file
·62 lines (44 loc) · 1.42 KB
/
stream_notify
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
53
54
55
56
57
58
59
60
61
#!/bin/sh -e
help() {
cat - >&2 <<EOF
stream_notify - show streams that are currently live
stream_notify
This script requires a line-by-line list of stream URLs at ~/.streams
(or another file specified by the NOTIFYSTREAMS environment variable)
and youtube-dl. Each URL may be followed by an optional nickname for the
stream (e.g. http://website.com/stream123 stream123).
Duplicate notifications will be suppressed via a state file. The file is
located at ~/.streams.state by default (also configurable by the
NOTIFYSTREAMS environment variable).
Examples using cron:
# */10 * * * * means to run every 10 minutes
# Using my snotify script
*/10 * * * * stream_notify | snotify -
# Using a simple file
*/10 * * * * stream_notify > ~/.livestreams
# Using nothing, expecting cron to send you mail
*/10 * * * * stream_notify
EOF
}
if [ "$*" ]; then
help; exit 1;
fi
file=${NOTIFYSTREAMS:-"${HOME:?}/.streams"}
if [ ! -f "$file.state" ]; then
touch "$file.state"
fi
unset -v newstate
exec < "$file"
while read -r url stream; do
[ "$url" = "${url#\#}" ] || continue
# ideally would use title, but the titles returned by ytdl for twitch
# are not useful here
desc=$(youtube-dl -q --get-description "$url" 2> /dev/null) || continue
newstate="$newstate
$url $desc"
if grep -Fxqe "$url $desc" "$file.state"; then
continue
fi
printf '%s\n' "${stream:-$url} is live: $desc"
done
printf '%s\n' "$newstate" > "$file.state"