Skip to content

Commit

Permalink
Add initial route to serve video player
Browse files Browse the repository at this point in the history
  • Loading branch information
robertknight committed May 1, 2023
1 parent 344644d commit dcbeb35
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 0 deletions.
41 changes: 41 additions & 0 deletions tests/unit/via/views/view_video_test.py
Original file line number Diff line number Diff line change
@@ -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
24 changes: 24 additions & 0 deletions via/templates/video_player.html.jinja2
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" href="favicon.ico" type="image/x-icon" />
<title>Hypothesis Video Player</title>
</head>
<body>
<div id="app"></div>
<script type="application/json" class="js-config">
{
"client_config": {{ client_config | tojson }},
"client_src": "{{ client_embed_url }}",
"video_id": "{{ video_id }}",
"transcript": {{ transcript | tojson }}
}
</script>

{% for url in asset_urls("video_player_js") %}
<script type="module" src="{{ url }}"></script>
{% endfor %}
</body>
</html>
1 change: 1 addition & 0 deletions via/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
31 changes: 31 additions & 0 deletions via/views/view_video.py
Original file line number Diff line number Diff line change
@@ -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,
}

0 comments on commit dcbeb35

Please sign in to comment.