__init__.py 1.97 KB
Newer Older
Agate's avatar
Agate committed
1
2
# -*- coding: utf-8 -*-
"""Top-level package for mopidy-funkwhale."""
Agate's avatar
Agate committed
3
4
5
6
7
8
9
from __future__ import unicode_literals

import logging
import mopidy.config
import mopidy.ext
import os

Agate's avatar
Agate committed
10
11

__author__ = """Eliot Berriot"""
Agate's avatar
Agate committed
12
13
__email__ = "contact+funkwhale@eliotberriot.com"
__version__ = "0.1.0"
Agate's avatar
Agate committed
14
15
16
17
18
19

logger = logging.getLogger(__name__)


class Extension(mopidy.ext.Extension):

Agate's avatar
Agate committed
20
21
    dist_name = "Mopidy-Funkwhale"
    ext_name = "funkwhale"
Agate's avatar
Agate committed
22
23
24
    version = __version__

    def get_default_config(self):
Agate's avatar
Agate committed
25
        conf_file = os.path.join(os.path.dirname(__file__), "ext.conf")
Agate's avatar
Agate committed
26
27
28
29
        return mopidy.config.read(conf_file)

    def get_config_schema(self):
        schema = super(Extension, self).get_config_schema()
Agate's avatar
Agate committed
30
        schema["url"] = mopidy.config.String()
Agate's avatar
Agate committed
31
32
33
34
35
        schema["authorization_endpoint"] = mopidy.config.String(optional=True)
        schema["token_endpoint"] = mopidy.config.String(optional=True)
        schema["client_secret"] = mopidy.config.String(optional=True)
        schema["client_id"] = mopidy.config.String(optional=True)

Agate's avatar
Agate committed
36
37
        schema["username"] = mopidy.config.String(optional=True)
        schema["password"] = mopidy.config.Secret(optional=True)
Agate's avatar
Agate committed
38
        schema["cache_duration"] = mopidy.config.Integer(optional=True)
Agate's avatar
Agate committed
39
        schema["verify_cert"] = mopidy.config.Boolean(optional=True)
Agate's avatar
Agate committed
40
41
        return schema

42
    def validate_config(self, config):
Agate's avatar
Agate committed
43
        if not config.getboolean("funkwhale", "enabled"):
44
            return
Agate's avatar
Agate committed
45
46
        username = config.getstring("funkwhale", "username")
        password = config.getstring("funkwhale", "password")
47
48
        if any([username, password]) and not all([username, password]):
            raise mopidy.ext.ExtensionError(
Agate's avatar
Agate committed
49
                "You need to provide username and password to authenticate with the funkwhale backend"
50
51
            )

Agate's avatar
Agate committed
52
    def setup(self, registry):
53
        from . import actor
Agate's avatar
Agate committed
54
55

        registry.add("backend", actor.FunkwhaleBackend)
Agate's avatar
Agate committed
56
57
58
59
60

    def get_command(self):
        from . import commands

        return commands.FunkwhaleCommand()