Wrangle
Convert and validate Spotify ID and item types.
Classes:
- class musify.libraries.remote.spotify.wrangle.SpotifyDataWrangler
Bases:
RemoteDataWranglerAttributes:
Methods:
get_id_type(value[, kind])Determine the remote ID type of the given
valueand return its type.validate_id_type(value[, kind])Check that the given
valueis a type of remote ID given bykindconvert(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'
- url_api = URL('https://api.spotify.com/v1')
- url_ext = URL('https://open.spotify.com')
- classmethod get_id_type(value, kind=None)
Determine the remote ID type of the given
valueand return its type.- Parameters:
value (
str|URL) – URL/URI/ID to check.kind (
RemoteObjectType|None(default:None)) – When this is equal toUSER, ignore checks and always returnIDas type.
- Returns:
RemoteIDType– TheRemoteIDType.- 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
valueis a type of remote ID given bykind- 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) – URL/URI/ID to convert.kind (
RemoteObjectType|None(default:None)) – Optionally, give the item type of the inputvalueto skip some checks. This is required when the givenvalueis an ID.type_in (
RemoteIDType(default:<RemoteIDType.ALL: 0>)) – Optionally, give the ID type of the inputvalueto skip some checks.type_out (
RemoteIDType(default:<RemoteIDType.ID: 22>)) – The ID type of the outputvalue.
- 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
valueas a type of the giventype_ini.e. thetype_indoes not match the actual type of thevalue.
- classmethod extract_ids(values, kind=None)
Extract a list of IDs from input
values.valuesmay 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
idkey,a valid item type value under a
typekey ifkindis 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 (
GenericAlias[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 inputvalueto skip some checks. This is required when the givenvalueis 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 inputvaluesparameter.