neddit

the frontend of the frontpage of the internet  https://neddit.ce9e.org
git clone https://git.ce9e.org/neddit.git

commit
6324c56c2ef5186d1060288ec65366386ccc53b4
parent
7f7e53c041558406f2efbdb51a1283a875406265
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2020-11-26 20:43
optimize video sources

Diffstat

M neddit.py 6 ++++++
M static/video.js 6 +++++-
M templates/_post.html 3 ++-

3 files changed, 13 insertions, 2 deletions


diff --git a/neddit.py b/neddit.py

@@ -1,3 +1,4 @@
   -1     1 import re
    1     2 import functools
    2     3 from datetime import datetime
    3     4 
@@ -48,6 +49,11 @@ def normalize_link(value):
   48    49 env.filters['link'] = normalize_link
   49    50 
   50    51 
   -1    52 def dash_resize(url):
   -1    53 	return re.sub('DASH_[0-9]*', 'DASH_240', url)
   -1    54 env.filters['dash_resize'] = dash_resize
   -1    55 
   -1    56 
   51    57 def fetch(url, **params):
   52    58 	app.logger.debug('fetch %s' % url)
   53    59 	r = requests.get(

diff --git a/static/video.js b/static/video.js

@@ -26,7 +26,11 @@
   26    26 	}, 100), {passive: true});
   27    27 
   28    28 	document.querySelectorAll('video').forEach(function(video) {
   29    -1 		var url = video.querySelectorAll('source')[3].src;
   -1    29 		if (video.canPlayType('audio/mpegurl') || video.canPlayType('application/dash+xml')) {
   -1    30 			return;
   -1    31 		}
   -1    32 
   -1    33 		var url = video.querySelectorAll('source')[4].src;
   30    34 		var audio = document.createElement('audio');
   31    35 		audio.src = url.replace('DASH_96', 'DASH_audio');
   32    36 		audio.preload = 'none';

diff --git a/templates/_post.html b/templates/_post.html

@@ -12,8 +12,9 @@
   12    12 	{% endif %}
   13    13 	{% if post.data.post_hint == 'hosted:video' %}
   14    14 		<video class="poster" controls muted loop preload="none" poster="{{ post.data.thumbnail }}">
   15    -1 			<source src="{{ post.data.media.reddit_video.hls_url }}">
   16    15 			<source src="{{ post.data.media.reddit_video.dash_url }}">
   -1    16 			<source src="{{ post.data.media.reddit_video.hls_url }}">
   -1    17 			<source src="{{ post.data.media.reddit_video.fallback_url|dash_resize }}" type="video/mp4">
   17    18 			<source src="{{ post.data.media.reddit_video.fallback_url }}" type="video/mp4">
   18    19 			<source src="{{ post.data.media.reddit_video.scrubber_media_url }}" type="video/mp4">
   19    20 		</video>