How to use the pyexpander.config.LANGUAGES_MAP.items function in pyexpander

To help you get started, we’ve selected a few pyexpander examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github omerbenamram / py-expander / pyexpander / subtitles.py View on Github external
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...')