From bcd9c6415438fc1f99df187bac3eaa838fe19080 Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Tue, 3 Sep 2024 13:59:54 -0600 Subject: [PATCH] inline script --- .../2024/09-02-podcast-rss-generator/index.md | 70 ++++++++++++++++++- 1 file changed, 67 insertions(+), 3 deletions(-) diff --git a/content/blog/2024/09-02-podcast-rss-generator/index.md b/content/blog/2024/09-02-podcast-rss-generator/index.md index 6560306..f58d6e1 100644 --- a/content/blog/2024/09-02-podcast-rss-generator/index.md +++ b/content/blog/2024/09-02-podcast-rss-generator/index.md @@ -20,9 +20,8 @@ description="An audiobook I like" url="https://example.com/ebooks/mine" ``` -The script: -[build.sh](build.sh). -It will create `rss.xml` in that directory. +The script +will create `rss.xml` in the directory where you dropped it. It uses `ffprobe` from ffmpeg to figure out each track's title. All my tracks have ID3 tags, @@ -32,3 +31,68 @@ It can deal with spaces in filenames, but not double-quotes. `&` and `<` might cause problems too. Anyway, it's good enough for me. + +`build.sh`: +```sh +#! /bin/sh + +set -e + +cd $(dirname $0) +. config.sh + +out="rss.xml" +exec 1>$out +echo "Writing to $out" 1>&2 + +cat < + + + $title + $url + en + $description + +EOF + +if [ -f cover.jpg ]; then + cat < + $url/cover.jpg + $title + $url + +EOF +fi + +for fn in *.mp3; do + echo "- $fn" 1>&2 + + ffprobe -loglevel quiet -show_entries format -output_format json "$fn" > format.json + title=$(cat format.json | jq -r '.format.tags.title') + duration=$(cat format.json | jq -r '.format.duration | tonumber | ceil') + #bps=$(cat format.json | jq -r '.format.bit_rate') + #kbps=$(($bps / 1000)) + rm format.json + guid=$(sha1sum "$fn" | awk '{print $1}') + size=$(stat -c %s "$fn") + mtime=$(date -R -d @$(stat -c %Y "$fn")) + ufn=$(echo $fn | tr ' ' '+') + + cat < + $title + $mtime + $duration + + $guid + +EOF +done + +cat < + +EOF +```