aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-11-24 13:53:34 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-11-24 13:53:34 +0100
commita63a08c533c55c541125a94b7f52b7722cc84644 (patch)
tree021caccfa137edcb4b76cc39e98986a9df3d3f4e
parent22ce06e37b1a12e638206559ef0dddd27879fa5e (diff)
add podcast2m3u script
-rwxr-xr-x.local/share/bin/podcast2m3u33
1 files changed, 33 insertions, 0 deletions
diff --git a/.local/share/bin/podcast2m3u b/.local/share/bin/podcast2m3u
new file mode 100755
index 0000000..c3b692e
--- /dev/null
+++ b/.local/share/bin/podcast2m3u
@@ -0,0 +1,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)
+}
+'
+