Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/music-assistant/server into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelveldt committed Feb 6, 2025
2 parents 99950c8 + a089610 commit be9371f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 31 deletions.
47 changes: 23 additions & 24 deletions music_assistant/providers/filesystem_local/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,8 @@ async def setup(
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(
Expand All @@ -137,17 +130,7 @@ 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):
Expand All @@ -159,10 +142,19 @@ 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]:
Expand Down Expand Up @@ -200,6 +192,13 @@ def name(self) -> str:
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,
Expand Down
22 changes: 15 additions & 7 deletions music_assistant/providers/filesystem_smb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
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,
)

Expand Down Expand Up @@ -46,7 +47,9 @@ async def setup(
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(
Expand All @@ -63,7 +66,7 @@ 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,
Expand Down Expand Up @@ -107,7 +110,6 @@ async def get_config_entries(
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,
Expand All @@ -121,6 +123,16 @@ async def get_config_entries(
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):
"""
Expand Down Expand Up @@ -149,19 +161,15 @@ def name(self) -> str:

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)
await self.mount()
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:
Expand Down

0 comments on commit be9371f

Please sign in to comment.