Collection

Inheritance diagram of musify.libraries.core.collection

The fundamental core collection classes for the entire package.

Classes:

ItemGetterStrategy(key)

Abstract base class for strategies relating to __getitem__ operations on a MusifyCollection

NameGetter(key)

Get an item via its name for a MusifyCollection

PathGetter(key)

Get an item via its path for a MusifyCollection

RemoteIDGetter(key)

Get an item via its remote ID for a MusifyCollection

RemoteURIGetter(key)

Get an item via its remote URI for a MusifyCollection

RemoteURLAPIGetter(key)

Get an item via its remote API URL for a MusifyCollection

RemoteURLEXTGetter(key)

Get an item via its remote external URL for a MusifyCollection

MusifyCollection()

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:

key

name

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

get_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)

class musify.libraries.core.collection.NameGetter(key)

Bases: ItemGetterStrategy

Get an item via its name for a MusifyCollection

Attributes:

name

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:

name

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:

name

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:

name

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:

name

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:

name

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:

items

The items in this collection

length

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 collection

index(_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 index

remove(_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 of fields for a simple sort. If set, all other fields apart from reverse are ignored. If None, fields, shuffle_mode, shuffle_by, and shuffle_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