new iOS/web extractors, image proxying done by views.py
- ythdd_globals.py - added helper function to get user-configured header - ythdd.py - now checks for config.toml in work directory - requirements.txt - add brotli, so that requests can decompress innertube request
This commit is contained in:
33
views.py
33
views.py
@@ -1,8 +1,9 @@
|
||||
#!/usr/bin/python3
|
||||
from flask import render_template
|
||||
from flask import render_template, Response
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
from markupsafe import escape
|
||||
import requests, json
|
||||
import ythdd_globals
|
||||
|
||||
def homepage():
|
||||
return "homepage"
|
||||
@@ -11,4 +12,32 @@ def home():
|
||||
return "welcome home!"
|
||||
|
||||
def index():
|
||||
return "index"
|
||||
return "index"
|
||||
|
||||
def thumbnailProxy(received_request):
|
||||
|
||||
# apparently, this can be set to
|
||||
# https://img.youtube.com/ as well
|
||||
prefix = "https://i.ytimg.com/"
|
||||
|
||||
if received_request.count("/") < 1 or received_request.index("/") != 11:
|
||||
return Response(json.dumps({
|
||||
'status': 400,
|
||||
'error_msg': 'invalid request. pretend this is a thumbnail :D'
|
||||
}), mimetype='application/json', status=400)
|
||||
|
||||
thumbnail = requests.get(prefix + "vi/" + received_request, headers=ythdd_globals.getHeaders(caller='proxy'), stream=True)
|
||||
thumbnail.raw.decode_content = True
|
||||
response = Response(thumbnail.raw, mimetype=thumbnail.headers['content-type'], status=thumbnail.status_code)
|
||||
|
||||
return response
|
||||
|
||||
def ggphtProxy(received_request):
|
||||
|
||||
prefix = "https://yt3.ggpht.com/"
|
||||
|
||||
ggpht = requests.get(prefix + received_request, headers=ythdd_globals.getHeaders(caller='proxy'), stream=True)
|
||||
ggpht.raw.decode_content = True
|
||||
response = Response(ggpht.raw, mimetype=ggpht.headers['content-type'], status=ggpht.status_code)
|
||||
|
||||
return response
|
||||
|
||||
Reference in New Issue
Block a user