Simplified has_subtitle_language and has_audio
This commit is contained in:
@@ -454,24 +454,14 @@ def get_file_name_without_extension(file_path):
|
|||||||
|
|
||||||
def has_subtitle_language(video_file, target_language):
|
def has_subtitle_language(video_file, target_language):
|
||||||
try:
|
try:
|
||||||
container = av.open(video_file)
|
with av.open(video_file) as container:
|
||||||
subtitle_stream = None
|
subtitle_stream = next((stream for stream in container.streams if stream.type == 'subtitle' and 'language' in stream.metadata and stream.metadata['language'] == target_language), None)
|
||||||
|
|
||||||
# Iterate through the streams in the video file
|
if subtitle_stream:
|
||||||
for stream in container.streams:
|
logging.debug(f"Subtitles in '{target_language}' language found in the video.")
|
||||||
if stream.type == 'subtitle':
|
return True
|
||||||
# Check if the subtitle stream has the target language
|
else:
|
||||||
if 'language' in stream.metadata and stream.metadata['language'] == target_language:
|
logging.debug(f"No subtitles in '{target_language}' language found in the video.")
|
||||||
subtitle_stream = stream
|
|
||||||
break
|
|
||||||
|
|
||||||
if subtitle_stream:
|
|
||||||
logging.debug(f"Subtitles in '{target_language}' language found in the video.")
|
|
||||||
return True
|
|
||||||
else:
|
|
||||||
logging.debug(f"No subtitles in '{target_language}' language found in the video.")
|
|
||||||
|
|
||||||
container.close()
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.info(f"An error occurred: {e}")
|
logging.info(f"An error occurred: {e}")
|
||||||
return False
|
return False
|
||||||
@@ -608,10 +598,7 @@ def get_jellyfin_admin(users):
|
|||||||
def has_audio(file_path):
|
def has_audio(file_path):
|
||||||
try:
|
try:
|
||||||
container = av.open(file_path)
|
container = av.open(file_path)
|
||||||
for stream in container.streams:
|
return any(stream.type == 'audio' for stream in container.streams)
|
||||||
if stream.type == 'audio':
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
except (av.AVError, UnicodeDecodeError):
|
except (av.AVError, UnicodeDecodeError):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user