diff --git a/views.py b/views.py index f301066..e63ebc9 100644 --- a/views.py +++ b/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 diff --git a/ythdd_globals.py b/ythdd_globals.py index f552c0b..78bceca 100644 --- a/ythdd_globals.py +++ b/ythdd_globals.py @@ -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):