From 3ba307300f5543691c01f5cfb40c7d5edf72ae61 Mon Sep 17 00:00:00 2001 From: jesopo Date: Wed, 6 Apr 2016 16:22:52 +0100 Subject: [PATCH] added more code to deal with lastfm having a ridiculously unreliably structured API. --- modules/lastfm.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/lastfm.py b/modules/lastfm.py index 7b56bfbd..77f693c1 100644 --- a/modules/lastfm.py +++ b/modules/lastfm.py @@ -41,7 +41,7 @@ class Module(object): "api_key": self.bot.config["lastfm-api-key"], "user": username, "format": "json"}, json=True) tags = [] - if "toptags" in info_page["track"]: + if "toptags" in info_page.get("track", []): for tag in info_page["track"]["toptags"]["tag"]: tags.append(tag["name"]) if tags: @@ -50,7 +50,7 @@ class Module(object): tags = "" play_count = "" - if "userplaycount" in info_page["track"]: + if "userplaycount" in info_page.get("track", []): play_count = int(info_page["track"]["userplaycount"]) play_count = " (%d play%s)" % (play_count, "s" if play_count > 1 else "")