Skip to content

Instantly share code, notes, and snippets.

@alexdelorenzo
Last active Nov 2, 2022
Embed
What would you like to do?
#!/usr/bin/env bash
export SCRIPT="${1:-airsonic.script}"
export TITLE="Airsonic Podcasts"
export SQL_REGEX="'https?://[^ ,]+','[^']*"
export TABLE="podcast_channel"
export NAME_SEP="','" QUOTE="'"
export FIRST=0 SECOND=1 JOBS=4
export TAG_FMT="<outline type='rss' xmlUrl='%s' text='%s' />"
export LINE_FMT="\t\t\t%s\n"
get-cores() {
type lscpu &> /dev/null && {
printf "%s" "$(lscpu | grep "^CPU(s):" | str col 1)"
return
}
printf "%s" "$JOBS"
}
process-line() {
local line="$1"
local info="$(grep -E -o "$SQL_REGEX" <<< "$line" | str nth $FIRST)"
local urlName="$(str split "$NAME_SEP" <<< "$info")"
local url="$(str nth $FIRST <<< "$urlName" | str strip "$QUOTE")"
test -z "$url" || {
local name="$(str nth $SECOND <<<"$urlName" | str replace '&' 'and' | str strip "$QUOTE")"
local xml="$(printf "$TAG_FMT" "$url" "$name")"
printf "$LINE_FMT" "$xml"
}
}
export -f process-line
main() {
local procs="$(get-cores)"
printf "<opml version='2.0'>
\t<body>
\t\t<outline text='$TITLE' title='$TITLE'>\n"
grep -i "$TABLE" "$SCRIPT" | parallel -j "$procs" process-line
printf "\t\t</outline>
\t</body>
</opml>\n"
}
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment