From bf3219b4e8b8de2db86ff0b1e9491a48ae1850b4 Mon Sep 17 00:00:00 2001 From: rlaphoenix Date: Fri, 17 Mar 2023 21:09:09 +0000 Subject: [PATCH] Ignore empty files when decrypting with Widevine This happens because the input file has no actual useful data, likely just a bunch of headers and nothing of use. Therefore shaka skips and returns OK, yet didnt make any file at the decrypted path. This fixes a crash when it tries to move the non-existent decrypted file to the input file location, causing the rest of the download to halt. --- devine/core/drm/widevine.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/devine/core/drm/widevine.py b/devine/core/drm/widevine.py index d31ed46..f12a8ac 100644 --- a/devine/core/drm/widevine.py +++ b/devine/core/drm/widevine.py @@ -258,11 +258,16 @@ class Widevine: universal_newlines=True ) + stream_skipped = False + shaka_log_buffer = "" for line in iter(p.stderr.readline, ""): line = line.strip() if not line: continue + if "Skip stream" in line: + # file/segment was so small that it didn't have any actual data, ignore + stream_skipped = True if ":INFO:" in line: continue if "Insufficient bits in bitstream for given AVC profile" in line: @@ -283,14 +288,15 @@ class Widevine: if p.returncode != 0: raise subprocess.CalledProcessError(p.returncode, arguments) + + path.unlink() + if not stream_skipped: + shutil.move(decrypted_path, path) except subprocess.CalledProcessError as e: if e.returncode == 0xC000013A: # STATUS_CONTROL_C_EXIT raise KeyboardInterrupt() raise - path.unlink() - shutil.move(decrypted_path, path) - class Exceptions: class PSSHNotFound(Exception): """PSSH (Protection System Specific Header) was not found."""