From a27a916a1fcb9f62a9f075d1316346ff2e6424b2 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Mon, 6 Aug 2018 17:05:33 +0200 Subject: 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. --- fbin/fbin.py | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) (limited to 'fbin/fbin.py') 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/') @app.route('/thumb/') 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') -- cgit v1.2.3