-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlivestream-ripper.sh
84 lines (76 loc) · 1.91 KB
/
livestream-ripper.sh
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/bash
#Version 1.0.4
#A script to record a livestream using streamlink
help="
Flag usage:
[-h] [-l YTLINK]
[-q NUMBER] [-f FILENAME] [-r]
Flag description
'-h' Display help text.
'-l' Youtube livestream link.
'-q' Playlist number.
'-f' Name of your output file (sans file format).
'-r' Lists the playlist numbers to use with '-q'. Must be used alongside '-l'.
"
#defines getformats function before the flag definition so it can be used in -r
function getformats() {
#read -p "Enter YT link: " LINK
if [[ -z "$LINK" ]];
then
echo "No link, please use -h for help."
exit 1
else
/usr/bin/youtube-dl --list-formats $LINK
fi
}
#flag definitions
while getopts hl:q:f:r option
do
case "${option}"
in
h) echo "$help"
exit;;
l) LINK=${OPTARG};;
q) RES=${OPTARG};;
f) FILENAME=${OPTARG};;
r) getformats
exit 1;;
\?) echo "Invalid flag: -"$OPTARG". Use '-h' for help." >&2
esac
done
shift $((OPTIND -1))
#Other function definitions
function getplaylist() {
if [[ -z "$RES" || -z "$LINK" ]];
then
echo "Error you must include a link and a playlist number. Please use -r to find your playlist number."
exit 1
else
PLAYLIST=$(/usr/bin/youtube-dl -f $RES -g $LINK)
fi
}
function startrip() {
getplaylist
if [[ -z "$PLAYLIST" || -z "$FILENAME" ]];
then
echo "Missing playlist or filename. Use -h for help."
exit 1
else
/usr/bin/screen -d -m -S "livestream-rip" /usr/bin/streamlink $PLAYLIST best -o "$FILENAME".mp4
fi
}
# Make sure user gave usable INPUT
if [[ -z "$PLAYLIST" && -z "$FILENAME" && -z "$RES" ]]; then
echo "No file inputs given."
echo "$help"
exit 1
fi
#Check if main vars are empty so main function can be run
if [[ -z "$FILENAME" || -z "$RES" || -z "$LINK" ]]; then
#echo $FILENAME $RES $LINK
echo "Missing file inputs or non given."
echo "$help"
exit 1
else
startrip
fi