diff --git a/README.md b/README.md index 1da4a71..b3b96cf 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ You can get video url for the Xblock directly from your browser's address bar. ![Wistia video URL](doc/img/wistia_video_url.png) -For better students experience make sure all player controls are enabled and video captions are uploaded. +For better students experience make sure all player controls are enabled, video captions, and video transcripts are uploaded. ![Wistia customize video](doc/img/wistia_customize_video.png) diff --git a/doc/img/wistia_video_edit.png b/doc/img/wistia_video_edit.png index 37c4a90..1d8564c 100644 Binary files a/doc/img/wistia_video_edit.png and b/doc/img/wistia_video_edit.png differ diff --git a/setup.py b/setup.py index a058f20..70062f7 100644 --- a/setup.py +++ b/setup.py @@ -22,7 +22,7 @@ def package_data(pkg, roots): setup( name='wistiavideo-xblock', - version='0.5', + version='1.0.0', description='wistiavideo XBlock', # TODO: write a better description. license='GPL v3', packages=[ diff --git a/wistiavideo/static/html/wistiavideo.html b/wistiavideo/static/html/wistiavideo.html index 2b6589a..a6360cd 100644 --- a/wistiavideo/static/html/wistiavideo.html +++ b/wistiavideo/static/html/wistiavideo.html @@ -7,7 +7,7 @@

- - + {% if show_captions_download %}{% endif %} + {% if show_transcripts_download %}{% endif %}

diff --git a/wistiavideo/tests/test_xblock.py b/wistiavideo/tests/test_xblock.py index 950b6b9..91d7882 100644 --- a/wistiavideo/tests/test_xblock.py +++ b/wistiavideo/tests/test_xblock.py @@ -1,4 +1,3 @@ -import json import unittest from mock import Mock, patch @@ -35,23 +34,31 @@ def test_student_view(self): student_view_html = xblock.student_view() self.assertIn(xblock.media_id, student_view_html.body_html()) + class WistiaXblockTranscriptsDownloadTests(WistiaXblockBaseTests, unittest.TestCase): - def __render_html(self): - xblock = self.make_xblock() + def __render_html(self, **kwargs): + xblock = self.make_xblock(**kwargs) return xblock.student_view().body_html() - def test_transcripts_block_exists(self): - self.assertIn("wistia_responsive_download_buttons", self.__render_html()) - def test_download_buttons_exist(self): - self.assertIn("wistia_captions_download", self.__render_html()) - self.assertIn("wistia_transcripts_download", self.__render_html()) + self.assertIn("wistia_captions_download", self.__render_html(show_captions_download=True)) + self.assertIn("wistia_transcripts_download", self.__render_html(show_transcripts_download=True)) + + def test_no_captions_download_button(self): + self.assertNotIn("wistia_captions_download", self.__render_html(show_captions_download=False)) + + def test_no_transcripts_download_button(self): + self.assertNotIn("wistia_transcripts_download", self.__render_html(show_transcripts_download=False)) def test_access_token_not_set(self): media_id = "12345abcde" href = "https://example.wistia.com/medias/{}".format(media_id) - xblock = self.make_xblock(href=href) + xblock = self.make_xblock( + href=href, + show_captions_download=True, + show_transcripts_download=True, + ) rendered_html = xblock.student_view().body_html() self.assertFalse(xblock.has_access_token) @@ -64,7 +71,12 @@ def test_access_token_set(self): media_id = "12345abcde" href = "https://example.wistia.com/medias/{}".format(media_id) - xblock = self.make_xblock(href=href, access_token="token") + xblock = self.make_xblock( + href=href, + access_token="token", + show_captions_download=True, + show_transcripts_download=True, + ) rendered_html = xblock.student_view().body_html() self.assertTrue(xblock.has_access_token) @@ -89,7 +101,9 @@ def test_send_request(self, mock_requests): xblock = self.make_xblock( href=href, - access_token=expected_token + access_token=expected_token, + show_captions_download=True, + show_transcripts_download=True, ) response = xblock.download_captions(Mock()) @@ -107,6 +121,7 @@ def test_send_request(self, mock_requests): params={"access_token": expected_token} ) + class WistiaXblockValidationTests(WistiaXblockBaseTests, unittest.TestCase): def test_validate_correct_inputs(self): xblock = self.make_xblock() @@ -124,7 +139,7 @@ def test_validate_correct_inputs(self): self.assertFalse(validation.add.called) @patch('xblock.validation.ValidationMessage') - def test_validate_incorrect_inputs(self, ValidationMessage): + def test_validate_incorrect_inputs(self, _): xblock = self.make_xblock() data = Mock(href='http://youtube.com/watch?v=something') diff --git a/wistiavideo/wistiavideo.py b/wistiavideo/wistiavideo.py index ab5ac9f..6c66633 100644 --- a/wistiavideo/wistiavideo.py +++ b/wistiavideo/wistiavideo.py @@ -15,7 +15,7 @@ from pathlib import Path from xblock.core import XBlock -from xblock.fields import Scope, String +from xblock.fields import Scope, String, Boolean from xblock.fragment import Fragment from xblock.validation import ValidationMessage @@ -31,13 +31,15 @@ VIDEO_URL_RE = re.compile(r'https?:\/\/(.+)?(wistia.com|wi.st)\/(medias|embed)\/.*') -class CaptionDownloadMixin: +class AssetsDownloadMixin: """ - Mixin providing utility functions and handler to download captions from Wistia. - + Mixin providing utility functions and handler to download captions and transcripts from Wistia. + The utility mixin is heavily depending on the media ID property provided by the XBlock. """ + __slots__ = ("media_id",) + access_token = String( default='', display_name=_('Wistia API key'), @@ -45,7 +47,25 @@ class CaptionDownloadMixin: scope=Scope.content, ) - caption_download_editable_fields = ('access_token',) + show_captions_download = Boolean( + default=False, + display_name=_('Captions download button visible'), + help=_('Show download captions button.'), + scope=Scope.content, + ) + + show_transcripts_download = Boolean( + default=True, + display_name=_('Transcripts download button visible'), + help=_('Show download transcripts button.'), + scope=Scope.content, + ) + + asset_download_editable_fields = ( + 'access_token', + 'show_captions_download', + 'show_transcripts_download', + ) def __send_request(self, url): """ @@ -125,7 +145,7 @@ def download_captions(self, request, suffix=""): ) -class WistiaVideoXBlock(StudioEditableXBlockMixin, CaptionDownloadMixin, XBlock): +class WistiaVideoXBlock(StudioEditableXBlockMixin, AssetsDownloadMixin, XBlock): display_name = String( default='Wistia video', @@ -142,7 +162,7 @@ class WistiaVideoXBlock(StudioEditableXBlockMixin, CaptionDownloadMixin, XBlock) ) editable_fields = ('display_name', 'href') - editable_fields += CaptionDownloadMixin.caption_download_editable_fields + editable_fields += AssetsDownloadMixin.asset_download_editable_fields @property def media_id(self): @@ -175,8 +195,10 @@ def student_view(self, context=None): context = { "download_captions_text": _("Download captions"), "download_transcripts_text": _("Download transcript"), - "media_id": self.media_id, "has_access_token": self.has_access_token, + "media_id": self.media_id, + "show_captions_download": self.show_captions_download, + "show_transcripts_download": self.show_transcripts_download, } frag = Fragment(loader.render_template('static/html/wistiavideo.html', context))