Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- __module_name__ = "Dabear's Itunes controller plugin, improved by Pepper"
- __module_version__ = '0.1'
- __module_description__ = 'Controls Itunes, and announces current song'
- import xchat
- from win32com.client import Dispatch
- from win32 import win32evtlog
- def announce(words, words_eol, data):
- try:
- app = Dispatch('iTunes.Application')
- track = app.CurrentTrack
- except:
- try:#sometimes must be run twice
- chan = xchat.get_context()
- chan.command('me doesn\'t have iTunes running')
- return
- #app = Dispatch('iTunes.Application')
- #track = app.CurrentTrack
- except:
- #definitely not running
- print 'Could not fetch Itunes, not running??'
- return
- def mute(): app.Mute=True
- def unmute(): app.Mute=False
- commands = {'play': app.Play, 'start': app.Play, 'pause': app.Pause,
- 'stop': app.Stop, 'replay ': app.BackTrack,
- 'forward': app.FastForward, 'rewind': app.Rewind,
- 'resume': app.Resume, 'next': app.NextTrack,
- 'prev': app.PreviousTrack, 'previous': app.PreviousTrack,
- 'quit': app.Quit,
- 'mute': mute, 'unmute': unmute
- }
- try:
- what = words[1].strip().lower()
- except IndexError: # no word, announce
- #if track:
- title = track.Name.strip()
- artist = track.Artist.strip()
- album = track.Album.strip()
- 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)
- chan = xchat.get_context()
- if album:
- chan.command('me is listening to %s by %s on %s (%s)' % (title, artist, album,position))
- else:
- chan.command('me is listening to %s by %s on an unknown album (%s)' % (title, artist, position))
- return xchat.EAT_XCHAT
- #else:
- # return
- if what == "say":
- print "%s by %s on %s" % (track.Name.strip(), track.Artist.strip(), track.Album.strip())
- return xchat.EAT_XCHAT
- else: # try changing options
- action = commands.get(what, None)
- if not action:
- print "No such action '%s'" % what
- return xchat.EAT_XCHAT
- action()
- return xchat.EAT_XCHAT
- def eventCallback(reason, context, event):
- print event
- print reason
- print context
- xchat.hook_command('announce', announce, help="/announce <command> starts,stops itunes, or announces current track if command is empty")
- xchat.hook_command('itunes', announce, help="/itunes <command> starts,stops itunes, or announces current track if command is empty")
- # 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=[])
- print 'xchat itunes plugin loaded'
Add Comment
Please, Sign In to add comment