blob: 3bcfb0c5a8db4d1a96f7eb223beceb3b403a03d9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# selfoss-youtube-subs-to-opml.py -- Convert YouTube subscriptions exported
# via Google Takeout (CSV format) into OPML, which can be then imported in Selfoss (https://selfoss.aditu.de/)
#
# Usage:
# python3 selfoss-youtube-subs-to-opml.py subscriptions.csv > yt-subs.opml
import sys
import csv
from xml.sax.saxutils import escape
with open(sys.argv[1], newline='') as csvfile:
subscriptions = csv.reader(csvfile, delimiter=',', quotechar='"')
print(f'''<?xml version="1.0" encoding="UTF-8"?>
<opml version="1.0">
<body>
<outline title="YouTube subscriptions" text="YouTube subscriptions">''')
for subscription in subscriptions:
title = escape(subscription[2])
channelId = escape(subscription[0])
print(f''' <outline title="{title}"
text="{title}"
xmlUrl="https://www.youtube.com/feeds/videos.xml?channel_id={channelId}"
htmlUrl="https://www.youtube.com/channel/{channelId}"
type="rss"
selfoss:spout="spouts\youtube\youtube"/>
''')
print('''
</outline>
</body>
</opml>
''')
|