fixed showing track tags in lastfm.py.
This commit is contained in:
parent
80818fad66
commit
1cc28a5581
1 changed files with 11 additions and 6 deletions
|
@ -34,22 +34,27 @@ class Module(object):
|
||||||
track_name = now_playing["name"]
|
track_name = now_playing["name"]
|
||||||
artist = now_playing["artist"]["#text"]
|
artist = now_playing["artist"]["#text"]
|
||||||
|
|
||||||
tags_page = Utils.get_url(URL_SCROBBLER, get_params={
|
info_page = Utils.get_url(URL_SCROBBLER, get_params={
|
||||||
"method": "track.getTags", "artist": artist,
|
"method": "track.getInfo", "artist": artist,
|
||||||
"track": track_name, "autocorrect": "1",
|
"track": track_name, "autocorrect": "1",
|
||||||
"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 tags_page.get("tags", {}).get("tag"):
|
print(info_page.keys())
|
||||||
for tag in tags_page["tags"]["tag"]:
|
if "toptags" in info_page["track"]:
|
||||||
|
for tag in info_page["track"]["toptags"]["tag"]:
|
||||||
tags.append(tag["name"])
|
tags.append(tag["name"])
|
||||||
if tags:
|
if tags:
|
||||||
tags = " (%s)" % ", ".join(tags)
|
tags = " (%s)" % ", ".join(tags)
|
||||||
else:
|
else:
|
||||||
tags = ""
|
tags = ""
|
||||||
|
play_count = int(info_page["track"]["userplaycount"])
|
||||||
|
play_count = "%d play%s" % (play_count,
|
||||||
|
"s" if play_count > 1 else "")
|
||||||
|
|
||||||
event["stdout"].write("%s is now playing: %s - %s%s" % (
|
event["stdout"].write(
|
||||||
username, artist, track_name, tags))
|
"%s is now playing: %s - %s (%s)%s" % (
|
||||||
|
username, artist, track_name, play_count, tags))
|
||||||
else:
|
else:
|
||||||
event["stderr"].write(
|
event["stderr"].write(
|
||||||
"The user '%s' has never scrobbled before" % (
|
"The user '%s' has never scrobbled before" % (
|
||||||
|
|
Loading…
Reference in a new issue