/
/
/
1"""Lidarr Integration plugin for Music Assistant.
2
3Automatically requests albums from Lidarr when tracks are played from
4streaming providers (Spotify, Tidal, etc.) and no local copy exists.
5"""
6
7from __future__ import annotations
8
9import logging
10from typing import TYPE_CHECKING
11
12from music_assistant_models.config_entries import ConfigEntry, ConfigValueType
13from music_assistant_models.enums import ConfigEntryType, ProviderFeature
14
15from music_assistant.models import ProviderInstanceType
16from music_assistant.providers.lidarr_integration.constants import (
17 CONF_ENABLED,
18 CONF_LOCAL_PROVIDER_DOMAINS,
19 CONF_STREAMING_PROVIDERS,
20)
21from music_assistant.providers.lidarr_integration.provider import LidarrIntegrationProvider
22
23if TYPE_CHECKING:
24 from music_assistant_models.config_entries import ProviderConfig
25 from music_assistant_models.provider import ProviderManifest
26
27 from music_assistant.mass import MusicAssistant
28
29SUPPORTED_FEATURES: set[ProviderFeature] = set()
30
31
32async def setup(
33 mass: MusicAssistant, manifest: ProviderManifest, config: ProviderConfig
34) -> ProviderInstanceType:
35 """Initialize provider(instance) with given configuration."""
36 provider = LidarrIntegrationProvider(mass, manifest, config, SUPPORTED_FEATURES)
37 if provider.logger.level == logging.DEBUG:
38 logging.getLogger("aiohttp").setLevel(logging.INFO)
39 return provider
40
41
42async def get_config_entries(
43 mass: MusicAssistant, # noqa: ARG001
44 instance_id: str | None = None, # noqa: ARG001
45 action: str | None = None, # noqa: ARG001
46 values: dict[str, ConfigValueType] | None = None,
47) -> tuple[ConfigEntry, ...]:
48 """Return Config entries to setup this provider.
49
50 :param mass: The MusicAssistant instance.
51 :param instance_id: ID of an existing provider instance (None if new instance setup).
52 :param action: Optional action key called from config entries UI.
53 :param values: The (intermediate) raw values for config entries sent with the action.
54 """
55 return (
56 ConfigEntry(
57 key=CONF_ENABLED,
58 type=ConfigEntryType.BOOLEAN,
59 label="Enable automatic Lidarr requests",
60 description="When enabled, albums will be automatically requested in Lidarr "
61 "when tracks are played from streaming providers and no local copy exists.",
62 default_value=True,
63 required=True,
64 value=values.get(CONF_ENABLED) if values else None,
65 ),
66 ConfigEntry(
67 key=CONF_STREAMING_PROVIDERS,
68 type=ConfigEntryType.STRING,
69 label="Streaming provider domains to monitor",
70 description="Comma-separated list of provider domains that should trigger "
71 "Lidarr requests (e.g. spotify,tidal,qobuz). "
72 "Leave empty to monitor all streaming providers.",
73 required=False,
74 default_value="",
75 value=values.get(CONF_STREAMING_PROVIDERS) if values else None,
76 ),
77 ConfigEntry(
78 key=CONF_LOCAL_PROVIDER_DOMAINS,
79 type=ConfigEntryType.STRING,
80 label="Local provider domains",
81 description="Comma-separated list of provider domains considered 'local' "
82 "(i.e. already downloaded). Tracks available on these providers won't trigger "
83 "Lidarr requests. Defaults to filesystem_local,filesystem_smb.",
84 required=False,
85 default_value="filesystem_local,filesystem_smb",
86 value=values.get(CONF_LOCAL_PROVIDER_DOMAINS) if values else None,
87 ),
88 )
89