2020-01-06 00:26:55 +00:00
|
|
|
import logging, json, pathlib
|
2019-04-18 09:03:38 +12:00
|
|
|
|
2020-01-06 00:29:48 +00:00
|
|
|
import pkg_resources
|
2019-04-18 09:03:38 +12:00
|
|
|
from mopidy import config, ext
|
|
|
|
|
|
2020-01-31 06:23:34 +13:00
|
|
|
__version__ = '3.44.0'
|
2020-01-06 00:29:48 +00:00
|
|
|
|
2019-04-18 09:03:38 +12:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
2020-01-06 00:29:48 +00:00
|
|
|
|
2019-04-18 09:03:38 +12:00
|
|
|
##
|
|
|
|
|
# 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'
|
2020-01-06 00:29:48 +00:00
|
|
|
version = __version__
|
2019-04-18 09:03:38 +12:00
|
|
|
|
|
|
|
|
def get_default_config(self):
|
2020-01-06 00:26:55 +00:00
|
|
|
return config.read(pathlib.Path(__file__).parent / "ext.conf")
|
2019-04-18 09:03:38 +12:00
|
|
|
|
|
|
|
|
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()
|
2019-11-02 08:02:50 +13:00
|
|
|
schema['data_dir'] = config.String()
|
2019-04-18 09:03:38 +12:00
|
|
|
return schema
|
|
|
|
|
|
|
|
|
|
def setup(self, registry):
|
2020-01-07 23:28:34 +00:00
|
|
|
from .frontend import IrisFrontend
|
2019-04-18 09:03:38 +12:00
|
|
|
# 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):
|
2020-01-07 23:28:34 +00:00
|
|
|
from tornado.web import StaticFileHandler
|
|
|
|
|
from .handlers import HttpHandler, ReactRouterHandler, WebsocketHandler
|
2019-04-18 09:03:38 +12:00
|
|
|
|
2019-12-27 14:10:01 +13:00
|
|
|
path = pathlib.Path(__file__).parent / 'static'
|
2019-10-23 17:03:00 +13:00
|
|
|
|
2019-04-18 09:03:38 +12:00
|
|
|
return [
|
|
|
|
|
(
|
|
|
|
|
r'/http/([^/]*)',
|
2020-01-07 23:28:34 +00:00
|
|
|
HttpHandler,
|
2019-04-18 09:03:38 +12:00
|
|
|
{
|
|
|
|
|
'core': core,
|
|
|
|
|
'config': config
|
|
|
|
|
}
|
|
|
|
|
),
|
|
|
|
|
(
|
|
|
|
|
r'/ws/?',
|
2020-01-07 23:28:34 +00:00
|
|
|
WebsocketHandler,
|
2019-10-23 17:03:00 +13:00
|
|
|
{
|
2019-04-18 09:03:38 +12:00
|
|
|
'core': core,
|
|
|
|
|
'config': config
|
|
|
|
|
}
|
|
|
|
|
),
|
|
|
|
|
(
|
|
|
|
|
r'/assets/(.*)',
|
2020-01-07 23:28:34 +00:00
|
|
|
StaticFileHandler,
|
2019-04-18 09:03:38 +12:00
|
|
|
{
|
2019-12-27 14:10:01 +13:00
|
|
|
'path': path / 'assets'
|
2019-04-18 09:03:38 +12:00
|
|
|
}
|
|
|
|
|
),
|
|
|
|
|
(
|
2019-04-19 07:29:17 +12:00
|
|
|
r'/((.*)(?:css|js|json|map)$)',
|
2020-01-07 23:28:34 +00:00
|
|
|
StaticFileHandler,
|
2019-04-18 09:03:38 +12:00
|
|
|
{
|
2019-04-19 07:29:17 +12:00
|
|
|
'path': path
|
2019-04-18 09:03:38 +12:00
|
|
|
}
|
|
|
|
|
),
|
|
|
|
|
(
|
|
|
|
|
r'/(.*)',
|
2020-01-07 23:28:34 +00:00
|
|
|
ReactRouterHandler,
|
|
|
|
|
{
|
2019-12-27 14:10:01 +13:00
|
|
|
'path': path / 'index.html'
|
2019-04-18 09:03:38 +12:00
|
|
|
}
|
|
|
|
|
),
|
|
|
|
|
]
|