Search no longer depends on Invidious
This commit is contained in:
parent
b82ba31661
commit
41f86a6892
@ -1,10 +1,11 @@
|
|||||||
from flask import render_template, flash, redirect, url_for, request, send_from_directory, Markup
|
from flask import render_template, flash, redirect, url_for, request, send_from_directory, Markup
|
||||||
from app.forms import LoginForm, RegistrationForm, EmptyForm, SearchForm, ChannelForm
|
from app.forms import LoginForm, RegistrationForm, EmptyForm, SearchForm, ChannelForm
|
||||||
from app.models import User, twitterPost, ytPost, Post, invidiousFollow
|
|
||||||
from flask_login import login_user, logout_user, current_user, login_required
|
from flask_login import login_user, logout_user, current_user, login_required
|
||||||
|
from app.models import User, twitterPost, ytPost, Post, invidiousFollow
|
||||||
from flask import Flask, Response, stream_with_context
|
from flask import Flask, Response, stream_with_context
|
||||||
from requests_futures.sessions import FuturesSession
|
from requests_futures.sessions import FuturesSession
|
||||||
from concurrent.futures import as_completed
|
from concurrent.futures import as_completed
|
||||||
|
from youtube_search import YoutubeSearch
|
||||||
from werkzeug.urls import url_parse
|
from werkzeug.urls import url_parse
|
||||||
from youtube_dl import YoutubeDL
|
from youtube_dl import YoutubeDL
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
@ -215,38 +216,38 @@ def ytsearch():
|
|||||||
form = ChannelForm()
|
form = ChannelForm()
|
||||||
button_form = EmptyForm()
|
button_form = EmptyForm()
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
ydl = YoutubeDL()
|
|
||||||
data = ydl
|
|
||||||
channelId = form.channelId.data
|
|
||||||
c = requests.get('https://{instance}/api/v1/search?type=channel&q={cid}'.format(instance=invidiousInstance, cid=channelId))
|
|
||||||
v = requests.get('https://{instance}/api/v1/search?type=video&q={cid}'.format(instance=invidiousInstance, cid=channelId))
|
|
||||||
if c.status_code == 200 and v.status_code == 200:
|
|
||||||
results = json.loads(c.content)
|
|
||||||
channels = []
|
channels = []
|
||||||
videos = []
|
videos = []
|
||||||
for res in results:
|
|
||||||
channels.append({
|
|
||||||
'username':res['author'],
|
|
||||||
'channelId':res['authorId'],
|
|
||||||
'thumbnail':res['authorThumbnails'][0]['url'],
|
|
||||||
'subCount':letterify(res['subCount'])
|
|
||||||
})
|
|
||||||
|
|
||||||
results = json.loads(v.content)
|
searchTerm = form.channelId.data
|
||||||
for data in results:
|
search = YoutubeSearch(searchTerm)
|
||||||
|
chnns = search.channels_to_dict()
|
||||||
|
vids = search.videos_to_dict()
|
||||||
|
|
||||||
|
for v in vids:
|
||||||
videos.append({
|
videos.append({
|
||||||
'instance':invidiousInstance,
|
'author':v['channel'],
|
||||||
'author':data['author'],
|
'videoTitle':v['title'],
|
||||||
'videoTitle':data['title'],
|
'description':Markup(v['long_desc']),
|
||||||
'description':Markup(data['description'][0:125]+'...'),
|
'id':v['id'],
|
||||||
'id':data['videoId'],
|
'videoThumb': v['thumbnails'][-1],
|
||||||
'videoThumb': data['videoThumbnails'][4]['url'],
|
'channelUrl':v['url_suffix'],
|
||||||
'channelUrl':data['authorUrl'],
|
'views':v['views'],
|
||||||
'views':data['viewCount'],
|
'timeStamp':v['publishedText']
|
||||||
'timeStamp':data['publishedText']
|
|
||||||
})
|
})
|
||||||
|
|
||||||
return render_template('ytsearch.html', form=form, btform=button_form, results=channels, videos=videos)
|
for c in chnns:
|
||||||
|
channels.append({
|
||||||
|
'username':c['name'],
|
||||||
|
'channelId':c['id'],
|
||||||
|
'thumbnail':'https:{}'.format(c['thumbnails'][0]),
|
||||||
|
'subCount':letterify(c['suscriberCountText'])
|
||||||
|
})
|
||||||
|
|
||||||
|
print(channels)
|
||||||
|
print(videos)
|
||||||
|
return render_template('ytsearch.html', form=form, btform=button_form, channels=channels, videos=videos)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
return render_template('ytsearch.html', form=form)
|
return render_template('ytsearch.html', form=form)
|
||||||
|
|
||||||
|
@ -14,20 +14,12 @@
|
|||||||
<p>{{ form.submit() }}</p>
|
<p>{{ form.submit() }}</p>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<div class="ui one column middle aligned grid">
|
|
||||||
<div class="ui message">
|
|
||||||
<div class="header">
|
|
||||||
Tip: Videos are shown below channels.
|
|
||||||
</div>
|
|
||||||
<p>Just scroll down!</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{% if results %}
|
|
||||||
<div class="ui one column centered grid">
|
<div class="ui one column centered grid">
|
||||||
|
{% if channels %}
|
||||||
<div class="ui middle aligned divided list">
|
<div class="ui middle aligned divided list">
|
||||||
<h3 class="ui dividing header">Users</h3>
|
<h3 class="ui dividing header">Users</h3>
|
||||||
{% for res in results %}
|
|
||||||
|
{% for res in channels %}
|
||||||
<div class="item">
|
<div class="item">
|
||||||
<div class="right floated content">
|
<div class="right floated content">
|
||||||
{% if not current_user.is_following_yt(res.channelId) %}
|
{% if not current_user.is_following_yt(res.channelId) %}
|
||||||
@ -56,6 +48,7 @@
|
|||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
|
||||||
<div class="ui middle aligned divided list">
|
<div class="ui middle aligned divided list">
|
||||||
@ -71,7 +64,6 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
@ -44,5 +44,7 @@ webencodings==0.5.1
|
|||||||
Werkzeug==1.0.1
|
Werkzeug==1.0.1
|
||||||
WTForms==2.3.1
|
WTForms==2.3.1
|
||||||
yarl==1.4.2
|
yarl==1.4.2
|
||||||
|
youtube-dl==2020.7.28
|
||||||
|
youtube-search-fork==1.1.0
|
||||||
zope.event==4.4
|
zope.event==4.4
|
||||||
zope.interface==5.1.0
|
zope.interface==5.1.0
|
||||||
|
Reference in New Issue
Block a user