|
47 | 47 | is_hls_playback_enabled, |
48 | 48 | get_branding_info, |
49 | 49 | get_course_by_id, |
50 | | - get_course_organization |
| 50 | + get_course_organization, |
| 51 | + is_youtube_deprecated, |
| 52 | + is_youtube_blocked_for_course, |
| 53 | + is_public_video_share_enabled, |
| 54 | + is_transcript_feedback_enabled |
51 | 55 | ) |
52 | 56 | from xblocks_contrib.video.utils import deserialize_field, own_metadata |
53 | 57 | from xblocks_contrib.video.validation import StudioValidation, StudioValidationMessage |
54 | | -# TODO: reimport following wild card import |
55 | | -from xblocks_contrib.video.constants import * |
| 58 | +from xblocks_contrib.video.constants import ( |
| 59 | + STUDENT_VIEW, |
| 60 | + PUBLIC_VIEW, |
| 61 | + ATTR_KEY_USER_ID, |
| 62 | + ATTR_KEY_REQUEST_COUNTRY_CODE, |
| 63 | + COURSE_VIDEO_SHARING_PER_VIDEO, |
| 64 | + COURSE_VIDEO_SHARING_ALL_VIDEOS, |
| 65 | + COURSE_VIDEO_SHARING_NONE, |
| 66 | +) |
56 | 67 | from xblocks_contrib.video.transcripts_utils import ( |
57 | 68 | Transcript, |
58 | 69 | VideoTranscriptsMixin, |
|
111 | 122 | LMS_ROOT_URL = "https://localhost:18000" |
112 | 123 |
|
113 | 124 |
|
| 125 | +# TODO: Add request_cache to the wants list |
114 | 126 | @XBlock.wants('settings', 'completion', 'i18n') |
115 | 127 | @XBlock.needs("i18n", 'user', 'video_config') |
116 | 128 | class VideoBlock( |
@@ -211,31 +223,25 @@ def youtube_deprecated(self): |
211 | 223 | """ |
212 | 224 | Return True if youtube is deprecated and hls as primary playback is enabled else False |
213 | 225 | """ |
214 | | - # # Return False if `hls` playback feature is disabled. |
215 | | - # if not HLSPlaybackEnabledFlag.feature_enabled(self.location.course_key): |
216 | | - # return False |
217 | | - # |
218 | | - # # check if youtube has been deprecated and hls as primary playback |
219 | | - # # is enabled for this course |
220 | | - # return DEPRECATE_YOUTUBE.is_enabled(self.location.course_key) |
221 | | - # TODO: Implement this method |
222 | | - return True |
| 226 | + # Return False if `hls` playback feature is disabled. |
| 227 | + if not is_hls_playback_enabled(self, self.location.course_key): |
| 228 | + return False |
| 229 | + |
| 230 | + # check if youtube has been deprecated and hls as primary playback |
| 231 | + # is enabled for this course |
| 232 | + return is_youtube_deprecated(self, self.location.course_key) |
223 | 233 |
|
224 | 234 | def youtube_disabled_for_course(self): # lint-amnesty, pylint: disable=missing-function-docstring |
225 | | - # TODO: Un comment following code |
226 | | - # if not self.location.context_key.is_course: |
227 | | - # return False # Only courses have this flag |
228 | | - # request_cache = RequestCache('youtube_disabled_for_course') |
229 | | - # cache_response = request_cache.get_cached_response(self.location.context_key) |
230 | | - # if cache_response.is_found: |
231 | | - # return cache_response.value |
232 | | - |
233 | | - # # TODO: Un comment following as its linked to model |
234 | | - # # youtube_is_disabled = CourseYoutubeBlockedFlag.feature_enabled(self.location.course_key) |
235 | | - # youtube_is_disabled = True |
236 | | - # request_cache.set(self.location.context_key, youtube_is_disabled) |
237 | | - # return youtube_is_disabled |
238 | | - return False |
| 235 | + if not self.location.context_key.is_course: |
| 236 | + return False # Only courses have this flag |
| 237 | + request_cache = RequestCache('youtube_disabled_for_course') |
| 238 | + cache_response = request_cache.get_cached_response(self.location.context_key) |
| 239 | + if cache_response.is_found: |
| 240 | + return cache_response.value |
| 241 | + |
| 242 | + youtube_is_disabled = is_youtube_blocked_for_course(self, self.location.course_key) |
| 243 | + request_cache.set(self.location.context_key, youtube_is_disabled) |
| 244 | + return youtube_is_disabled |
239 | 245 |
|
240 | 246 | def prioritize_hls(self, youtube_streams, html5_sources): |
241 | 247 | """ |
@@ -326,7 +332,6 @@ def get_html(self, view=STUDENT_VIEW, |
326 | 332 | try: |
327 | 333 | val_profiles = ["youtube", "desktop_webm", "desktop_mp4"] |
328 | 334 |
|
329 | | - # Use VideoConfigService to check HLS playback enabled |
330 | 335 | if is_hls_playback_enabled(self, self.course_id): |
331 | 336 | val_profiles.append('hls') |
332 | 337 |
|
@@ -557,9 +562,7 @@ def is_public_sharing_enabled(self): |
557 | 562 | return False # Only courses support this feature at all (not libraries) |
558 | 563 | try: |
559 | 564 | # Video share feature must be enabled for sharing settings to take effect |
560 | | - # TODO: How to access waffle flag |
561 | | - # feature_enabled = PUBLIC_VIDEO_SHARE.is_enabled(self.context_key) |
562 | | - feature_enabled = False |
| 565 | + feature_enabled = is_public_video_share_enabled(self, self.context_key) |
563 | 566 | except Exception as err: # pylint: disable=broad-except |
564 | 567 | log.exception(f"Error retrieving course for course ID: {self.context_key}") |
565 | 568 | return False |
@@ -590,9 +593,7 @@ def is_transcript_feedback_enabled(self): |
590 | 593 | return False # Only courses support this feature at all (not libraries) |
591 | 594 | try: |
592 | 595 | # Video transcript feedback must be enabled in order to show the widget |
593 | | - # TODO: How to access waffle flags |
594 | | - # feature_enabled = TRANSCRIPT_FEEDBACK.is_enabled(self.context_key) |
595 | | - feature_enabled = False |
| 596 | + feature_enabled = is_transcript_feedback_enabled(self, self.context_key) |
596 | 597 | except Exception as err: # pylint: disable=broad-except |
597 | 598 | log.exception(f"Error retrieving course for course ID: {self.context_key}") |
598 | 599 | return False |
@@ -1048,7 +1049,7 @@ def get_youtube_link(video_id): |
1048 | 1049 | if self.edx_video_id and edxval_api: |
1049 | 1050 |
|
1050 | 1051 | val_profiles = ['youtube', 'desktop_webm', 'desktop_mp4'] |
1051 | | - if True: # TODO: HLSPlaybackEnabledFlag.feature_enabled(self.scope_ids.usage_id.context_key.for_branch(None)): |
| 1052 | + if is_hls_playback_enabled(self.scope_ids.usage_id.context_key.for_branch(None)): |
1052 | 1053 | val_profiles.append('hls') |
1053 | 1054 |
|
1054 | 1055 | # Get video encodings for val profiles. |
@@ -1306,7 +1307,7 @@ def student_view_data(self, context=None): |
1306 | 1307 | # Check in VAL data first if edx_video_id exists |
1307 | 1308 | if self.edx_video_id: |
1308 | 1309 | video_profile_names = context.get("profiles", ["mobile_low", 'desktop_mp4', 'desktop_webm', 'mobile_high']) |
1309 | | - if True: # TODO: HLSPlaybackEnabledFlag.feature_enabled(self.location.course_key) and 'hls' not in video_profile_names: |
| 1310 | + if is_hls_playback_enabled(self.location.course_key) and 'hls' not in video_profile_names: |
1310 | 1311 | video_profile_names.append('hls') |
1311 | 1312 |
|
1312 | 1313 | # get and cache bulk VAL data for course |
|
0 commit comments