Checking for corruption in bytes to avoid unicode error.

This commit is contained in:
Roland 2022-05-18 18:36:12 -06:00
parent df72735289
commit c681c500e8
No known key found for this signature in database
GPG key ID: 9D6DBD3ACF11AB93
3 changed files with 10 additions and 8 deletions

View file

@ -54,6 +54,9 @@ videos = list(videos)
for video in videos:
get_video_duration(video.video_path.path)
Check local variables:
locals().keys()
'''

View file

@ -275,14 +275,13 @@ def check_for_video_corruption(video_path: Path) -> bool:
return True # video is corrupt.
messages = (
'Invalid NAL unit size',
'Error splitting the input into NAL units',
b'Invalid NAL unit size',
b'Error splitting the input into NAL units',
)
stderr = proc.stderr.decode()
corrupt = False
for error in messages:
if error in stderr:
logger.warning(f'Possible video corruption ({error}): {video_path}')
if error in proc.stderr:
logger.warning(f'Possible video corruption ({error.decode()}): {video_path}')
corrupt = True
return corrupt

View file

@ -435,9 +435,9 @@ def test_check_for_video_corruption(video_file, test_directory):
# Check for specific ffprobe errors.
with mock.patch('modules.videos.common.subprocess') as mock_subprocess:
# `video_file` is ignored for these calls.
mock_subprocess.run().stderr.decode.return_value = 'Something\nInvalid NAL unit size'
mock_subprocess.run().stderr = b'Something\nInvalid NAL unit size'
assert common.check_for_video_corruption(video_file) is True
mock_subprocess.run().stderr.decode.return_value = 'Something\nError splitting the input into NAL units'
mock_subprocess.run().stderr = b'Something\nError splitting the input into NAL units'
assert common.check_for_video_corruption(video_file) is True
mock_subprocess.run().stderr.decode.return_value = 'Some stderr is fine'
mock_subprocess.run().stderr = b'Some stderr is fine'
assert common.check_for_video_corruption(video_file) is False