]> git.gir.st - subscriptionfeed.git/blob - app/dangerous/__init__.py
first draft of non-invidious search (needs cleanup!)
[subscriptionfeed.git] / app / dangerous / __init__.py
1 # this is an alternative to proxying through invidious. the search endpoint has only been (loosely) tested by
2 #17:50 < perflyst[m]> appears to be working
3 #, so i hopeā„¢ this works. if not, that's why it's in the 'dangerous' blueprint
4 import requests
5 from flask import Blueprint, render_template, request, flash, g, url_for
6
7 from ..common.common import *
8 from .lib import *
9
10 frontend = Blueprint('dangerous', __name__,
11 template_folder='templates',
12 static_folder='static',
13 static_url_path='/static/ys')
14
15 @frontend.route('/search')
16 def search():
17 #token = getattr(current_user, 'token', 'guest')
18 q = request.args.get('q')
19 page = int(request.args.get('page', 1))
20
21 sp = None #TODO: search filters (protobuf)
22 # https://github.com/iv-org/invidious/blob/452d1e8307d6344dd51c5437ccd032a566291c34/src/invidious/search.cr#L266
23
24 if q:
25 yt_results = fetch_searchresults(q, page, sp)
26
27 results = prepare_searchresults(yt_results)
28 else:
29 results = None
30
31 return render_template('search.html.j2', rows=results, query=q, page=page)
32
33 @frontend.before_app_request
34 def inject_button():
35 if not 'header_items' in g:
36 g.header_items = []
37 g.header_items.append({
38 'name': 'search',
39 'url': url_for('dangerous.search'),
40 'parent': frontend.name,
41 'priority': 15,
42 })
Imprint / Impressum