summaryrefslogtreecommitdiff
path: root/fbin/fbin.py
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2018-08-06 17:05:33 +0200
committerJon Bergli Heier <snakebite@jvnv.net>2018-08-06 17:09:04 +0200
commita27a916a1fcb9f62a9f075d1316346ff2e6424b2 (patch)
tree178704da15f77d8c038160cf18d6b2876744c23b /fbin/fbin.py
parente1e82a8c93b667ac9dd35a6dd34cb30e26545798 (diff)
Add video list and video thumbnails
Add a separate video page for listing uploaded videos. The thumbnail endpoint now supports generating video thumbnails using ffmpegthumbnailer.
Diffstat (limited to 'fbin/fbin.py')
-rwxr-xr-xfbin/fbin.py38
1 files changed, 29 insertions, 9 deletions
diff --git a/fbin/fbin.py b/fbin/fbin.py
index ffc6a5b..af35bdb 100755
--- a/fbin/fbin.py
+++ b/fbin/fbin.py
@@ -358,22 +358,42 @@ def images():
}
return render_template('images.html', **context)
+@app.route('/v')
+@app.route('/videos')
+@login_required
+def videos():
+ files = [f for f in get_files(current_user.user) if f.is_video()]
+ context = {
+ 'title': 'Videos',
+ 'fullwidth': True,
+ 'files': files,
+ 'total_size': db.File.pretty_size(sum(f.get_size() for f in files if f.exists)),
+ }
+ return render_template('images.html', **context)
+
@app.route('/t/<hash:hash>')
@app.route('/thumb/<hash:hash>')
def thumb(hash):
thumbfile = os.path.join(current_app.config['THUMB_DIRECTORY'], hash + '.jpg')
if not os.access(thumbfile, os.F_OK):
f = get_file(hash, update_accessed = False)
- try:
- im = Image.open(f.get_path())
- except IOError:
- # We can't generate a thumbnail for this file, just say it doesn't exist.
+ if f.is_image():
+ try:
+ im = Image.open(f.get_path())
+ except IOError:
+ # We can't generate a thumbnail for this file, just say it doesn't exist.
+ abort(404)
+ # Check for valid JPEG modes.
+ if im.mode not in ('1', 'L', 'RGB', 'RGBX', 'CMYK', 'YCbCr'):
+ im = im.convert('RGB')
+ im.thumbnail(current_app.config.get('THUMB_SIZE', (128, 128)), Image.ANTIALIAS)
+ im.save(thumbfile)
+ elif f.is_video():
+ p = subprocess.run(['ffmpegthumbnailer', '-i', f.get_path(), '-o', thumbfile])
+ if p.returncode != 0:
+ abort(404)
+ else:
abort(404)
- # Check for valid JPEG modes.
- if im.mode not in ('1', 'L', 'RGB', 'RGBX', 'CMYK', 'YCbCr'):
- im = im.convert('RGB')
- im.thumbnail(current_app.config.get('THUMB_SIZE', (128, 128)), Image.ANTIALIAS)
- im.save(thumbfile)
return send_file(thumbfile)
@app.route('/h')