コード例 #1
0
ファイル: Server.py プロジェクト: N0V0S/webplayer
 def run(self):
     while True:
         try:
             receivedMessage = self.c.recv(1024).decode("utf-8")
             print(receivedMessage + "\n")
             if receivedMessage:
                 Server.getnachrichten(Server).append(receivedMessage)        
                 if ('next' in receivedMessage):
                     win32api.keybd_event(self.VK_MEDIA_NEXT_TRACK, self.hwcode1)
                 if ('prev' in receivedMessage):
                     win32api.keybd_event(self.VK_MEDIA_PREV_TRACK, self.hwcode3)
                 if ('pause' in receivedMessage):
                     win32api.keybd_event(self.VK_MEDIA_PLAY_PAUSE, self.hwcode2)
                 if ('stop' in receivedMessage):
                     win32api.keybd_event(self.VK_MEDIA_STOP, self.hwcode4)
                 if ('volup' in receivedMessage):
                     for i in range(0,15):
                         win32api.keybd_event(self.VK_VOLUME_UP, self.hwcode5)
                         x = i
                 if ('voldown' in receivedMessage):
                     for i in range(0,15):
                         win32api.keybd_event(self.VK_VOLUME_DOWN, self.hwcode6)
                         x = i
                 if ('mute' in receivedMessage):
                     win32api.keybd_event(self.VK_VOLUME_MUTE, self.hwcode7)
                 time.sleep(0.5)
                 spotify = Spotify()
                 songInfo = spotify.getCurrentTrack()
                 if songInfo:
                     songInfo += ', Artist: ' + spotify.getCurrentArtist()
                     print(songInfo + "\n")
                     self.c.send(bytes(songInfo))
                     break;
                 self.c.send(bytes('Error gettin SongInfo'))
                 break;
         except Exception:
             traceback.print_exc(file=sys.stdout)
             break;
コード例 #2
0
username = '******'
password_hash = 'd8578edf8458ce06fbc5bb76a58c5ca4'

#A Last.fm network object
network = pylast.LastFMNetwork(api_key = API_KEY, api_secret = 
                API_SECRET, username = username, password_hash = password_hash)

#Create Spotify object
spotify = Spotify()

# Get current playing track on spotify.
track_name = spotify.getCurrentTrack()
print track_name.lower()

# Get current playing artist on spotify.
artist_name = spotify.getCurrentArtist()

#Return a track object.
track_2_love = network.get_track(artist_name,track_name)

#Adds the track to the user's loved tracks
track_2_love.love()

#Return User Object
user_object = network.get_user(username)

#Return the last loved track
loved_track_list = user_object.get_loved_tracks(1)

#Return user's total playcount
playcount = user_object.get_playcount()