'Configuration::
subliminal:
languages: List of languages (as IETF codes) in order of preference. At least one is required.
alternatives: List of second-choice languages; subs will be downloaded but entries rejected.
exact_match: Use file hash only to search for subs, otherwise Subliminal will try to guess by filename.
providers: List of providers from where to download subtitles.
single: Download subtitles in single mode (no language code added to subtitle filename).
directory: Path to directory where to save the subtitles, default is next to the video.
hearing_impaired: Prefer subtitles for the hearing impaired when available
authentication: >
Dictionary of configuration options for different providers.
Keys correspond to provider names, and values are dictionaries, usually specifying `username` and
`password`.'

def on_task_output(self, task, config):

    if (not task.accepted):
        log.debug(u'nothing    accepted,    aborting')
        return
    from babelfish import Language
    from dogpile.cache.exception import RegionAlreadyConfigured
    import subliminal
    from subliminal import scan_video, save_subtitles
    from subliminal.cli import MutexLock
    from subliminal.core import ARCHIVE_EXTENSIONS, scan_archive, refine, search_external_subtitles
    from subliminal.score import episode_scores, movie_scores
    from subliminal.video import VIDEO_EXTENSIONS
    try:
        subliminal.region.configure(u'dogpile.cache.dbm', arguments={u'filename': os.path.join(tempfile.gettempdir(), u'cachefile.dbm'), u'lock_factory': MutexLock})
    except RegionAlreadyConfigured:
        pass
    if log.isEnabledFor(logging.DEBUG):
        logging.getLogger(u'subliminal').setLevel(logging.INFO)
    else:
        logging.getLogger(u'subliminal').setLevel(logging.CRITICAL)
    logging.getLogger(u'dogpile').setLevel(logging.CRITICAL)
    logging.getLogger(u'enzyme').setLevel(logging.WARNING)
    try:
        languages = set([Language.fromietf(s) for s in config.get(u'languages', [])])
        alternative_languages = set([Language.fromietf(s) for s in config.get(u'alternatives', [])])
    except ValueError as e:
        raise plugin.PluginError(e)
    downloaded_subtitles = collections.defaultdict(list)
    providers_list = config.get(u'providers', None)
    provider_configs = config.get(u'authentication', None)
    single_mode = (config.get(u'single', u'') and (len((languages | alternative_languages)) <= 1))
    hearing_impaired = config.get(u'hearing_impaired', False)
    with subliminal.core.ProviderPool(providers=providers_list, provider_configs=provider_configs) as provider_pool:
        for entry in task.accepted:
            if (u'location' not in entry):
                log.warning(u'Cannot    act    on    entries    that    do    not    represent    a    local    file.')
                continue
            if (not os.path.exists(entry[u'location'])):
                entry.fail((u'file    not    found:    %s' % entry[u'location']))
                continue
            if (u'$RECYCLE.BIN' in entry[u'location']):
                continue
            try:
                entry_languages = (set(entry.get(u'subtitle_languages', [])) or languages)
                if entry[u'location'].endswith(VIDEO_EXTENSIONS):
                    video = scan_video(entry[u'location'])
                elif entry[u'location'].endswith(ARCHIVE_EXTENSIONS):
                    video = scan_archive(entry[u'location'])
                else:
                    entry.reject(u'File    extension    is    not    a    supported    video    or    archive    extension')
                    continue
                refiner = (u'metadata',)
                refine(video, episode_refiners=refiner, movie_refiners=refiner)
                existing_subtitles = set(search_external_subtitles(entry[u'location']).values())
                video.subtitle_languages |= existing_subtitles
                if isinstance(video, subliminal.Episode):
                    title = video.series
                    hash_scores = episode_scores[u'hash']
                else:
                    title = video.title
                    hash_scores = movie_scores[u'hash']
                log.info(u'Name    computed    for    %s    was    %s', entry[u'location'], title)
                msc = (hash_scores if config[u'exact_match'] else 0)
                if (entry_languages.issubset(video.subtitle_languages) or (single_mode and video.subtitle_languages)):
                    log.debug(u'All    preferred    languages    already    exist    for    "%s"', entry[u'title'])
                    entry[u'subtitles_missing'] = set()
                    continue
                else:
                    all_subtitles = provider_pool.list_subtitles(video, (entry_languages | alternative_languages))
                    subtitles = provider_pool.download_best_subtitles(all_subtitles, video, entry_languages, min_score=msc, hearing_impaired=hearing_impaired)
                    if subtitles:
                        downloaded_subtitles[video].extend(subtitles)
                        log.info(u'Subtitles    found    for    %s', entry[u'location'])
                    else:
                        subtitles = provider_pool.download_best_subtitles(all_subtitles, video, alternative_languages, min_score=msc, hearing_impaired=hearing_impaired)
                        if subtitles:
                            downloaded_subtitles[video].extend(subtitles)
                            entry.fail(u'subtitles    found    for    a    second-choice    language.')
                        else:
                            entry.fail(u'cannot    find    any    subtitles    for    now.')
                    downloaded_languages = set([Language.fromietf(str(l.language)) for l in subtitles])
                    if entry_languages:
                        entry[u'subtitles_missing'] = (entry_languages - downloaded_languages)
                        if (len(entry[u'subtitles_missing']) > 0):
                            entry.fail(u'Subtitles    for    all    primary    languages    not    found')
            except ValueError as e:
                log.error(u'subliminal    error:    %s', e)
                entry.fail()
    if downloaded_subtitles:
        if task.options.test:
            log.verbose(u'Test    mode.    Found    subtitles:')
        for (video, subtitle) in downloaded_subtitles.items():
            if subtitle:
                _directory = config.get(u'directory')
                if _directory:
                    _directory = os.path.expanduser(_directory)
                if task.options.test:
                    log.verbose(u'                    FOUND    LANGUAGES    %s    for    %s', [str(l.language) for l in subtitle], video.name)
                    continue
                save_subtitles(video, subtitle, single=single_mode, directory=_directory)
