"""xchat_smplayer by CsigaaPrints 'NICK is playing FILENAME [SMPlayer version]' action to the active channel/dialog.Fully Windows NT/2k/XP/Vista/7 and Linux/BSD compatible.Requiers enabled logging in SMPlayer (Preferences/Advanced/Logs/Save SMPlayer log to file)NOTE FOR PASTEBIN: save the file as xchat_smplayer.py to your xchat directoryContact: csigaa@gmail.comLicense: Beer-ware (by phk) ;p---------------------------------------------------------------------------- "THE BEER-WARE LICENSE" (Revision 42): Csigaa wrote this file. As long as you retain this notice you can do whatever you want with this stuff. If we meet some day, and you think this stuff is worth it, you can buy me a beer in return----------------------------------------------------------------------------"""__module_name__ = "xchat_smplayer"__module_version__ = "1.00"__module_description__ = "XChat-SMPlayer 'now playing' script by Csigaa"import xchatimport osimport re# Determine OS type, then wether SMPlayer is running; then set the configuration home according to OS typeif os.name == 'nt': # We are under Windows NT smphome = os.getenv('USERPROFILE')+os.sep+'.smplayer' # Using WMI for process list, to avoid flashing cmd window from win32com.client import GetObject WMI = GetObject('winmgmts:')elif os.name == 'posix': smphome = os.getenv('HOME')+os.sep+'.config'+os.sep+'smplayer'else: raise NotImplementedError,'OS not supported!'def getFnVer(): # Get the video file name from SMPlayer output log if os.name == 'nt': # We are under Windows NT, get process list and look for running SMPlayer # If none found, return empty processes = WMI.InstancesOf('Win32_Process') isRunning = False for exe in [process.Properties_('Name').Value for process in processes]: if exe == 'smplayer.exe': isRunning = True if isRunning == False: return ['',''] elif os.name == 'posix': # We are under some POSIX, get process list and look for running SMPlayer # If none found, return empty if os.system('ps -A|grep smplayer >/dev/null'): return ['',''] # Open and parse log file logfile = open(smphome+os.sep+'smplayer_log.txt','r') while True: line = logfile.readline().strip('\n').strip('\r') if line == '': break else: try: # Look for version string; if [0] returns exception, none fond ver = re.sub('v[.]\s','',re.findall("SMPlayer\sv[.]\s\d+[.]\d+[.]\d+",line)[0]) except: try: # Look for MPlayer 'Playing $filename." output; remove tailing playline = re.findall("\'Playing\s.+\.\'$",line,re.I)[0].strip('.\'') if playline.split(' ').pop() == 'dvdnav://': # We are playing a DVD, no further information available (FIXME)... file = 'a DVD' else: # We have a regular file, just split the path by /'s and display last file = playline.split('/').pop() except: # All above failed => uninsteresting logline continue return [file,ver]def smplayer_msg(world,world_eol,userdata): try: fn,ver = getFnVer() if (fn != '') and (ver != ''): # The search was successfull irccmd = 'me is playing '+fn+' ['+ver+']' xchat.command(irccmd) else: # The search returned empty xchat.prnt('SMPlayer is not running!') return xchat.EAT_ALL except: # Someting went wrong, eat the command anyway return xchat.EAT_ALLxchat.hook_command('smplayer',smplayer_msg)xchat.prnt('XChat-SMPlayer '+__module_version__+' loaded - Turn on logging in SMPlayer, and use /smplayer to print now playing message')