Limit
Processor that limits the items in a given collection of items
Classes:
|
Represents the possible limit types to apply when filtering a playlist. |
|
Sort items in-place based on given conditions. |
- class musify.processors.limit.LimitType(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)
Bases:
MusifyEnum
Represents the possible limit types to apply when filtering a playlist.
Attributes:
- ITEMS = 0
- ALBUMS = 1
- SECONDS = 11
- MINUTES = 12
- HOURS = 13
- DAYS = 14
- WEEKS = 15
- BYTES = 20
- KILOBYTES = 21
- MEGABYTES = 22
- GIGABYTES = 23
- TERABYTES = 24
- class musify.processors.limit.ItemLimiter(limit=0, on=LimitType.ITEMS, sorted_by=None, allowance=1.0)
Bases:
DynamicProcessor
Sort items in-place based on given conditions.
- Parameters:
limit (
int
(default:0
)) – The number of items to limit to. A value of 0 applies no limiting.on (
LimitType
(default:<LimitType.ITEMS: 0>
)) – The type to limit on e.g. items, albums, minutes.sorted_by (
str
|None
(default:None
)) – When limiting, sort the collection of items by this function first.allowance (
float
(default:1.0
)) – When limiting on bytes or length, add this extra allowance factor to the max size limit on comparison. e.g. say the limiter currently has 29 minutes worth of songs in its final list and the max limit is 30 minutes. The limiter has to now consider whether to include the next song it sees with length 3 minutes. With an allowance of 0, this song will not be added. However, with an allowance of say 1.33 it will as the max limit for this comparison becomes 30 * 1.33 = 40. Now, with 32 minutes worth of songs in the final playlist, the limit is >30 minutes and the limiter stops processing.
Attributes:
String representation of the sorting method to use before limiting
The number of items to limit to.
The type to limit on e.g. items, albums, minutes.
When limiting on bytes or length, add this extra allowance factor to the max size limit on comparison.
Methods:
limit
(items[, ignore])Limit
items
in-place based on set conditions.as_dict
()Return a dictionary representation of the key attributes of this object.
- property limit_sort: str | None
String representation of the sorting method to use before limiting
- limit_max
The number of items to limit to.
- kind
The type to limit on e.g. items, albums, minutes.
- allowance
When limiting on bytes or length, add this extra allowance factor to the max size limit on comparison.
- limit(items, ignore=())
Limit
items
in-place based on set conditions.- Parameters:
items (
list
[TypeVar
(T
, bound=MusifyItem
)]) – The list of items to limit.ignore (
Collection
[TypeVar
(T
, bound=MusifyItem
)] (default:()
)) – list of items to ignore when limiting. i.e. keep them in the list regardless.
- 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