# Path: Subliminal/subliminal/subtitle.py
# def get_subtitle_path(video_path, language=None):
#     """Create the subtitle path from the given `video_path` and `language`
# 
#     :param string video_path: path to the video
#     :param language: language of the subtitle to put in the path
#     :type language: :class:`babelfish.Language` or None
#     :return: path of the subtitle
#     :rtype: string
# 
#     """
#     subtitle_path = os.path.splitext(video_path)[0]
#     if isinstance(subtitle_path, str):
#         try:
#             subtitle_path = subtitle_path.decode('utf-8', errors='ignore')
#         except TypeError:
#             # python <= 2.6
#             subtitle_path = subtitle_path.decode('utf-8', 'ignore')
# 
#     if language is not None:
#         try:
#             return subtitle_path + '.%s.%s' % (language.alpha2, 'srt')
#         except babelfish.LanguageConvertError:
#             return subtitle_path + '.%s.%s' % (language.alpha3, 'srt')
#     return subtitle_path + '.srt'


import collections
import io
import logging
import operator
import babelfish
import pkg_resources
from os.path import basename
from .exceptions import ProviderNotAvailable, InvalidSubtitle
from .subtitle import get_subtitle_path
from socket import error as socket_error
                    logger.info('Found %d subtitle(s) on %s' % (
                        len(provider_subtitles),
                        provider_name,
                    ))
                    subtitles.extend(provider_subtitles)

            # find the best subtitles and download them
            for subtitle, score in sorted([(s, s.compute_score(video, hi_score_adjust)) \
                    for s in subtitles], key=operator.itemgetter(1), reverse=True):

                # filter
                if subtitle.provider_name in discarded_providers:
                    logger.debug('Skipping subtitle from discarded provider %r', subtitle.provider_name)
                    continue

                if hearing_impaired is not None:
                    if subtitle.hearing_impaired != hearing_impaired:
                        logger.debug('Skipping subtitle: hearing impaired != %r', hearing_impaired)
                        continue

                if score < min_score:
                    logger.debug('Skipping subtitle: score < %d', min_score)
                    continue

                if subtitle.language in downloaded_languages:
                    logger.debug('Skipping subtitle: %r already downloaded', subtitle.language)
                    continue

                # download
                provider = initialized_providers[subtitle.provider_name]

# Path: Subliminal/subliminal/subtitle.py
# def get_subtitle_path(video_path, language=None):
#     """Create the subtitle path from the given `video_path` and `language`
# 
#     :param string video_path: path to the video
#     :param language: language of the subtitle to put in the path
#     :type language: :class:`babelfish.Language` or None
#     :return: path of the subtitle
#     :rtype: string
# 
#     """
#     subtitle_path = os.path.splitext(video_path)[0]
#     if isinstance(subtitle_path, str):
#         try:
#             subtitle_path = subtitle_path.decode('utf-8', errors='ignore')
#         except TypeError:
#             # python <= 2.6
#             subtitle_path = subtitle_path.decode('utf-8', 'ignore')
# 
#     if language is not None:
#         try:
#             return subtitle_path + '.%s.%s' % (language.alpha2, 'srt')
#         except babelfish.LanguageConvertError:
#             return subtitle_path + '.%s.%s' % (language.alpha3, 'srt')
#     return subtitle_path + '.srt'


# Path: Subliminal/subliminal/api.py
import collections
import io
import logging
import operator
import babelfish
import pkg_resources
from os.path import basename
from .exceptions import ProviderNotAvailable, InvalidSubtitle
from .subtitle import get_subtitle_path
from socket import error as socket_error

                    logger.info('Found %d subtitle(s) on %s' % (
                        len(provider_subtitles),
                        provider_name,
                    ))
                    subtitles.extend(provider_subtitles)

            # find the best subtitles and download them
            for subtitle, score in sorted([(s, s.compute_score(video, hi_score_adjust)) \
                    for s in subtitles], key=operator.itemgetter(1), reverse=True):

                # filter
                if subtitle.provider_name in discarded_providers:
                    logger.debug('Skipping subtitle from discarded provider %r', subtitle.provider_name)
                    continue

                if hearing_impaired is not None:
                    if subtitle.hearing_impaired != hearing_impaired:
                        logger.debug('Skipping subtitle: hearing impaired != %r', hearing_impaired)
                        continue

                if score < min_score:
                    logger.debug('Skipping subtitle: score < %d', min_score)
                    continue

                if subtitle.language in downloaded_languages:
                    logger.debug('Skipping subtitle: %r already downloaded', subtitle.language)
                    continue

                # download
                provider = initialized_providers[subtitle.provider_name]

                subtitle_path = get_subtitle_path(video.name, None if single else subtitle.language)