From 0719800145d30e741a3154b4faf956fd0af561ab Mon Sep 17 00:00:00 2001 From: Puyodead1 <14828766+Puyodead1@users.noreply.github.com> Date: Mon, 22 Nov 2021 11:36:05 -0500 Subject: [PATCH] fix: KID extraction error handling + extract_kid method will raise an error if the file does not exist + If KID extraction fails, the lecture will be skipped instead of causing the program to exit --- main.py | 16 ++++++++++++---- utils.py | 3 +++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index 121ea13..15af6e4 100644 --- a/main.py +++ b/main.py @@ -918,11 +918,19 @@ def handle_segments(url, format_id, video_title, print("Return code from the downloader was non-0 (error), skipping!") return - video_kid = extract_kid(video_filepath_enc) - print("KID for video file is: " + video_kid) + try: + video_kid = extract_kid(video_filepath_enc) + print("KID for video file is: " + video_kid) + except Exception as e: + print(f"Error extracting video kid: {e}") + return - audio_kid = extract_kid(audio_filepath_enc) - print("KID for audio file is: " + audio_kid) + try: + audio_kid = extract_kid(audio_filepath_enc) + print("KID for audio file is: " + audio_kid) + except Exception as e: + print(f"Error extracting audio kid: {e}") + return try: decrypt(video_kid, video_filepath_enc, video_filepath_dec) diff --git a/utils.py b/utils.py index a180796..5e23f97 100644 --- a/utils.py +++ b/utils.py @@ -2,6 +2,7 @@ import mp4parse import codecs import widevine_pssh_pb2 import base64 +import os def extract_kid(mp4_file): """ @@ -18,6 +19,8 @@ def extract_kid(mp4_file): """ boxes = mp4parse.F4VParser.parse(filename=mp4_file) + if not os.path.exists(mp4_file): + raise Exception("File does not exist") for box in boxes: if box.header.box_type == 'moov': pssh_box = next(x for x in box.pssh if x.system_id == "edef8ba979d64acea3c827dcd51d21ed")