Playlog Displayer
Posted by they4kman on Sunday, February 15, 2009 at 7:46 p.m. (1 year, 5 months ago)
I never did show you the full source code for the playlog page, so here you go! One day I'll comment it for you :D
from mod_python import apache, util
from PIL import Image
import eyeD3 as id3
import MySQLdb, time, cStringIO
def handler(req):
args = util.parse_qs(req.args or "")
if args.has_key("pic"):
return pic(req, args["pic"])
return main(req)
def main(req):
req.content_type = "text/html"
req.write("""
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>theY4Kman's Playlog</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>""")
db = MySQLdb.connect(host="localhost", user="root", passwd="fooledu", db="amarok")
crs = db.cursor()
crs.execute("""SELECT playlog.play_time, song_paths.song_path, song_paths.song_id
FROM playlog, song_paths
WHERE playlog.song_id = song_paths.song_id
ORDER BY playlog.play_time DESC
LIMIT 0,20""")
grey = False
res = crs.fetchone()
while res:
title = artist = album = "<none>"
year = ""
tag = id3.Tag()
try:
tag.link(res[1])
title = tag.getTitle()
artist = tag.getArtist()
album = tag.getAlbum()
year = tag.getYear()
except:
res = crs.fetchone()
continue
req.write("""
<div class="track %s">
<div class="basicinfo">
<div class="extendedinfo">
<br />
</div>
<em class="time">%s</em>
<div class="cover">
<img class="coverimg" src="music.py?pic=%s" />
</div>
<div class="trackinfo">
<strong>%s</strong>%s%s
</div>
</div>
</div>
"""
% ( ( grey != False and "bg1" or "bg2" ),
time.strftime( "%Z %I:%M%p %A, %B %d", time.localtime(res[0]) ),
res[2],
title,
artist != "" and ("<br /> by <strong>%s</strong>" % artist) or "",
album != "" and ("<br /> on <strong>%s</strong>" % album) or "" ) )
grey = not grey # Toggle between grey and white backgrounds.
res = crs.fetchone()
req.write("</none></body>n</html>")
return apache.OK
def pic(req, id):
req.content_type = "text/html"
db = MySQLdb.connect(host="localhost", user="root", passwd="fooledu", db="playlog")
crs = db.cursor()
crs.execute("SELECT song_path FROM songs WHERE song_id = %s LIMIT 1", id)
res = crs.fetchone()
if not res: return defaultpic(req)
tag = id3.Tag()
try:
tag.link(res[0])
imgs = tag.getImages()
if not tag or len(imgs) < 1: return defaultpic(req)
req.content_type = imgs[0].mimeType
im_str = cStringIO.StringIO(imgs[0].imageData)
im = Image.open(im_str)
if im.size[0] > 130:
im = im.resize( (130, 130), Image.ANTIALIAS )
im_str.close()
im_str = cStringIO.StringIO()
im.save(im_str, "JPEG")
req.write("%s" % im_str.getvalue())
im_str.close()
except:
return defaultpic(req)
return apache.OK
def defaultpic(req):
img = open("/home/they4kman/site/music/covers/__default.png", "rb")
if not img: return apache.OK
req.content_type = "image/png"
req.write(img.read())
img.close()
return apache.OK
Comments
Re: Playlog Displayer
Posted by queening on Wednesday, June 16, 2010 at 5:58 a.m. (1 month, 2 weeks ago)
Evening dresses
With more 1000 Designer dresses,we supply Evening Dresses,Custom Dresses,formal gowns,cocktail dresses with wholesale price
prom dresses
Dresses, evening, cocktail, prom dresses, formal gowns from dresseslife. Homecoming dresses and bridesmaid
Graduation Dresses
Looking For discount Balenciaga handbags? The store online sells the Balenciaga bags.
Welcome to visit and buy Balenciaga handbags. we offer Balenciaga Handbags,Balenciaga
Balenciaga Handbags
Balenciaga
Balenciaga sale
Re: Playlog Displayer
Posted by fiwedding on Thursday, June 10, 2010 at 5:56 a.m. (1 month, 2 weeks ago)
supply in stock and custom lace front wigs, full lace wigs, lace wigs, human hair wigs,
remy lace front wigs, cheap wigs, cheap, buy, celebrity
full lace wigs
lace wigs
lace wigs sale
lace front wigs
synthetic front lace wigs
A Famous Dresses Shop which sell directly Wedding Dresses, Evening Dress, Bridesmaid Dresses,Prom dresses
cheap wedding dresses
cheap evening dresses
cheap prom dresses
cheap evening dresses
cheap prom dresses
Elegant evening dresses are always associated with the brides and their bridesmaids.Shopping for evening dresses and your wedding dress in stylish bridal ..