forked from DRMTalks/devine
Add support for data URIs from HLS playlists in ClearKey
This commit is contained in:
parent
221cd1c283
commit
45c9ba5198
|
@ -1,5 +1,6 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import base64
|
||||||
import shutil
|
import shutil
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Optional, Union
|
from typing import Optional, Union
|
||||||
|
@ -58,23 +59,32 @@ class ClearKey:
|
||||||
if not m3u_key.uri:
|
if not m3u_key.uri:
|
||||||
raise ValueError("No URI in M3U Key, unable to get Key.")
|
raise ValueError("No URI in M3U Key, unable to get Key.")
|
||||||
|
|
||||||
res = requests.get(
|
if m3u_key.uri.startswith("data:"):
|
||||||
url=urljoin(m3u_key.base_uri, m3u_key.uri),
|
media_types, data = m3u_key.uri[5:].split(",")
|
||||||
headers={
|
media_types = media_types.split(";")
|
||||||
"User-Agent": "smartexoplayer/1.1.0 (Linux;Android 8.0.0) ExoPlayerLib/2.13.3"
|
if "base64" in media_types:
|
||||||
},
|
data = base64.b64decode(data)
|
||||||
proxies={"all": proxy} if proxy else None
|
key = data
|
||||||
)
|
else:
|
||||||
res.raise_for_status()
|
url = urljoin(m3u_key.base_uri, m3u_key.uri)
|
||||||
if not res.content:
|
res = requests.get(
|
||||||
raise EOFError("Unexpected Empty Response by M3U Key URI.")
|
url=url,
|
||||||
if len(res.content) < 16:
|
headers={
|
||||||
raise EOFError(f"Unexpected Length of Key ({len(res.content)} bytes) in M3U Key.")
|
"User-Agent": "smartexoplayer/1.1.0 (Linux;Android 8.0.0) ExoPlayerLib/2.13.3"
|
||||||
|
},
|
||||||
|
proxies={"all": proxy} if proxy else None
|
||||||
|
)
|
||||||
|
res.raise_for_status()
|
||||||
|
if not res.content:
|
||||||
|
raise EOFError("Unexpected Empty Response by M3U Key URI.")
|
||||||
|
if len(res.content) < 16:
|
||||||
|
raise EOFError(f"Unexpected Length of Key ({len(res.content)} bytes) in M3U Key.")
|
||||||
|
key = res.content
|
||||||
|
|
||||||
key = res.content
|
|
||||||
iv = None
|
|
||||||
if m3u_key.iv:
|
if m3u_key.iv:
|
||||||
iv = bytes.fromhex(m3u_key.iv.replace("0x", ""))
|
iv = bytes.fromhex(m3u_key.iv.replace("0x", ""))
|
||||||
|
else:
|
||||||
|
iv = None
|
||||||
|
|
||||||
return cls(key=key, iv=iv)
|
return cls(key=key, iv=iv)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue