From 8a772fb01cd8092d7d57c0fa98edeee20315027f Mon Sep 17 00:00:00 2001 From: Colin Powell Date: Fri, 26 Jun 2026 12:04:57 -0400 Subject: [PATCH] [geneators] llama4 is not showtime --- src/mopidy_smartplaylists/generators.py | 71 +++++++++---------------- 1 file changed, 26 insertions(+), 45 deletions(-) diff --git a/src/mopidy_smartplaylists/generators.py b/src/mopidy_smartplaylists/generators.py index fbfd78f..46e4672 100644 --- a/src/mopidy_smartplaylists/generators.py +++ b/src/mopidy_smartplaylists/generators.py @@ -189,53 +189,34 @@ def build_smart_queue_tracks( seed = seed_tracks[0] if seed_tracks else None if seed: -- genres = [g.strip() for g in (seed.genre or "").split("/") if g.strip()] -- if genres: -- other_genre = random.choice(genres) -- variety = _search(core, "genre", other_genre, uris=uris) -- else: -- variety = _search(core, "artist", seed.artists[0].name if seed.artists else "", uris=uris) -+ potential_attributes: list[tuple[str, str]] = [] # [(attribute_type, attribute_value)] -+ genres = [g.strip() for g in (seed.genre or "").split("/") if g.strip()] -+ if genres: -+ potential_attributes.extend([("genre", g) for g in genres]) -+ -+ artist_names = [a_ref.name for a_ref in seed.artists if a_ref.name] -+ if artist_names: -+ potential_attributes.extend([("artist", name) for name in artist_names]) -+ -+ variety: list[Track] = [] -+ for attr_type, attr_value in potential_attributes: -+ try: -+ if attr_type == "genre": -+ search_result_tracks = _search(core, "genre", attr_value, uris=uris) -+ elif attr_type == "artist": -+ search_result_tracks = _search(core, "artist", attr_value, uris=uris) -+ else: -+ continue -+ -+ for t in search_result_tracks: -+ if t.uri and t.uri != seed_uri and t not in variety: -+ variety.append(t) -+ except Exception as e: -+ logger.warning("Could not generate variety for %s=%s: %s", attr_type, attr_value, str(e)) + potential_attributes: list[tuple[str, str]] = [] + genres = [g.strip() for g in (seed.genre or "").split("/") if g.strip()] + if genres: + potential_attributes.extend([("genre", g) for g in genres]) -- random.shuffle(variety) -- variety = variety[:variety_count] -+ # Shuffle all collected unique tracks and cap at the required count -+ variety = list(set(variety)) # Ensure uniqueness first -+ random.shuffle(variety) -+ variety = variety[:variety_count] + artist_names = [a_ref.name for a_ref in seed.artists if a_ref.name] + if artist_names: + potential_attributes.extend([("artist", name) for name in artist_names]) - if seed: - genres = [g.strip() for g in (seed.genre or "").split("/") if g.strip()] -- if genres: -- other_genre = random.choice(genres) -- variety = _search(core, "genre", other_genre, uris=uris) -- else: -- variety = _search(core, "artist", seed.artists[0].name if seed.artists else "", uris=uris) -- random.shuffle(variety) -- variety = variety[:variety_count] + variety: list[Track] = [] + for attr_type, attr_value in potential_attributes: + try: + if attr_type == "genre": + search_result_tracks = _search(core, "genre", attr_value, uris=uris) + elif attr_type == "artist": + search_result_tracks = _search(core, "artist", attr_value, uris=uris) + else: + continue + + for t in search_result_tracks: + if t.uri and t.uri != seed_uri and t not in variety: + variety.append(t) + except Exception as e: + logger.warning("Could not generate variety for %s=%s: %s", attr_type, attr_value, str(e)) + + variety = list(set(variety)) + random.shuffle(variety) + variety = variety[:variety_count] result = instant + variety random.shuffle(result)