Skip to content

Commit b967384

Browse files
committed
chore: code ++
1 parent 6030df7 commit b967384

2 files changed

Lines changed: 21 additions & 12 deletions

File tree

‎xblocks_contrib/video/video.py‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,9 @@ def youtube_deprecated(self):
345345
Return True if youtube is deprecated and hls as primary playback is enabled else False
346346
"""
347347
video_config_service = self.runtime.service(self, 'video_config')
348+
if not video_config_service:
349+
return False
350+
348351
# Return False if `hls` playback feature is disabled.
349352
if not video_config_service.is_hls_playback_enabled(self.location.course_key):
350353
return False
@@ -362,7 +365,8 @@ def youtube_disabled_for_course(self): # lint-amnesty, pylint: disable=missing-
362365
return cache_response.value
363366

364367
video_config_service = self.runtime.service(self, 'video_config')
365-
youtube_is_disabled = video_config_service.is_youtube_blocked_for_course(self.location.course_key)
368+
youtube_is_disabled = video_config_service.is_youtube_blocked_for_course(
369+
self.location.course_key) if video_config_service else False
366370
request_cache.set(self.location.context_key, youtube_is_disabled)
367371
return youtube_is_disabled
368372

@@ -452,7 +456,7 @@ def get_html(self, view=STUDENT_VIEW, context=None): # lint-amnesty, pylint: dis
452456
val_profiles = ["youtube", "desktop_webm", "desktop_mp4"]
453457

454458
video_config_service = self.runtime.service(self, 'video_config')
455-
if video_config_service.is_hls_playback_enabled(self.course_id):
459+
if video_config_service and video_config_service.is_hls_playback_enabled(self.course_id):
456460
val_profiles.append('hls')
457461

458462
# strip edx_video_id to prevent ValVideoNotFoundError error if unwanted spaces are there. TNL-5769
@@ -641,7 +645,7 @@ def get_html(self, view=STUDENT_VIEW, context=None): # lint-amnesty, pylint: dis
641645
}
642646
try:
643647
video_config_service = self.runtime.service(self, 'video_config')
644-
sharing_context = video_config_service.get_public_sharing_context(self, self.course_id)
648+
sharing_context = video_config_service.get_public_sharing_context(self, self.course_id) if video_config_service else None
645649
if sharing_context:
646650
template_context.update(sharing_context)
647651
except Exception as err:
@@ -658,7 +662,8 @@ def is_transcript_feedback_enabled(self):
658662
try:
659663
# Video transcript feedback must be enabled in order to show the widget
660664
video_config_service = self.runtime.service(self, 'video_config')
661-
feature_enabled = video_config_service.is_transcript_feedback_enabled(self.context_key)
665+
feature_enabled = video_config_service.is_transcript_feedback_enabled(
666+
self.context_key) if video_config_service else False
662667
except Exception as err: # pylint: disable=broad-except
663668
log.exception(f"Error retrieving course for course ID: {self.context_key}")
664669
return False
@@ -1111,7 +1116,7 @@ def get_youtube_link(video_id):
11111116

11121117
val_profiles = ['youtube', 'desktop_webm', 'desktop_mp4']
11131118
video_config_service = self.runtime.service(self, 'video_config')
1114-
if video_config_service.is_hls_playback_enabled(self.scope_ids.usage_id.context_key.for_branch(None)):
1119+
if video_config_service and video_config_service.is_hls_playback_enabled(self.scope_ids.usage_id.context_key.for_branch(None)):
11151120
val_profiles.append('hls')
11161121

11171122
# Get video encodings for val profiles.
@@ -1370,7 +1375,7 @@ def student_view_data(self, context=None):
13701375
if self.edx_video_id:
13711376
video_profile_names = context.get("profiles", ["mobile_low", 'desktop_mp4', 'desktop_webm', 'mobile_high'])
13721377
video_config_service = self.runtime.service(self, 'video_config')
1373-
if video_config_service.is_hls_playback_enabled(self.location.course_key) and 'hls' not in video_profile_names:
1378+
if video_config_service and video_config_service.is_hls_playback_enabled(self.location.course_key) and 'hls' not in video_profile_names:
13741379
video_profile_names.append('hls')
13751380

13761381
# get and cache bulk VAL data for course

‎xblocks_contrib/video/video_handlers.py‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,8 @@ def yt_video_metadata(self, request, suffix=''): # lint-amnesty, pylint: disabl
427427
return Response('{}', status=400)
428428
try:
429429
video_config_service = self.runtime.service(self, 'video_config')
430+
if not video_config_service:
431+
return Response('{"error": "Video config service not found"}', status=500)
430432
metadata, status_code = video_config_service.get_youtube_metadata(self.youtube_id_1_0, request)
431433
response = Response(json.dumps(metadata), status=status_code)
432434
response.content_type = 'application/json'
@@ -569,9 +571,10 @@ def _studio_transcript_upload(self, request):
569571
filename = f"static/{filename}"
570572
try:
571573
video_config_service = self.runtime.service(self, 'video_config')
572-
success = video_config_service.add_library_static_asset(self.usage_key, filename, content)
573-
if not success:
574-
log.error(f"Failed to add library static asset {filename} for usage key: {self.usage_key}")
574+
if video_config_service:
575+
success = video_config_service.add_library_static_asset(self.usage_key, filename, content)
576+
if not success:
577+
log.error(f"Failed to add library static asset {filename} for usage key: {self.usage_key}")
575578
except Exception as e:
576579
log.exception(f"Error adding library static asset {filename} for usage key: {self.usage_key}")
577580
else:
@@ -632,9 +635,10 @@ def _studio_transcript_delete(self, request):
632635
filename = f"static/{transcript_name}"
633636
try:
634637
video_config_service = self.runtime.service(self, 'video_config')
635-
success = video_config_service.delete_library_static_asset(self.usage_key, filename)
636-
if not success:
637-
log.error(f"Failed to delete library static asset {filename} for usage key: {self.usage_key}")
638+
if video_config_service:
639+
success = video_config_service.delete_library_static_asset(self.usage_key, filename)
640+
if not success:
641+
log.error(f"Failed to delete library static asset {filename} for usage key: {self.usage_key}")
638642
except Exception as e:
639643
log.exception(f"Error deleting library static asset {filename} for usage key: {self.usage_key}")
640644
self._save_transcript_field()

0 commit comments

Comments
 (0)