-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ability for direct 3PlayMedia transcripts usage #251
Add ability for direct 3PlayMedia transcripts usage #251
Conversation
Codecov Report
@@ Coverage Diff @@
## dev #251 +/- ##
=========================================
+ Coverage 84.12% 84.9% +0.77%
=========================================
Files 41 41
Lines 2381 2530 +149
Branches 26 26
=========================================
+ Hits 2003 2148 +145
- Misses 377 381 +4
Partials 1 1
Continue to review full report at Codecov.
|
c4df361
to
a5dfde0
Compare
a5dfde0
to
d7dbcea
Compare
f605f23
to
be8f77e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good in general, few issues need to be addressed before a merge.
video_xblock/backends/base.py
Outdated
@@ -132,8 +132,8 @@ def advanced_fields(self): | |||
""" | |||
return [ | |||
'start_time', 'end_time', 'handout', 'transcripts', | |||
'threeplaymedia_file_id', 'threeplaymedia_apikey', 'download_transcript_allowed', | |||
'default_transcripts', 'download_video_allowed', 'download_video_url' | |||
'threeplaymedia_file_id', 'threeplaymedia_apikey', 'direct_enabled', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
direct_enabled
-> threeplaymedia_streaming
or threeplaymedia_direct_enabled
video_xblock/mixins.py
Outdated
@@ -58,6 +56,31 @@ class TranscriptsMixin(XBlock): | |||
TranscriptsMixin class to encapsulate transcripts-related logic. | |||
""" | |||
|
|||
THREE_PLAY_MEDIA_API_DOMAIN = 'https://static.3playmedia.com/' | |||
|
|||
direct_enabled = Boolean( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
direct_enabled
-> threeplaymedia_streaming
or threeplaymedia_direct_enabled
video_xblock/mixins.py
Outdated
direct_enabled = Boolean( | ||
default=False, | ||
display_name=_('Direct 3PlayMedia'), | ||
scope=Scope.settings, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Scope.content
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. But what if we would like to use 3PM streaming only in one course Unit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fields are scoped to a single xblock instance. So no problem here.
video_xblock/mixins.py
Outdated
tran['url'] = self.runtime.handler_url( | ||
self, 'srt_to_vtt', query=tran['url'] | ||
self, 'fetch_from_tree_play_media', query="{}={}".format(tran['lang_id'], tran['id']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tree -> three
video_xblock/mixins.py
Outdated
) | ||
else: | ||
if not tran['url'].endswith('.vtt'): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
else if -> elif
video_xblock/video_xblock.py
Outdated
transcripts = json.loads(self.transcripts) if self.transcripts else [] | ||
|
||
for transcript in transcripts: | ||
yield transcript |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This for loop looks useless.
Why don't just return transcripts
?
|
||
|
||
Transcript = namedtuple('Transcript', [ | ||
'id', 'label', 'lang', 'lang_id', 'content', 'format', 'video_id', 'source', 'url' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice :)
video_xblock/mixins.py
Outdated
@@ -369,7 +501,7 @@ def player_state(self): | |||
""" | |||
Return video player state as a dictionary. | |||
""" | |||
transcripts = json.loads(self.transcripts) if self.transcripts else [] | |||
transcripts = list(self.get_enabled_transcripts()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking few lines below, this conversion to a list seems redundant.
'use strict'; | ||
var isValid = []; | ||
var $visibleLangChoiceItems = $langChoiceItem.find('li:visible'); | ||
var urls; | ||
e.preventDefault(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@@ -53,12 +53,11 @@ function getTranscriptUrl(transcriptsArray, langCode) { | |||
/** | |||
* Validate transcript data before save it to video xblock. | |||
*/ | |||
function validateTranscripts(e, $langChoiceItem) { | |||
function validateTranscripts($langChoiceItem) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
24ad935
to
2750ed8
Compare
2750ed8
to
2488f40
Compare
1ed0f96
to
a37020d
Compare
video_xblock/mixins.py
Outdated
|
||
def get_available_3pm_transcripts(self, file_id, apikey): | ||
""" | ||
Make API request to fetch list of available transcripts for given file ID. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add difference of return types of API in documentation
video_xblock/mixins.py
Outdated
results = response.json() | ||
else: | ||
results = {"failed": True} | ||
return results |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Proposal: return response.json(), status
video_xblock/mixins.py
Outdated
raise StopIteration | ||
for transcript_data in results: | ||
transcript = self.fetch_3pm_translation(transcript_data) | ||
transcript_ordered_dict = transcript._asdict() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Please add test for empty transcript
- Think if we need to show this error to user.
video_xblock/mixins.py
Outdated
for transcript_data in results: | ||
transcript = self.fetch_3pm_translation(transcript_data) | ||
transcript_ordered_dict = transcript._asdict() | ||
transcript_ordered_dict['content'] = '' # we don't want to parse it to JSON |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extend comment.
content = requests.get(external_api_url).text | ||
except Exception: # pylint: disable=broad-except | ||
log.exception(_("Transcript fetching failure: language [{}]").format(TPMApiLanguage(lang_id))) | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please think about consistency in corner cases. Here you do return, but in def init(self, language_id): you do raise.
video_xblock/mixins.py
Outdated
Returns: | ||
webob.Response: WebVTT transcripts wrapped in Response object. | ||
""" | ||
lang_id, tid = request.query_string.split('=') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is tid, please use better naming.
video_xblock/mixins.py
Outdated
|
||
results = self.get_available_3pm_transcripts(file_id, api_key) | ||
|
||
is_valid = False if isinstance(results, dict) else True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix it!
data: JSON.stringify(data) | ||
}; | ||
|
||
if (!(data.api_key && data.file_id)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add docstring and comment
options | ||
) | ||
.done(function(response) { | ||
message = response.message; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why you need message?
*/ | ||
function getThreePlayMediaConfig() { | ||
var $apiKey = $('.threeplaymedia-api-key', element).val(); | ||
var $fileId = $('#xb-field-edit-threeplaymedia_file_id', element).val(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not think you need $ here.
d4f3283
to
c0fbacd
Compare
1662d86
to
17316cf
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good in general.
I have only a few concerns here.
video_xblock/constants.py
Outdated
|
||
DEFAULT_LANG = 'en' | ||
|
||
# STATUS - (instance of namedtuple) - may be used like: "STATUS.success", returns status string value. | ||
STATUS = namedtuple('STATUS', ['success', 'error', 'warning'])._make(['success', 'error', 'warning']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You actually need an enum
here, not a namedtuple
.
See here
video_xblock/mixins.py
Outdated
) | ||
} | ||
except Exception: # pylint: disable=broad-except |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, narrow down exception catching.
video_xblock/mixins.py
Outdated
@XBlock.handler | ||
def validate_three_play_media_config(self, request, _suffix=''): | ||
""" | ||
Handler to validate actuality of provided API credentials. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Handler to validate provided API credentials.
video_xblock/mixins.py
Outdated
""" | ||
api_key = request.json.get('api_key') | ||
file_id = request.json.get('file_id') | ||
streaming_enabled = bool(int(request.json.get('streaming_enabled'))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a docstring saying what values do you expect to receive here.
E.g. # streaming_enabled is expected to be 1 or 0
# Act | ||
normalized_transcripts = normalize_transcripts(test_transcripts) | ||
# Assert | ||
self.assertEqual(test_transcripts, normalized_transcripts) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So essentially, you are checking, that normalization did nothing with the input data.
I think you need to add few more cases. Or change test name to better reflect your intent.
…nscripts-settings-accordion' and 'feature/transcripts-settings-accordion' of github.com:raccoongang/xblock-video into feature/transcripts-settings-accordion * 'feature/transcripts-settings-accordion' of github.com:raccoongang/xblock-video: Add ability for direct 3PlayMedia transcripts usage (#251) * 'feature/transcripts-settings-accordion' of github.com:raccoongang/xblock-video: Add ability for direct 3PlayMedia transcripts usage (#251) * 'feature/transcripts-settings-accordion' of github.com:raccoongang/xblock-video: Add ability for direct 3PlayMedia transcripts usage (#251)
General implementation of direct (streaming) transcripts usage from 3PlayMedia service.
Till the PR VideoXBlock already has ability to use transcripts from 3PlayMedia service. But those '3playmedia' transcripts were used by downloading them into xblock as course assets.
So, if any changes was made on the 3PlayMedia service to mirror those changes on the xblock User should manually perform downloading each time.
The Client requested ability of VideoXBlock to use 3PlayMedia's transcripts directly (so, changes on 3PM service take effect immediately).
And PR adds described functionality.