Added last.fm scrobbler plugin, solves #21

This commit is contained in:
Fabio Manganiello 2018-01-15 02:40:22 +01:00
parent 632255d2dc
commit ac15e581ce
2 changed files with 45 additions and 0 deletions

View file

@ -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)

View file

@ -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: