Media lan check (#1856)

* Add require_lan

#1853
This commit is contained in:
Clinton Hall 2021-10-11 07:16:00 +13:00 committed by GitHub
parent 36eddcfb92
commit 162143b1cd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 73 additions and 15 deletions

View file

@ -28,6 +28,8 @@
ffmpeg_path = ffmpeg_path =
# Enable/Disable media file checking using ffprobe. # Enable/Disable media file checking using ffprobe.
check_media = 1 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. # Enable/Disable a safety check to ensure we don't process all downloads in the default_downloadDirectories by mistake.
safe_mode = 1 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. # Turn this on to disable additional extraction attempts for failed downloads. Default = 0 will attempt to extract and verify if media is present.

View file

@ -265,6 +265,7 @@ SHOWEXTRACT = 0
PAR2CMD = None PAR2CMD = None
FFPROBE = None FFPROBE = None
CHECK_MEDIA = None CHECK_MEDIA = None
REQUIRE_LAN = None
NICENESS = [] NICENESS = []
HWACCEL = False HWACCEL = False
@ -383,6 +384,7 @@ def configure_general():
global FFMPEG_PATH global FFMPEG_PATH
global SYS_PATH global SYS_PATH
global CHECK_MEDIA global CHECK_MEDIA
global REQUIRE_LAN
global SAFE_MODE global SAFE_MODE
global NOEXTRACTFAILED global NOEXTRACTFAILED
@ -396,6 +398,7 @@ def configure_general():
FFMPEG_PATH = CFG['General']['ffmpeg_path'] FFMPEG_PATH = CFG['General']['ffmpeg_path']
SYS_PATH = CFG['General']['sys_path'] SYS_PATH = CFG['General']['sys_path']
CHECK_MEDIA = int(CFG['General']['check_media']) CHECK_MEDIA = int(CFG['General']['check_media'])
REQUIRE_LAN = CFG['General']['require_lan'] or None
SAFE_MODE = int(CFG['General']['safe_mode']) SAFE_MODE = int(CFG['General']['safe_mode'])
NOEXTRACTFAILED = int(CFG['General']['no_extract_failed']) NOEXTRACTFAILED = int(CFG['General']['no_extract_failed'])

View file

@ -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) input_name, dir_name = convert_to_ascii(input_name, dir_name)
good_files = 0 good_files = 0
valid_files = 0
num_files = 0 num_files = 0
# Check video files for corruption # Check video files for corruption
for video in list_media_files(dir_name, media=True, audio=False, meta=False, archives=False): for video in list_media_files(dir_name, media=True, audio=False, meta=False, archives=False):
num_files += 1 num_files += 1
if transcoder.is_video_good(video, status): if transcoder.is_video_good(video, status):
good_files += 1
if not core.REQUIRE_LAN or transcoder.is_video_good(video, status, require_lan=core.REQUIRE_LAN):
valid_files += 1
import_subs(video) import_subs(video)
rename_subs(dir_name) rename_subs(dir_name)
good_files += 1 if num_files and valid_files == num_files:
if num_files and good_files == num_files:
if status: if status:
logger.info('Status shown as failed from Downloader, but {0} valid video files found. Setting as success.'.format(good_files), section) logger.info('Status shown as failed from Downloader, but {0} valid video files found. Setting as success.'.format(good_files), section)
status = 0 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) 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': if 'NZBOP_VERSION' in os.environ and os.environ['NZBOP_VERSION'][0:5] >= '14.0':
print('[NZB] MARK=BAD') 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' failure_link += '&corrupt=true'
status = 1
elif client_agent == 'manual': elif client_agent == 'manual':
logger.warning('No media files found in directory {0} to manually process.'.format(dir_name), section) logger.warning('No media files found in directory {0} to manually process.'.format(dir_name), section)
return ProcessResult( return ProcessResult(

View file

@ -131,25 +131,32 @@ def process(section, dir_name, input_name=None, failed=False, client_agent='manu
# Check video files for corruption # Check video files for corruption
good_files = 0 good_files = 0
valid_files = 0
num_files = 0 num_files = 0
for video in list_media_files(dir_name, media=True, audio=False, meta=False, archives=False): for video in list_media_files(dir_name, media=True, audio=False, meta=False, archives=False):
num_files += 1 num_files += 1
if transcoder.is_video_good(video, status): if transcoder.is_video_good(video, status):
good_files += 1 good_files += 1
if not core.REQUIRE_LAN or transcoder.is_video_good(video, status, require_lan=core.REQUIRE_LAN):
valid_files += 1
import_subs(video) import_subs(video)
rename_subs(dir_name) rename_subs(dir_name)
if num_files > 0: 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') logger.info('Found Valid Videos. Setting status Success')
status = 0 status = 0
failed = 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') logger.info('Found corrupt videos. Setting status Failed')
status = 1 status = 1
failed = 1 failed = 1
if 'NZBOP_VERSION' in os.environ and os.environ['NZBOP_VERSION'][0:5] >= '14.0': if 'NZBOP_VERSION' in os.environ and os.environ['NZBOP_VERSION'][0:5] >= '14.0':
print('[NZB] MARK=BAD') 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' failure_link += '&corrupt=true'
elif client_agent == 'manual': elif client_agent == 'manual':
logger.warning('No media files found in directory {0} to manually process.'.format(dir_name), section) logger.warning('No media files found in directory {0} to manually process.'.format(dir_name), section)

View file

@ -322,8 +322,8 @@ class ConfigObj(configobj.ConfigObj, Section):
cfg_new[section][option] = value cfg_new[section][option] = value
section = 'General' section = 'General'
env_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', '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)): for index in range(len(env_keys)):
key = 'NZBPO_{index}'.format(index=env_keys[index]) key = 'NZBPO_{index}'.format(index=env_keys[index])
if key in os.environ: if key in os.environ:

View file

@ -27,7 +27,7 @@ from core.utils import make_dir
__author__ = 'Justin' __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_ext = os.path.basename(videofile)
file_name, file_ext = os.path.splitext(file_name_ext) file_name, file_ext = os.path.splitext(file_name_ext)
disable = False disable = False
@ -63,7 +63,11 @@ def is_video_good(videofile, status):
if video_details.get('streams'): if video_details.get('streams'):
video_streams = [item for item in video_details['streams'] if item['codec_type'] == 'video'] 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'] 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') logger.info('SUCCESS: [{0}] has no corruption.'.format(file_name_ext), 'TRANSCODER')
return True return True
else: else:

View file

@ -25,6 +25,11 @@
# Enable/Disable media file checking using ffprobe. # Enable/Disable media file checking using ffprobe.
#check_media=1 #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). # 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. # Enable/Disable a safety check to ensure we don't process all downloads in the default_downloadDirectory by mistake.

View file

@ -26,6 +26,11 @@
# Enable/Disable media file checking using ffprobe. # Enable/Disable media file checking using ffprobe.
#check_media=1 #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). # 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. # Enable/Disable a safety check to ensure we don't process all downloads in the default_downloadDirectory by mistake.

View file

@ -25,6 +25,11 @@
# Enable/Disable media file checking using ffprobe. # Enable/Disable media file checking using ffprobe.
#check_media=1 #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). # 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. # Enable/Disable a safety check to ensure we don't process all downloads in the default_downloadDirectory by mistake.

View file

@ -25,6 +25,11 @@
# Enable/Disable media file checking using ffprobe. # Enable/Disable media file checking using ffprobe.
#check_media=1 #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). # 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. # Enable/Disable a safety check to ensure we don't process all downloads in the default_downloadDirectory by mistake.

View file

@ -25,6 +25,11 @@
# Enable/Disable media file checking using ffprobe. # Enable/Disable media file checking using ffprobe.
#check_media=1 #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). # 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. # Enable/Disable a safety check to ensure we don't process all downloads in the default_downloadDirectory by mistake.

View file

@ -25,6 +25,11 @@
# Enable/Disable media file checking using ffprobe. # Enable/Disable media file checking using ffprobe.
#check_media=1 #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). # 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. # Enable/Disable a safety check to ensure we don't process all downloads in the default_downloadDirectory by mistake.

View file

@ -25,6 +25,11 @@
# Enable/Disable media file checking using ffprobe. # Enable/Disable media file checking using ffprobe.
#check_media=1 #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). # 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. # Enable/Disable a safety check to ensure we don't process all downloads in the default_downloadDirectory by mistake.