Last active
November 2, 2022 03:21
-
-
Save alexdelorenzo/47267d8ba7cd50735517fe2c9da84414 to your computer and use it in GitHub Desktop.
Generate an OPML file from Airsonic podcast subscriptions https://alexdelorenzo.dev/notes/airsonic-opml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# License: GPLv3 | |
export SCRIPT="${1:-airsonic.script}" | |
export TITLE="Airsonic Podcasts" | |
export SQL_REGEX="'https?://[^ ,]+','[^']*" | |
export TABLE="podcast_channel" | |
export DELIM=',' | |
export TAG_FMT="<outline type='rss' xmlUrl='%s' text='%s' />" | |
export LINE_FMT="\t\t\t%s\n" | |
export JOBS=4 RC_ERR=1 | |
get-outline() { | |
local line="$1" | |
local info="$(grep -E -o "$SQL_REGEX" <<< "$line" | head -1 | tr -d "'")" | |
local url="$(cut -d $DELIM -f 1 <<< "$info")" | |
local name="$(cut -d $DELIM -f 2- <<< "$info")" | |
name="${name//\&/and}" | |
test -z "$url" && return $RC_ERR | |
printf "$TAG_FMT" "$url" "$name" | |
} | |
export -f get-outline | |
print-line() { | |
local line="$1" tag= | |
tag="$(get-outline "$line")" && printf "$LINE_FMT" "$tag" | |
} | |
export -f print-line | |
print-xml() { | |
printf "<opml version='2.0'> | |
\t<body> | |
\t\t<outline text='$TITLE' title='$TITLE'>\n" | |
grep -i "$TABLE" "$SCRIPT" | parallel -j $JOBS print-line | |
printf '\t\t</outline> | |
\t</body> | |
</opml>\n' | |
} | |
print-xml |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment