diff --git a/larigira/audiogen_mpdrandom.py b/larigira/audiogen_mpdrandom.py index dd50197..3ec5521 100644 --- a/larigira/audiogen_mpdrandom.py +++ b/larigira/audiogen_mpdrandom.py @@ -9,8 +9,7 @@ log = logging.getLogger(__name__) def generate_by_artist(spec): - """choose HOWMANY random artists, and for each one choose a random song""" - + """Choose HOWMANY random artists, and for each one choose a random song.""" spec.setdefault("howmany", 1) prefix = spec.get("prefix", "").rstrip("/") log.info("generating") @@ -19,7 +18,8 @@ def generate_by_artist(spec): c.connect(conf["MPD_HOST"], conf["MPD_PORT"]) if prefix: - # TODO: listallinfo is discouraged. how else could we achieve the same result? + # TODO: listallinfo is discouraged. + # how else could we achieve the same result? artists = list( {r["artist"] for r in c.listallinfo(prefix) if "artist" in r} ) @@ -29,6 +29,9 @@ def generate_by_artist(spec): raise ValueError("no artists in your mpd database") for _ in range(spec["howmany"]): artist = random.choice(artists) # pick one artist + if type(artist) is not str: + # different mpd library versions have different behavior + artist = artist['artist'] # pick one song from that artist artist_songs = (res["file"] for res in c.find("artist", artist)) if prefix: