Advertisement
jpvain

Untitled

Jul 28th, 2013
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.51 KB | None | 0 0
  1. import serial, time
  2. import sys
  3. import win32gui
  4.  
  5. class Spotify(object):
  6.    
  7.        
  8.         APPCOMMAND      = 0x0319
  9.  
  10.         # Command IDs
  11.         CMD_PLAYPAUSE   = 917504
  12.  
  13.         # Instance vars
  14.         _hwnd            = None
  15.         def __init__(self):
  16.                 try:
  17.                         self._hwnd = win32gui.FindWindow("SpotifyMainWindow", None)
  18.                 except:
  19.                         raise self.SpotifyWindowNotFoundException()
  20.         def playpause(self):
  21.                 self._sendCommand(self.CMD_PLAYPAUSE)
  22.  
  23.         def focus(self):
  24.                 win32gui.ShowWindow(self._hwnd, 1)
  25.                 win32gui.SetForegroundWindow(self._hwnd)
  26.                 win32gui.SetFocus(self._hwnd)
  27.  
  28.         def _sendCommand(self, id):
  29.                 win32gui.SendMessage(self._hwnd, self.APPCOMMAND, 0, id)
  30.  
  31. COMMANDLINE_COMMANDS = {
  32.                 'playpause': Spotify.playpause
  33. }
  34. if __name__ == "__main__":
  35.         def fail():
  36.                 print ("Usage: pytify.py "+"|".join(COMMANDLINE_COMMANDS.keys()))
  37.                 sys.exit(0)
  38.         ser =serial.Serial('COM5', 9600)
  39.         cmd_name = ser.readline()
  40.         if not(cmd_name) in COMMANDLINE_COMMANDS: fail()
  41.  
  42.         cmd = COMMANDLINE_COMMANDS[cmd_name]
  43.         print('hello')
  44.         try:
  45.                 spotify = Spotify()
  46.                
  47.                
  48.         except:
  49.                 #print "Spotify is not running"
  50.                 sys.exit(0)
  51.  
  52.         res = cmd(spotify)
  53.         if res : print(res)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement