Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def find_file_subtitles(path):
"""
Finds subtitles for the given video file path.
:param path: The path of the video file to find subtitles to.
:return: The list of subtitles file paths, or None if a problem occurred.
"""
logger.info('Searching subtitles for file: {}'.format(path))
try:
# Get required video information.
video = subliminal.scan_video(path)
other_languages = []
subtitle_results = []
for language, providers in LANGUAGES_MAP.items():
# Filter providers the user didn't ask for.
if not providers:
other_languages.append(language)
else:
current_result = subliminal.download_best_subtitles(
{video}, languages={language}, providers=providers).values()
if len(current_result) > 0:
subtitle_results.extend(list(current_result)[0])
# Download all other languages.
for language in other_languages:
current_result = subliminal.download_best_subtitles({video}, languages={language}).values()
if len(current_result) > 0:
subtitle_results.extend(list(current_result)[0])
# Handle results.
if len(subtitle_results) == 0:
logger.info('No subtitles were found. Moving on...')