from __future__ import unicode_literals

from mopidy import ext
from mopidy.exceptions import ExtensionError

__doc__ = """A extension for playing music from SoundCloud.

This extension handles URIs starting with ``soundcloud:`` and enables you,
to play music from SoundCloud web service.

See https://github.com/dz0ny/mopidy-soundcloud/ for further instructions on
using this extension.

**Issues:**

https://github.com/dz0ny/mopidy-soundcloud/issues

**Dependencies:**

requests

**Settings:**

- :attr:`mopidy.settings.auth_token`
- :attr:`mopidy.settings.explore`
- :attr:`mopidy.settings.explore_pages`
"""

__version__ = '1.0.5'


class SoundCloudExtension(ext.Extension):

    name = 'Mopidy-SoundCloud'
    version = __version__

    def get_default_config(self):
        return """[ext.soundcloud]
        enabled = True
        auth_token = False
        explore = "pop/Easy Listening,rock/Indie,electronic/Ambient"
        explore_pages = 1
        """

    def validate_config(self, config):
        if not config.getboolean('soundcloud', 'enabled'):
            return
        if not config.get('soundcloud', 'auth_token'):
            raise ExtensionError("In order to use SoundCloud extension you\
             must provide auth_token, for more information referrer to \
             https://github.com/dz0ny/mopidy-soundcloud/")

    def validate_environment(self):
        try:
            import requests  # noqa
        except ImportError as e:
            raise ExtensionError('Library requests not found', e)

    def get_backend_classes(self):
        from .actor import SoundCloudBackend
        return [SoundCloudBackend]

from __future__ import unicode_literals

from mopidy import ext
from mopidy.exceptions import ExtensionError
from mopidy.utils import config

__doc__ = """A extension for playing music from SoundCloud.

This extension handles URIs starting with ``soundcloud:`` and enables you,
to play music from SoundCloud web service.

See https://github.com/dz0ny/mopidy-soundcloud/ for further instructions on
using this extension.

**Issues:**

https://github.com/dz0ny/mopidy-soundcloud/issues

**Dependencies:**

requests

**Settings:**

- :attr:`mopidy.settings.auth_token`
- :attr:`mopidy.settings.explore`
- :attr:`mopidy.settings.explore_pages`
"""

__version__ = '1.0.8'


class SoundCloudExtension(ext.Extension):

    name = 'Mopidy-SoundCloud'
    version = __version__

    def get_default_config(self):
        return """[ext.soundcloud]
            enabled = True
            auth_token = False
            explore = "pop/Easy Listening,rock/Indie,electronic/Ambient"
            explore_pages = 1
        """

    def get_config_schema(self):
        schema = config.ExtensionConfigSchema()
        schema['explore'] = config.String()
        schema['explore_pages'] = config.Integer()
        schema['auth_token'] = config.String(required=True, secret=True)
        return schema

    def validate_config(self, config):
        if not config.getboolean('soundcloud', 'enabled'):
            return
        if not config.get('soundcloud', 'auth_token'):
            raise ExtensionError("In order to use SoundCloud extension you\
             must provide auth_token, for more information referrer to \
             https://github.com/dz0ny/mopidy-soundcloud/")

    def validate_environment(self):
        try:
            import requests  # noqa
        except ImportError as e:
            raise ExtensionError('Library requests not found', e)

    def get_backend_classes(self):
        from .actor import SoundCloudBackend
        return [SoundCloudBackend]

Add config validation aka get_config_schema