# 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.debug('Skipping subtitle: %r already downloaded', subtitle.language)
                    continue
                if subtitle.provider_name in discarded_providers:
                    logger.debug('Skipping subtitle from discarded provider %r', subtitle.provider_name)
                    continue

                # initialize provider
                if subtitle.provider_name in initialized_providers:
                    provider = initialized_providers[subtitle.provider_name]
                else:
                    provider = providers_by_name[subtitle.provider_name](**provider_configs.get(subtitle.provider_name, {}))
                    try:
                        provider.initialize()
                    except ProviderNotAvailable as err:
                        logger.warning('Provider %r is not available, discarding it', subtitle.provider_name)
                        logger.debug('ProviderNotAvailable error: %r', str(err))
                        discarded_providers.add(subtitle.provider_name)
                        continue
                    except socket_error as err:
                        logger.warning('Provider %r is not responding, discarding it', subtitle.provider_name)
                        logger.debug('Provider socket error: %r', str(err))
                        discarded_providers.add(subtitle.provider_name)
                        continue
                    except:
                        logger.exception('Unexpected error in provider %r', subtitle.provider_name)
                        discarded_providers.add(subtitle.provider_name)
                        continue
                    initialized_providers[subtitle.provider_name] = provider

                # download subtitles

# 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.debug('Skipping subtitle: %r already downloaded', subtitle.language)
                    continue
                if subtitle.provider_name in discarded_providers:
                    logger.debug('Skipping subtitle from discarded provider %r', subtitle.provider_name)
                    continue

                # initialize provider
                if subtitle.provider_name in initialized_providers:
                    provider = initialized_providers[subtitle.provider_name]
                else:
                    provider = providers_by_name[subtitle.provider_name](**provider_configs.get(subtitle.provider_name, {}))
                    try:
                        provider.initialize()
                    except ProviderNotAvailable as err:
                        logger.warning('Provider %r is not available, discarding it', subtitle.provider_name)
                        logger.debug('ProviderNotAvailable error: %r', str(err))
                        discarded_providers.add(subtitle.provider_name)
                        continue
                    except socket_error as err:
                        logger.warning('Provider %r is not responding, discarding it', subtitle.provider_name)
                        logger.debug('Provider socket error: %r', str(err))
                        discarded_providers.add(subtitle.provider_name)
                        continue
                    except:
                        logger.exception('Unexpected error in provider %r', subtitle.provider_name)
                        discarded_providers.add(subtitle.provider_name)
                        continue
                    initialized_providers[subtitle.provider_name] = provider

                # download subtitles

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