Exemple #1
0
def list_subtitles(tv_episode, video_path=None, limit=40):
    """List subtitles for the given episode in the given path.

    :param tv_episode:
    :type tv_episode: medusa.tv.Episode
    :param video_path:
    :type video_path: text_type
    :param limit:
    :type limit: int
    :return:
    :rtype: list of dict
    """
    subtitles_dir = get_subtitles_dir(video_path)
    release_name = tv_episode.release_name

    languages = from_codes(wanted_languages())

    video = get_video(tv_episode,
                      video_path,
                      subtitles_dir=subtitles_dir,
                      subtitles=False,
                      embedded_subtitles=False,
                      release_name=release_name)
    pool = get_provider_pool()
    pool.discarded_providers.clear()
    subtitles_list = pool.list_subtitles(video, languages)
    scored_subtitles = score_subtitles(subtitles_list, video)[:limit]
    for subtitle, _ in scored_subtitles:
        cache.set(
            subtitle_key.format(id=subtitle.id).encode('utf-8'), subtitle)

    logger.debug('Scores computed for release: {release}'.format(
        release=os.path.basename(video_path)))

    max_score = episode_scores['hash']
    max_scores = set(episode_scores) - {'hearing_impaired', 'hash'}
    factor = max_score / 9
    return [{
        'id':
        subtitle.id,
        'provider':
        subtitle.provider_name,
        'missing_guess':
        sorted(list(max_scores - subtitle.get_matches(video))),
        'lang':
        subtitle.language.opensubtitles,
        'score':
        round(10 * (factor / (float(factor - 1 - score + max_score)))),
        'sub_score':
        score,
        'hearing_impaired':
        subtitle.hearing_impaired,
        'max_score':
        max_score,
        'min_score':
        get_min_score(),
        'filename':
        get_subtitle_description(subtitle)
    } for subtitle, score in scored_subtitles]
Exemple #2
0
def list_subtitles(tv_episode, video_path=None, limit=40):
    """List subtitles for the given episode in the given path.

    :param tv_episode:
    :type tv_episode: medusa.tv.Episode
    :param video_path:
    :type video_path: text_type
    :param limit:
    :type limit: int
    :return:
    :rtype: list of dict
    """
    subtitles_dir = get_subtitles_dir(video_path)
    release_name = tv_episode.release_name

    languages = from_codes(wanted_languages())

    video = get_video(tv_episode, video_path, subtitles_dir=subtitles_dir, subtitles=False,
                      embedded_subtitles=False, release_name=release_name)
    pool = get_provider_pool()
    pool.discarded_providers.clear()
    subtitles_list = pool.list_subtitles(video, languages)
    scored_subtitles = score_subtitles(subtitles_list, video)[:limit]
    for subtitle, _ in scored_subtitles:
        cache.set(subtitle_key.format(id=subtitle.id).encode('utf-8'), subtitle)

    logger.debug('Scores computed for release: {release}'.format(release=os.path.basename(video_path)))

    max_score = episode_scores['hash']
    max_scores = set(episode_scores) - {'hearing_impaired', 'hash'}
    factor = max_score / 9
    return [{'id': subtitle.id,
             'provider': subtitle.provider_name,
             'missing_guess': sorted(list(max_scores - subtitle.get_matches(video))),
             'lang': subtitle.language.opensubtitles,
             'score': round(10 * (factor / (float(factor - 1 - score + max_score)))),
             'sub_score': score,
             'hearing_impaired': subtitle.hearing_impaired,
             'max_score': max_score,
             'min_score': get_min_score(),
             'filename': get_subtitle_description(subtitle)}
            for subtitle, score in scored_subtitles]