Skip to content

Commit

Permalink
Media lan check (#1856)
Browse files Browse the repository at this point in the history
* Add require_lan

#1853
  • Loading branch information
clinton-hall authored Oct 10, 2021
1 parent 36eddcf commit 162143b
Show file tree
Hide file tree
Showing 13 changed files with 73 additions and 15 deletions.
2 changes: 2 additions & 0 deletions autoProcessMedia.cfg.spec
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@
PAR2CMD = None
FFPROBE = None
CHECK_MEDIA = None
REQUIRE_LAN = None
NICENESS = []
HWACCEL = False

Expand Down Expand Up @@ -383,6 +384,7 @@ def configure_general():
global FFMPEG_PATH
global SYS_PATH
global CHECK_MEDIA
global REQUIRE_LAN
global SAFE_MODE
global NOEXTRACTFAILED

Expand All @@ -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'])

Expand Down
19 changes: 13 additions & 6 deletions core/auto_process/movies.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
17 changes: 12 additions & 5 deletions core/auto_process/tv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions core/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 6 additions & 2 deletions core/transcoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions nzbToCouchPotato.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions nzbToMedia.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions nzbToNzbDrone.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions nzbToRadarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions nzbToSiCKRAGE.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions nzbToSickBeard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions nzbToWatcher3.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 162143b

Please sign in to comment.