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

Difference between
modified post 291 by iggykoopa on Sun 2nd Aug 20:18 and
original post 290 by iggykoopa on Sun 2nd Aug 19:32
Show old version | new version | both versions

    
11
#!/usr/bin/python
33
import os,commands, urllib, Image, ImageFont, ImageDraw
55
def reflect(home, artist, album, title, found):
66
    final_image = Image.new('RGBA', (300, 160) , (0, 0, 0, 0))
77
    mid_image = Image.new('RGBA', (300, 80) , (0, 0, 0, 0))
88
    image_flipped = Image.new('RGBA', (300, 80) , (0, 0, 0, 0))
99
    if found:
1010
        image = Image.open(home + "/.album")
1111
    else:
1212
        image = Image.open(home + "/.noalbum")
1313
    gradient = Image.new('L', (1,255))
1414
    for y in range(255, 0, -1):
1515
        if y < 128:
1616
            gradient.putpixel((0,y),255 - (y * 2))
1717
        else:
1818
            gradient.putpixel((0,255-y),0)
1919
    font = ImageFont.truetype("/usr/share/fonts/truetype/ttf-bitstream-vera/Vera.ttf",12)
2020
    draw = ImageDraw.Draw(mid_image)
2121
    draw.text((85, 30), artist, font=font)
2222
    draw.text((85, 45), album, font=font)
2323
    draw.text((85, 60), title, font=font)
2424
    image = image.resize((80,80))
2525
    mid_image.paste(image, (0, 0))
2626
    image_flipped = mid_image.transpose(Image.FLIP_TOP_BOTTOM)
2727
    alpha = gradient.resize(image_flipped.size)
2828
    r,g,b,a = image_flipped.split()
2929
    a_loaded = a.load()
3030
    alpha_loaded = alpha.load()
3131
    for x in range(300):
3232
        for y in range(80):
3333
            if a_loaded[x,y] < alpha_loaded[x,y]:
3434
                alpha_loaded[x,y] = a_loaded[x,y]
3535
    image_flipped.putalpha(alpha)
3636
    final_image.paste(mid_image, (0, 0))
3737
    final_image.paste(image_flipped, (0, 80))
3838
    final_image.save(home + "/.album", "png")
4040
home = os.getenv("HOME")
4141
artist=commands.getoutput("mocp -Q %artist")
4242
album=commands.getoutput("mocp -Q %album")
4343
title=commands.getoutput("mocp -Q %song")
4444
if artist == "" and album == "":
4545
    if os.path.exists(home + "/.album"):
4646
        os.remove(home + "/.album")
4747
else:
4848
    url = "http://www.albumart.org/index.php?srchkey=" + urllib.quote_plus(artist) + "+" + urllib.quote_plus(album) + "&itempage=1&newsearch=1&searchindex=Music"
4949
    albumart = urllib.urlopen(url).read()
5050
    image = ""
5151
    for line in albumart.split("\n"):
5252
        if "http://www.albumart.org/images/zoom-icon.jpg" in line:
5353
            image = line.partition('src="')[2].partition('"')[0]
5454
            break
5555
    if image:
5656
        if os.path.exists("/tmp/imagepath") and os.path.exists(home + "/.album"):
5757
            imagepath = open("/tmp/imagepath").read()
58-
            if imagepath == image:
58+
            if imagepath == artist + album + title:
5959
                pass
6060
            else:
6161
                urllib.urlretrieve(image, home + "/.album")
6262
                reflect(home, artist, album, title, 1)
6363
        else:
6464
            urllib.urlretrieve(image, home + "/.album")
6565
            reflect(home, artist, album, title, 1)
66-
        open("/tmp/imagepath","w").write(image)
66+
        open("/tmp/imagepath","w").write(artist + album + title)
6767
    else:
6868
        open("/tmp/imagepath","w").write("album_not_found")
6969
        reflect(home, artist, album, title, 0)

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me