diff options
author | Jon Bergli Heier <snakebite@jvnv.net> | 2018-08-06 17:05:33 +0200 |
---|---|---|
committer | Jon Bergli Heier <snakebite@jvnv.net> | 2018-08-06 17:09:04 +0200 |
commit | a27a916a1fcb9f62a9f075d1316346ff2e6424b2 (patch) | |
tree | 178704da15f77d8c038160cf18d6b2876744c23b | |
parent | e1e82a8c93b667ac9dd35a6dd34cb30e26545798 (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.
-rw-r--r-- | fbin/db.py | 3 | ||||
-rwxr-xr-x | fbin/fbin.py | 38 | ||||
-rw-r--r-- | fbin/templates/base.html | 1 | ||||
-rw-r--r-- | fbin/templates/images.html | 4 |
4 files changed, 35 insertions, 11 deletions
@@ -98,6 +98,9 @@ class File(Base): def is_image(self): return self.get_mime_type().startswith('image') + def is_video(self): + return self.get_mime_type().startswith('video') + @property def ext(self): return os.path.splitext(self.filename)[1] 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') diff --git a/fbin/templates/base.html b/fbin/templates/base.html index dfd6d06..beb1e17 100644 --- a/fbin/templates/base.html +++ b/fbin/templates/base.html @@ -28,6 +28,7 @@ {% if current_user.is_authenticated %} {{ nav_html('.files', 'Files') }} {{ nav_html('.images', 'Images') }} + {{ nav_html('.videos', 'Videos') }} {{ nav_html('.account', 'Account') }} {{ nav_html('.api', 'API') }} {{ nav_html('.logout', 'Logout') }} diff --git a/fbin/templates/images.html b/fbin/templates/images.html index c4bfd8f..e6c1ad0 100644 --- a/fbin/templates/images.html +++ b/fbin/templates/images.html @@ -1,7 +1,7 @@ {% extends "base.html" %} {% block content %} -<p>You have {{ files|length() }} uploaded images totaling {{ total_size }}.</p> {% if files %} +<p>You have {{ files|length() }} uploaded {{ title|lower }} totaling {{ total_size }}.</p> <div class="row"> {% for file in files %} <div class="image-thumbnail"> @@ -13,7 +13,7 @@ {% endfor %} </div> {% else %} -<div><em>(No image uploads yet.)</em></div> +<div><em>(No {{ title|lower }} uploaded yet.)</em></div> {% endif %} {% endblock %} {% block scripts %} |