mirror of
https://github.com/beetbox/beets.git
synced 2025-12-15 21:14:19 +01:00
Added an option to define the field to use for equal chance sampling
This commit is contained in:
parent
15515bec95
commit
9ed6ca613d
1 changed files with 10 additions and 1 deletions
|
|
@ -29,6 +29,7 @@ def random_func(lib: Library, opts: optparse.Values, args: list[str]):
|
|||
number=opts.number,
|
||||
time_minutes=opts.time,
|
||||
equal_chance=opts.equal_chance,
|
||||
equal_chance_field=opts.field,
|
||||
):
|
||||
print_(format(obj))
|
||||
|
||||
|
|
@ -55,6 +56,13 @@ random_cmd.parser.add_option(
|
|||
type="float",
|
||||
help="total length in minutes of objects to choose",
|
||||
)
|
||||
random_cmd.parser.add_option(
|
||||
"-f",
|
||||
"--field",
|
||||
action="store",
|
||||
type="string",
|
||||
help="field to use for equal chance sampling (default: albumartist)",
|
||||
)
|
||||
random_cmd.parser.add_all_common_options()
|
||||
random_cmd.func = random_func
|
||||
|
||||
|
|
@ -124,6 +132,7 @@ def random_objs(
|
|||
number: int = 1,
|
||||
time_minutes: float | None = None,
|
||||
equal_chance: bool = False,
|
||||
equal_chance_field: str = "albumartist",
|
||||
) -> Iterable[T]:
|
||||
"""Get a random subset of items, optionally constrained by time or count.
|
||||
|
||||
|
|
@ -140,7 +149,7 @@ def random_objs(
|
|||
# artist-balanced way.
|
||||
perm: Iterable[T]
|
||||
if equal_chance:
|
||||
perm = _equal_chance_permutation(objs)
|
||||
perm = _equal_chance_permutation(objs, field=equal_chance_field)
|
||||
else:
|
||||
perm = list(objs)
|
||||
random.shuffle(perm)
|
||||
|
|
|
|||
Loading…
Reference in a new issue