From 1668647e4deae4c92d3ddc2ef7f7fe27acf145e8 Mon Sep 17 00:00:00 2001 From: rlaphoenix Date: Mon, 8 May 2023 17:41:55 +0100 Subject: [PATCH] Change ConstError for ValidationError when ignoring tenc errors The change to pymp4 may result in it complaining when validating parameters of the tenc box data, i.e., if the version byte is not 0 or 1, e.t.c. It shouldn't do a ConstError on tenc boxes anymore as the definition of the tenc box has been much improved in pymp4 v1.4.0. --- devine/core/utilities.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/devine/core/utilities.py b/devine/core/utilities.py index 541b054..0706203 100644 --- a/devine/core/utilities.py +++ b/devine/core/utilities.py @@ -16,7 +16,7 @@ from urllib.parse import urlparse import pproxy import requests -from construct import ConstError +from construct import ValidationError from langcodes import Language, closest_match from pymp4.parser import Box from unidecode import unidecode @@ -129,7 +129,7 @@ def get_boxes(data: bytes, box_type: bytes, as_bytes: bool = False) -> Box: """Scan a byte array for a wanted box, then parse and yield each find.""" # using slicing to get to the wanted box is done because parsing the entire box and recursively # scanning through each box and its children often wouldn't scan far enough to reach the wanted box. - # since it doesnt care what child box the wanted box is from, this works fine. + # since it doesn't care what child box the wanted box is from, this works fine. if not isinstance(data, (bytes, bytearray)): raise ValueError("data must be bytes") while True: @@ -145,11 +145,12 @@ def get_boxes(data: bytes, box_type: bytes, as_bytes: bool = False) -> Box: try: box = Box.parse(data) except IOError: - # TODO: Does this miss any data we may need? + # since get_init_segment might cut off unexpectedly, pymp4 may be unable to read + # the expected amounts of data and complain, so let's just end the function here break - except ConstError as e: + except ValidationError as e: if box_type == b"tenc": - # ignore this error on tenc boxes as the tenc definition isn't consistent + # ignore this error on tenc boxes as the tenc definition isn't consistent, # some services don't even put valid data and mix it up with avc1... continue raise e