diff --git a/tests/unit/via/views/view_video_test.py b/tests/unit/via/views/view_video_test.py new file mode 100644 index 00000000..03cdfc06 --- /dev/null +++ b/tests/unit/via/views/view_video_test.py @@ -0,0 +1,41 @@ +from unittest.mock import sentinel + +import pytest + +from via.views.view_video import view_video + + +class TestViewVideo: + def test_it(self, pyramid_request, Configuration): + pyramid_request.matchdict["id"] = "abcdef" + + response = view_video({}, pyramid_request) + + assert response["client_embed_url"] == "http://hypothes.is/embed.js" + assert ( + response["client_config"] + == Configuration.extract_from_params.return_value[1] + ) + assert response["transcript"] == { + "segments": [ + { + "time": 0, + "text": "First segment of transcript", + }, + { + "time": 30, + "text": "Second segment of transcript", + }, + ], + } + assert response["video_id"] == "abcdef" + + @pytest.fixture + def Configuration(self, patch): + Configuration = patch("via.views.view_video.Configuration") + Configuration.extract_from_params.return_value = ( + sentinel.via_config, + sentinel.h_config, + ) + + return Configuration diff --git a/via/templates/video_player.html.jinja2 b/via/templates/video_player.html.jinja2 new file mode 100644 index 00000000..599dae18 --- /dev/null +++ b/via/templates/video_player.html.jinja2 @@ -0,0 +1,24 @@ + + + + + + + Hypothesis Video Player + + +
+ + + {% for url in asset_urls("video_player_js") %} + + {% endfor %} + + diff --git a/via/views/__init__.py b/via/views/__init__.py index 6df4b81b..470d4e55 100644 --- a/via/views/__init__.py +++ b/via/views/__init__.py @@ -9,6 +9,7 @@ def add_routes(config): # pragma: no cover config.add_route("index", "/", factory=QueryURLResource) config.add_route("get_status", "/_status") config.add_route("view_pdf", "/pdf", factory=QueryURLResource) + config.add_route("view_video", "/video/{id}") config.add_route("route_by_content", "/route", factory=QueryURLResource) config.add_route("debug_headers", "/debug/headers") config.add_route( diff --git a/via/views/view_video.py b/via/views/view_video.py new file mode 100644 index 00000000..13112370 --- /dev/null +++ b/via/views/view_video.py @@ -0,0 +1,31 @@ +from h_vialib import Configuration +from pyramid.view import view_config + + +@view_config( + renderer="via:templates/video_player.html.jinja2", + route_name="view_video", +) +def view_video(context, request): + _, h_config = Configuration.extract_from_params(request.params) + + video_id = request.matchdict["id"] + transcript = { + "segments": [ + { + "time": 0, + "text": "First segment of transcript", + }, + { + "time": 30, + "text": "Second segment of transcript", + }, + ], + } + + return { + "client_embed_url": request.registry.settings["client_embed_url"], + "client_config": h_config, + "transcript": transcript, + "video_id": video_id, + }