Processors

Inheritance diagram of musify.libraries.remote.spotify.processors

Convert and validate Spotify ID and item types.

Classes:

SpotifyDataWrangler()

class musify.libraries.remote.spotify.processors.SpotifyDataWrangler

Bases: RemoteDataWrangler

Attributes:

source

unavailable_uri_dummy

url_api

url_ext

Methods:

get_id_type(value[, kind])

Determine the remote ID type of the given value and return its type.

validate_id_type(value[, kind])

Check that the given value is a type of remote ID given by kind

convert(value[, kind, type_in, type_out])

Converts ID to required format - API URL, EXT URL, URI, or ID.

extract_ids(values[, kind])

Extract a list of IDs from input values.

source = 'Spotify'
unavailable_uri_dummy = 'spotify:track:unavailable'
url_api = 'https://api.spotify.com/v1'
url_ext = 'https://open.spotify.com'
classmethod get_id_type(value, kind=None)

Determine the remote ID type of the given value and return its type.

Parameters:
  • value (str) – URL/URI/ID to check.

  • kind (RemoteObjectType | None (default: None)) – When this is equal to USER, ignore checks and always return ID as type.

Returns:

RemoteIDType – The RemoteIDType.

Raises:

RemoteIDTypeError – Raised when the function cannot determine the ID type of the input value.

classmethod validate_id_type(value, kind=RemoteIDType.ALL)

Check that the given value is a type of remote ID given by kind

Return type:

bool

classmethod convert(value, kind=None, type_in=RemoteIDType.ALL, type_out=RemoteIDType.ID)

Converts ID to required format - API URL, EXT URL, URI, or ID.

Parameters:
  • value (str) – URL/URI/ID to convert.

  • kind (RemoteObjectType | None (default: None)) – Optionally, give the item type of the input value to skip some checks. This is required when the given value is an ID.

  • type_in (RemoteIDType (default: <RemoteIDType.ALL: 0>)) – Optionally, give the ID type of the input value to skip some checks.

  • type_out (RemoteIDType (default: <RemoteIDType.ID: 22>)) – The ID type of the output value.

Returns:

str – Formatted string.

Raises:
  • RemoteIDTypeError – Raised when the function cannot determine the item type of the input value.

  • RemoteObjectTypeError – Raised when the function cannot process the input value as a type of the given type_in i.e. the type_in does not match the actual type of the value.

classmethod extract_ids(values, kind=None)

Extract a list of IDs from input values.

values may be:
  • A string representing a URL/URI/ID.

  • A MutableSequence of strings representing URLs/URIs/IDs of the same type.

  • A remote API JSON response for a collection including:
    • a valid ID value under an id key,

    • a valid item type value under a type key if kind is None.

  • A MutableSequence of remote API JSON responses for a collection including the same structure as above.

  • A RemoteResponse of the appropriate type for this RemoteAPI which holds a valid API JSON response as described above.

  • A Sequence of RemoteResponses as above.

Parameters:
  • values (Union[str, MutableSequence[str], MutableMapping[str, Any], MutableSequence[MutableMapping[str, Any]], RemoteResponse, Sequence[RemoteResponse]]) – The values representing some remote objects. See description for allowed value types. These items may be of mixed item types e.g. some tracks AND some artists.

  • kind (RemoteObjectType | None (default: None)) – Optionally, give the item type of the input value to skip some checks. This is required when the given value is an ID.

Returns:

list[str] – List of IDs.

Raises:

RemoteError – Raised when the function cannot determine the item type of the input values. Or when it does not recognise the type of the input values parameter.