From c53af71e990339b920008fd39a58dd2fa1839cee Mon Sep 17 00:00:00 2001 From: HeNine <> Date: Mon, 18 Oct 2021 12:24:29 +0200 Subject: [PATCH] Tagging API --- professor-api/professor_api/professor_api.py | 23 +++++++++- professor/constants.less | 2 + professor/professor.html | 44 ++++++++++++++++++++ professor/script.js | 34 +++++++++++++++ professor/style.less | 6 +++ 5 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 professor/constants.less create mode 100644 professor/professor.html create mode 100644 professor/script.js create mode 100644 professor/style.less diff --git a/professor-api/professor_api/professor_api.py b/professor-api/professor_api/professor_api.py index e7cc032..0176ea1 100644 --- a/professor-api/professor_api/professor_api.py +++ b/professor-api/professor_api/professor_api.py @@ -1,8 +1,9 @@ import re +import urllib.parse import flask from common import database -from flask import jsonify, request +from flask import jsonify, request, copy_current_request_context from psycopg2.extras import execute_values app = flask.Flask('buscribe') @@ -22,6 +23,26 @@ def get_line(line_id): "line_data": line.transcription_json} +@app.route('/professor/line//playlist.m3u8', methods=["GET"]) +def get_playlist(line_id): + db_conn = app.db_manager.get_conn() + + line = database.query(db_conn, "SELECT * FROM buscribe_transcriptions WHERE id = %(id)s;", id=line_id).fetchone() + + if line is None: + return "Line not found.", 404 + else: + start_time_iso = line.start_time.isoformat() + end_time_iso = line.end_time.isoformat() + duration = line.end_time - line.start_time + return f"""#EXTM3U +#EXT-X-TARGETDURATION:{duration.total_seconds()} +#EXT-X-PROGRAM-DATE-TIME:{start_time_iso} +#EXTINF:{duration.total_seconds()} +//localhost/cut/desertbus/source.ts?start={urllib.parse.quote_plus(start_time_iso)}&end={urllib.parse.quote_plus(end_time_iso)}&type=rough&allow_holes=true +#EXT-X-ENDLIST""" + + @app.route('/professor/line/', methods=["POST"]) def update_line(line_id): db_conn = app.db_manager.get_conn() diff --git a/professor/constants.less b/professor/constants.less new file mode 100644 index 0000000..ff0edd1 --- /dev/null +++ b/professor/constants.less @@ -0,0 +1,2 @@ +@sans-serif: Tahoma, sans-serif; +@serif: Georgia, Garamond, serif; \ No newline at end of file diff --git a/professor/professor.html b/professor/professor.html new file mode 100644 index 0000000..814f4d7 --- /dev/null +++ b/professor/professor.html @@ -0,0 +1,44 @@ + + + + + Buscribe -- Professor + + + + + + + + + + + + + + +
+ +
+ +
+ +
+ +
+

+
+ + + + + \ No newline at end of file diff --git a/professor/script.js b/professor/script.js new file mode 100644 index 0000000..7e48022 --- /dev/null +++ b/professor/script.js @@ -0,0 +1,34 @@ +function pageReady() { + + const params = new URLSearchParams(document.location.search.substring(1)); + line_id = parseInt(params.get("line"), 10); + + videojs("player", { + // src: "test.m3u8", + controls: true, + autoplay: false, + width: 900, + height: 420, + playbackRates: [0.5, 1, 1.25, 1.5, 2], + inactivityTimeout: 0, + controlBar: { + fullscreenToggle: true, + volumePanel: { + inline: false, + }, + } + }, + function () { + this.src({src: `//localhost:8005/professor/line/${line_id}/playlist.m3u8`}); + }); + + fetch(`//localhost:8005/professor/line/${line_id}`) + .then(response => response.json()) + .then(fillLineInfo) + +} + +function fillLineInfo(line_json) { + document.getElementById("original_transcription").innerText = line_json.line_data.text + +} \ No newline at end of file diff --git a/professor/style.less b/professor/style.less new file mode 100644 index 0000000..c6da1bc --- /dev/null +++ b/professor/style.less @@ -0,0 +1,6 @@ +body { + color: aliceblue; + background: dimgray; + + max-width: 900px; +}