Skip to content

Instantly share code, notes, and snippets.

@lina-bh
Last active March 25, 2025 18:15
Show Gist options
  • Select an option

  • Save lina-bh/774f545d0ebd5eee8d00ec8eb1c6c17b to your computer and use it in GitHub Desktop.

Select an option

Save lina-bh/774f545d0ebd5eee8d00ec8eb1c6c17b to your computer and use it in GitHub Desktop.
Transform Google Takeout YouTube subscriptions into OPML file for RSS readers.
import csv
import sys
import xml.etree.ElementTree as ET
opml = ET.Element("opml")
xmldoc = ET.ElementTree(element=opml)
body = ET.SubElement(opml, "body")
with open(sys.argv[1], "r") as f:
rd = csv.reader(f)
it = iter(rd)
next(it) # skip header
for row in it:
if len(row) < 3:
continue
outline = ET.SubElement(body, "outline")
outline.set("text", row[2])
outline.set("htmlUrl", row[1])
outline.set(
"xmlUrl", f"https://www.youtube.com/feeds/videos.xml?channel_id={row[0]}"
)
xmldoc.write(sys.stdout, encoding="unicode", xml_declaration=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment