示例#1
0
def config_subtitles():
    return {
        'enabled':
        bool(app.USE_SUBTITLES),
        'languages':
        app.SUBTITLES_LANGUAGES,
        'wantedLanguages': [{
            'id': code,
            'name': name_from_code(code)
        } for code in wanted_languages()],
        'codeFilter': [{
            'id': code,
            'name': name_from_code(code)
        } for code in subtitle_code_filter()],
        'services':
        app.SUBTITLE_SERVICES,
        'stopAtFirst':
        bool(app.SUBTITLES_STOP_AT_FIRST),
        'eraseCache':
        bool(app.SUBTITLES_ERASE_CACHE),
        'location':
        app.SUBTITLES_DIR,
        'finderFrequency':
        int(app.SUBTITLES_FINDER_FREQUENCY),
        'perfectMatch':
        bool(app.SUBTITLES_PERFECT_MATCH),
        'logHistory':
        bool(app.SUBTITLES_HISTORY),
        'multiLanguage':
        bool(app.SUBTITLES_MULTI),
        'keepOnlyWanted':
        bool(app.SUBTITLES_KEEP_ONLY_WANTED),
        'ignoreEmbeddedSubs':
        bool(app.IGNORE_EMBEDDED_SUBS),
        'acceptUnknownEmbeddedSubs':
        bool(app.ACCEPT_UNKNOWN_EMBEDDED_SUBS),
        'hearingImpaired':
        bool(app.SUBTITLES_HEARING_IMPAIRED),
        'preScripts':
        app.SUBTITLES_PRE_SCRIPTS,
        'extraScripts':
        app.SUBTITLES_EXTRA_SCRIPTS,
        'wikiUrl':
        app.SUBTITLES_URL,
        'providerLogins': {
            'addic7ed': {
                'user': app.ADDIC7ED_USER,
                'pass': app.ADDIC7ED_PASS
            },
            'legendastv': {
                'user': app.LEGENDASTV_USER,
                'pass': app.LEGENDASTV_PASS
            },
            'opensubtitles': {
                'user': app.OPENSUBTITLES_USER,
                'pass': app.OPENSUBTITLES_PASS
            }
        }
    }
示例#2
0
def test_name_from_code__unknown_code():
    # Given
    code = 'trash'

    # When
    actual = sut.name_from_code(code)

    # Then
    assert 'Undetermined' == actual
示例#3
0
def test_name_from_code__valid_code():
    # Given
    code = 'pob'

    # When
    actual = sut.name_from_code(code)

    # Then
    assert 'Portuguese' == actual
示例#4
0
def test_name_from_code__unknown_code():
    # Given
    code = 'trash'

    # When
    actual = sut.name_from_code(code)

    # Then
    assert 'Undetermined' == actual
示例#5
0
def test_name_from_code__valid_code():
    # Given
    code = 'pob'

    # When
    actual = sut.name_from_code(code)

    # Then
    assert 'Portuguese' == actual
示例#6
0
    def searchEpisodeSubtitles(self,
                               showslug=None,
                               season=None,
                               episode=None,
                               lang=None):
        # retrieve the episode object and fail if we can't get one
        series_obj = Series.find_by_identifier(
            SeriesIdentifier.from_slug(showslug))
        ep_obj = series_obj.get_episode(season, episode)
        if not ep_obj:
            return json.dumps({
                'result': 'failure',
            })

        try:
            if lang:
                logger.log(
                    'Manual re-downloading subtitles for {show} with language {lang}'
                    .format(show=ep_obj.series.name, lang=lang))
            new_subtitles = ep_obj.download_subtitles(lang=lang)
        except Exception as error:
            return json.dumps({
                'result':
                'failure',
                'description':
                'Error while downloading subtitles: {error}'.format(
                    error=error)
            })

        if new_subtitles:
            new_languages = [
                subtitles.name_from_code(code) for code in new_subtitles
            ]
            description = 'New subtitles downloaded: {languages}'.format(
                languages=', '.join(new_languages))
            result = 'success'
        else:
            new_languages = []
            description = 'No subtitles downloaded'
            result = 'failure'

        ui.notifications.message(ep_obj.series.name, description)
        return json.dumps({
            'result': result,
            'subtitles': ep_obj.subtitles,
            'languages': new_languages,
            'description': description
        })