Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
"""
Ideal API:
# myplugin/apps.py
from funkwhale_api import plugins
class Plugin(plugins.Plugin):
name = 'scrobbler'
config_options = [
{
'id': 'user_agent',
'verbose_name': 'User agent string',
'help_text': 'The user agent string used by this plugin for external HTTP request',
'default': None,
},
{
'id': 'timeout',
'type': 'int',
'verbose_name': 'Timeout (in seconds)'
'help_text': 'Max timeout for HTTP calls',
'default': 10,
},
]
def get_user_options(self):
from . import options
return [
options.ListenBrainz,
options.LastFm,
]
# myplugin/hooks.py
from .apps import Plugin
@Plugin.register_action('history.listening_created')
def scrobble(plugin, user, listening, **kwargs):
user_options = plugin.get_options(user)
if len(options) == 0:
return
for option in user_options:
if option.id == 'listenbrainz':
broadcast_to_listenbrainz()
"""
from django.apps import AppConfig, apps
from . import mutations
class CommonConfig(AppConfig):
name = "funkwhale_api.common"
def ready(self):
super().ready()
app_names = [app.name for app in apps.app_configs.values()]
mutations.registry.autodiscover(app_names)