Last active
August 1, 2023 00:42
-
-
Save telmen/4d67cba98ba7181424a681c1cbfc5f34 to your computer and use it in GitHub Desktop.
Export Google Podcasts subscriptions to OPML file.
This file contains hidden or 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
// To date(2021-02-08) Google Podcasts has no option to export a subscription list in any form. | |
async function getPodcastData(url) { | |
const domParser = new DOMParser() | |
const res = await fetch(url) | |
const html = await res.text() | |
const $ = domParser.parseFromString(html, 'text/html') | |
const title = text = $.querySelector('.AZqljb').getAttribute('data-title') | |
try { | |
return { | |
title, | |
text, | |
feed: $.querySelector('.AZqljb').getAttribute('data-feed'), | |
home: $.querySelector('.jcGgqc') ? $.querySelector('.jcGgqc').href : '' | |
} | |
} catch(e) { | |
console.log(title, e) | |
} | |
} | |
const subs = document.querySelectorAll('.PKhmud.sc-it .c9x52d'); | |
Promise.all(Array.from(subs).map(sub => getPodcastData(sub.href))).then(outlines => { | |
const opml = ` | |
<?xml version="1.0"?> | |
<opml version="1.0"> | |
<head> | |
<title>Google Podcasts Subscriptions</title> | |
</head> | |
<body> | |
${outlines.map(outline => `<outline type="rss" text="${outline.text}" title="${outline.title}" xmlUrl="${outline.feed}" htmlUrl="${outline.home}" />`).join('\n')} | |
</body> | |
</opml> | |
` | |
console.log(opml) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Set the TrustedTypes policy before running this script to avoid errors:
window.trustedTypes.createPolicy('default', {createHTML: (string, sink) => string})