Last active
March 25, 2025 18:15
-
-
Save lina-bh/774f545d0ebd5eee8d00ec8eb1c6c17b to your computer and use it in GitHub Desktop.
Transform Google Takeout YouTube subscriptions into OPML file for RSS readers.
This file contains hidden or 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
| 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