From 214500e707d84420ec3a7953fd0241671ed65648 Mon Sep 17 00:00:00 2001 From: 0ihgk1uVBLlTBzVo7F9B <0ihgk1uVBLlTBzVo7F9B@protonmail.com> Date: Fri, 4 Sep 2020 14:26:27 +0200 Subject: [PATCH 1/4] set registrations to true because there is no key in the config file --- app/routes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/routes.py b/app/routes.py index 227a2bc..060af16 100644 --- a/app/routes.py +++ b/app/routes.py @@ -31,7 +31,7 @@ config = json.load(open('yotter-config.json')) ########################## NITTERINSTANCE = config['nitterInstance'] # Must be https://.../ YOUTUBERSS = "https://www.youtube.com/feeds/videos.xml?channel_id=" -REGISTRATIONS = config['registrations'] +REGISTRATIONS = True ########################## #### Global variables #### From c572662112294f5653f57cc4552d929c314897be Mon Sep 17 00:00:00 2001 From: 0ihgk1uVBLlTBzVo7F9B <0ihgk1uVBLlTBzVo7F9B@protonmail.com> Date: Fri, 4 Sep 2020 14:42:35 +0200 Subject: [PATCH 2/4] add option to import newpipe subscriptions --- app/routes.py | 14 ++++++++++++-- app/templates/settings.html | 9 ++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/app/routes.py b/app/routes.py index 060af16..b496d88 100644 --- a/app/routes.py +++ b/app/routes.py @@ -441,12 +441,16 @@ def importdata(): flash('No selected file') return redirect(request.referrer) if file and allowed_file(file.filename): - importAccounts(file) + option = request.form['import_format'] + if option == 'yotter': + importYotterSubscriptions(file) + elif option == 'newpipe': + importNewPipeSubscriptions(file) return redirect(request.referrer) return redirect(request.referrer) -def importAccounts(file): +def importYotterSubscriptions(file): filename = secure_filename(file.filename) data = json.load(file) for acc in data['twitter']: @@ -455,6 +459,12 @@ def importAccounts(file): for acc in data['youtube']: r = followYoutubeChannel(acc['channelId']) +def importNewPipeSubscriptions(file): + filename = secure_filename(file.filename) + data = json.load(file) + for acc in data['subscriptions']: + r = followYoutubeChannel(re.search('(UC[a-zA-Z0-9_-]{22})|(?<=user\/)[a-zA-Z0-9_-]+', acc['url']).group()) + def allowed_file(filename): return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS diff --git a/app/templates/settings.html b/app/templates/settings.html index 70e02b3..d3d542f 100644 --- a/app/templates/settings.html +++ b/app/templates/settings.html @@ -40,7 +40,14 @@
-
+
+ + +
Import from JSON export.
From ae7aefb5c202133267e644d294944776b36a42ec Mon Sep 17 00:00:00 2001 From: 0ihgk1uVBLlTBzVo7F9B <0ihgk1uVBLlTBzVo7F9B@protonmail.com> Date: Fri, 4 Sep 2020 14:57:45 +0200 Subject: [PATCH 3/4] add option to import youtube subscriptions --- app/routes.py | 11 ++++++++++- app/templates/settings.html | 5 ++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/app/routes.py b/app/routes.py index b496d88..cdfde74 100644 --- a/app/routes.py +++ b/app/routes.py @@ -12,6 +12,7 @@ from werkzeug.urls import url_parse from youtube_dl import YoutubeDL from numerize import numerize from bs4 import BeautifulSoup +from xml.dom import minidom from app import app, db from re import findall import random, string @@ -440,12 +441,14 @@ def importdata(): if file.filename == '': flash('No selected file') return redirect(request.referrer) - if file and allowed_file(file.filename): + if file and allowed_file(file.filename) or 'subscription_manager' in file.filename: option = request.form['import_format'] if option == 'yotter': importYotterSubscriptions(file) elif option == 'newpipe': importNewPipeSubscriptions(file) + elif option == 'youtube': + importYoutubeSubscriptions(file) return redirect(request.referrer) return redirect(request.referrer) @@ -465,6 +468,12 @@ def importNewPipeSubscriptions(file): for acc in data['subscriptions']: r = followYoutubeChannel(re.search('(UC[a-zA-Z0-9_-]{22})|(?<=user\/)[a-zA-Z0-9_-]+', acc['url']).group()) +def importYoutubeSubscriptions(file): + filename = secure_filename(file.filename) + itemlist = minidom.parse(file).getElementsByTagName('outline') + for item in itemlist[1:]: + r = followYoutubeChannel(re.search('UC[a-zA-Z0-9_-]{22}', item.attributes['xmlUrl'].value).group()) + def allowed_file(filename): return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS diff --git a/app/templates/settings.html b/app/templates/settings.html index d3d542f..db821b5 100644 --- a/app/templates/settings.html +++ b/app/templates/settings.html @@ -47,8 +47,11 @@ + -
Import from JSON export.
+
Import subscription data.
From bf600c1a16fe5411a2d78c90881ad23616e164e4 Mon Sep 17 00:00:00 2001 From: 0ihgk1uVBLlTBzVo7F9B <0ihgk1uVBLlTBzVo7F9B@protonmail.com> Date: Fri, 4 Sep 2020 15:05:32 +0200 Subject: [PATCH 4/4] add option to import freetube subscriptions --- app/routes.py | 10 +++++++++- app/templates/settings.html | 3 +++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/routes.py b/app/routes.py index cdfde74..fbbd5c2 100644 --- a/app/routes.py +++ b/app/routes.py @@ -37,7 +37,7 @@ REGISTRATIONS = True ########################## #### Global variables #### ########################## -ALLOWED_EXTENSIONS = {'json'} +ALLOWED_EXTENSIONS = {'json', 'db'} ######################### #### Twitter Logic ###### @@ -449,6 +449,8 @@ def importdata(): importNewPipeSubscriptions(file) elif option == 'youtube': importYoutubeSubscriptions(file) + elif option == 'freetube': + importFreeTubeSubscriptions(file) return redirect(request.referrer) return redirect(request.referrer) @@ -474,6 +476,12 @@ def importYoutubeSubscriptions(file): for item in itemlist[1:]: r = followYoutubeChannel(re.search('UC[a-zA-Z0-9_-]{22}', item.attributes['xmlUrl'].value).group()) +def importFreeTubeSubscriptions(file): + filename = secure_filename(file.filename) + data = re.findall('UC[a-zA-Z0-9_-]{22}', file.read().decode('utf-8')) + for acc in data: + r = followYoutubeChannel(acc) + def allowed_file(filename): return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS diff --git a/app/templates/settings.html b/app/templates/settings.html index db821b5..bac76a0 100644 --- a/app/templates/settings.html +++ b/app/templates/settings.html @@ -50,6 +50,9 @@ +
Import subscription data.