connections¶
Connection classes for managing provider service connections.
This module defines the base connection classes that handle initialization and authentication with music provider services. Connections manage the underlying API clients and authentication state.
| CLASS | DESCRIPTION |
|---|---|
Connection |
Abstract base class for provider connections. |
AuthenticatedConnection |
Connection class for providers that require user authentication. |
Connection
¶
Connection(
options: dict | None = None,
logger: "LoggerLike" = ConsoleLogger(),
)
Abstract base class for provider connections.
A connection manages the lifecycle of connecting to a music provider's service, including initialization and URL validation. Subclasses must implement the abstract methods to handle provider-specific logic.
| ATTRIBUTE | DESCRIPTION |
|---|---|
_default_options |
Default configuration options for the connection.
TYPE:
|
_initialized |
Whether the connection has been initialized.
TYPE:
|
_client |
The underlying API client instance.
TYPE:
|
Initialize the connection with options and a logger.
| PARAMETER | DESCRIPTION |
|---|---|
|
Configuration options to merge with defaults.
TYPE:
|
|
Logger instance for logging messages.
TYPE:
|
Source code in src/downmixer/providers/connections.py
38 39 40 41 42 43 44 45 46 47 48 | |
initialize
abstractmethod
¶
initialize() -> bool
Initializes the connection to the provider. Should set the initialized attribute to True if successful.
Source code in src/downmixer/providers/connections.py
60 61 62 63 | |
check_valid_url
abstractmethod
¶
check_valid_url(
url: str, type_filter: list[ResourceType] = None
) -> bool
Check if a URL or URI is valid for this provider.
| PARAMETER | DESCRIPTION |
|---|---|
|
The URL or URI to validate.
TYPE:
|
|
Optional list of resource types to filter against. If provided, the URL must match one of these types to be valid.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if the URL is valid for this provider, False otherwise. |
Source code in src/downmixer/providers/connections.py
65 66 67 68 69 70 71 72 73 74 75 76 77 | |
get_resource_type
abstractmethod
¶
get_resource_type(value: str) -> ResourceType | None
Determine the resource type of a URL or URI for this provider.
| PARAMETER | DESCRIPTION |
|---|---|
|
The URL or URI to analyze.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ResourceType | None
|
The ResourceType if recognized, or None if the URL is not valid. |
Source code in src/downmixer/providers/connections.py
79 80 81 82 83 84 85 86 87 88 89 | |
AuthenticatedConnection
¶
AuthenticatedConnection(
options: dict | None = None,
logger: "LoggerLike" = ConsoleLogger(),
)
Bases: Connection
Connection class for providers that require user authentication.
Extends Connection to add authentication state tracking. The connection is only considered ready when both initialized and authenticated.
| ATTRIBUTE | DESCRIPTION |
|---|---|
_authenticated |
Whether the user has been authenticated.
TYPE:
|
Source code in src/downmixer/providers/connections.py
38 39 40 41 42 43 44 45 46 47 48 | |
authenticate
abstractmethod
¶
authenticate(**kwargs) -> bool
Authenticate the user with the provider.
Should set the _authenticated attribute to True if successful.
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if authentication was successful, False otherwise. |
Source code in src/downmixer/providers/connections.py
109 110 111 112 113 114 115 116 117 118 | |
require_authentication
¶
require_authentication(func)
Decorator to ensure a method is only called when authenticated.
| PARAMETER | DESCRIPTION |
|---|---|
|
The function to wrap.
|
| RETURNS | DESCRIPTION |
|---|---|
|
A wrapped function that raises NotAuthenticatedException if |
|
|
the connection is not authenticated. |
Source code in src/downmixer/providers/connections.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | |