added more code to deal with lastfm having a ridiculously unreliably structured API.
This commit is contained in:
parent
20058c4b67
commit
3ba307300f
1 changed files with 2 additions and 2 deletions
|
@ -41,7 +41,7 @@ class Module(object):
|
||||||
"api_key": self.bot.config["lastfm-api-key"],
|
"api_key": self.bot.config["lastfm-api-key"],
|
||||||
"user": username, "format": "json"}, json=True)
|
"user": username, "format": "json"}, json=True)
|
||||||
tags = []
|
tags = []
|
||||||
if "toptags" in info_page["track"]:
|
if "toptags" in info_page.get("track", []):
|
||||||
for tag in info_page["track"]["toptags"]["tag"]:
|
for tag in info_page["track"]["toptags"]["tag"]:
|
||||||
tags.append(tag["name"])
|
tags.append(tag["name"])
|
||||||
if tags:
|
if tags:
|
||||||
|
@ -50,7 +50,7 @@ class Module(object):
|
||||||
tags = ""
|
tags = ""
|
||||||
|
|
||||||
play_count = ""
|
play_count = ""
|
||||||
if "userplaycount" in info_page["track"]:
|
if "userplaycount" in info_page.get("track", []):
|
||||||
play_count = int(info_page["track"]["userplaycount"])
|
play_count = int(info_page["track"]["userplaycount"])
|
||||||
play_count = " (%d play%s)" % (play_count,
|
play_count = " (%d play%s)" % (play_count,
|
||||||
"s" if play_count > 1 else "")
|
"s" if play_count > 1 else "")
|
||||||
|
|
Loading…
Reference in a new issue