aboutsummaryrefslogtreecommitdiff
path: root/modules/lastfm.py
diff options
context:
space:
mode:
Diffstat (limited to 'modules/lastfm.py')
-rw-r--r--modules/lastfm.py22
1 files changed, 12 insertions, 10 deletions
diff --git a/modules/lastfm.py b/modules/lastfm.py
index e8a2545e..a0ef49d2 100644
--- a/modules/lastfm.py
+++ b/modules/lastfm.py
@@ -1,21 +1,23 @@
-#--require-config lastfm-api-key
+# --require-config lastfm-api-key
import Utils
URL_SCROBBLER = "http://ws.audioscrobbler.com/2.0/"
+
class Module(object):
def __init__(self, bot):
self.bot = bot
bot.events.on("postboot").on("configure").on(
"set").assure_call(setting="lastfm",
- help="Set username on last.fm")
+ help="Set username on last.fm")
bot.events.on("received").on("command").on("np",
- "listening", "nowplaying").hook(self.np,
- help="Get the last listened to track from a user",
- usage="[username]")
+ "listening",
+ "nowplaying").hook(self.np,
+ help="Get the last listened to track from a user",
+ usage="[username]")
def np(self, event):
if event["args_split"]:
@@ -23,7 +25,7 @@ class Module(object):
shown_username = lastfm_username
else:
lastfm_username = event["user"].get_setting("lastfm",
- event["user"].nickname)
+ event["user"].nickname)
shown_username = event["user"].nickname
page = Utils.get_url(URL_SCROBBLER, get_params={
"method": "user.getrecenttracks", "user": lastfm_username,
@@ -31,7 +33,7 @@ class Module(object):
"format": "json", "limit": "1"}, json=True)
if page:
if "recenttracks" in page and len(page["recenttracks"
- ]["track"]):
+ ]["track"]):
now_playing = page["recenttracks"]["track"][0]
track_name = now_playing["name"]
artist = now_playing["artist"]["#text"]
@@ -54,14 +56,14 @@ class Module(object):
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 "")
+ "s" if play_count > 1 else "")
event["stdout"].write(
"%s is now playing: %s - %s%s%s" % (
- shown_username, artist, track_name, play_count, tags))
+ shown_username, artist, track_name, play_count, tags))
else:
event["stderr"].write(
"The user '%s' has never scrobbled before" % (
- shown_username))
+ shown_username))
else:
event["stderr"].write("Failed to load results")