Files
Iris/mopidy_iris/__init__.py

64 lines
1.8 KiB
Python
Raw Normal View History

2020-02-03 16:48:39 +13:00
import logging
import pathlib
from mopidy import config, ext
2020-02-14 11:38:57 +13:00
__version__ = '3.44.2'
logger = logging.getLogger(__name__)
##
# Core extension class
#
# Loads config and gets the party started. Initiates any additional frontends, etc.
##
2020-02-03 16:14:04 +13:00
class Extension(ext.Extension):
2020-02-03 16:14:04 +13:00
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)
2020-02-03 16:14:04 +13:00
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
2020-02-03 16:14:04 +13:00
# Add web extension
2020-02-03 16:48:39 +13:00
registry.add(
2020-02-06 10:12:28 +13:00
"http:app", {"name": self.ext_name, "factory": iris_factory}
)
# Add our frontend
2020-02-03 16:14:04 +13:00
registry.add("frontend", IrisFrontend)
##
# Frontend factory
##
def iris_factory(config, core):
from tornado.web import StaticFileHandler
from .handlers import HttpHandler, ReactRouterHandler, WebsocketHandler
2020-02-03 16:14:04 +13:00
path = pathlib.Path(__file__).parent / "static"
return [
2020-02-03 16:14:04 +13:00
(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"}),
]