-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathQuick URL Record.bash
executable file
·80 lines (80 loc) · 1.33 KB
/
Quick URL Record.bash
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
#!/bin/bash
url_rgx='^https?://(www\.)?bbc\.co\.uk/.*/([b-df-hj-np-tv-z0-9]{8,})([/?#]|$)'
urls=()
if [[ $# -gt 0 ]]
then
for arg in "$@"
do
files=()
if [[ -d $arg ]]
then
echo DIR: $arg
files=("$arg"/*.webloc)
elif [[ -f $arg && $arg =~ \.webloc$ ]]
then
files=("$arg")
fi
for file in "${files[@]}"
do
echo FILE: $file
url=
url=$(/usr/libexec/PlistBuddy -c "Print :URL" "$file")
if [[ $? -eq 0 && -n $url ]]
then
if [[ $url =~ $url_rgx ]]
then
echo URL: $url
urls+=($url)
else
echo INVALID: $url
fi
fi
done
done
else
read url
if [[ -n $url ]]
then
echo FILE: stdin
if [[ $url =~ $url_rgx ]]
then
echo URL: $url
urls+=($url)
else
echo INVALID: $url
fi
fi
fi
for url in "${urls[@]}"
do
[[ $url =~ $url_rgx ]]
pid=${BASH_REMATCH[2]}
if [[ $url =~ /ad/ ]]
then
pids_ad=${pids_ad:+${pids_ad},}$pid
elif [[ $url =~ /sign/ ]]
then
pids_sl=${pids_sl:+${pids_sl},}$pid
else
pids=${pids:+${pids},}$pid
fi
done
cmds=()
cmd_base="/usr/local/bin/get_iplayer --log-progress"
if [[ -n $pids_ad ]]
then
cmds+=("$cmd_base --versions=audiodescribed --pid=$pids_ad")
fi
if [[ -n $pids_sl ]]
then
cmds+=("$cmd_base --versions=signed --pid=$pids_sl")
fi
if [[ -n $pids ]]
then
cmds+=("$cmd_base --pid=$pids")
fi
for cmd in "${cmds[@]}"
do
echo RUN: $cmd
$cmd
done