-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstreamrecord
More file actions
executable file
·38 lines (32 loc) · 1.27 KB
/
Copy pathstreamrecord
File metadata and controls
executable file
·38 lines (32 loc) · 1.27 KB
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
#!/usr/bin/env sh
DEFAULT_URL="https://www.twitch.tv/tsoding"
DEFAULT_RETRY='180'
DEFAULT_QUALITY='720p60,720p,best'
msg () {
echo "[Streamlink Loop] [$(date +%T)] [$1]: $2"
}
check_app () {
if command -v "$1" > /dev/null 2>&1; then return 0; else return 1; fi
}
msg 'INFO' 'Starting the Streamlink Loop script...'
trap "msg 'INFO' 'Received a signal to stop. Bye!'; exit 0" INT HUP TERM
while getopts 'q:r:u:' OPT; do
case $OPT in
q) QUALITY="$OPTARG";;
r) RETRY="$OPTARG";;
u) URL="$OPTARG";;
\?) msg 'ERROR' 'Invalid option. Use -q for quality, -r for retry (in seconds), and -u for URL.'; exit 1;;
esac
done
if check_app streamlink; then
while streamlink --can-handle-url "${URL:-$DEFAULT_URL}"; do
if ! streamlink --output '~/Documents/STREAMS/TWITCH/tsoding/tsoding-{time:%y%m%d}_{time:%a}_{time:%H}.{time:%M%p}.ts' --default-stream "${QUALITY:-$DEFAULT_QUALITY}" --url "${URL:-$DEFAULT_URL}"; then
msg 'WARNING' 'Unable to find a live stream at this moment.'
fi
msg 'WARNING' "Streamlink closed. Will retry in ${RETRY:-$DEFAULT_RETRY} seconds."
sleep "${RETRY:-$DEFAULT_RETRY}"
done
msg 'ERROR' "The URL ${URL:-$DEFAULT_URL} is not valid."; exit 1
else
msg 'ERROR' "Streamlink is not installed or is not reachable at $PATH."; exit 1
fi