if not url.startswith(self._base_url):
LOG.error('cannot convert {} to a relative URL of {}'.format(
url, self._base_url))
- return self._error(404)
+ return self._error(404, stream=stream)
if url == self._base_url:
return None
return url[len(self._base_url):]
LOG.debug('index page')
return self._directory(self._base_path, stream=stream)
- def _thumb(self, image, max_width=None, max_height=None):
+ def _thumb(self, image, max_width=None, max_height=None, stream=None):
if not _os_path.exists(self._cache_path):
_os.makedirs(self._cache_path)
dirname,filename = _os_path.split(image)
image_path = _os_path.join(self._base_path, image)
if not _os_path.isfile(image_path):
LOG.error('image path for thumbnail does not exist')
- return self._error(404)
+ return self._error(404, stream=stream)
if (not _os_path.isfile(thumb_path)
or _os_path.getmtime(image_path) > _os_path.getmtime(thumb_path)):
invoke(['convert', '-format', 'png', '-strip', '-quality', '95',
thumb_path])
return thumb_url
- def _mp4(self, video, *args):
+ def _mp4(self, video, stream=None):
if not video.endswith('.mov'):
LOG.error("can't translate {} to MPEGv4".format(video))
dirname,filename = _os_path.split(video)
mp4_path = _os_path.join(cache_dir, mp4_filename)
if not _os_path.isfile(video):
LOG.error('source video path does not exist')
- return self._error(404)
+ return self._error(404, stream=stream)
if (not _os_path.isfile(mp4_path)
or _os_path.getmtime(video) > _os_path.getmtime(mp4_path)):
arg = ['ffmpeg', '-i', video, '-acodec', 'libfaac', '-aq', '200',
invoke(arg)
return self._url(mp4_url)
- def _ogv(self, video, *args):
+ def _ogv(self, video, stream=None):
if not video.endswith('.mov'):
LOG.error("can't translate {} to Ogg Video".format(video))
dirname,filename = _os_path.split(video)
ogv_path = _os_path.join(cache_dir, ogv_filename)
if not _os_path.isfile(video):
LOG.error('source video path does not exist')
- return self._error(404)
+ return self._error(404, stream=stream)
if (not _os_path.isfile(ogv_path)
or _os_path.getmtime(video) > _os_path.getmtime(ogv_path)):
arg = ['ffmpeg2theora', '--optimize']
except IOError:
return None
- def _get_image_video(self, path, fallback=None):
+ def _get_image_video(self, path, fallback=None, stream=None):
base_path = image_base(path)
for extension in VIDEO_EXTENSIONS:
video_path = base_path + extension
if _os_path.isfile(video_path):
- return self._video(video_path, fallback=fallback)
+ return self._video(
+ video_path, fallback=fallback, stream=stream)
return None
- def _captioned_video(self, path, href=None):
- img = self._image(path, max_width=640, max_height=480)
+ def _captioned_video(self, path, href=None, stream=None):
+ img = self._image(path, max_width=640, max_height=480, stream=stream)
caption = self._get_image_caption(path)
- video = self._get_image_video(path, fallback=[img])
+ video = self._get_image_video(path, fallback=[img], stream=stream)
content = []
if video:
content.extend(video)
content.append('<p>{}</p>'.format(caption))
return content
- def _video(self, video, fallback=None, **kwargs):
+ def _video(self, video, fallback=None, stream=None, **kwargs):
if fallback is None:
fallback = [
'<p>Your browser does not support the <video> tag, try',
'</p>',
]
fallback = [' '+line for line in fallback]
- ogv = self._ogv(video)
- mp4 = self._mp4(video)
+ ogv = self._ogv(video, stream=stream)
+ mp4 = self._mp4(video, stream=stream)
return [
'<p>',
(' <video preloads="none" controls="controls" '
image = _random.choice(images)
LOG.debug('selected random image {}'.format(image))
page = self._image_page(image)
- content = self._captioned_video(path=image, href=page)
+ content = self._captioned_video(path=image, href=page, stream=stream)
self._response(content='\n'.join(content), stream=stream)
def is_cached(self, url):
except IOError, e:
LOG.error('invalid url')
LOG.error(e)
- self._error(404)
+ self._error(404, stream=stream)
if mime in ['video/ogg']:
self._response_stream(
header=header, content=content, stream=stream)
LOG.debug('HTML page')
if not url.endswith('/'):
LOG.error('HTML page URLs must end with a slash')
- self._error(404)
+ self._error(404, stream=stream)
abspath = _os_path.join(self._base_path, url)
if _os_path.isdir(abspath):
self._directory(path=abspath, page=page, stream=stream)
content.append('</ul>')
return content
- def _directory_images(self, path, images):
+ def _directory_images(self, path, images, stream=None):
content = ['<table style="margin-left: auto; margin-right: auto;">']
column = 0
for image in images:
page = self._image_page(image)
- img = self._image(image, max_width=300, max_height=300)
+ img = self._image(
+ image, max_width=300, max_height=300, stream=stream)
link = self._link(page, img)
if column == 0:
content.append(' <tr>')
LOG.error(
'page out of bounds for this gallery 0 <= {:d} < {:d}'.format(
page, pages))
- self._error(404)
+ self._error(404, stream=stream)
first_image = images_per_page * page
images = images[first_image:first_image+images_per_page]
content = []
nav = self._directory_page_navigation(path, page=page, pages=pages)
content.extend(nav)
content.extend(self._directory_subdirs(path))
- content.extend(self._directory_images(path, images=images))
+ content.extend(self._directory_images(
+ path, images=images, stream=stream))
content.extend(nav)
content.extend(self.footer)
self._response(content='\n'.join(content), stream=stream)
self._link(next_page, 'next'),
'</p>',
])
- content.extend(self._captioned_video(path))
+ content.extend(self._captioned_video(path, stream=stream))
content.append('</div>')
content.extend(self.footer)
self._response(content='\n'.join(content), stream=stream)