forked from albertz/music-player
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtracker_lastfm.py
37 lines (31 loc) · 1.03 KB
/
tracker_lastfm.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# MusicPlayer, https://github.com/albertz/music-player
# Copyright (c) 2012, Albert Zeyer, www.az2000.de
# All rights reserved.
# This code is under the 2-clause BSD license, see License.txt in the root directory of this project.
""" This is the Last.fm tracker module. """
from utils import *
import sys
from State import state
from player import PlayerEventCallbacks
import appinfo
import lastfm
def track(event, args, kwargs):
if event is PlayerEventCallbacks.onSongChange:
oldSong = kwargs["oldSong"]
newSong = kwargs["newSong"]
lastfm.onSongChange(newSong)
if event is PlayerEventCallbacks.onSongFinished:
song = kwargs["song"]
timestamp = kwargs["timestamp"]
lastfm.onSongFinished(song, timestamp=timestamp)
def tracker_lastfmMain():
if not appinfo.config.lastFm: return
lastfm.login()
for ev,args,kwargs in state.updates.read(
listType = lambda: PersistentObject(deque, "lastfm-queue.dat", namespace=globals())
):
try:
track(ev, args, kwargs)
except Exception:
sys.excepthook(*sys.exc_info())
lastfm.quit()