Mercurial > hg > index.fcgi > www > www-1
diff pics2/pics_app.py @ 57:b7966ae653f2
pics2: add support for .webm files; add pics.fcgi and index.css
author | paulo |
---|---|
date | Tue, 14 Jan 2014 23:44:24 -0800 |
parents | 0249782e231e |
children | 6318de36e334 |
line diff
1.1 --- a/pics2/pics_app.py Tue Sep 10 01:04:24 2013 -0700 1.2 +++ b/pics2/pics_app.py Tue Jan 14 23:44:24 2014 -0800 1.3 @@ -45,11 +45,29 @@ 1.4 1.5 1.6 def _get_images(d): 1.7 + exts = [".jpg", ".webm"] 1.8 + 1.9 thumb_fns = glob.glob(os.path.join(d, "thumbs", "*.jpg")) 1.10 thumb_fns = sorted(thumb_fns, key=_numeric_pad_basename) 1.11 logging.debug("thumb_fns = %s" % thumb_fns) 1.12 1.13 - browse_fns = [os.path.join(d, "browse", os.path.basename(i)) for i in thumb_fns] 1.14 + browse_dir = os.path.join(d, "browse") 1.15 + browse_contents = set(os.listdir(browse_dir)) 1.16 + logging.debug("browse_contents = %s" % browse_contents) 1.17 + 1.18 + browse_fns = [] 1.19 + for i in thumb_fns: 1.20 + i_basename = os.path.splitext(os.path.basename(i))[0] 1.21 + try: 1.22 + for j in exts: 1.23 + browse_fn_basename = i_basename + j 1.24 + if browse_fn_basename in browse_contents: 1.25 + browse_fns.append(os.path.join(browse_dir, browse_fn_basename)) 1.26 + raise StopIteration 1.27 + except StopIteration: 1.28 + pass 1.29 + else: 1.30 + raise RuntimeError("Cannot find browse image for %s" % i) 1.31 logging.debug("browse_fns = %s" % browse_fns) 1.32 1.33 return zip(thumb_fns, browse_fns) 1.34 @@ -88,6 +106,16 @@ 1.35 1.36 body.text(' ') 1.37 1.38 + 1.39 + def _go_browse_image_html_body(self, body, img): 1.40 + browse_img_url = self._get_pics_url(img) 1.41 + 1.42 + ext = os.path.splitext(img)[1] 1.43 + if ext == ".webm": 1.44 + body.video(src=browse_img_url, autoplay="true", loop="true") 1.45 + else: 1.46 + body.img(src=browse_img_url) 1.47 + 1.48 1.49 def __init__(self, environ): 1.50 self._environ = environ 1.51 @@ -200,8 +228,7 @@ 1.52 1.53 html_header.script('', type="text/javascript", src=self._get_pics_url("np_keys.js")) 1.54 1.55 - browse_img_url = self._get_pics_url(img) 1.56 - html_body.p.img(src=browse_img_url) 1.57 + self._go_browse_image_html_body(html_body.p, img) 1.58 1.59 logging.debug("imgs_circ = %s" % imgs_circ) 1.60