From ac15e581cebca151903015334e7d7a60c5908408 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Mon, 15 Jan 2018 02:40:22 +0100 Subject: [PATCH] Added last.fm scrobbler plugin, solves #21 --- platypush/event/processor/__init__.py | 1 + platypush/plugins/lastfm/__init__.py | 44 +++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 platypush/plugins/lastfm/__init__.py diff --git a/platypush/event/processor/__init__.py b/platypush/event/processor/__init__.py index f9444c947..574b2c4bb 100644 --- a/platypush/event/processor/__init__.py +++ b/platypush/event/processor/__init__.py @@ -35,6 +35,7 @@ class EventProcessor(object): if match.is_match: if match.score > max_score: matched_hooks = set((hook,)) + max_score = match.score elif match.score == max_score: matched_hooks.add(hook) diff --git a/platypush/plugins/lastfm/__init__.py b/platypush/plugins/lastfm/__init__.py new file mode 100644 index 000000000..434874f86 --- /dev/null +++ b/platypush/plugins/lastfm/__init__.py @@ -0,0 +1,44 @@ +import pylast +import time + +from platypush.message.response import Response + +from .. import Plugin + +class LastfmPlugin(Plugin): + def __init__(self, api_key, api_secret, username, password): + self.api_key = api_key + self.api_secret = api_secret + self.username = username + self.password = password + + self.lastfm = pylast.LastFMNetwork( + api_key = self.api_key, + api_secret = self.api_secret, + username = self.username, + password_hash = pylast.md5(self.password)) + + + def scrobble(self, artist, title, album=None, **kwargs): + self.lastfm.scrobble( + artist = artist, + title = title, + album = album, + timestamp = int(time.time()), + ) + + return Response() + + + def update_now_playing(self, artist, title, album=None, **kwargs): + self.lastfm.update_now_playing( + artist = artist, + title = title, + album = album, + ) + + return Response() + + +# vim:sw=4:ts=4:et: +