Skip to content

Instantly share code, notes, and snippets.

@ergoithz
Created November 20, 2020 13:19
Show Gist options
  • Save ergoithz/e0fe064e89798d4f5bf01e58d6d5d844 to your computer and use it in GitHub Desktop.
Save ergoithz/e0fe064e89798d4f5bf01e58d6d5d844 to your computer and use it in GitHub Desktop.
CODE | PY | Youtube subscriptions.json to OPML
#!/bin/env python
import pathlib
import json
import datetime
import html
tpl_file = '''
<opml version="1.1">
<head><title>Superduper exporter 9000</title><dateCreated>{today}</dateCreated></head>
<body><outline text="Subscriptions">{body}</outline></body>
</opml>
'''
tpl_item = '''
<outline
title="{snippet[title]}"
text="{snippet[title]}"
type="rss"
xmlUrl="https://www.youtube.com/feeds/videos.xml?channel_id={snippet[resourceId][channelId]}"
/>
'''
pathlib.Path('subscriptions.opml').write_text(
tpl_file
.format(
today=datetime.datetime.now(),
body='\n'.join(
tpl_item.format(**item)
for item in json.loads(pathlib.Path('subscriptions.json').read_text())
)
)
.strip()
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment