Skip to content

Instantly share code, notes, and snippets.

@DearRude
Last active January 27, 2021 05:45
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 DearRude/8a753b5634338ebd635b3ada9a851ccb to your computer and use it in GitHub Desktop.
Save DearRude/8a753b5634338ebd635b3ada9a851ccb to your computer and use it in GitHub Desktop.
Make RSS OPML out of YouTube Subscriptions
import json
from lxml import etree
BRIDGE = "https://sebsauvage.net/rss-bridge/?action=display&bridge=Youtube&context=By+channel+id&c=CHANNELID&format=Mrss"
with open("youtube.json", "r") as p:
page = json.load(p)
opml = etree.Element("opml", version="1.0")
head = etree.SubElement(opml, "head")
etree.SubElement(head, "title").text = "YouTube Sub"
body = etree.SubElement(opml, "body")
parent = etree.SubElement(body, "outline", title="YouTube", text="YouTube")
for item in page["items"]:
channel_id = item["snippet"]["resourceId"]["channelId"]
title = item["snippet"]["title"]
url = BRIDGE.replace("CHANNELID", channel_id)
etree.SubElement(parent, "outline", title=title, text=title, type="rss", xmlUrl=url)
et = etree.ElementTree(opml)
et.write('output.opml', pretty_print=True)
  1. Get your YouTube subscribed channels by Google API
  2. Save it locally as youtube.json
  3. Run export_opml.py to generate output.opml
  4. Import generated OPML file in your RSS client
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment