]>
git.gir.st - subscriptionfeed.git/blob - app/invidious/__init__.py
2 from flask
import Blueprint
, render_template
, request
, flash
4 from ..common
.common
import fallback_route
6 frontend
= Blueprint('invidious', __name__
,
7 template_folder
='templates',
8 static_folder
='static',
9 static_url_path
='/static/iv')
11 # TODO: minimal implementation (invidio.us hardcoded, videos only, no optional_params)
12 @frontend.route('/search')
14 #token = getattr(current_user, 'token', 'guest')
15 q
= request
.args
.get('q')
16 page
= int(request
.args
.get('page', 1))
17 provider
= request
.args
.get('provider', 'invidio.us:443')
20 sort_by: "relevance", "rating", "upload_date", "view_count"
21 date: "hour", "today", "week", "month", "year"
22 duration: "short", "long"
23 type: "video", "playlist", "channel", "all", (default: video)
24 features: "hd", "subtitles", "creative_commons", "3d", "live",
25 "purchased", "4k", "360", "location", "hdr" (comma separated)
26 region: ISO 3166 country code (default: "US")
29 p
: request
.args
.get(p
)
30 for p
in ['sort_by', 'date', 'duration', 'type', 'features', 'region']
34 return "no search query", 400
36 r
= requests
.get(f
"https://invidio.us/api/v1/search", {
42 return "error fetching search results", 502 # TODO: better
44 # XXX: should check r.json if it really are search results (if other provider)
45 # XXX: should transform invidious-json to our naming scheme
46 return render_template('search.html.j2', rows
=r
.json(), query
=q
, page
=page
,
47 optional_params
=optional_params
)
49 @frontend.route('/channel/<channel_id>')
50 @frontend.route('/user/<channel_id>')
51 def channel(channel_id
):
52 # proxying invidious is way slower, so we don't do it for page 0 (i.e the 15 newest videos we can get from youtube ourselves)
53 if 'page' not in request
.args
:
54 return fallback_route(channel_id
)
56 page
= int(request
.args
.get('page', 1))
57 sort_by
= request
.args
.get('sort_by', 'newest')
58 provider
= request
.args
.get('provider', 'invidio.us:443')
60 r
= requests
.get(f
"https://invidio.us/api/v1/channels/{channel_id}/videos", {
63 }, allow_redirects
=False)
64 if not r
.ok
or r
.status_code
!= 200:
65 flash("invidious did not find the channel or is blocked. showing minimal response", "error")
66 return fallback_route(channel_id
)
68 return render_template('channel.html.j2', rows
=r
.json(), sort_by
=sort_by
, page
=page
)
70 @frontend.route('/playlist')
72 # proxying invidious is way slower, so we don't do it for page 0 (i.e the 15 newest videos we can get from youtube ourselves)
73 if 'page' not in request
.args
:
74 return fallback_route()
76 playlist_id
= request
.args
.get('list')
78 return "bad list id", 400 # todo
80 page
= int(request
.args
.get('page', 1))
81 provider
= request
.args
.get('provider', 'invidio.us:443')
83 r
= requests
.get(f
"https://invidio.us/api/v1/playlists/{playlist_id}", {
85 }, allow_redirects
=False)
86 if not r
.ok
or r
.status_code
!= 200:
87 flash("invidious did not find the channel or is blocked. showing minimal response", "error")
88 return fallback_route(playlist_id
)
90 return render_template('channel.html.j2', rows
=r
.json().get('videos',[]), page
=page
)