Skip to content

Instantly share code, notes, and snippets.

@alexdelorenzo
Last active November 2, 2022 03:25
Show Gist options
  • Save alexdelorenzo/cc33c49ff704b4e0c461e6d0f70e422c to your computer and use it in GitHub Desktop.
Save alexdelorenzo/cc33c49ff704b4e0c461e6d0f70e422c to your computer and use it in GitHub Desktop.
#!/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