# HG changeset patch # User paulo # Date 1389771864 28800 # Node ID b7966ae653f247da0c459b5dd910dce342bfe515 # Parent 0249782e231e5d292b0d0f6fd2b4bd6196ebc779 pics2: add support for .webm files; add pics.fcgi and index.css diff -r 0249782e231e -r b7966ae653f2 pics2/index.css --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pics2/index.css Tue Jan 14 23:44:24 2014 -0800 @@ -0,0 +1,20 @@ +@import "/index.css"; + +img +{ + border-width: 0px; +} + +img.sel +{ + padding: 2px; + border-width: 4px; + border-style: solid; +} + +img.sel2 +{ + padding: 2px; + border-width: 2px; + border-style: dashed; +} diff -r 0249782e231e -r b7966ae653f2 pics2/pics.fcgi --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pics2/pics.fcgi Tue Jan 14 23:44:24 2014 -0800 @@ -0,0 +1,9 @@ +#!/usr/bin/env python + +from flup.server.fcgi import WSGIServer +#from flup.server.fcgi_single import WSGIServer + +import pics_app + + +WSGIServer(pics_app.app).run() diff -r 0249782e231e -r b7966ae653f2 pics2/pics_app.py --- a/pics2/pics_app.py Tue Sep 10 01:04:24 2013 -0700 +++ b/pics2/pics_app.py Tue Jan 14 23:44:24 2014 -0800 @@ -45,11 +45,29 @@ def _get_images(d): + exts = [".jpg", ".webm"] + thumb_fns = glob.glob(os.path.join(d, "thumbs", "*.jpg")) thumb_fns = sorted(thumb_fns, key=_numeric_pad_basename) logging.debug("thumb_fns = %s" % thumb_fns) - browse_fns = [os.path.join(d, "browse", os.path.basename(i)) for i in thumb_fns] + browse_dir = os.path.join(d, "browse") + browse_contents = set(os.listdir(browse_dir)) + logging.debug("browse_contents = %s" % browse_contents) + + browse_fns = [] + for i in thumb_fns: + i_basename = os.path.splitext(os.path.basename(i))[0] + try: + for j in exts: + browse_fn_basename = i_basename + j + if browse_fn_basename in browse_contents: + browse_fns.append(os.path.join(browse_dir, browse_fn_basename)) + raise StopIteration + except StopIteration: + pass + else: + raise RuntimeError("Cannot find browse image for %s" % i) logging.debug("browse_fns = %s" % browse_fns) return zip(thumb_fns, browse_fns) @@ -88,6 +106,16 @@ body.text(' ') + + def _go_browse_image_html_body(self, body, img): + browse_img_url = self._get_pics_url(img) + + ext = os.path.splitext(img)[1] + if ext == ".webm": + body.video(src=browse_img_url, autoplay="true", loop="true") + else: + body.img(src=browse_img_url) + def __init__(self, environ): self._environ = environ @@ -200,8 +228,7 @@ html_header.script('', type="text/javascript", src=self._get_pics_url("np_keys.js")) - browse_img_url = self._get_pics_url(img) - html_body.p.img(src=browse_img_url) + self._go_browse_image_html_body(html_body.p, img) logging.debug("imgs_circ = %s" % imgs_circ) diff -r 0249782e231e -r b7966ae653f2 pics2/pics_test_server.py --- a/pics2/pics_test_server.py Tue Sep 10 01:04:24 2013 -0700 +++ b/pics2/pics_test_server.py Tue Jan 14 23:44:24 2014 -0800 @@ -13,13 +13,19 @@ server.stop() +MIMETYPE = { + ".webm": "video/webm", +} + + class FileServerRoot: def default(self, *args): if len(args) == 0: raise cherrypy.HTTPError(404) filepath = os.path.abspath(os.path.join(*args)) - return cherrypy.lib.static.serve_file(filepath) + ext = os.path.splitext(filepath)[1] + return cherrypy.lib.static.serve_file(filepath, content_type=MIMETYPE.get(ext)) default.exposed = True