Created
September 20, 2022 08:53
-
-
Save blacklight/d3c77101550aa29b984dcdbeac1f976b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ~/.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