Merge pull request #21 from 0ihgk1uVBLlTBzVo7F9B/dev-indep
Add option to import subscription data from newpipe, youtube and freetube.
This commit is contained in:
commit
5c9d19f5d7
@ -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
|
||||
@ -31,12 +32,12 @@ 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 ####
|
||||
##########################
|
||||
ALLOWED_EXTENSIONS = {'json'}
|
||||
ALLOWED_EXTENSIONS = {'json', 'db'}
|
||||
|
||||
#########################
|
||||
#### Twitter Logic ######
|
||||
@ -440,13 +441,21 @@ def importdata():
|
||||
if file.filename == '':
|
||||
flash('No selected file')
|
||||
return redirect(request.referrer)
|
||||
if file and allowed_file(file.filename):
|
||||
importAccounts(file)
|
||||
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)
|
||||
elif option == 'freetube':
|
||||
importFreeTubeSubscriptions(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 +464,24 @@ 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 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 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
|
||||
|
||||
|
@ -40,8 +40,21 @@
|
||||
<form action = "{{ url_for('importdata') }}" method = "POST" enctype = "multipart/form-data">
|
||||
<input type = "file" name = "file"/>
|
||||
<input type = "submit"/>
|
||||
<br>
|
||||
<label class="radio-inline">
|
||||
<input type="radio" name="import_format" id="yotter" value="yotter" checked> Yotter
|
||||
</label>
|
||||
<label class="radio-inline">
|
||||
<input type="radio" name="import_format" id="newpipe" value="newpipe"> NewPipe
|
||||
</label>
|
||||
<label class="radio-inline">
|
||||
<input type="radio" name="import_format" id="youtube" value="youtube"> Youtube
|
||||
</label>
|
||||
<label class="radio-inline">
|
||||
<input type="radio" name="import_format" id="freetube" value="freetube"> FreeTube
|
||||
</label>
|
||||
</form>
|
||||
<div class="description">Import from JSON export.</div>
|
||||
<div class="description">Import subscription data.</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
Reference in New Issue
Block a user