add support for GUC proxy, move safeTraverse to ythdd_globals
This commit is contained in:
10
views.py
10
views.py
@@ -41,3 +41,13 @@ def ggphtProxy(received_request):
|
|||||||
response = Response(ggpht.raw, mimetype=ggpht.headers['content-type'], status=ggpht.status_code)
|
response = Response(ggpht.raw, mimetype=ggpht.headers['content-type'], status=ggpht.status_code)
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
def gucProxy(received_request):
|
||||||
|
|
||||||
|
prefix = "https://yt3.googleusercontent.com/"
|
||||||
|
|
||||||
|
guc = requests.get(prefix + received_request, headers=ythdd_globals.getHeaders(caller='proxy'), stream=True)
|
||||||
|
guc.raw.decode_content = True
|
||||||
|
response = Response(guc.raw, mimetype=guc.headers['content-type'], status=guc.status_code)
|
||||||
|
|
||||||
|
return response
|
||||||
1
ythdd.py
1
ythdd.py
@@ -62,6 +62,7 @@ def setup():
|
|||||||
app.add_url_rule('/api/<path:received_request>', view_func=ythdd_api.api_global_catchall)
|
app.add_url_rule('/api/<path:received_request>', view_func=ythdd_api.api_global_catchall)
|
||||||
app.add_url_rule('/vi/<path:received_request>', view_func=views.thumbnailProxy)
|
app.add_url_rule('/vi/<path:received_request>', view_func=views.thumbnailProxy)
|
||||||
app.add_url_rule('/ggpht/<path:received_request>', view_func=views.ggphtProxy)
|
app.add_url_rule('/ggpht/<path:received_request>', view_func=views.ggphtProxy)
|
||||||
|
app.add_url_rule('/guc/<path:received_request>', view_func=views.gucProxy)
|
||||||
db = ythdd_db.initDB(app, config)
|
db = ythdd_db.initDB(app, config)
|
||||||
|
|
||||||
with app.app_context():
|
with app.app_context():
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
import brotli, yt_dlp, requests, json, time
|
import brotli, yt_dlp, requests, json, time
|
||||||
|
from ythdd_globals import safeTraverse
|
||||||
import ythdd_globals
|
import ythdd_globals
|
||||||
|
|
||||||
ytdl_opts = {
|
ytdl_opts = {
|
||||||
|
|||||||
@@ -86,8 +86,21 @@ def translateLinks(link):
|
|||||||
|
|
||||||
link = link.replace("https://i.ytimg.com/", config['general']['public_facing_url'])
|
link = link.replace("https://i.ytimg.com/", config['general']['public_facing_url'])
|
||||||
link = link.replace("https://yt3.ggpht.com/", config['general']['public_facing_url'] + "ggpht/")
|
link = link.replace("https://yt3.ggpht.com/", config['general']['public_facing_url'] + "ggpht/")
|
||||||
|
link = link.replace("https://yt3.googleusercontent.com/", config['general']['public_facing_url'] + "guc/")
|
||||||
|
|
||||||
return link
|
return link
|
||||||
|
|
||||||
def getUptime():
|
def getUptime():
|
||||||
return int(time.time()) - starttime
|
return int(time.time()) - starttime
|
||||||
|
|
||||||
|
def safeTraverse(obj: dict, path: list, default=None):
|
||||||
|
result = obj
|
||||||
|
try:
|
||||||
|
for x in path:
|
||||||
|
#print(f"traversing {result} with respect to {x}")
|
||||||
|
result = result[x]
|
||||||
|
except KeyError:
|
||||||
|
result = default
|
||||||
|
print(f"error reading: {' -> '.join(path)} - returning: {default}")
|
||||||
|
finally:
|
||||||
|
return result
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
from flask import Response, request, redirect
|
from flask import Response, request, redirect
|
||||||
from markupsafe import escape
|
from markupsafe import escape
|
||||||
from time import strftime, gmtime, time
|
from time import strftime, gmtime, time
|
||||||
|
from ythdd_globals import safeTraverse
|
||||||
import json, datetime
|
import json, datetime
|
||||||
import invidious_formats
|
import invidious_formats
|
||||||
import ythdd_globals
|
import ythdd_globals
|
||||||
@@ -78,17 +79,6 @@ def trending():
|
|||||||
def popular():
|
def popular():
|
||||||
return send(200, [{}])
|
return send(200, [{}])
|
||||||
|
|
||||||
def safeTraverse(obj: dict, path: list, default=None):
|
|
||||||
result = obj
|
|
||||||
try:
|
|
||||||
for x in path:
|
|
||||||
result = result[x]
|
|
||||||
except KeyError:
|
|
||||||
result = default
|
|
||||||
print(f"error reading: {' -> '.join(path)} - returning: {default}")
|
|
||||||
finally:
|
|
||||||
return result
|
|
||||||
|
|
||||||
def getError(idata: dict):
|
def getError(idata: dict):
|
||||||
unknown_error = {"status": "Unknown error", "reason": "This is a generic ythdd error."}
|
unknown_error = {"status": "Unknown error", "reason": "This is a generic ythdd error."}
|
||||||
error = ""
|
error = ""
|
||||||
|
|||||||
Reference in New Issue
Block a user