# Path: subdownloader/provider/provider.py
# class SubtitleProvider(object):
#     """
#     Represents an abstract SubtitleProvider..
#     """
#     # FIXME: add documentation
# 
#     def __init__(self):
#         pass
# 
#     def __del__(self):
#         try:
#             self.disconnect()
#         except ProviderConnectionError:
#             log.debug('Disconnect failed during destructor', exc_info=sys.exc_info())
# 
#     def get_settings(self):
#         raise NotImplementedError()
# 
#     def set_settings(self, settings):
#         raise NotImplementedError()
# 
#     def connect(self):
#         raise NotImplementedError()
# 
#     def disconnect(self):
#         raise NotImplementedError()
# 
#     def connected(self):
#         raise NotImplementedError()
# 
#     def login(self):
#         raise NotImplementedError()
# 
#     def logout(self):
#         raise NotImplementedError()
# 
#     def logged_in(self):
#         raise NotImplementedError()
# 
#     def search_videos(self, videos, callback, language=None):
#         raise NotImplementedError()
# 
#     def query_text(self, query):
#         raise NotImplementedError()
# 
#     def upload_subtitles(self, local_movie):
#         raise NotImplementedError()
# 
#     def ping(self):
#         raise NotImplementedError()
# 
#     def provider_info(self):
#         raise NotImplementedError()
# 
#     # @classmethod
#     # def supports_mode(cls, method):
#     #     raise NotImplementedError()
# 
#     @classmethod
#     def get_name(cls):
#         raise NotImplementedError()
# 
#     @classmethod
#     def get_short_name(cls):
#         raise NotImplementedError()
# 
#     @classmethod
#     def get_icon(cls):
#         raise NotImplementedError()


import importlib
import logging
from pathlib import Path
from subdownloader.provider.provider import SubtitleProvider

class NoProviderException(Exception):
    pass


# FIXME: list available providers
class ProviderFactory(object):
    def __init__(self):
        pass

    @classmethod
    def local_search(cls, provider):
        try:
            module_name = 'subdownloader.provider.{provider}'.format(provider=provider)
            log.debug('Attempting to import "{}"...'.format(module_name))
            provider_module = importlib.import_module(module_name)
            log.debug('... OK')
        except ImportError:
            log.debug('... FAILED')
            raise NoProviderException('Unknown provider "{}"'.format(provider))
        try:
            log.debug('Attempting to get "providers" from module...')
            provider_classes = provider_module.providers
            log.debug('... OK')
        except AttributeError:
            log.debug('... FAILED')
            raise NoProviderException('"{}" must provide a "providers" attribute'.format(provider))
        log.debug('Checking provider types:')
        for provider_class in provider_classes:
            log.debug('- {}:'.format(provider_class))

# Path: subdownloader/provider/provider.py
# class SubtitleProvider(object):
#     """
#     Represents an abstract SubtitleProvider..
#     """
#     # FIXME: add documentation
# 
#     def __init__(self):
#         pass
# 
#     def __del__(self):
#         try:
#             self.disconnect()
#         except ProviderConnectionError:
#             log.debug('Disconnect failed during destructor', exc_info=sys.exc_info())
# 
#     def get_settings(self):
#         raise NotImplementedError()
# 
#     def set_settings(self, settings):
#         raise NotImplementedError()
# 
#     def connect(self):
#         raise NotImplementedError()
# 
#     def disconnect(self):
#         raise NotImplementedError()
# 
#     def connected(self):
#         raise NotImplementedError()
# 
#     def login(self):
#         raise NotImplementedError()
# 
#     def logout(self):
#         raise NotImplementedError()
# 
#     def logged_in(self):
#         raise NotImplementedError()
# 
#     def search_videos(self, videos, callback, language=None):
#         raise NotImplementedError()
# 
#     def query_text(self, query):
#         raise NotImplementedError()
# 
#     def upload_subtitles(self, local_movie):
#         raise NotImplementedError()
# 
#     def ping(self):
#         raise NotImplementedError()
# 
#     def provider_info(self):
#         raise NotImplementedError()
# 
#     # @classmethod
#     # def supports_mode(cls, method):
#     #     raise NotImplementedError()
# 
#     @classmethod
#     def get_name(cls):
#         raise NotImplementedError()
# 
#     @classmethod
#     def get_short_name(cls):
#         raise NotImplementedError()
# 
#     @classmethod
#     def get_icon(cls):
#         raise NotImplementedError()


# Path: subdownloader/provider/factory.py
import importlib
import logging
from pathlib import Path
from subdownloader.provider.provider import SubtitleProvider


class NoProviderException(Exception):
    pass


# FIXME: list available providers
class ProviderFactory(object):
    def __init__(self):
        pass

    @classmethod
    def local_search(cls, provider):
        try:
            module_name = 'subdownloader.provider.{provider}'.format(provider=provider)
            log.debug('Attempting to import "{}"...'.format(module_name))
            provider_module = importlib.import_module(module_name)
            log.debug('... OK')
        except ImportError:
            log.debug('... FAILED')
            raise NoProviderException('Unknown provider "{}"'.format(provider))
        try:
            log.debug('Attempting to get "providers" from module...')
            provider_classes = provider_module.providers
            log.debug('... OK')
        except AttributeError:
            log.debug('... FAILED')
            raise NoProviderException('"{}" must provide a "providers" attribute'.format(provider))
        log.debug('Checking provider types:')
        for provider_class in provider_classes:
            log.debug('- {}:'.format(provider_class))

            if not issubclass(provider_class, SubtitleProvider):