mirror of
https://github.com/jlu5/SupyPlugins.git
synced 2025-04-26 13:01:07 -05:00
LastFM: better error displays when the fields we want are empty
This commit is contained in:
parent
4cf64095ff
commit
9aaf4f7db7
@ -82,24 +82,24 @@ class LastFM(callbacks.Plugin):
|
|||||||
url = "%sapi_key=%s&method=user.getrecenttracks&user=%s&format=json" % (self.APIURL, apiKey, user)
|
url = "%sapi_key=%s&method=user.getrecenttracks&user=%s&format=json" % (self.APIURL, apiKey, user)
|
||||||
try:
|
try:
|
||||||
f = utils.web.getUrl(url).decode("utf-8")
|
f = utils.web.getUrl(url).decode("utf-8")
|
||||||
except utils.web.Error:
|
except utils.web.Error as e:
|
||||||
irc.error("Unknown user %s." % user, Raise=True)
|
irc.error(str(e), Raise=True)
|
||||||
self.log.debug("LastFM.nowPlaying: url %s", url)
|
self.log.debug("LastFM.np: url %s", url)
|
||||||
|
|
||||||
try:
|
data = json.loads(f)
|
||||||
data = json.loads(f)["recenttracks"]
|
if "error" in data:
|
||||||
except KeyError:
|
irc.error("%s: %s" % (data["error"], data.get("message")), Raise=True)
|
||||||
irc.error("Unknown user %s." % user, Raise=True)
|
elif "recenttracks" not in data:
|
||||||
|
irc.error("No recenttracks data found for %s" % user, Raise=True)
|
||||||
|
|
||||||
user = data["@attr"]["user"]
|
user = data["recenttracks"]["@attr"]["user"]
|
||||||
tracks = data["track"]
|
tracks = data["recenttracks"]["track"]
|
||||||
|
|
||||||
# Work with only the first track.
|
# Work with only the first track.
|
||||||
try:
|
if not tracks:
|
||||||
trackdata = tracks[0]
|
|
||||||
except IndexError:
|
|
||||||
irc.error("%s doesn't seem to have listened to anything." % user, Raise=True)
|
irc.error("%s doesn't seem to have listened to anything." % user, Raise=True)
|
||||||
|
|
||||||
|
trackdata = tracks[0]
|
||||||
artist = trackdata["artist"]["#text"].strip() # Artist name
|
artist = trackdata["artist"]["#text"].strip() # Artist name
|
||||||
track = trackdata["name"].strip() # Track name
|
track = trackdata["name"].strip() # Track name
|
||||||
# Album name (may or may not be present)
|
# Album name (may or may not be present)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user