From eb33711ff87f9af1dcf459238ea78e08c82d2683 Mon Sep 17 00:00:00 2001 From: Mike Lang Date: Sun, 19 May 2019 01:18:24 -0700 Subject: [PATCH] restreamer: Hack in a path to re-stream "last 20 seconds", for live 'replays' --- restreamer/restreamer/main.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/restreamer/restreamer/main.py b/restreamer/restreamer/main.py index 18b70c3..7e3559f 100644 --- a/restreamer/restreamer/main.py +++ b/restreamer/restreamer/main.py @@ -225,6 +225,27 @@ def generate_media_playlist(stream, variant): return generate_hls.generate_media(segments, os.path.join(app.static_url_path, stream, variant)) +@app.route('/replay//.m3u8') +@has_path_args +def replay(stream, variant): + hours_path = os.path.join(app.static_folder, stream, variant) + if not os.path.isdir(hours_path): + abort(404) + + start = datetime.datetime.utcnow() - datetime.timedelta(seconds=20) + end = datetime.datetime.utcnow() - datetime.timedelta(seconds=5) + + segments = get_best_segments(hours_path, start, end) + if segments == [None]: + print "No replay, serving placeholder" + stream, variant = 'ekimekim', 'source' + segments = get_best_segments(os.path.join(app.static_folder, stream, variant), + datetime.datetime(2019, 5, 14, 9, 58, 46), + datetime.datetime(2019, 5, 14, 9, 58, 48), + ) + return generate_hls.generate_media(segments, os.path.join(app.static_url_path, stream, variant)) + + @app.route('/cut//.ts') @stats @has_path_args