Files
Iris/mopidy_iris/__init__.py

95 lines
2.2 KiB
Python
Raw Normal View History

2020-01-06 00:26:55 +00:00
import logging, json, pathlib
import pkg_resources
from mopidy import config, ext
__version__ = '3.44.0'
logger = logging.getLogger(__name__)
##
# Core extension class
#
# Loads config and gets the party started. Initiates any additional frontends, etc.
##
class Extension( ext.Extension ):
dist_name = 'Mopidy-Iris'
ext_name = 'iris'
version = __version__
def get_default_config(self):
2020-01-06 00:26:55 +00:00
return config.read(pathlib.Path(__file__).parent / "ext.conf")
def get_config_schema(self):
schema = config.ConfigSchema(self.ext_name)
schema['enabled'] = config.Boolean()
schema['country'] = config.String()
schema['locale'] = config.String()
schema['spotify_authorization_url'] = config.String()
schema['lastfm_authorization_url'] = config.String()
schema['genius_authorization_url'] = config.String()
schema['data_dir'] = config.String()
return schema
def setup(self, registry):
from .frontend import IrisFrontend
# Add web extension
registry.add('http:app', {
'name': self.ext_name,
'factory': iris_factory
})
# Add our frontend
registry.add('frontend', IrisFrontend)
##
# Frontend factory
##
def iris_factory(config, core):
from tornado.web import StaticFileHandler
from .handlers import HttpHandler, ReactRouterHandler, WebsocketHandler
path = pathlib.Path(__file__).parent / 'static'
return [
(
r'/http/([^/]*)',
HttpHandler,
{
'core': core,
'config': config
}
),
(
r'/ws/?',
WebsocketHandler,
{
'core': core,
'config': config
}
),
(
r'/assets/(.*)',
StaticFileHandler,
{
'path': path / 'assets'
}
),
(
r'/((.*)(?:css|js|json|map)$)',
StaticFileHandler,
{
'path': path
}
),
(
r'/(.*)',
ReactRouterHandler,
{
'path': path / 'index.html'
}
),
]