Merge pull request #92 from 0ihgk1uVBLlTBzVo7F9B/dev-indep
Simplify import process.
This commit is contained in:
commit
d27990e56a
@ -47,7 +47,6 @@ YOUTUBERSS = "https://www.youtube.com/feeds/videos.xml?channel_id="
|
|||||||
##########################
|
##########################
|
||||||
#### Global variables ####
|
#### Global variables ####
|
||||||
##########################
|
##########################
|
||||||
ALLOWED_EXTENSIONS = {'json', 'db'}
|
|
||||||
|
|
||||||
#########################
|
#########################
|
||||||
#### Twitter Logic ######
|
#### Twitter Logic ######
|
||||||
@ -300,6 +299,7 @@ def ytfollow(channelId):
|
|||||||
return redirect(request.referrer)
|
return redirect(request.referrer)
|
||||||
|
|
||||||
def followYoutubeChannel(channelId):
|
def followYoutubeChannel(channelId):
|
||||||
|
try:
|
||||||
channelData = YoutubeSearch.channelInfo(channelId, False)
|
channelData = YoutubeSearch.channelInfo(channelId, False)
|
||||||
try:
|
try:
|
||||||
if not current_user.is_following_yt(channelId):
|
if not current_user.is_following_yt(channelId):
|
||||||
@ -317,6 +317,11 @@ def followYoutubeChannel(channelId):
|
|||||||
print(e)
|
print(e)
|
||||||
flash("Youtube: Couldn't follow {}. Already followed?".format(channelData[0]['name']))
|
flash("Youtube: Couldn't follow {}. Already followed?".format(channelData[0]['name']))
|
||||||
return False
|
return False
|
||||||
|
except KeyError as ke:
|
||||||
|
print("KeyError: {}:'{}' could not be found".format(ke, channelId))
|
||||||
|
flash("Youtube: ChannelId '{}' is not valid".format(channelId))
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
@app.route('/ytunfollow/<channelId>', methods=['POST'])
|
@app.route('/ytunfollow/<channelId>', methods=['POST'])
|
||||||
@login_required
|
@login_required
|
||||||
@ -571,16 +576,12 @@ 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) or 'subscription_manager' in file.filename:
|
else:
|
||||||
option = request.form['import_format']
|
option = request.form['import_format']
|
||||||
if option == 'yotter':
|
if option == 'yotter':
|
||||||
importYotterSubscriptions(file)
|
importYotterSubscriptions(file)
|
||||||
elif option == 'newpipe':
|
|
||||||
importNewPipeSubscriptions(file)
|
|
||||||
elif option == 'youtube':
|
elif option == 'youtube':
|
||||||
importYoutubeSubscriptions(file)
|
importYoutubeSubscriptions(file)
|
||||||
elif option == 'freetube':
|
|
||||||
importFreeTubeSubscriptions(file)
|
|
||||||
return redirect(request.referrer)
|
return redirect(request.referrer)
|
||||||
|
|
||||||
return redirect(request.referrer)
|
return redirect(request.referrer)
|
||||||
@ -594,6 +595,15 @@ def deleteme():
|
|||||||
logout_user()
|
logout_user()
|
||||||
return redirect(url_for('index'))
|
return redirect(url_for('index'))
|
||||||
|
|
||||||
|
def importYoutubeSubscriptions(file):
|
||||||
|
filename = secure_filename(file.filename)
|
||||||
|
try:
|
||||||
|
data = re.findall('(UC[a-zA-Z0-9_-]{22})|(?<=user/)[a-zA-Z0-9_-]+', file.read().decode('utf-8'))
|
||||||
|
for acc in data:
|
||||||
|
r = followYoutubeChannel(acc)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
flash("File is not valid.")
|
||||||
|
|
||||||
def importYotterSubscriptions(file):
|
def importYotterSubscriptions(file):
|
||||||
filename = secure_filename(file.filename)
|
filename = secure_filename(file.filename)
|
||||||
@ -604,27 +614,6 @@ def importYotterSubscriptions(file):
|
|||||||
for acc in data['youtube']:
|
for acc in data['youtube']:
|
||||||
r = followYoutubeChannel(acc['channelId'])
|
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
|
|
||||||
|
|
||||||
@app.route('/register', methods=['GET', 'POST'])
|
@app.route('/register', methods=['GET', 'POST'])
|
||||||
def register():
|
def register():
|
||||||
form = RegistrationForm()
|
form = RegistrationForm()
|
||||||
|
@ -31,7 +31,7 @@
|
|||||||
<div class="ui blue segment">
|
<div class="ui blue segment">
|
||||||
<i class="large upload middle aligned icon"></i>
|
<i class="large upload middle aligned icon"></i>
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<div class="description"><h5 class="ui header">Import suscription data</h5></div>
|
<div class="description"><h5 class="ui header">Import subscription data</h5></div>
|
||||||
<form action = "{{ url_for('importdata') }}" method = "POST" enctype = "multipart/form-data">
|
<form action = "{{ url_for('importdata') }}" method = "POST" enctype = "multipart/form-data">
|
||||||
<input type = "file" name = "file"/>
|
<input type = "file" name = "file"/>
|
||||||
<input type = "submit"/>
|
<input type = "submit"/>
|
||||||
@ -39,15 +39,9 @@
|
|||||||
<label class="radio-inline">
|
<label class="radio-inline">
|
||||||
<input type="radio" name="import_format" id="yotter" value="yotter" checked> Yotter
|
<input type="radio" name="import_format" id="yotter" value="yotter" checked> Yotter
|
||||||
</label>
|
</label>
|
||||||
<label class="radio-inline">
|
<label class="radio-inline" data-tooltip="Includes FreeTube, Invidious and NewPipe.">
|
||||||
<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
|
<input type="radio" name="import_format" id="youtube" value="youtube"> Youtube
|
||||||
</label>
|
</label>
|
||||||
<label class="radio-inline">
|
|
||||||
<input type="radio" name="import_format" id="freetube" value="freetube"> FreeTube
|
|
||||||
</label>
|
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Reference in New Issue
Block a user