aboutsummaryrefslogtreecommitdiff
path: root/.local/share/bin/podcast2m3u
blob: c3b692edfa65f7fdd60974e729841b9519ca3d9b (plain)
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
#!/bin/sh
URL="$1"
TAB="$(printf '\t')"
curl -sLo- "$URL" |\
xmlstarlet select --template \
	--match '/rss/channel/item' \
	--value-of './itunes:duration' \
	--output "$TAB" \
	--value-of './title' \
	--output "$TAB" \
	--value-of './enclosure/@url' \
	--nl |\
awk -F "$TAB" '
BEGIN {
	printf("#EXTM3U\n")
}
function time2secs(time) {
	seconds = 0
	gsub(/,/, ".", time)
	els = split(time, el, ":")
	if (els == 0) return seconds;
	seconds += el[els--]
	if (els == 0) return seconds;
	seconds += el[els--] * 60
	if (els == 0) return seconds;
	seconds += el[els--] * 60 * 60
	return seconds;
}
{
	printf("#EXTINF:%s,%s\n%s\n", time2secs($1), $2, $3)
}
'