Sort
Processor that sorts the given collection of items based on given configuration.
Classes:
|
Represents the possible shuffle modes to use when shuffling items using |
|
Sort items in-place based on given conditions. |
- class musify.processors.sort.ShuffleMode(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)
Bases:
MusifyEnum
Represents the possible shuffle modes to use when shuffling items using
ItemSorter
.Attributes:
- RANDOM = 0
- HIGHER_RATING = 1
- RECENT_ADDED = 2
- DIFFERENT_ARTIST = 3
- class musify.processors.sort.ItemSorter(fields=(), shuffle_mode=None, shuffle_weight=0.0)
Bases:
Processor
Sort items in-place based on given conditions.
fields
may be:List of tags/properties to sort by.
Map of
{<tag/property>: <reversed>}
. If reversed is true, sort thetag/property
in reverse.
- When
shuffle_mode
==HIGHER_RATING
orRECENT_ADDED
: A
shuffle_weight
of 0 will sort the tracks in order according to the desiredshuffle_mode
.A positive
shuffle_weight
shuffles according to the desiredshuffle_mode
. Theshuffle_weight
will determine how much randomness is applied to lower ranking items.A negative
shuffle_weight
works as above but reverses the final sort order.
- When
shuffle_mode
==DIFFERENT_ARTIST
: A
shuffle_weight
of 1 will group the tracks by artist, shuffling artists randomly.A
shuffle_weight
of -1 will shuffle the items randomly.
- Parameters:
fields (
GenericAlias
[Field
|None
] |Mapping
[Field
|None
,bool
] (default:()
)) – Fields to sort by. If defined, this value will always take priority over any shuffle settings i.e. shuffle settings will be ignored.shuffle_mode (
ShuffleMode
|None
(default:None
)) – The mode to use for shuffling. Only used when nofields
are given. WARNING: Currently onlyRANDOM
shuffle mode has been implemented. Any other given value will default toRANDOM
shuffling.shuffle_weight (
float
(default:0.0
)) – The weights (between -1 and 1) to apply to certain shuffling modes. This value will automatically be limited to within the valid range -1 and 1. Only used when nofields
are given and shuffle_mode is not None orRANDOM
.
Methods:
sort_by_field
(items[, field, reverse])Sort items by the values of a given field.
group_by_field
(items[, field])Group items by the values of a given field.
sort
(items)Sorts a list of
items
in-place.as_dict
()Return a dictionary representation of the key attributes of this object.
Attributes:
- classmethod sort_by_field(items, field=None, reverse=False)
Sort items by the values of a given field.
- Parameters:
items (
list
[MusifyItem
]) – List of items to sortfield (
Field
|None
(default:None
)) – Tag or property to sort on. If None and reverse is True, reverse the order of the list.reverse (
bool
(default:False
)) – If true, reverse the order of the sort.
- Return type:
None
- classmethod group_by_field(items, field=None)
Group items by the values of a given field.
- Parameters:
items (
GenericAlias
[TypeVar
(T
, bound=MusifyItem
)]) – List of items to sort.field (
Field
|None
(default:None
)) – Tag or property to group by. None returns map of{None: <items>}
.
- Returns:
dict
[Any
,list
[TypeVar
(T
, bound=MusifyItem
)]] – Map of grouped items.
- shuffle_mode
- shuffle_weight
- sort(items)
Sorts a list of
items
in-place.- Return type:
None
- 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