Skip to content

Instantly share code, notes, and snippets.

@telmen
Last active August 1, 2023 00:42
Show Gist options
  • Save telmen/4d67cba98ba7181424a681c1cbfc5f34 to your computer and use it in GitHub Desktop.
Save telmen/4d67cba98ba7181424a681c1cbfc5f34 to your computer and use it in GitHub Desktop.
Export Google Podcasts subscriptions to OPML file.
// 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)
})
@mruac
Copy link

mruac commented Dec 1, 2022

Set the TrustedTypes policy before running this script to avoid errors:
window.trustedTypes.createPolicy('default', {createHTML: (string, sink) => string})

@vingel
Copy link

vingel commented Jan 6, 2023

Thanks for the snippet, it save my day

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment