blob: 6a368400a5b303af963ca7a5428f2336e296ac21 (
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
import sys
"""
This little script lets you export your entire youtube subscriptions list to a opml file.
To use it go to your google account and go to your user data collection and find the part on youtube to download your subscriptions.
It will give you a subscriptions.csv file and pass that file to the script and it will output the rss opml data to stdout.
Do what you need with that data.
"""
# XML doesn't like some characters
def fix_name(name):
no_no_list = ["\n", '"', "&"]
name = "".join(filter(lambda x: x not in no_no_list, name))
return name
def main():
# Get name of the csv file.
if len(sys.argv) < 1:
print("File name required")
sys.exit()
file_name = sys.argv[1]
with open(file_name, "r") as fp:
print('<?xml version="1.0" encoding="UTF-8"?>')
print('<opml version="2.0">')
print('<head><title>OPML Feeds</title></head>')
print('<body>')
for line in fp.readlines()[1::]: # Skips the first line.
# Empty line.
if line == "\n":
continue
line_data = line.split(",")
feed_url = f"https://www.youtube.com/feeds/videos.xml?channel_id={line_data[0]}"
print(f'\t<outline text="{fix_name(line_data[2])}" type="rss" xmlUrl="{feed_url}"/>')
print('</body>')
print('</opml>')
if __name__ == "__main__":
main()
|