From 41ee6d594c83a5bca9ff7c9ad93830f21a15fe6d Mon Sep 17 00:00:00 2001 From: Joinemm Date: Fri, 14 Jun 2024 16:57:31 +0300 Subject: [PATCH] Filter out trash from tags --- cogs/lastfm.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/cogs/lastfm.py b/cogs/lastfm.py index 3ba1678..17d9d02 100644 --- a/cogs/lastfm.py +++ b/cogs/lastfm.py @@ -523,7 +523,9 @@ async def nowplaying(self, ctx: MisoContext): f"{content.description}\n> {format_playcount(play_count)}" ) content.set_footer( - text=", ".join(tag["name"] for tag in track_info["toptags"]["tag"]) + text=", ".join( + filter_tags(tag["name"] for tag in track_info["toptags"]["tag"]) + ) ) if (duration := int(track_info["duration"])) > 0: @@ -861,7 +863,7 @@ def filter_artist(ta_data: dict): ) content.set_footer( - text=", ".join([x["name"] for x in artistinfo["tags"]["tag"]]) + text=", ".join(filter_tags([x["name"] for x in artistinfo["tags"]["tag"]])) ) await ctx.send(embed=content) @@ -1021,9 +1023,9 @@ async def album_tracklist(self, ctx: MisoContext, albuminfo: dict): if tags := albuminfo["tags"]: # sometimes it's a dict, maybe when there's only one tag(?) if isinstance(tags["tag"], dict): - tags_list = ", ".join(tags["tag"]["name"]) + tags_list = ", ".join(filter_tags(tags["tag"]["name"])) else: - tags_list = ", ".join(t["name"] for t in tags["tag"]) + tags_list = ", ".join(filter_tags(t["name"] for t in tags["tag"])) tracklist = [] for track in tracks: @@ -2490,6 +2492,19 @@ async def task_wrapper(task: asyncio.Future, ref: Any): return result, ref +def filter_tags(tags: list[str]): + """get rid of useless tags""" + clean_tags = [] + for tag in tags: + if tag == "MySpotigramBot": + continue + if tag.startswith("-") and len(tag) == 14 and tag.strip("-").isdigit(): + continue + clean_tags.append(tag) + + return clean_tags + + def playcount_mapped( x: int, input_start: int,