Fixed arxiv plugin to respect rate limits. Fixed lastfm np to search genre tags and song length

This commit is contained in:
2026-05-07 03:49:33 -05:00
parent dba205685b
commit 972f34a25a
2 changed files with 140 additions and 43 deletions
+33
View File
@@ -450,6 +450,39 @@ async def cmd_np(room, message, bot, args):
if youtube_link:
message_text += f" | [YouTube]({youtube_link})"
# ---- New: fetch track genres ----
# --- Fetch genres: try track-level first, fall back to artist ---
genre_tags = []
# 1) Try track top tags
track_tag_data = await call_lastfm_api("track.getTopTags", {"artist": artist, "track": name, "autocorrect": "1"})
if track_tag_data:
tags = track_tag_data.get("toptags", {}).get("tag", [])
genre_tags = [safe_text(t, "name") for t in tags if safe_text(t, "name")]
# 2) If empty, fall back to artist top tags
if not genre_tags:
artist_tag_data = await call_lastfm_api("artist.getTopTags", {"artist": artist, "autocorrect": "1"})
if artist_tag_data:
tags = artist_tag_data.get("toptags", {}).get("tag", [])
genre_tags = [safe_text(t, "name") for t in tags if safe_text(t, "name")]
# 3) Append to message if we got anything
if genre_tags:
genre_str = " | 🏷️ " + ", ".join(genre_tags[:3])
message_text += genre_str
# ---- Fetch track duration (new) ----
track_info = await call_lastfm_api("track.getInfo", {
"artist": artist,
"track": name,
"autocorrect": "1"
})
if track_info:
track_obj = track_info.get("track", {})
duration_ms = safe_int(track_obj, "duration")
if duration_ms > 0:
mins = duration_ms // 60000
secs = (duration_ms % 60000) // 1000
message_text += f" | ⏱️ {mins}:{secs:02d}"
await bot.api.send_markdown_message(room.room_id, message_text)
logging.info(f"Sent now playing for {lastfm_user}")