Collectionο
The fundamental core collection classes for the entire package.
Classes:
|
Abstract base class for strategies relating to __getitem__ operations on a |
|
Get an item via its name for a |
|
Get an item via its path for a |
|
Get an item via its remote ID for a |
|
Get an item via its remote URI for a |
|
Get an item via its remote API URL for a |
|
Get an item via its remote external URL for a |
Generic class for storing a collection of musify items. |
- class musify.libraries.core.collection.ItemGetterStrategy(key)ο
Bases:
Generic
Abstract base class for strategies relating to __getitem__ operations on a
MusifyCollection
Attributes:
The name to assign to this ItemGetter when logging
Methods:
get_value_from_item
(item)Retrieve the appropriate value from a given
item
for this ItemGetter typeget_item
(collection)Run this strategy and return the matched item from the given
collection
-
key:
TypeVar
(KT
)ο
- abstract property name: strο
The name to assign to this ItemGetter when logging
- abstract get_value_from_item(item)ο
Retrieve the appropriate value from a given
item
for this ItemGetter type- Return type:
KT
- get_item(collection)ο
Run this strategy and return the matched item from the given
collection
- Return type:
TypeVar
(IT
)
-
key:
- class musify.libraries.core.collection.NameGetter(key)ο
Bases:
ItemGetterStrategy
Get an item via its name for a
MusifyCollection
Attributes:
The name to assign to this ItemGetter when logging
Methods:
get_value_from_item
(item)Retrieve the appropriate value from a given
item
for this ItemGetter type- property name: strο
The name to assign to this ItemGetter when logging
- get_value_from_item(item)ο
Retrieve the appropriate value from a given
item
for this ItemGetter type- Return type:
str
- class musify.libraries.core.collection.PathGetter(key)ο
Bases:
ItemGetterStrategy
Get an item via its path for a
MusifyCollection
Attributes:
The name to assign to this ItemGetter when logging
Methods:
get_value_from_item
(item)Retrieve the appropriate value from a given
item
for this ItemGetter type- property name: strο
The name to assign to this ItemGetter when logging
- get_value_from_item(item)ο
Retrieve the appropriate value from a given
item
for this ItemGetter type- Return type:
Path
- class musify.libraries.core.collection.RemoteIDGetter(key)ο
Bases:
ItemGetterStrategy
Get an item via its remote ID for a
MusifyCollection
Attributes:
The name to assign to this ItemGetter when logging
Methods:
get_value_from_item
(item)Retrieve the appropriate value from a given
item
for this ItemGetter type- property name: strο
The name to assign to this ItemGetter when logging
- get_value_from_item(item)ο
Retrieve the appropriate value from a given
item
for this ItemGetter type- Return type:
str
- class musify.libraries.core.collection.RemoteURIGetter(key)ο
Bases:
ItemGetterStrategy
Get an item via its remote URI for a
MusifyCollection
Attributes:
The name to assign to this ItemGetter when logging
Methods:
get_value_from_item
(item)Retrieve the appropriate value from a given
item
for this ItemGetter type- property name: strο
The name to assign to this ItemGetter when logging
- get_value_from_item(item)ο
Retrieve the appropriate value from a given
item
for this ItemGetter type- Return type:
str
- class musify.libraries.core.collection.RemoteURLAPIGetter(key)ο
Bases:
ItemGetterStrategy
Get an item via its remote API URL for a
MusifyCollection
Attributes:
The name to assign to this ItemGetter when logging
Methods:
get_value_from_item
(item)Retrieve the appropriate value from a given
item
for this ItemGetter type- property name: strο
The name to assign to this ItemGetter when logging
- get_value_from_item(item)ο
Retrieve the appropriate value from a given
item
for this ItemGetter type- Return type:
URL
- class musify.libraries.core.collection.RemoteURLEXTGetter(key)ο
Bases:
ItemGetterStrategy
Get an item via its remote external URL for a
MusifyCollection
Attributes:
The name to assign to this ItemGetter when logging
Methods:
get_value_from_item
(item)Retrieve the appropriate value from a given
item
for this ItemGetter type- property name: strο
The name to assign to this ItemGetter when logging
- get_value_from_item(item)ο
Retrieve the appropriate value from a given
item
for this ItemGetter type- Return type:
URL
- class musify.libraries.core.collection.MusifyCollectionο
Bases:
MusifyObject
,MutableSequence
,HasLength
,Generic
Generic class for storing a collection of musify items.
Attributes:
The items in this collection
Total duration of all items in this collection in seconds
Methods:
count
(_MusifyCollection__item)Return the number of occurrences of the given
MusifyItem
in this collectionindex
(_MusifyCollection__item[,Β ...])Return first index of item from items in this collection.
copy
()Return a shallow copy of the list of items in this collection
append
(_MusifyCollection__item[,Β ...])Append one item to the items in this collection
extend
(_MusifyCollection__items[,Β ...])Append many items to the items in this collection
insert
(_MusifyCollection__index,Β ...[,Β ...])Insert given
MusifyItem
before the given indexremove
(_MusifyCollection__item)Remove one item from the items in this collection
pop
([_MusifyCollection__item])Remove one item from the items in this collection and return it
reverse
()Reverse the order of items in this collection in-place
clear
()Remove all items from this collection
sort
([fields,Β shuffle_mode,Β shuffle_weight,Β ...])Sort items in this collection in-place based on given conditions.
intersection
(other)Return the intersection between the items in this collection and an
other
collection as a new list.difference
(other)Return the difference between the items in this collection and an
other
collection as a new list.outer_difference
(other)Return the outer difference between the items in this collection and an
other
collection as a new list.as_dict
()Return a dictionary representation of the key attributes of this object.
- abstract property items: list[T]ο
The items in this collection
- abstract property length: float | Noneο
Total duration of all items in this collection in seconds
- count(_MusifyCollection__item)ο
Return the number of occurrences of the given
MusifyItem
in this collection- Return type:
int
- index(_MusifyCollection__item, _MusifyCollection__start=None, _MusifyCollection__stop=None)ο
Return first index of item from items in this collection.
- Raises:
ValueError β If the value is not present.
MusifyTypeError β If given item does not match the item type of this collection.
- Return type:
int
- copy()ο
Return a shallow copy of the list of items in this collection
- Return type:
list[T]
- append(_MusifyCollection__item, allow_duplicates=True)ο
Append one item to the items in this collection
- Return type:
None
- extend(_MusifyCollection__items, allow_duplicates=True)ο
Append many items to the items in this collection
- Return type:
None
- insert(_MusifyCollection__index, _MusifyCollection__item, allow_duplicates=True)ο
Insert given
MusifyItem
before the given index- Return type:
None
- remove(_MusifyCollection__item)ο
Remove one item from the items in this collection
- Return type:
None
- pop(_MusifyCollection__item=None)ο
Remove one item from the items in this collection and return it
- Return type:
T
- reverse()ο
Reverse the order of items in this collection in-place
- Return type:
None
- clear()ο
Remove all items from this collection
- Return type:
None
- sort(fields=(), shuffle_mode=None, shuffle_weight=1.0, key=None, reverse=False)ο
Sort items in this collection in-place based on given conditions. If key is given,
- Parameters:
fields (
GenericAlias
[Field
|None
] |Mapping
[Field
|None
,bool
] (default:()
)) βWhen None and ShuffleMode is RANDOM, shuffle the tracks. Otherwise, do nothing.
List of tags/properties to sort by.
Map of {<tag/property>: <reversed>}. If reversed is true, sort the
tag/property
in reverse.
shuffle_mode (
ShuffleMode
|None
(default:None
)) β The mode to use for shuffling.shuffle_weight (
float
(default:1.0
)) β The weights (between 0 and 1) to apply to shuffling modes that can use it. This value will automatically be limited to within the accepted range 0 and 1.key (
Field
|None
(default:None
)) β Tag or property to sort on. Can be given instead offields
for a simple sort. If set, all other fields apart fromreverse
are ignored. If None,fields
,shuffle_mode
,shuffle_by
, andshuffle_weight
are used to apply sorting.reverse (
bool
(default:False
)) β If true, reverse the order of the sort at the end.
- Return type:
None
- intersection(other)ο
Return the intersection between the items in this collection and an
other
collection as a new list.(i.e. all items that are in both this collection and the
other
collection).- Return type:
list[T]
- difference(other)ο
Return the difference between the items in this collection and an
other
collection as a new list.(i.e. all items that are in this collection but not the
other
collection).- Return type:
list[T]
- outer_difference(other)ο
Return the outer difference between the items in this collection and an
other
collection as a new list.(i.e. all items that are in the
other
collection but not in this collection).- Return type:
list[T]
- as_dict()ο
Return a dictionary representation of the key attributes of this object.
- The results of this function are used to produce the following:
A JSON representation of the object when calling
json()
The string representation of the object when calling str() on the object
The representation of the object when calling repr() on the object