pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

Python pastebin - collaborative debugging tool View Help


Posted by Csigaa on Sat 2 Aug 14:27
report spam | download | new post

  1. """
  2. xchat_mplayer by Csigaa
  3. Prints 'NICK is playing FILENAME [MPlayer version]' action to the actual channel.
  4. Initial release, tested only on Linux, but should work also on other *NIX
  5.  
  6. Contact: csigaa@gmail.com
  7. License: Beer-ware (thx to phk) ;p
  8. ----------------------------------------------------------------------------
  9. "THE BEER-WARE LICENSE" (Revision 42):
  10. Csigaa wrote this file. As long as you retain this notice you
  11. can do whatever you want with this stuff. If we meet some day, and you think
  12. this stuff is worth it, you can buy me a beer in return
  13. ----------------------------------------------------------------------------
  14.  
  15. """
  16.  
  17. __module_name__ = "xchat_mplayer"
  18. __module_version__ = "0.1"
  19. __module_description__ = "MPlayer 'now playing' script for XChat by Csigaa"
  20.  
  21. import xchat
  22. import commands
  23. import re
  24.  
  25. def getPid(progname):
  26.     # Get the PID from ps output
  27.     cmd = 'ps -C '+progname
  28.     pid = re.compile('\d+\s').findall(commands.getoutput(cmd))[0]
  29.     return pid
  30.  
  31. def getFilename():
  32.     # Get the video file name (identified by naming pattern) from lsof output
  33.     cmd = 'lsof -F n -p '+getPid('mplayer')
  34.     lines = re.compile('\.*\\n').split(commands.getoutput(cmd))
  35.     i = 0
  36.     path = []
  37.     while (i<len(lines)):
  38.         if re.compile('.*(avi|mpg|mkv|ogg|ogm|wmv|iso)$',re.I).match(lines[i]):
  39.             path = re.compile('\.*/\.*').split(lines[i])
  40.         i+=1
  41.     return path[len(path)-1]
  42.  
  43. def getVersion():
  44.     return re.compile(r'^MPlayer\s\d[.]\d+\w{0,4}-\d[.]\d[.]\d').findall(commands.getoutput('mplayer'))[0]
  45.  
  46. def mplayer_msg(world,world_eol,userdata):
  47.     try:
  48.         xchat.command('me is playing '+getFilename()+' ['+getVersion()+']')
  49.         return xchat.EAT_ALL
  50.     except:
  51.         return xchat.EAT_ALL
  52.  
  53. xchat.hook_command('mplayer',mplayer_msg)
  54. xchat.prnt('MPlayer nowplay script loaded.')

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me