Created
November 20, 2020 13:19
CODE | PY | Youtube subscriptions.json to OPML
This file contains 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
#!/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