aboutsummaryrefslogtreecommitdiffstats
path: root/youtube/subscriptions.py
diff options
context:
space:
mode:
authorJames Taylor <user234683@users.noreply.github.com>2021-08-31 14:46:18 -0700
committerJesús <heckyel@hyperbola.info>2021-08-31 18:36:10 -0500
commit5bf4c284a5da4e7cc3bc76af2093cdc0e04f9d4e (patch)
tree44c6699b832e421aa2ed2cb9e6e84f2aaf83effb /youtube/subscriptions.py
parent2ab5b96178892fd7ca2f40ec7644cf525e039eb4 (diff)
downloadyt-local-5bf4c284a5da4e7cc3bc76af2093cdc0e04f9d4e.tar.lz
yt-local-5bf4c284a5da4e7cc3bc76af2093cdc0e04f9d4e.tar.xz
yt-local-5bf4c284a5da4e7cc3bc76af2093cdc0e04f9d4e.zip
subscriptions: Support new subscriptions.csv format
According to https://github.com/iv-org/invidious/issues/2319 Google Takeout changed the format from json to csv Signed-off-by: Jesús <heckyel@hyperbola.info>
Diffstat (limited to 'youtube/subscriptions.py')
-rw-r--r--youtube/subscriptions.py22
1 files changed, 21 insertions, 1 deletions
diff --git a/youtube/subscriptions.py b/youtube/subscriptions.py
index afc3df9..6ab12c7 100644
--- a/youtube/subscriptions.py
+++ b/youtube/subscriptions.py
@@ -15,6 +15,8 @@ import math
import secrets
import collections
import calendar # bullshit! https://bugs.python.org/issue6280
+import csv
+import re
import flask
from flask import request
@@ -729,8 +731,26 @@ def import_subscriptions():
except (AssertionError, IndexError, defusedxml.ElementTree.ParseError) as e:
return '400 Bad Request: Unable to read opml xml file, or the file is not the expected format', 400
+ elif mime_type == 'text/csv':
+ content = file.read().decode('utf-8')
+ reader = csv.reader(content.splitlines())
+ channels = []
+ for row in reader:
+ if not row or row[0].lower().strip() == 'channel id':
+ continue
+ elif len(row) > 1 and re.fullmatch(r'UC[-_\w]{22}',
+ row[0].strip()):
+ channels.append( (row[0], row[-1]) )
+ else:
+ print('WARNING: Unknown row format:', row)
else:
- return '400 Bad Request: Unsupported file format: ' + mime_type + '. Only subscription.json files (from Google Takeouts) and XML OPML files exported from YouTube\'s subscription manager page are supported', 400
+ error = 'Unsupported file format: ' + mime_type
+ error += (' . Only subscription.json, subscriptions.csv files'
+ ' (from Google Takeouts)'
+ ' and XML OPML files exported from Youtube\'s'
+ ' subscription manager page are supported')
+ return (flask.render_template('error.html', error_message=error),
+ 400)
_subscribe(channels)