feat: support for md5 videoplayback url shortening
md5(url) can be supplied as md5 param to shorten videoplayback url
This commit is contained in:
13
views.py
13
views.py
@@ -1,8 +1,8 @@
|
||||
#!/usr/bin/python3
|
||||
from flask import render_template, request, Response
|
||||
from flask import redirect, render_template, request, Response
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
from markupsafe import escape
|
||||
import json, re, requests
|
||||
import hashlib, json, re, requests
|
||||
import ythdd_globals
|
||||
|
||||
def homepage():
|
||||
@@ -93,6 +93,15 @@ def videoplaybackProxy():
|
||||
proxy_headers["Range"] = headers["Range"]
|
||||
|
||||
params = dict(request.args)
|
||||
# support md5 videoplayback url shortening
|
||||
if "md5" in params:
|
||||
if params["md5"] not in ythdd_globals.general_cache["hashed_videoplayback"]:
|
||||
return Response(json.dumps({"error": "Videoplayback request not cached or expired."}), mimetype="application/json", status=404)
|
||||
return redirect(ythdd_globals.general_cache["hashed_videoplayback"][params["md5"]]["original_url"])
|
||||
else:
|
||||
md5sum = hashlib.md5(request.url.encode("utf-8")).hexdigest()
|
||||
ythdd_globals.general_cache["hashed_videoplayback"][md5sum] = {"original_url": request.url}
|
||||
|
||||
|
||||
# reconstruct the url
|
||||
# first attempt: from host param
|
||||
|
||||
@@ -23,7 +23,7 @@ version = "0.0.1"
|
||||
apiVersion = "1"
|
||||
randomly_generated_passcode = 0
|
||||
video_cache = {}
|
||||
general_cache = {"search": [], "continuations": {"channels": {}, "comments": {}}, "channels": {}, "playlists": {}}
|
||||
general_cache = {"search": [], "continuations": {"channels": {}, "comments": {}}, "channels": {}, "playlists": {}, "hashed_videoplayback": {}}
|
||||
|
||||
def getConfig(configfile):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user