Guest User

Untitled

a guest
Jan 18th, 2019
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.05 KB | None | 0 0
  1.  
  2. __module_name__ = "Dabear's Itunes controller plugin, improved by Pepper"
  3. __module_version__ = '0.1'
  4. __module_description__ = 'Controls Itunes, and announces current song'
  5.  
  6. import xchat
  7.  
  8. from win32com.client import Dispatch
  9. from win32 import win32evtlog
  10.  
  11. def announce(words, words_eol, data):
  12.     try:
  13.         app = Dispatch('iTunes.Application')
  14.         track = app.CurrentTrack
  15.     except:
  16.         try:#sometimes must be run twice
  17.             chan = xchat.get_context()
  18.             chan.command('me doesn\'t have iTunes running')
  19.             return
  20.             #app = Dispatch('iTunes.Application')
  21.             #track = app.CurrentTrack
  22.         except:
  23.              #definitely not running
  24.              print 'Could not fetch Itunes, not running??'
  25.              return
  26.    
  27.     def mute(): app.Mute=True
  28.     def unmute(): app.Mute=False
  29.        
  30.     commands = {'play': app.Play, 'start': app.Play, 'pause': app.Pause,
  31.      'stop': app.Stop, 'replay  ': app.BackTrack,
  32.      'forward': app.FastForward, 'rewind': app.Rewind,
  33.      'resume': app.Resume, 'next': app.NextTrack,
  34.      'prev': app.PreviousTrack, 'previous': app.PreviousTrack,
  35.      'quit': app.Quit,
  36.      'mute': mute, 'unmute': unmute
  37.  
  38.     }
  39.     try:
  40.         what = words[1].strip().lower()
  41.     except IndexError: # no word, announce
  42.         #if track:
  43.         title      = track.Name.strip()
  44.         artist     = track.Artist.strip()
  45.         album      = track.Album.strip()
  46.        
  47.         position = '%01d:%02d/%s' % (app.PlayerPosition / 60,app.PlayerPosition % 60, track.Time) if app.PlayerPosition < 600 else '%02d:%02d/%s' % (app.PlayerPosition / 60,app.PlayerPosition % 60, track.Time)
  48.        
  49.         chan = xchat.get_context()
  50.        
  51.         if album:
  52.             chan.command('me is listening to %s by %s on %s (%s)'  % (title, artist, album,position))
  53.         else:
  54.             chan.command('me is listening to %s by %s on an unknown album (%s)'  % (title, artist, position))
  55.  
  56.        
  57.         return xchat.EAT_XCHAT
  58.         #else:
  59.          #   return
  60.     if what == "say":
  61.         print "%s by %s on %s" % (track.Name.strip(), track.Artist.strip(), track.Album.strip())
  62.         return xchat.EAT_XCHAT
  63.     else: # try changing options
  64.         action = commands.get(what, None)
  65.         if not action:
  66.             print "No such action '%s'" % what
  67.             return xchat.EAT_XCHAT
  68.        
  69.         action()
  70.         return xchat.EAT_XCHAT
  71.                      
  72. def eventCallback(reason, context, event):
  73.     print event
  74.     print reason
  75.     print context
  76.  
  77. xchat.hook_command('announce', announce, help="/announce <command> starts,stops itunes, or announces current track if command is empty")
  78. xchat.hook_command('itunes', announce, help="/itunes <command> starts,stops itunes, or announces current track if command is empty")
  79. # this is COM stuff I don't know; trying to register for a push even from iTunes win32evtlog.EvtSubscribe(,win32evtlog.EvtSubscribeStartAtOldestRecord, Query='', Callback=eventCallback, Context=[])
  80. print 'xchat itunes plugin loaded'
Add Comment
Please, Sign In to add comment