Esempio n. 1
0
    def _get_missing_subtitle_languages(self, available_subtitles, wanted_languages=None):
        # Use custom wanted languages or globally configured wanted languages if not provided
        if wanted_languages is None:
            wanted_languages = get_wanted_languages()

        available_languages = []
        for subtitle in available_subtitles:
            available_languages.append(subtitle.language)

        # Return the missing languages (= not in available languages)
        return [language for language in wanted_languages if language not in available_languages]
Esempio n. 2
0
def check_missing_subtitle_languages(dirname,
                                     filename,
                                     scan_embedded=False,
                                     scan_hardcoded=False,
                                     detect_invalid=False,
                                     wanted_languages=None):
    log.debug('Checking for missing subtitle(s)')
    missing_languages = []

    # Check embedded languages
    embedded_languages = []
    if scan_embedded:
        embedded_languages = [
            s.language
            for s in get_embedded_subtitles(dirname, filename, log_scan=True)
        ]

    # Check hardcoded languages
    hardcoded_languages = []
    if scan_hardcoded:
        hardcoded_languages = [
            s.language for s in get_hardcoded_subtitles(dirname, filename)
        ]

    # Determine list of languages to check
    languages_to_check = set(wanted_languages or get_wanted_languages())

    # Check default language
    detect_language = False
    if autosubliminal.DEFAULTLANGUAGE and autosubliminal.DEFAULTLANGUAGE in languages_to_check:
        log.debug('Checking for missing default language')
        languages_to_check.remove(autosubliminal.DEFAULTLANGUAGE)
        default_language = Language.fromietf(autosubliminal.DEFAULTLANGUAGE)

        # Check with or without language code suffix depending on configuration
        if autosubliminal.DEFAULTLANGUAGESUFFIX:
            srt_file = os.path.splitext(filename)[
                0] + u'.' + autosubliminal.DEFAULTLANGUAGE + SUBTITLE_EXTENSION
        else:
            srt_file = os.path.splitext(filename)[0] + SUBTITLE_EXTENSION
            detect_language = detect_invalid  # Only for default subtitle without suffix
        srt_path = os.path.join(dirname, srt_file)
        sub_exists = os.path.exists(srt_path)
        if not sub_exists and default_language not in embedded_languages + hardcoded_languages:
            log.debug('Video is missing the default language: %s',
                      autosubliminal.DEFAULTLANGUAGE)
            missing_languages.append(autosubliminal.DEFAULTLANGUAGE)
        elif sub_exists and detect_language:
            log.debug(
                'Subtitle found, checking if it is not an invalid default language'
            )
            detected_language = _detect_subtitle_language(srt_path)
            if detected_language and detected_language != default_language:
                log.warning('Detected an invalid default language: %s',
                            detected_language)
                # Remove the subtitle with an invalid detected language in order to search for a new one
                if _delete_subtitle_file(srt_path, detected_language):
                    log.debug('Video is missing the default language: %s',
                              autosubliminal.DEFAULTLANGUAGE)
                    missing_languages.append(autosubliminal.DEFAULTLANGUAGE)
            else:
                log.debug('No invalid default language detected')

    # Check additional languages
    if languages_to_check:
        log.debug('Checking for missing additional language(s)')

        # Always check with language code suffix for additional languages
        for language in languages_to_check:
            additional_language = Language.fromietf(language)
            srt_file = os.path.splitext(
                filename)[0] + u'.' + language + SUBTITLE_EXTENSION
            if not os.path.exists(
                    os.path.join(dirname, srt_file)
            ) and additional_language not in embedded_languages:
                log.debug('Video is missing the additional language: %s',
                          language)
                missing_languages.append(language)

    return missing_languages
Esempio n. 3
0
def test_get_wanted_languages(monkeypatch):
    monkeypatch.setattr('autosubliminal.DEFAULTLANGUAGE', 'nl')
    monkeypatch.setattr('autosubliminal.ADDITIONALLANGUAGES', ['en', 'fr'])
    assert ['nl', 'en', 'fr'] == get_wanted_languages()
Esempio n. 4
0
 def default_settings(cls, imdb_id):
     return cls(imdb_id=imdb_id,
                wanted_languages=get_wanted_languages(),
                refine=autosubliminal.REFINEVIDEO,
                hearing_impaired=autosubliminal.PREFERHEARINGIMPAIRED,
                utf8_encoding=autosubliminal.SUBTITLEUTF8ENCODING)
Esempio n. 5
0
 def default_settings(cls, imdb_id):
     return cls(imdb_id=imdb_id,
                wanted_languages=get_wanted_languages(),
                refine=autosubliminal.REFINEVIDEO,
                hearing_impaired=autosubliminal.PREFERHEARINGIMPAIRED,
                utf8_encoding=autosubliminal.SUBTITLEUTF8ENCODING)
Esempio n. 6
0
def check_missing_subtitle_languages(dirname, filename, scan_embedded=False, scan_hardcoded=False,
                                     detect_invalid=False, wanted_languages=None):
    log.debug('Checking for missing subtitle(s)')
    missing_languages = []

    # Check embedded languages
    embedded_languages = []
    if scan_embedded:
        embedded_languages = [s.language for s in get_embedded_subtitles(dirname, filename, log_scan=True)]

    # Check hardcoded languages
    hardcoded_languages = []
    if scan_hardcoded:
        hardcoded_languages = [s.language for s in get_hardcoded_subtitles(dirname, filename)]

    # Determine list of languages to check
    languages_to_check = set(wanted_languages or get_wanted_languages())

    # Check default language
    detect_language = False
    if autosubliminal.DEFAULTLANGUAGE and autosubliminal.DEFAULTLANGUAGE in languages_to_check:
        log.debug('Checking for missing default language')
        languages_to_check.remove(autosubliminal.DEFAULTLANGUAGE)
        default_language = Language.fromietf(autosubliminal.DEFAULTLANGUAGE)

        # Check with or without language code suffix depending on configuration
        if autosubliminal.DEFAULTLANGUAGESUFFIX:
            srt_file = os.path.splitext(filename)[0] + u'.' + autosubliminal.DEFAULTLANGUAGE + SUBTITLE_EXTENSION
        else:
            srt_file = os.path.splitext(filename)[0] + SUBTITLE_EXTENSION
            detect_language = detect_invalid  # Only for default subtitle without suffix
        srt_path = os.path.join(dirname, srt_file)
        sub_exists = os.path.exists(srt_path)
        if not sub_exists and default_language not in embedded_languages + hardcoded_languages:
            log.debug('Video is missing the default language: %s', autosubliminal.DEFAULTLANGUAGE)
            missing_languages.append(autosubliminal.DEFAULTLANGUAGE)
        elif sub_exists and detect_language:
            log.debug('Subtitle found, checking if it is not an invalid default language')
            detected_language = _detect_subtitle_language(srt_path)
            if detected_language and detected_language != default_language:
                log.warning('Detected an invalid default language: %s', detected_language)
                # Remove the subtitle with an invalid detected language in order to search for a new one
                if _delete_subtitle_file(srt_path, detected_language):
                    log.debug('Video is missing the default language: %s', autosubliminal.DEFAULTLANGUAGE)
                    missing_languages.append(autosubliminal.DEFAULTLANGUAGE)
            else:
                log.debug('No invalid default language detected')

    # Check additional languages
    if languages_to_check:
        log.debug('Checking for missing additional language(s)')

        # Always check with language code suffix for additional languages
        for language in languages_to_check:
            additional_language = Language.fromietf(language)
            srt_file = os.path.splitext(filename)[0] + u'.' + language + SUBTITLE_EXTENSION
            if not os.path.exists(os.path.join(dirname, srt_file)) and additional_language not in embedded_languages:
                log.debug('Video is missing the additional language: %s', language)
                missing_languages.append(language)

    return missing_languages