From c681c500e8479bcbdf00776ca404f46e3d82b215 Mon Sep 17 00:00:00 2001 From: Roland Date: Wed, 18 May 2022 18:36:12 -0600 Subject: [PATCH] Checking for corruption in bytes to avoid unicode error. --- main.py | 3 +++ modules/videos/common.py | 9 ++++----- modules/videos/test/test_common.py | 6 +++--- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/main.py b/main.py index 4ead2952..3be0cf2c 100755 --- a/main.py +++ b/main.py @@ -54,6 +54,9 @@ videos = list(videos) for video in videos: get_video_duration(video.video_path.path) +Check local variables: +locals().keys() + ''' diff --git a/modules/videos/common.py b/modules/videos/common.py index 1c450f5d..f40167b6 100644 --- a/modules/videos/common.py +++ b/modules/videos/common.py @@ -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 diff --git a/modules/videos/test/test_common.py b/modules/videos/test/test_common.py index 25ee41eb..1bb99010 100644 --- a/modules/videos/test/test_common.py +++ b/modules/videos/test/test_common.py @@ -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