Skip to content

Instantly share code, notes, and snippets.

@blacklight
Created September 20, 2022 08:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blacklight/d3c77101550aa29b984dcdbeac1f976b to your computer and use it in GitHub Desktop.
Save blacklight/d3c77101550aa29b984dcdbeac1f976b to your computer and use it in GitHub Desktop.
# ~/.config/platypush/scripts/music/sync.py
from logging import getLogger
from platypush.context import get_plugin
from platypush.event.hook import hook
from platypush.message.event.music import NewPlayingTrackEvent
logger = getLogger('music_sync')
# Hook that react to NewPlayingTrackEvent events
@hook(NewPlayingTrackEvent)
def on_new_track_playing(event, **_):
track = event.track
# Skip if the track has no artist/title specified
if not (track.get('artist') and track.get('title')):
return
lastfm = get_plugin('lastfm')
logger.info(
'Scrobbling track: %s - %s',
track['artist'], track['title']
)
lastfm.scrobble(
artist=track['artist'],
title=track['title'],
album=track.get('album'),
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment