Skip to content

Instantly share code, notes, and snippets.

@jaronheard
Created May 11, 2020 01:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaronheard/f2673a01d6b1f992de55c764f8269a45 to your computer and use it in GitHub Desktop.
Save jaronheard/f2673a01d6b1f992de55c764f8269a45 to your computer and use it in GitHub Desktop.
Bash script to export Podcasts from Mac OS Catalina to OPML
#!/bin/bash
sql() {
sqlite3 "${HOME}/Library/Group Containers/"*.groups.com.apple.podcasts/Documents/MTLibrary.sqlite "select ${1} from ZMTPODCAST ${2:+"where ${2} = '${3}'"};" |\
sed -e 's/&/\&/g' \
-e 's/</\&lt;/g' \
-e 's/>/\&lgt;/g' \
-e "s/'/\&apos;/g"
}
opml_export=${HOME}/Desktop/podcasts.opml
cat > ${opml_export} << HEAD
<?xml version="1.0" encoding="utf-8"?>
<opml version="1.0">
<head><title>Podcast Subscriptions</title></head>
<body>
<outline text="feeds">
HEAD
sql ZUUID | while read -r uuid ; do
feed_url=$(sql ZFEEDURL ZUUID "${uuid}")
home_url=$(sql ZWEBPAGEURL ZUUID "${uuid}")
title=$(sql ZTITLE ZUUID "${uuid}")
cat <<EOT
<outline type="rss" text="${title}" title="${title}" xmlUrl="${feed_url}" htmlUrl="${home_url}" />
EOT
done >> ${opml_export}
cat >> ${opml_export} << TAIL
</outline>
</body>
</opml>
TAIL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment