mass: MusicAssistant, manifest: ProviderManifest, config: ProviderConfig
) -> ProviderInstanceType:
"""Initialize provider(instance) with given configuration."""
- conf_path = config.get_value(CONF_PATH)
- if not await isdir(conf_path):
- msg = f"Music Directory {conf_path} does not exist"
- raise SetupFailedError(msg)
- prov = LocalFileSystemProvider(mass, manifest, config)
- prov.base_path = str(config.get_value(CONF_PATH))
- await prov.check_write_access()
- prov.media_content_type = cast(str, config.get_value(CONF_ENTRY_CONTENT_TYPE.key))
- return prov
+ base_path = cast(str, config.get_value(CONF_PATH))
+ return LocalFileSystemProvider(mass, manifest, config, base_path)
async def get_config_entries(
CONF_ENTRY_PATH,
CONF_ENTRY_MISSING_ALBUM_ARTIST,
)
- media_type = values.get(CONF_ENTRY_CONTENT_TYPE.key)
- if media_type == "music":
- return (
- CONF_ENTRY_PATH,
- CONF_ENTRY_CONTENT_TYPE_READ_ONLY,
- CONF_ENTRY_MISSING_ALBUM_ARTIST,
- )
- return (
- CONF_ENTRY_PATH,
- CONF_ENTRY_CONTENT_TYPE_READ_ONLY,
- )
+ return (CONF_ENTRY_PATH, CONF_ENTRY_CONTENT_TYPE_READ_ONLY, CONF_ENTRY_MISSING_ALBUM_ARTIST)
class LocalFileSystemProvider(MusicProvider):
Supports m3u files for playlists.
"""
- base_path: str
- write_access: bool = False
- sync_running: bool = False
- media_content_type: str = "music"
+ def __init__(
+ self,
+ mass: MusicAssistant,
+ manifest: ProviderManifest,
+ config: ProviderConfig,
+ base_path: str,
+ ) -> None:
+ """Initialize MusicProvider."""
+ super().__init__(mass, manifest, config)
+ self.base_path: str = base_path
+ self.write_access: bool = False
+ self.sync_running: bool = False
+ self.media_content_type = cast(str, config.get_value(CONF_ENTRY_CONTENT_TYPE.key))
@property
def supported_features(self) -> set[ProviderFeature]:
postfix = self.base_path.split(os.sep)[-1]
return f"{self.manifest.name} {postfix}"
+ async def handle_async_init(self) -> None:
+ """Handle async initialization of the provider."""
+ if not await isdir(self.base_path):
+ msg = f"Music Directory {self.base_path} does not exist"
+ raise SetupFailedError(msg)
+ await self.check_write_access()
+
async def search(
self,
search_query: str,
from music_assistant.providers.filesystem_local import LocalFileSystemProvider, exists, makedirs
from music_assistant.providers.filesystem_local.constants import (
CONF_ENTRY_CONTENT_TYPE,
+ CONF_ENTRY_CONTENT_TYPE_READ_ONLY,
CONF_ENTRY_MISSING_ALBUM_ARTIST,
)
if not share or "/" in share or "\\" in share:
msg = "Invalid share name"
raise LoginFailed(msg)
- return SMBFileSystemProvider(mass, manifest, config)
+ # base_path will be the path where we're going to mount the remote share
+ base_path = f"/tmp/{config.instance_id}" # noqa: S108
+ return SMBFileSystemProvider(mass, manifest, config, base_path)
async def get_config_entries(
values: the (intermediate) raw values for config entries sent with the action.
"""
# ruff: noqa: ARG001
- return (
+ base_entries = (
ConfigEntry(
key=CONF_HOST,
type=ConfigEntryType.STRING,
description="[optional] Use if your music is stored in a sublevel of the share. "
"E.g. 'collections' or 'albums/A-K'.",
),
- CONF_ENTRY_CONTENT_TYPE,
ConfigEntry(
key=CONF_MOUNT_OPTIONS,
type=ConfigEntryType.STRING,
CONF_ENTRY_MISSING_ALBUM_ARTIST,
)
+ if instance_id is None or values is None:
+ return (
+ CONF_ENTRY_CONTENT_TYPE,
+ *base_entries,
+ )
+ return (
+ *base_entries,
+ CONF_ENTRY_CONTENT_TYPE_READ_ONLY,
+ )
+
class SMBFileSystemProvider(LocalFileSystemProvider):
"""
async def handle_async_init(self) -> None:
"""Handle async initialization of the provider."""
- # base_path will be the path where we're going to mount the remote share
- self.base_path = f"/tmp/{self.instance_id}" # noqa: S108
if not await exists(self.base_path):
await makedirs(self.base_path)
-
try:
# do unmount first to cleanup any unexpected state
await self.unmount(ignore_error=True)
except Exception as err:
msg = f"Connection failed for the given details: {err}"
raise LoginFailed(msg) from err
-
await self.check_write_access()
async def unload(self, is_removed: bool = False) -> None: