From 988f8cfc74446e7aa58f6e0ce916110e9ed23ca8 Mon Sep 17 00:00:00 2001 From: Yves Fischer Date: Thu, 31 Dec 2015 17:35:15 +0100 Subject: video thumbnails --- mediabrowser/__init__.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'mediabrowser/__init__.py') diff --git a/mediabrowser/__init__.py b/mediabrowser/__init__.py index 6927205..8766ac2 100644 --- a/mediabrowser/__init__.py +++ b/mediabrowser/__init__.py @@ -70,7 +70,7 @@ def build(root_directory, cache): '.webm': 'video/webm', '.flv': 'video/x-flv', '.mp4': 'video/mp4', - '.mpg': 'video/mp2t'} + '.mpg': 'video/MP2T'} (filetype, encoding) = mimetypes.guess_type(path) if filetype is None: @@ -145,6 +145,20 @@ def build(root_directory, cache): r.last_modified = mtime return r + @blueprint.route('//thumbnail_video') + def thumbnail_video(path): + path = os.path.normpath(path) + ospath = os.path.join(root_directory, path) + client_mtime = request.if_modified_since + mtime = datetime.fromtimestamp(os.stat(ospath).st_mtime) + if client_mtime is not None and mtime <= client_mtime: + return Response(status=304) + else: + thumbnail_stream = ffmpeg.thumbnail_video(ospath, 90, 50) + r = Response(thumbnail_stream, mimetype="video/webm") + r.last_modified = mtime + return r + @blueprint.route('//download/inline') def download_inline(path): return download(path, inline=True) -- cgit v1.2.1