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
85
86
87
88
89
90
91
92
93
94
95
96
|
#!/usr/bin/env bash
####
# FILE NAME: launch_youtube_chat.sh
#
# Launch a web browser with the chat pop-out for a YouTube live stream.
#
####
__DEFAULT_BROWSER=xdg-open
__YOUTUBE_URL=""
function __usage () {
echo ""
echo "launch_youtube_chat.sh <YouTube-URL> [optional options]"
echo ""
echo " Takes the provided URL for a YouTube Live Stream and starts a"
echo " web browser pointing to the address of the chat for that stream."
echo ""
echo " -h"
echo " --help Display this help message."
echo ""
echo " -b <browser>"
echo " --browser <browser> Use <browser> as the web browser instead"
echo " of default as provided by xdg-open."
echo ""
exit 0
}
function __parse_youtube_url {
__YOUTUBE_URL=$(echo $1 | sed -r 's/^.*[&?]v=(.{11})([&#].*)?$/\1/')
}
function __parse_args () {
if [[ -z "$1" ]]
then
echo "Try --help or -h."
exit 1
fi
while [[ $# -gt 0 ]]
do
case "${1}" in
-b|--browser)
__DEFAULT_BROWSER="$2"
shift
shift
;;
-h|--help)
__usage
shift
;;
*)
if [[ "$__YOUTUBE_URL" == "" ]]
then
__parse_youtube_url $1
else
echo "Did you try to set the URL twice?"
echo "Please run with --help for usage."
exit 1
fi
shift
;;
--)
shift
break
;;
esac
done
if [[ "$__YOUTUBE_URL" == "" ]]
then
echo "URL not set"
echo "Please run with --help for usage."
exit 1
fi
}
function __main () {
#echo "Browser: " $__DEFAULT_BROWSER
#echo "YouTube video-id: " $__YOUTUBE_URL
local __final_url
__final_url="https://www.youtube.com/live_chat?is_popout=true&v=""${__YOUTUBE_URL}"
#echo $__final_url
$__DEFAULT_BROWSER $__final_url
}
__parse_args "${@}"
__main
|