-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstream_address_finder.sh
executable file
·74 lines (62 loc) · 1.53 KB
/
stream_address_finder.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
#!/bin/bash
function download_playlist {
/bin/rm -f "$playlist"
wget -q -O "$playlist" "$input"
}
function is_beginning_with_http {
[[ $1 == [hH][tT][tT][pP]* ]]
}
function get_first_http_line_of_playlist {
local line
old_ifs=$IFS
IFS=$'\n'
# shellcheck disable=SC2013
# shellcheck disable=SC2094
for line in $(cat "$playlist"); do
line=$(replace_all_after_file "$line")
is_beginning_with_http "$line" && IFS=$old_ifs && echo "$line" && return
done < "$playlist"
IFS=$old_ifs
# no http found!
echo
}
function replace_all_after_file {
local line=$1
# e.g. "File1="
local search="[Ff][Ii][Ll][Ee][0-9]*="
local result="${line#*$search}"
if [ -n "$result" ]; then
echo "$result"
else
echo "$line"
fi
}
function find_stream_address {
local playlist_suffix
playlist=""
for playlist_suffix in "${playlist_suffixes[@]}"; do
if [[ ${input} == *.${playlist_suffix} ]]; then
playlist="tmp_stream_address_finder_playlist.${playlist_suffix}"
break
fi
done
if [ -z "$playlist" ]; then
echo "$input"
else
if download_playlist; then
get_first_http_line_of_playlist
/bin/rm -f "$playlist"
else
echo
fi
fi
}
###########################################################
if [ ! ${#} -eq 1 ]; then
echo Usage: "$0" URL
exit 1
fi
# Supported playlist types (suffixes)
declare -a playlist_suffixes=(m3u pls)
input=$1
find_stream_address