Skip to content

Commit 9810d9f

Browse files
committed
PR kid extraction and fix cache response
1 parent 8ef5ef0 commit 9810d9f

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

getwvkeys/libraries.py

+17-13
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import logging
2222
import secrets
2323
import time
24+
import uuid
2425
import xml.etree.ElementTree as ET
2526
from urllib.parse import urlsplit
2627

@@ -390,6 +391,8 @@ def run(self, curl=False):
390391
result = self.library.search(self.pssh)
391392
if result and len(result) > 0:
392393
cached = self.library.search_res_to_dict(self.kid, result)
394+
if not curl and self.is_web:
395+
return render_template("cache.html", results=cached)
393396
r = jsonify(cached)
394397
r.headers.add_header("X-Cache", "HIT")
395398
return r, 302
@@ -582,9 +585,11 @@ def __init__(
582585
self.downgrade = downgrade
583586
self.is_web = is_web
584587

585-
# if pssh:
586-
# kids = [x.read_attributes()[0] for x in self.pssh.wrm_headers]
587-
# self.kid = base64.b64decode(kids[0][0].value).hex()
588+
if pssh:
589+
kids = [x.read_attributes()[0] for x in self.pssh.wrm_headers]
590+
kid = kids[0][0].value
591+
decoded_kid = base64.b64decode(kid)
592+
self.kid = str(uuid.UUID(bytes_le=decoded_kid))
588593

589594
@staticmethod
590595
def post_data(license_url, headers, data, proxy):
@@ -649,17 +654,16 @@ def external_license(self, method, params, web=False):
649654
raise Exception("Unknown method")
650655

651656
def run(self, curl=False):
652-
# TODO:
653657
# Search for cached keys first
654-
# if not self.force:
655-
# result = self.library.search(kid)
656-
# if result and len(result) > 0:
657-
# cached = self.library.search_res_to_dict(kid, result)
658-
# if not curl:
659-
# return render_template("cache.html", results=cached)
660-
# r = jsonify(cached)
661-
# r.headers.add_header("X-Cache", "HIT")
662-
# return r, 302
658+
if not self.force and self.kid:
659+
result = self.library.search(self.kid)
660+
if result and len(result) > 0:
661+
cached = self.library.search_res_to_dict(self.kid, result)
662+
if not curl and self.is_web:
663+
return render_template("cache.html", results=cached)
664+
r = jsonify(cached)
665+
r.headers.add_header("X-Cache", "HIT")
666+
return r, 302
663667

664668
if self.license_response is None:
665669
# Headers

0 commit comments

Comments
 (0)