def setUp(self): super(ScrapeVideoThumbnailsTestCase, self).setUp() course_ids = [unicode(self.course.id)] profiles = ['youtube'] created = datetime.now(pytz.utc) previous_uploads = [ { 'edx_video_id': 'test1', 'client_video_id': 'test1.mp4', 'duration': 42.0, 'status': 'upload', 'courses': course_ids, 'encoded_videos': [], 'created': created }, { 'edx_video_id': 'test-youtube-video-1', 'client_video_id': 'test-youtube-id.mp4', 'duration': 128.0, 'status': 'file_complete', 'courses': course_ids, 'created': created, 'encoded_videos': [ { 'profile': 'youtube', 'url': '3_yD_cEKoCk', 'file_size': 1600, 'bitrate': 100, } ], }, { 'edx_video_id': 'test-youtube-video-2', 'client_video_id': 'test-youtube-id.mp4', 'image': 'image2.jpg', 'duration': 128.0, 'status': 'file_complete', 'courses': course_ids, 'created': created, 'encoded_videos': [ { 'profile': 'youtube', 'url': '3_yD_cEKoCk', 'file_size': 1600, 'bitrate': 100, } ], }, ] for profile in profiles: create_profile(profile) for video in previous_uploads: create_video(video) # Create video images. with make_image_file() as image_file: update_video_image( 'test-youtube-video-2', unicode(self.course.id), image_file, 'image.jpg' )
def setUp(self): super(ScrapeVideoThumbnailsTestCase, self).setUp() course_ids = [unicode(self.course.id)] profiles = ['youtube'] created = datetime.now(pytz.utc) previous_uploads = [ { 'edx_video_id': 'test1', 'client_video_id': 'test1.mp4', 'duration': 42.0, 'status': 'upload', 'courses': course_ids, 'encoded_videos': [], 'created': created }, { 'edx_video_id': 'test-youtube-video-1', 'client_video_id': 'test-youtube-id.mp4', 'duration': 128.0, 'status': 'file_complete', 'courses': course_ids, 'created': created, 'encoded_videos': [ { 'profile': 'youtube', 'url': '3_yD_cEKoCk', 'file_size': 1600, 'bitrate': 100, } ], }, { 'edx_video_id': 'test-youtube-video-2', 'client_video_id': 'test-youtube-id.mp4', 'image': 'image2.jpg', 'duration': 128.0, 'status': 'file_complete', 'courses': course_ids, 'created': created, 'encoded_videos': [ { 'profile': 'youtube', 'url': '3_yD_cEKoCk', 'file_size': 1600, 'bitrate': 100, } ], }, ] for profile in profiles: create_profile(profile) for video in previous_uploads: create_video(video) # Create video images. with make_image_file() as image_file: update_video_image( 'test-youtube-video-2', unicode(self.course.id), image_file, 'image.jpg' )
def validate_and_update_video_image(course_key_string, edx_video_id, image_file, image_filename): """ Validates image content and updates video image. """ error = validate_video_image(image_file, skip_aspect_ratio=True) if error: LOGGER.info( u'VIDEOS: Scraping youtube video thumbnail failed for edx_video_id [%s] in course [%s] with error: %s', edx_video_id, course_key_string, error) return update_video_image(edx_video_id, course_key_string, image_file, image_filename) LOGGER.info( u'VIDEOS: Scraping youtube video thumbnail for edx_video_id [%s] in course [%s]', edx_video_id, course_key_string)
def validate_and_update_video_image(course_key_string, edx_video_id, image_file, image_filename): """ Validates image content and updates video image. """ error = validate_video_image(image_file, skip_aspect_ratio=True) if error: LOGGER.info( u'VIDEOS: Scraping youtube video thumbnail failed for edx_video_id [%s] in course [%s] with error: %s', edx_video_id, course_key_string, error ) return update_video_image(edx_video_id, course_key_string, image_file, image_filename) LOGGER.info( u'VIDEOS: Scraping youtube video thumbnail for edx_video_id [%s] in course [%s]', edx_video_id, course_key_string )
def video_images_handler(request, course_key_string, edx_video_id=None): # respond with a 404 if image upload is not enabled. if not WAFFLE_SWITCHES.is_enabled(VIDEO_IMAGE_UPLOAD_ENABLED): return HttpResponseNotFound() if 'file' not in request.FILES: return JsonResponse({'error': _(u'An image file is required.')}, status=400) image_file = request.FILES['file'] error = validate_video_image(image_file) if error: return JsonResponse({'error': error}, status=400) with closing(image_file): image_url = update_video_image(edx_video_id, course_key_string, image_file, image_file.name) LOGGER.info( u'VIDEOS: Video image uploaded for edx_video_id [%s] in course [%s]', edx_video_id, course_key_string ) return JsonResponse({'image_url': image_url})
def video_images_handler(request, course_key_string, edx_video_id=None): # respond with a 404 if image upload is not enabled. if not WAFFLE_SWITCHES.is_enabled(VIDEO_IMAGE_UPLOAD_ENABLED): return HttpResponseNotFound() if 'file' not in request.FILES: return JsonResponse({'error': _(u'An image file is required.')}, status=400) image_file = request.FILES['file'] error = validate_video_image(image_file) if error: return JsonResponse({'error': error}, status=400) with closing(image_file): image_url = update_video_image(edx_video_id, course_key_string, image_file, image_file.name) LOGGER.info( 'VIDEOS: Video image uploaded for edx_video_id [%s] in course [%s]', edx_video_id, course_key_string ) return JsonResponse({'image_url': image_url})