Skip to content

Commit

Permalink
Filter out trash from tags
Browse files Browse the repository at this point in the history
  • Loading branch information
joinemm committed Jun 14, 2024
1 parent 89b07c8 commit 41ee6d5
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions cogs/lastfm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 41ee6d5

Please sign in to comment.