]> git.gir.st - subscriptionfeed.git/blob - app/proxy/__init__.py
fix premiere video handling
[subscriptionfeed.git] / app / proxy / __init__.py
1 import requests, requests_cache
2 from flask import Flask, Blueprint, request, Response
3 from flask_login import current_user
4
5 frontend = Blueprint('proxy', __name__)
6
7 def app():
8 app = Flask(__name__)
9 app.register_blueprint(frontend)
10 return app
11
12 @frontend.route("/videoplayback")
13 def videoplayback():
14 fvip = request.args.get("fvip", "3")
15 mn = request.args.get("mn", "").split(",")[-1]
16 host = f"r{fvip}---{mn}.googlevideo.com"
17
18 REQUEST_HEADERS_WHITELIST = {
19 "accept",
20 "accept-encoding",
21 "cache-control",
22 "range",
23 }
24 RESPONSE_HEADERS_WHITELIST = {
25 "accept-ranges",
26 "cache-control",
27 "content-length",
28 "content-range",
29 "content-type",
30 "expires",
31 "x-content-type-options",
32 }
33
34 req_headers = {
35 k:v for k,v in request.headers
36 if k.lower() in REQUEST_HEADERS_WHITELIST
37 }
38 with requests_cache.disabled():
39 r = requests.get(f"https://{host}/videoplayback", request.args.to_dict(), headers=req_headers, stream=True)
40
41 resp_headers = {
42 k:v for k,v in r.headers.items()
43 if k.lower() in RESPONSE_HEADERS_WHITELIST
44 }
45 response = Response(r.iter_content(chunk_size=8192), status=r.status_code, headers=resp_headers)
46 response.call_on_close(lambda: r.close()) # XXX: does this work?
47 return response
48
49
50 if __name__ == '__main__':
51 app().run(debug=True)
Imprint / Impressum