/
/
/
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_LIDARR_API_KEY,
19 CONF_LIDARR_URL,
20 CONF_LOCAL_PROVIDER_DOMAINS,
21 CONF_METADATA_PROFILE_ID,
22 CONF_QUALITY_PROFILE_ID,
23 CONF_ROOT_FOLDER_PATH,
24 CONF_STREAMING_PROVIDERS,
25)
26from music_assistant.providers.lidarr_integration.provider import LidarrIntegrationProvider
27
28if TYPE_CHECKING:
29 from music_assistant_models.config_entries import ProviderConfig
30 from music_assistant_models.provider import ProviderManifest
31
32 from music_assistant.mass import MusicAssistant
33
34SUPPORTED_FEATURES: set[ProviderFeature] = set()
35
36
37async def setup(
38 mass: MusicAssistant, manifest: ProviderManifest, config: ProviderConfig
39) -> ProviderInstanceType:
40 """Initialize provider(instance) with given configuration."""
41 provider = LidarrIntegrationProvider(mass, manifest, config, SUPPORTED_FEATURES)
42 if provider.logger.level == logging.DEBUG:
43 logging.getLogger("aiohttp").setLevel(logging.INFO)
44 return provider
45
46
47async def get_config_entries(
48 mass: MusicAssistant, # noqa: ARG001
49 instance_id: str | None = None, # noqa: ARG001
50 action: str | None = None, # noqa: ARG001
51 values: dict[str, ConfigValueType] | None = None,
52) -> tuple[ConfigEntry, ...]:
53 """Return Config entries to setup this provider.
54
55 :param mass: The MusicAssistant instance.
56 :param instance_id: ID of an existing provider instance (None if new instance setup).
57 :param action: Optional action key called from config entries UI.
58 :param values: The (intermediate) raw values for config entries sent with the action.
59 """
60 return (
61 ConfigEntry(
62 key=CONF_ENABLED,
63 type=ConfigEntryType.BOOLEAN,
64 label="Enable automatic Lidarr requests",
65 description="When enabled, albums will be automatically requested in Lidarr "
66 "when tracks are played from streaming providers and no local copy exists.",
67 default_value=True,
68 required=True,
69 value=values.get(CONF_ENABLED) if values else None,
70 ),
71 ConfigEntry(
72 key=CONF_LIDARR_URL,
73 type=ConfigEntryType.STRING,
74 label="Lidarr URL",
75 description="The base URL of your Lidarr instance (e.g. http://localhost:8686).",
76 required=True,
77 default_value="http://localhost:8686",
78 value=values.get(CONF_LIDARR_URL) if values else None,
79 ),
80 ConfigEntry(
81 key=CONF_LIDARR_API_KEY,
82 type=ConfigEntryType.SECURE_STRING,
83 label="Lidarr API Key",
84 description="Found in Lidarr under Settings > General > Security.",
85 required=True,
86 value=values.get(CONF_LIDARR_API_KEY) if values else None,
87 ),
88 ConfigEntry(
89 key=CONF_ROOT_FOLDER_PATH,
90 type=ConfigEntryType.STRING,
91 label="Root folder path",
92 description="The root folder in Lidarr where music is stored. "
93 "This should match the path your filesystem_local provider watches.",
94 required=True,
95 default_value="/music",
96 value=values.get(CONF_ROOT_FOLDER_PATH) if values else None,
97 ),
98 ConfigEntry(
99 key=CONF_QUALITY_PROFILE_ID,
100 type=ConfigEntryType.INTEGER,
101 label="Quality profile ID",
102 description="The Lidarr quality profile ID to use for new artists. "
103 "Find this in Lidarr under Settings > Profiles (usually 1).",
104 required=True,
105 default_value=1,
106 value=values.get(CONF_QUALITY_PROFILE_ID) if values else None,
107 ),
108 ConfigEntry(
109 key=CONF_METADATA_PROFILE_ID,
110 type=ConfigEntryType.INTEGER,
111 label="Metadata profile ID",
112 description="The Lidarr metadata profile ID to use for new artists. "
113 "Find this in Lidarr under Settings > Profiles (usually 1).",
114 required=True,
115 default_value=1,
116 value=values.get(CONF_METADATA_PROFILE_ID) if values else None,
117 ),
118 ConfigEntry(
119 key=CONF_STREAMING_PROVIDERS,
120 type=ConfigEntryType.STRING,
121 label="Streaming provider domains to monitor",
122 description="Comma-separated list of provider domains that should trigger "
123 "Lidarr requests (e.g. spotify,tidal,qobuz). "
124 "Leave empty to monitor all streaming providers.",
125 required=False,
126 default_value="",
127 value=values.get(CONF_STREAMING_PROVIDERS) if values else None,
128 ),
129 ConfigEntry(
130 key=CONF_LOCAL_PROVIDER_DOMAINS,
131 type=ConfigEntryType.STRING,
132 label="Local provider domains",
133 description="Comma-separated list of provider domains considered 'local' "
134 "(i.e. already downloaded). Tracks available on these providers won't trigger "
135 "Lidarr requests. Defaults to filesystem_local,filesystem_smb.",
136 required=False,
137 default_value="filesystem_local,filesystem_smb",
138 value=values.get(CONF_LOCAL_PROVIDER_DOMAINS) if values else None,
139 ),
140 )
141