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.
This commit is contained in:
rlaphoenix 2023-05-08 17:41:55 +01:00
parent bf82065400
commit 1668647e4d
1 changed files with 6 additions and 5 deletions

View File

@ -16,7 +16,7 @@ from urllib.parse import urlparse
import pproxy import pproxy
import requests import requests
from construct import ConstError from construct import ValidationError
from langcodes import Language, closest_match from langcodes import Language, closest_match
from pymp4.parser import Box from pymp4.parser import Box
from unidecode import unidecode 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.""" """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 # 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. # 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)): if not isinstance(data, (bytes, bytearray)):
raise ValueError("data must be bytes") raise ValueError("data must be bytes")
while True: while True:
@ -145,11 +145,12 @@ def get_boxes(data: bytes, box_type: bytes, as_bytes: bool = False) -> Box:
try: try:
box = Box.parse(data) box = Box.parse(data)
except IOError: 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 break
except ConstError as e: except ValidationError as e:
if box_type == b"tenc": 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... # some services don't even put valid data and mix it up with avc1...
continue continue
raise e raise e