From 8268825ba8fa84f92e9669565e98920acff18ded Mon Sep 17 00:00:00 2001 From: rlaphoenix Date: Tue, 21 Feb 2023 08:02:32 +0000 Subject: [PATCH] Use Widevine.from_init_data when downloading DASH This is required as some DASH manifests do not explicitly list the PSSH with the Widevine ContentProtection, only listing that its a supported. --- devine/core/manifests/dash.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/devine/core/manifests/dash.py b/devine/core/manifests/dash.py index f9f417e..7d93cf3 100644 --- a/devine/core/manifests/dash.py +++ b/devine/core/manifests/dash.py @@ -392,6 +392,17 @@ class DASH: )) res.raise_for_status() init_data = res.content + if not drm: + try: + drm = Widevine.from_init_data(init_data) + except Widevine.Exceptions.PSSHNotFound: + # it might not have Widevine DRM, or might not have found the PSSH + log.warning("No Widevine PSSH was found for this track, is it DRM free?") + else: + # license and grab content keys + if not license_widevine: + raise ValueError("license_widevine func must be supplied to use Widevine DRM") + license_widevine(drm) for i, segment_url in enumerate(tqdm(segment_urls, unit="segments")): segment_filename = str(i).zfill(len(str(len(segment_urls)))) @@ -447,6 +458,17 @@ class DASH: res = session.get(source_url) res.raise_for_status() init_data = res.content + if not drm: + try: + drm = Widevine.from_init_data(init_data) + except Widevine.Exceptions.PSSHNotFound: + # it might not have Widevine DRM, or might not have found the PSSH + log.warning("No Widevine PSSH was found for this track, is it DRM free?") + else: + # license and grab content keys + if not license_widevine: + raise ValueError("license_widevine func must be supplied to use Widevine DRM") + license_widevine(drm) for i, segment_url in enumerate(tqdm(segment_list.findall("SegmentURL"), unit="segments")): segment_filename = str(i).zfill(len(str(len(segment_urls))))