-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathdl-ubuntu-podcasts
174 lines (144 loc) · 4.65 KB
/
dl-ubuntu-podcasts
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#!/bin/bash
#----------------------------------------------------------------------------------
# Project Name - dl-ubuntu-podcasts
# Started On - Sat 7 Oct 19:08:59 BST 2017
# Last Change - Wed 4 Apr 08:21:09 BST 2018
# Author E-Mail - [email protected]
# Author GitHub - https://github.com/terminalforlife
#----------------------------------------------------------------------------------
# This really needs a rewrite; it's pretty sloppy. If this is something you'd be
# interested in, please let me know.
#----------------------------------------------------------------------------------
_VERSION_="2018-04-04"
XERR(){ printf "[L%0.4d] ERROR: %s\n" "$1" "$2" 1>&2; exit 1; }
ERR(){ printf "[L%0.4d] ERROR: %s\n" "$1" "$2" 1>&2; }
#TODO - Currently won't download S01E01.
#TODO - IMPORTANT: Fix filenames; they're a mess. :(
USAGE(){
while read -r; do
printf "%s\n" "$REPLY"
done <<-EOF
DL-UBUNTU-PODCASTS ($_VERSION_)
Written by terminalforlife ([email protected])
Simple program to download all of the old Ubuntu Podcast episodes.
SYNTAX: dl-ubuntu-podcasts [OPTS] PAGE PAGE PAGE . . .
OPTS: --help|-h|-? - Displays this help information.
--version|-v - Output only the version datestamp.
--quiet|-q - Runs in quiet mode. Errors still output.
--debug|-D - Enables the built-in bash debugging.
--dest|-d PATH - Where PATH is an alternative destination.
--get-season-eight - Grab the newer episodes from season eight.
--get-season-nine - Grab the newer episodes from season nine.
--get-season-ten - Grab the newer episodes from season ten.
NOTE: Files will by default be saved in OGG to the current directory.
Using one of the extra season flags will download all of the available
podcasts in that given season.
SITES: Seasons 1-7: http://podcast.ubuntu-uk.org
Seasons 8-10: http://static.ubuntupodcast.org
EOF
}
while [ "$1" ]; do
case "$1" in
--help|-h|-\?)
USAGE; exit 0 ;;
--version|-v)
printf "%s\n" "$_VERSION_"
exit 0 ;;
--quiet|-q)
BEQUIET="true" ;;
--debug)
DEBUGME="true" ;;
--dest|-s)
shift
ALTDEST="$1"
if ! [ -d "$ALTDEST" ]; then
XERR "Destination directory not found."
fi ;;
--get-season-eight)
EXTRA="08 01 42" ;;
--get-season-nine)
EXTRA="09 01 44" ;;
--get-season-ten)
EXTRA="10 01 38" ;;
*)
break ;;
esac
shift
done
if ! [ -x /usr/bin/wget ]; then
XERR "$LINENO" "Dependency '/usr/bin/wget' not met."
fi
read -a WGET_VER_LINE <<< "$(/usr/bin/wget --version)"
WGET_VERSION=0${WGET_VER_LINE[2]//[!0-9]}
if [ $WGET_VERSION -ge 01192 -a $WGET_VERSION -lt 01194 ]; then
NOWARC="--no-warc-compression"
fi
EXTRA_SEASON(){
for E in `eval printf "%d\\\\\n" {$2..$3}`; {
printf "%s\n" "$E"
}
URL="http://static.ubuntupodcast.org/ubuntupodcast"
/usr/bin/wget $NOWARC -qc --show-progress\
"$URL/s${1}/e${E}/ubuntupodcast_s${1}e${E}.mp3"
}
if [ "$EXTRA" ]; then
case "$EXTRA" in
8)
EXTRA_SEASON $EXTRA ;;
9)
EXTRA_SEASON $EXTRA ;;
10)
EXTRA_SEASON $EXTRA ;;
esac
fi
if [ "$*" ]; then
USERPAGE="true"
while [ -n "$1" ]; do
if ! [[ "$1" =~ [0-9]+ ]]; then
XERR "$LINENO" "Incorrect page number specified."
else
[ $1 -eq 2 ] || NUM+=" $1"
fi
shift
done
else
NUM=193
fi
[ "$BEQUIET" == "true" ] && exec 1> /dev/null
[ "$DEBUGME" == "true" ] && set -x
while :; do
if ! [ "$USERPAGE" == "true" ]; then
[ $NUM -le 2 ] && break || let NUM--
else
NUM="${NUM%% *}"
fi
#TODO - Fix custom pages not working.
PAGE=`/usr/bin/wget $NOWARC -q "http://podcast.ubuntu-uk.org/page/$NUM" -O -`
DL_LINK_MATCH="http://podcast\.ubuntu-uk\.org/download/.*\.ogg"
OUTNAME_MATCH="[Ss][0-9]+[Ee][0-9]+\s+–\s+[[:space:][:alnum:]]+"
while read; do
if [[ "$REPLY" =~ $DL_LINK_MATCH ]]; then
[ "$DL_LINK" ] || DL_LINK="$REPLY"
elif [[ "$REPLY" =~ $OUTNAME_MATCH ]]; then
[ "$OUTNAME" ] || OUTNAME="$REPLY"
elif [ "$DL_LINK" -a "$OUTNAME" ]; then
break
fi
done <<< "$PAGE"
if [ -z "$ALTDEST" ]; then
printf "NUM: %s\n" "$NUM"
printf "OUTNAME: %s\n" "$OUTNAME"
[ -z "$OUTNAME" ] && break
/usr/bin/wget $NOWARC -cq --show-progress\
"$DL_LINK" -O "./${OUTNAME}.ogg"
else
[ -z "$OUTNAME" ] && break
/usr/bin/wget $NOWARC -cq --show-progress\
"$DL_LINK" -O "${ALTDEST%\/}/${OUTNAME}.ogg"
fi
[ "$USERPAGE" == "true" ] || NUM="${NUM/* }"
if ! [ "$NUM" ]; then
break
fi
done
# vim: ft=sh noexpandtab colorcolumn=84 tabstop=8 noswapfile nobackup