5 from time
import sleep
, time
6 from hashlib
import md5
10 logging
.basicConfig(filename
="lastfmnotify.log", level
= logging
.DEBUG
)
12 class NotifyNowPlaying():
13 def __init__(self
,user
,password
):
15 self
.password
= password
18 self
.unixtimestamp
= time().__int
__()
21 self
.auth
= md5(md5(str(self
.password
)).hexdigest() + str(self
.unixtimestamp
)).hexdigest()
25 response
= urllib
.urlopen("http://post.audioscrobbler.com/?hs=true&p=1.2&c=%s&v=%s&u=%s&t=%s&a=%s"%(self
.client
,self
.version
,self
.user
,self
.unixtimestamp
,self
.auth
))
26 r
= str(response
.read()).split("\n")
29 self
.UrlNotification
= r
[2]
33 debug("Handshake Error")
36 def SendNotification(self
,artist
,track
,album
,sec
,track_number
,mb_trackid
=""):
38 params
['s'] = self
.SessionId
44 params
['m'] = mb_trackid
46 params
= urllib
.urlencode(params
)
47 response
= urllib
.urlopen(self
.UrlNotification
,params
)
48 r
= str(response
.read()).split("\n")
50 debug("Notification sent")
52 debug("Error while sending song data")
57 """ Prints debug message to stdout """
58 logging
.debug(message
)
60 # Notification callbacks. Implement these functions to react to specific notification
64 artist
= str(os
.popen("dcop amarok player artist").read().strip())
65 track
= str(os
.popen("dcop amarok player title").read().strip())
66 album
= str(os
.popen("dcop amarok player album").read().strip())
67 sec
= str(os
.popen("dcop amarok player trackTotalTime").read().strip())
68 pista
= str(os
.popen("dcop amarok player track").read().strip())
71 os
.system("dcop amarok playlist shortStatusMessage 'Sending notification to Last.fm'")
72 if lastfm
.SendNotification(artist
,track
,album
,sec
,pista
):
74 os
.system("dcop amarok playlist shortStatusMessage '%s - %s sent'"%(artist
,track
))
76 os
.system("dcop amarok playlist shortStatusMessage 'An error occurred while sending %s-%s'"%(artist
,track
))
84 if __name__
== "__main__":
85 user
= os
.popen("dcop amarok script readConfig 'ScrobblerUsername'").read().strip()
86 password
= os
.popen("dcop amarok script readConfig 'ScrobblerPassword'").read().strip()
88 debug("Notifier Starting...")
89 lastfm
= NotifyNowPlaying(user
, password
)
92 debug("Starting main thread...")
94 line
= sys
.stdin
.readline()
97 debug( "Received notification: %s " % line
)
99 if line
.find( "trackChange" ) == 0:
100 debug("track changed!")
This page took 0.103118 seconds and 5 git commands to generate.