1
0
mirror of https://github.com/spaam/svtplay-dl.git synced 2024-11-27 21:54:17 +01:00

fetcher: we need to send a custom header to fetch key in HLS

This commit is contained in:
Johan Andersson 2018-02-12 00:08:09 +01:00
parent 70c94e4131
commit c4f3c8d6f2
2 changed files with 8 additions and 3 deletions

View File

@ -16,6 +16,7 @@ class VideoRetriever(object):
self.audio = kwargs.pop("audio", None)
self.files = kwargs.pop("files", None)
self.keycookie = kwargs.pop("keycookie", None)
self.authorization = kwargs.pop("authorization", None)
def __repr__(self):
return "<Video(fetcher=%s, bitrate=%s>" % (self.__class__.__name__, self.bitrate)

View File

@ -53,6 +53,7 @@ def hlsparse(options, res, url, **kwargs):
m3u8 = M3U8(res.text)
keycookie = kwargs.pop("keycookie", None)
authorization = kwargs.pop("authorization", None)
media = {}
options.segments = m3u8.segments
@ -77,10 +78,10 @@ def hlsparse(options, res, url, **kwargs):
else:
continue # Needs to be changed to utilise other tags.
streams[int(bit_rate)] = HLS(copy.copy(options), urls, bit_rate, cookies=res.cookies, keycookie=keycookie, audio=audio_url)
streams[int(bit_rate)] = HLS(copy.copy(options), urls, bit_rate, cookies=res.cookies, keycookie=keycookie, authorization=authorization, audio=audio_url)
elif m3u8.media_segment:
streams[0] = HLS(copy.copy(options), url, 0, cookies=res.cookies, keycookie=keycookie)
streams[0] = HLS(copy.copy(options), url, 0, cookies=res.cookies, keycookie=keycookie, authorization=authorization)
else:
streams[0] = ServiceError("Can't find HLS playlist in m3u8 file.")
@ -144,15 +145,18 @@ class HLS(VideoRetriever):
break
data = data.content
if m3u8.encrypted:
headers = {}
if self.keycookie:
keycookies = self.keycookie
else:
keycookies = cookies
if self.authorization:
headers["authorization"] = self.authorization
# Update key/decryptor
if "EXT-X-KEY" in i:
keyurl = _get_full_url(i["EXT-X-KEY"]["URI"], url)
key = self.http.request("get", keyurl, cookies=keycookies).content
key = self.http.request("get", keyurl, cookies=keycookies, headers=headers).content
decryptor = AES.new(key, AES.MODE_CBC, os.urandom(16))
if decryptor: