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
This commit is contained in:
Puyodead1 2021-11-22 11:36:05 -05:00
parent 59538b24ce
commit 0719800145
2 changed files with 15 additions and 4 deletions

16
main.py
View File

@ -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)

View File

@ -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")