CrunchBang Linux 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.

CrunchBang Linux Pastebin

Posted by iggykoopa on Mon 3rd Aug 20:34 (modification of post by iggykoopa view diff)
diff | download | new post

  1. #!/usr/bin/python
  2.  
  3. import os, commands, urllib, Image, sys, types, shutil
  4. from optparse import OptionParser
  5.  
  6. def get_info(player):
  7.     check_running = commands.getoutput("ps aux")
  8.     check_running = check_running.split("\n")
  9.     if player == "moc":
  10.         for line in check_running:
  11.             if "mocp" in line:
  12.                 return commands.getoutput("mocp -Q %artist"),commands.getoutput("mocp -Q %album"),commands.getoutput("mocp -Q %song")
  13.         return "","",""
  14.     if player == "rhythmbox":     
  15.         for line in check_running:
  16.             if "/usr/bin/rhythmbox" in line:
  17.                 return commands.getoutput("rhythmbox-client --print-playing-format %ta"),commands.getoutput("rhythmbox-client --print-playing-format %at"),commands.getoutput("rhythmbox-client --print-playing-format %tt")
  18.         return "","",""
  19.  
  20. def size_image(width, height):
  21.     image = Image.open(home + "/.album")
  22.     image = image.resize((width, height))
  23.     image.save(home + "/.album", "png")
  24.    
  25. def reflect(width, height):
  26.     image = Image.open(home + "/.album")
  27.     flipped_image = image.transpose(Image.FLIP_TOP_BOTTOM)
  28.     final_image = Image.new('RGBA', (width, (height * 2) + 1) , (0, 0, 0, 0))
  29.     gradient = Image.new('L', (1,255))
  30.     for y in range(255, 0, -1):
  31.         if y < 128:
  32.             gradient.putpixel((0,y),255 - (y * 2))
  33.         else:
  34.             gradient.putpixel((0,255-y),0)
  35.     alpha = gradient.resize(flipped_image.size)
  36.     flipped_image.putalpha(alpha)
  37.     final_image.paste(image, (0, 0))
  38.     final_image.paste(flipped_image, (0, height + 1))
  39.     final_image.save(home + "/.album", "png")
  40.                                        
  41. parser = OptionParser()
  42. parser.add_option("-p", "--player", dest="player", default="moc", help="media player")
  43. parser.add_option("-s", "--size", dest="size", default="80x80", help="image size")
  44. parser.add_option("-r", "--reflect", action="store_true", dest="reflect", default=False, help="image reflection")
  45. (options, args) = parser.parse_args()
  46.  
  47. try:
  48.     width,height = options.size.split("x")
  49.     width = int(width)
  50.     height = int(height)
  51. except:
  52.     parser.error("please specify size in WIDTHxHEIGHT format")
  53.    
  54. if options.player in ["moc", "rhythmbox"]:
  55.     artist, album, title = get_info(options.player)
  56. else:
  57.     parser.error("player not supported")
  58.    
  59. home = os.getenv("HOME")
  60. if artist == "" and album == "":
  61.     if os.path.exists(home + "/.album"):
  62.         os.remove(home + "/.album")
  63.     if os.path.exists("/tmp/trackinfo"):
  64.         os.remove("/tmp/trackinfo")
  65. elif os.path.exists("/tmp/trackinfo") and open("/tmp/trackinfo").read() == artist + album:
  66.     pass
  67. else:
  68.     url = "http://www.albumart.org/index.php?srchkey=" + urllib.quote_plus(artist) + "+" + urllib.quote_plus(album) + "&itempage=1&newsearch=1&searchindex=Music"
  69.     albumart = urllib.urlopen(url).read()
  70.     image = ""
  71.     for line in albumart.split("\n"):
  72.         if "http://www.albumart.org/images/zoom-icon.jpg" in line:
  73.             image = line.partition('src="')[2].partition('"')[0]
  74.             break
  75.     if image:
  76.         urllib.urlretrieve(image, home + "/.album")
  77.         open("/tmp/trackinfo","w").write(artist + album)
  78.     else:
  79.         open("/tmp/trackinfo","w").write("album_not_found")
  80.         shutil.copy(home + "/.noalbum", home + "/.album")
  81.     size_image(width, height)
  82.     if options.reflect:
  83.         reflect(width, height)

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