From 162143b1cdbbf90d53e7d53531ad3390506fbd32 Mon Sep 17 00:00:00 2001 From: Clinton Hall Date: Mon, 11 Oct 2021 07:16:00 +1300 Subject: [PATCH] Media lan check (#1856) * Add require_lan #1853 --- autoProcessMedia.cfg.spec | 2 ++ core/__init__.py | 3 +++ core/auto_process/movies.py | 19 +++++++++++++------ core/auto_process/tv.py | 17 ++++++++++++----- core/configuration.py | 4 ++-- core/transcoder.py | 8 ++++++-- nzbToCouchPotato.py | 5 +++++ nzbToMedia.py | 5 +++++ nzbToNzbDrone.py | 5 +++++ nzbToRadarr.py | 5 +++++ nzbToSiCKRAGE.py | 5 +++++ nzbToSickBeard.py | 5 +++++ nzbToWatcher3.py | 5 +++++ 13 files changed, 73 insertions(+), 15 deletions(-) diff --git a/autoProcessMedia.cfg.spec b/autoProcessMedia.cfg.spec index 479a69499..15bda31e0 100644 --- a/autoProcessMedia.cfg.spec +++ b/autoProcessMedia.cfg.spec @@ -28,6 +28,8 @@ ffmpeg_path = # Enable/Disable media file checking using ffprobe. check_media = 1 + # Required media audio language for media to be deemed valid. Leave blank to disregard media audio language check. + require_lan = # Enable/Disable a safety check to ensure we don't process all downloads in the default_downloadDirectories by mistake. safe_mode = 1 # Turn this on to disable additional extraction attempts for failed downloads. Default = 0 will attempt to extract and verify if media is present. diff --git a/core/__init__.py b/core/__init__.py index 8407fbc55..866b84c3c 100644 --- a/core/__init__.py +++ b/core/__init__.py @@ -265,6 +265,7 @@ PAR2CMD = None FFPROBE = None CHECK_MEDIA = None +REQUIRE_LAN = None NICENESS = [] HWACCEL = False @@ -383,6 +384,7 @@ def configure_general(): global FFMPEG_PATH global SYS_PATH global CHECK_MEDIA + global REQUIRE_LAN global SAFE_MODE global NOEXTRACTFAILED @@ -396,6 +398,7 @@ def configure_general(): FFMPEG_PATH = CFG['General']['ffmpeg_path'] SYS_PATH = CFG['General']['sys_path'] CHECK_MEDIA = int(CFG['General']['check_media']) + REQUIRE_LAN = CFG['General']['require_lan'] or None SAFE_MODE = int(CFG['General']['safe_mode']) NOEXTRACTFAILED = int(CFG['General']['no_extract_failed']) diff --git a/core/auto_process/movies.py b/core/auto_process/movies.py index 076a05370..aebd9a9c9 100644 --- a/core/auto_process/movies.py +++ b/core/auto_process/movies.py @@ -124,25 +124,32 @@ def process(section, dir_name, input_name=None, status=0, client_agent='manual', input_name, dir_name = convert_to_ascii(input_name, dir_name) good_files = 0 + valid_files = 0 num_files = 0 # Check video files for corruption for video in list_media_files(dir_name, media=True, audio=False, meta=False, archives=False): num_files += 1 if transcoder.is_video_good(video, status): - import_subs(video) - rename_subs(dir_name) good_files += 1 - if num_files and good_files == num_files: + if not core.REQUIRE_LAN or transcoder.is_video_good(video, status, require_lan=core.REQUIRE_LAN): + valid_files += 1 + import_subs(video) + rename_subs(dir_name) + if num_files and valid_files == num_files: if status: logger.info('Status shown as failed from Downloader, but {0} valid video files found. Setting as success.'.format(good_files), section) status = 0 - elif num_files and good_files < num_files: + elif num_files and valid_files < num_files: logger.info('Status shown as success from Downloader, but corrupt video files found. Setting as failed.', section) + status = 1 if 'NZBOP_VERSION' in os.environ and os.environ['NZBOP_VERSION'][0:5] >= '14.0': print('[NZB] MARK=BAD') - if failure_link: + if good_files == num_files: + logger.debug('Video marked as failed due to missing required language: {0}'.format(core.REQUIRE_LAN), section) + else: + logger.debug('Video marked as failed due to missing playable audio or video', section) + if good_files < num_files and failure_link: # only report corrupt files failure_link += '&corrupt=true' - status = 1 elif client_agent == 'manual': logger.warning('No media files found in directory {0} to manually process.'.format(dir_name), section) return ProcessResult( diff --git a/core/auto_process/tv.py b/core/auto_process/tv.py index 40d64cc15..84a93427a 100644 --- a/core/auto_process/tv.py +++ b/core/auto_process/tv.py @@ -131,25 +131,32 @@ def process(section, dir_name, input_name=None, failed=False, client_agent='manu # Check video files for corruption good_files = 0 + valid_files = 0 num_files = 0 for video in list_media_files(dir_name, media=True, audio=False, meta=False, archives=False): num_files += 1 if transcoder.is_video_good(video, status): good_files += 1 - import_subs(video) - rename_subs(dir_name) + if not core.REQUIRE_LAN or transcoder.is_video_good(video, status, require_lan=core.REQUIRE_LAN): + valid_files += 1 + import_subs(video) + rename_subs(dir_name) if num_files > 0: - if good_files == num_files and not status == 0: + if valid_files == num_files and not status == 0: logger.info('Found Valid Videos. Setting status Success') status = 0 failed = 0 - if good_files < num_files and status == 0: + if valid_files < num_files and status == 0: logger.info('Found corrupt videos. Setting status Failed') status = 1 failed = 1 if 'NZBOP_VERSION' in os.environ and os.environ['NZBOP_VERSION'][0:5] >= '14.0': print('[NZB] MARK=BAD') - if failure_link: + if good_files == num_files: + logger.debug('Video marked as failed due to missing required language: {0}'.format(core.REQUIRE_LAN), section) + else: + logger.debug('Video marked as failed due to missing playable audio or video', section) + if good_files < num_files and failure_link: # only report corrupt files failure_link += '&corrupt=true' elif client_agent == 'manual': logger.warning('No media files found in directory {0} to manually process.'.format(dir_name), section) diff --git a/core/configuration.py b/core/configuration.py index 0f3b62784..1fb05c0c5 100644 --- a/core/configuration.py +++ b/core/configuration.py @@ -322,8 +322,8 @@ def addnzbget(): cfg_new[section][option] = value section = 'General' - env_keys = ['AUTO_UPDATE', 'CHECK_MEDIA', 'SAFE_MODE', 'NO_EXTRACT_FAILED'] - cfg_keys = ['auto_update', 'check_media', 'safe_mode', 'no_extract_failed'] + env_keys = ['AUTO_UPDATE', 'CHECK_MEDIA', 'REQUIRE_LAN', 'SAFE_MODE', 'NO_EXTRACT_FAILED'] + cfg_keys = ['auto_update', 'check_media', 'require_lan', 'safe_mode', 'no_extract_failed'] for index in range(len(env_keys)): key = 'NZBPO_{index}'.format(index=env_keys[index]) if key in os.environ: diff --git a/core/transcoder.py b/core/transcoder.py index f0da8dd45..e8e83c9f7 100644 --- a/core/transcoder.py +++ b/core/transcoder.py @@ -27,7 +27,7 @@ __author__ = 'Justin' -def is_video_good(videofile, status): +def is_video_good(videofile, status, require_lan=None): file_name_ext = os.path.basename(videofile) file_name, file_ext = os.path.splitext(file_name_ext) disable = False @@ -63,7 +63,11 @@ def is_video_good(videofile, status): if video_details.get('streams'): video_streams = [item for item in video_details['streams'] if item['codec_type'] == 'video'] audio_streams = [item for item in video_details['streams'] if item['codec_type'] == 'audio'] - if len(video_streams) > 0 and len(audio_streams) > 0: + if require_lan: + valid_audio = [item for item in audio_streams if 'tags' in item and 'language' in item['tags'] and item['tags']['language'] == require_lan ] + else: + valid_audio = audio_streams + if len(video_streams) > 0 and len(valid_audio) > 0: logger.info('SUCCESS: [{0}] has no corruption.'.format(file_name_ext), 'TRANSCODER') return True else: diff --git a/nzbToCouchPotato.py b/nzbToCouchPotato.py index 60638200f..9fd263d88 100755 --- a/nzbToCouchPotato.py +++ b/nzbToCouchPotato.py @@ -25,6 +25,11 @@ # Enable/Disable media file checking using ffprobe. #check_media=1 +# Required Language +# +# Required Audio Language for media to be deemed valid e.g. = eng will only accept a video as valid if it contains English audio. Leave blank to disregard. +#require_lan= + # Safe Mode protection of DestDir (0, 1). # # Enable/Disable a safety check to ensure we don't process all downloads in the default_downloadDirectory by mistake. diff --git a/nzbToMedia.py b/nzbToMedia.py index 092c1a2df..240033cc9 100755 --- a/nzbToMedia.py +++ b/nzbToMedia.py @@ -26,6 +26,11 @@ # Enable/Disable media file checking using ffprobe. #check_media=1 +# Required Language +# +# Required Audio Language for media to be deemed valid e.g. = eng will only accept a video as valid if it contains English audio. Leave blank to disregard. +#require_lan= + # Safe Mode protection of DestDir (0, 1). # # Enable/Disable a safety check to ensure we don't process all downloads in the default_downloadDirectory by mistake. diff --git a/nzbToNzbDrone.py b/nzbToNzbDrone.py index 1a49233f7..818bca144 100755 --- a/nzbToNzbDrone.py +++ b/nzbToNzbDrone.py @@ -25,6 +25,11 @@ # Enable/Disable media file checking using ffprobe. #check_media=1 +# Required Language +# +# Required Audio Language for media to be deemed valid e.g. = eng will only accept a video as valid if it contains English audio. Leave blank to disregard. +#require_lan= + # Safe Mode protection of DestDir (0, 1). # # Enable/Disable a safety check to ensure we don't process all downloads in the default_downloadDirectory by mistake. diff --git a/nzbToRadarr.py b/nzbToRadarr.py index 2c4e1810c..7e7510d36 100755 --- a/nzbToRadarr.py +++ b/nzbToRadarr.py @@ -25,6 +25,11 @@ # Enable/Disable media file checking using ffprobe. #check_media=1 +# Required Language +# +# Required Audio Language for media to be deemed valid e.g. = eng will only accept a video as valid if it contains English audio. Leave blank to disregard. +#require_lan= + # Safe Mode protection of DestDir (0, 1). # # Enable/Disable a safety check to ensure we don't process all downloads in the default_downloadDirectory by mistake. diff --git a/nzbToSiCKRAGE.py b/nzbToSiCKRAGE.py index 13e3c28ea..31bd939f6 100755 --- a/nzbToSiCKRAGE.py +++ b/nzbToSiCKRAGE.py @@ -25,6 +25,11 @@ # Enable/Disable media file checking using ffprobe. #check_media=1 +# Required Language +# +# Required Audio Language for media to be deemed valid e.g. = eng will only accept a video as valid if it contains English audio. Leave blank to disregard. +#require_lan= + # Safe Mode protection of DestDir (0, 1). # # Enable/Disable a safety check to ensure we don't process all downloads in the default_downloadDirectory by mistake. diff --git a/nzbToSickBeard.py b/nzbToSickBeard.py index 2cdcfcbf3..24892e2b2 100755 --- a/nzbToSickBeard.py +++ b/nzbToSickBeard.py @@ -25,6 +25,11 @@ # Enable/Disable media file checking using ffprobe. #check_media=1 +# Required Language +# +# Required Audio Language for media to be deemed valid e.g. = eng will only accept a video as valid if it contains English audio. Leave blank to disregard. +#require_lan= + # Safe Mode protection of DestDir (0, 1). # # Enable/Disable a safety check to ensure we don't process all downloads in the default_downloadDirectory by mistake. diff --git a/nzbToWatcher3.py b/nzbToWatcher3.py index 6fafcba2e..e60170eca 100755 --- a/nzbToWatcher3.py +++ b/nzbToWatcher3.py @@ -25,6 +25,11 @@ # Enable/Disable media file checking using ffprobe. #check_media=1 +# Required Language +# +# Required Audio Language for media to be deemed valid e.g. = eng will only accept a video as valid if it contains English audio. Leave blank to disregard. +#require_lan= + # Safe Mode protection of DestDir (0, 1). # # Enable/Disable a safety check to ensure we don't process all downloads in the default_downloadDirectory by mistake.