add option to import youtube subscriptions
This commit is contained in:
parent
c572662112
commit
ae7aefb5c2
@ -12,6 +12,7 @@ from werkzeug.urls import url_parse
|
|||||||
from youtube_dl import YoutubeDL
|
from youtube_dl import YoutubeDL
|
||||||
from numerize import numerize
|
from numerize import numerize
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
|
from xml.dom import minidom
|
||||||
from app import app, db
|
from app import app, db
|
||||||
from re import findall
|
from re import findall
|
||||||
import random, string
|
import random, string
|
||||||
@ -440,12 +441,14 @@ def importdata():
|
|||||||
if file.filename == '':
|
if file.filename == '':
|
||||||
flash('No selected file')
|
flash('No selected file')
|
||||||
return redirect(request.referrer)
|
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']
|
option = request.form['import_format']
|
||||||
if option == 'yotter':
|
if option == 'yotter':
|
||||||
importYotterSubscriptions(file)
|
importYotterSubscriptions(file)
|
||||||
elif option == 'newpipe':
|
elif option == 'newpipe':
|
||||||
importNewPipeSubscriptions(file)
|
importNewPipeSubscriptions(file)
|
||||||
|
elif option == 'youtube':
|
||||||
|
importYoutubeSubscriptions(file)
|
||||||
return redirect(request.referrer)
|
return redirect(request.referrer)
|
||||||
|
|
||||||
return redirect(request.referrer)
|
return redirect(request.referrer)
|
||||||
@ -465,6 +468,12 @@ def importNewPipeSubscriptions(file):
|
|||||||
for acc in data['subscriptions']:
|
for acc in data['subscriptions']:
|
||||||
r = followYoutubeChannel(re.search('(UC[a-zA-Z0-9_-]{22})|(?<=user\/)[a-zA-Z0-9_-]+', acc['url']).group())
|
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):
|
def allowed_file(filename):
|
||||||
return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
|
return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
|
||||||
|
|
||||||
|
@ -47,8 +47,11 @@
|
|||||||
<label class="radio-inline">
|
<label class="radio-inline">
|
||||||
<input type="radio" name="import_format" id="newpipe" value="newpipe"> NewPipe
|
<input type="radio" name="import_format" id="newpipe" value="newpipe"> NewPipe
|
||||||
</label>
|
</label>
|
||||||
|
<label class="radio-inline">
|
||||||
|
<input type="radio" name="import_format" id="youtube" value="youtube"> Youtube
|
||||||
|
</label>
|
||||||
</form>
|
</form>
|
||||||
<div class="description">Import from JSON export.</div>
|
<div class="description">Import subscription data.</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user