-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add initial route to serve video player
- Loading branch information
1 parent
344644d
commit dcbeb35
Showing
4 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} |