Added MusicProviderRegistry
This commit is contained in:
3
app/registry/__init__.py
Normal file
3
app/registry/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
from .music_provider_registry import MusicProviderRegistry
|
||||||
|
|
||||||
|
__all__ = ["MusicProviderRegistry"]
|
||||||
35
app/registry/music_provider_registry.py
Normal file
35
app/registry/music_provider_registry.py
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
from app.providers.base import MusicProviderClient
|
||||||
|
|
||||||
|
|
||||||
|
class MusicProviderRegistry:
|
||||||
|
"""
|
||||||
|
Registry to manage and retrieve music provider clients.
|
||||||
|
"""
|
||||||
|
_providers = {}
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def register_provider(cls, provider: MusicProviderClient):
|
||||||
|
"""
|
||||||
|
Registers a music provider client instance.
|
||||||
|
:param provider: An instance of a MusicProviderClient subclass.
|
||||||
|
"""
|
||||||
|
cls._providers[provider._identifier] = provider
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_provider(cls, identifier: str) -> MusicProviderClient:
|
||||||
|
"""
|
||||||
|
Retrieves a registered music provider client by its identifier.
|
||||||
|
:param identifier: The unique identifier for the provider.
|
||||||
|
:return: An instance of MusicProviderClient.
|
||||||
|
"""
|
||||||
|
if identifier not in cls._providers:
|
||||||
|
raise ValueError(f"No provider found with identifier '{identifier}'.")
|
||||||
|
return cls._providers[identifier]
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def list_providers(cls) -> list:
|
||||||
|
"""
|
||||||
|
Lists all registered providers.
|
||||||
|
:return: A list of registered provider identifiers.
|
||||||
|
"""
|
||||||
|
return list(cls._providers.keys())
|
||||||
Reference in New Issue
Block a user