Conversions
Conversions between Spotify IDs, URIs and URLs.
Convert an ID to an URI of the appropriate type. |
|
Convert an ID to an URL of the appropriate type. |
|
Parse type and ID from an URI. |
|
Parse type and ID from an URL. |
|
Error in conversion. |
|
Valid types of Spotify IDs. |
|
Validate resource ID to be base 62. |
|
Validate type of an ID. |
import tekore as tk
# Create ULR for opening an album in the browser
mountain = '3RBULTZJ97bvVzZLpxcB0j'
m_url = tk.to_url('album', mountain)
# Parse input
type_, id_ = tk.from_url(m_url)
print(f'Got type `{type_}` with ID `{id_}`')
- tekore.check_id(id_)
Validate resource ID to be base 62.
Note that user IDs can have special characters, so they cannot be validated.
- Raises:
ConversionError – When ID is invalid.
- Parameters:
id_ (str) –
- Return type:
None
- tekore.check_type(type_)
Validate type of an ID.
- Raises:
ConversionError – When type is invalid.
- Parameters:
type_ (str | IdentifierType) –
- Return type:
None
- class tekore.ConversionError
Bases:
Exception
Error in conversion.
- tekore.from_uri(uri)
Parse type and ID from an URI.
- Parameters:
uri (str) – URI to parse
- Returns:
type and ID parsed from the URI
- Return type:
tuple[str, str]
- Raises:
ConversionError – On invalid format, prefix, type or ID.
- tekore.from_url(url)
Parse type and ID from an URL.
Any parameters in the URL will be ignored.
- Parameters:
url (str) – URL to parse
- Returns:
type and ID parsed from the URL
- Return type:
tuple[str, str]
- Raises:
ConversionError – On invalid format, prefix, type or ID.
- tekore.to_uri(type_, id_)
Convert an ID to an URI of the appropriate type.
- Parameters:
type – valid
IdentifierType
id – resource identifier
type_ (str | IdentifierType) –
id_ (str) –
- Returns:
converted URI
- Return type:
str
- Raises:
ConversionError – On invalid type or ID.
- tekore.to_url(type_, id_)
Convert an ID to an URL of the appropriate type.
- Parameters:
type – valid
IdentifierType
id – resource identifier
type_ (str | IdentifierType) –
id_ (str) –
- Returns:
converted URL
- Return type:
str
- Raises:
ConversionError – On invalid type or ID.