/
/
/
1"""Helpers for collections."""
2
3from music_assistant_models.enums import MediaType
4
5from music_assistant.constants import COLLECTION_ITEM_ID_SEPARATOR
6
7
8def get_collection_item_id(collection_name: str, item_media_type: MediaType) -> str:
9 """Get item id for a collection."""
10 return COLLECTION_ITEM_ID_SEPARATOR.join((item_media_type.value.lower(), collection_name))
11
12
13def get_collection_name_from_item_id(collection_item_id: str) -> str:
14 """Get collection's name from item id."""
15 return collection_item_id.split(COLLECTION_ITEM_ID_SEPARATOR, maxsplit=1)[1]
16
17
18def get_collection_item_media_type_from_item_id(collection_item_id: str) -> MediaType:
19 """Get media_type of items in a collection."""
20 return MediaType(collection_item_id.split(COLLECTION_ITEM_ID_SEPARATOR, maxsplit=1)[0].lower())
21