def validate_transcript_credentials(provider, **credentials): """ Validates transcript credentials. Validations: Providers must be either 3PlayMedia or Cielo24. In case of: 3PlayMedia - 'api_key' and 'api_secret_key' are required. Cielo24 - 'api_key' and 'username' are required. It ignores any extra/unrelated parameters passed in credentials and only returns the validated ones. """ error_message, validated_credentials = '', {} valid_providers = get_3rd_party_transcription_plans().keys() if provider in valid_providers: must_have_props = [] if provider == TranscriptProvider.THREE_PLAY_MEDIA: must_have_props = ['api_key', 'api_secret_key'] elif provider == TranscriptProvider.CIELO24: must_have_props = ['api_key', 'username'] missing = [must_have_prop for must_have_prop in must_have_props if must_have_prop not in credentials.keys()] if missing: error_message = u'{missing} must be specified.'.format(missing=' and '.join(missing)) return error_message, validated_credentials validated_credentials.update({ prop: credentials[prop] for prop in must_have_props }) else: error_message = u'Invalid Provider {provider}.'.format(provider=provider) return error_message, validated_credentials
def get_all_transcript_languages(): """ Returns all possible languages for transcript. """ third_party_transcription_languages = {} transcription_plans = get_3rd_party_transcription_plans() cielo_fidelity = transcription_plans[ TranscriptProvider.CIELO24]['fidelity'] # Get third party transcription languages. third_party_transcription_languages.update( transcription_plans[TranscriptProvider.THREE_PLAY_MEDIA]['languages']) third_party_transcription_languages.update( cielo_fidelity['MECHANICAL']['languages']) third_party_transcription_languages.update( cielo_fidelity['PREMIUM']['languages']) third_party_transcription_languages.update( cielo_fidelity['PROFESSIONAL']['languages']) all_languages_dict = dict(settings.ALL_LANGUAGES, **third_party_transcription_languages) # Return combined system settings and 3rd party transcript languages. all_languages = [] for key, value in sorted(six.iteritems(all_languages_dict), key=lambda k_v: k_v[1]): all_languages.append({'language_code': key, 'language_text': value}) return all_languages
def videos_index_html(course): """ Returns an HTML page to display previous video uploads and allow new ones """ is_video_transcript_enabled = VideoTranscriptEnabledFlag.feature_enabled( course.id) context = { 'context_course': course, 'image_upload_url': reverse_course_url('video_images_handler', unicode(course.id)), 'video_handler_url': reverse_course_url('videos_handler', unicode(course.id)), 'encodings_download_url': reverse_course_url('video_encodings_download', unicode(course.id)), 'default_video_image_url': _get_default_video_image_url(), 'previous_uploads': _get_index_videos(course), 'concurrent_upload_limit': settings.VIDEO_UPLOAD_PIPELINE.get('CONCURRENT_UPLOAD_LIMIT', 0), 'video_supported_file_formats': VIDEO_SUPPORTED_FILE_FORMATS.keys(), 'video_upload_max_file_size': VIDEO_UPLOAD_MAX_FILE_SIZE_GB, 'video_image_settings': { 'video_image_upload_enabled': WAFFLE_SWITCHES.is_enabled(VIDEO_IMAGE_UPLOAD_ENABLED), 'max_size': settings.VIDEO_IMAGE_SETTINGS['VIDEO_IMAGE_MAX_BYTES'], 'min_size': settings.VIDEO_IMAGE_SETTINGS['VIDEO_IMAGE_MIN_BYTES'], 'max_width': settings.VIDEO_IMAGE_MAX_WIDTH, 'max_height': settings.VIDEO_IMAGE_MAX_HEIGHT, 'supported_file_formats': settings.VIDEO_IMAGE_SUPPORTED_FILE_FORMATS }, 'is_video_transcript_enabled': is_video_transcript_enabled, 'video_transcript_settings': None, 'active_transcript_preferences': None } if is_video_transcript_enabled: context['video_transcript_settings'] = { 'transcript_preferences_handler_url': reverse_course_url('transcript_preferences_handler', unicode(course.id)), 'transcription_plans': get_3rd_party_transcription_plans(), } context['active_transcript_preferences'] = get_transcript_preferences( unicode(course.id)) return render_to_response('videos_index.html', context)
def videos_index_html(course, pagination_conf=None): """ Returns an HTML page to display previous video uploads and allow new ones """ is_video_transcript_enabled = VideoTranscriptEnabledFlag.feature_enabled(course.id) previous_uploads, pagination_context = _get_index_videos(course, pagination_conf) context = { 'context_course': course, 'image_upload_url': reverse_course_url('video_images_handler', six.text_type(course.id)), 'video_handler_url': reverse_course_url('videos_handler', six.text_type(course.id)), 'encodings_download_url': reverse_course_url('video_encodings_download', six.text_type(course.id)), 'default_video_image_url': _get_default_video_image_url(), 'previous_uploads': previous_uploads, 'concurrent_upload_limit': settings.VIDEO_UPLOAD_PIPELINE.get('CONCURRENT_UPLOAD_LIMIT', 0), 'video_supported_file_formats': list(VIDEO_SUPPORTED_FILE_FORMATS.keys()), 'video_upload_max_file_size': VIDEO_UPLOAD_MAX_FILE_SIZE_GB, 'video_image_settings': { 'video_image_upload_enabled': WAFFLE_SWITCHES.is_enabled(VIDEO_IMAGE_UPLOAD_ENABLED), 'max_size': settings.VIDEO_IMAGE_SETTINGS['VIDEO_IMAGE_MAX_BYTES'], 'min_size': settings.VIDEO_IMAGE_SETTINGS['VIDEO_IMAGE_MIN_BYTES'], 'max_width': settings.VIDEO_IMAGE_MAX_WIDTH, 'max_height': settings.VIDEO_IMAGE_MAX_HEIGHT, 'supported_file_formats': settings.VIDEO_IMAGE_SUPPORTED_FILE_FORMATS }, 'is_video_transcript_enabled': is_video_transcript_enabled, 'active_transcript_preferences': None, 'transcript_credentials': None, 'transcript_available_languages': get_all_transcript_languages(), 'video_transcript_settings': { 'transcript_download_handler_url': reverse('transcript_download_handler'), 'transcript_upload_handler_url': reverse('transcript_upload_handler'), 'transcript_delete_handler_url': reverse_course_url('transcript_delete_handler', six.text_type(course.id)), 'trancript_download_file_format': Transcript.SRT }, 'pagination_context': pagination_context } if is_video_transcript_enabled: context['video_transcript_settings'].update({ 'transcript_preferences_handler_url': reverse_course_url( 'transcript_preferences_handler', six.text_type(course.id) ), 'transcript_credentials_handler_url': reverse_course_url( 'transcript_credentials_handler', six.text_type(course.id) ), 'transcription_plans': get_3rd_party_transcription_plans(), }) context['active_transcript_preferences'] = get_transcript_preferences(six.text_type(course.id)) # Cached state for transcript providers' credentials (org-specific) context['transcript_credentials'] = get_transcript_credentials_state_for_org(course.id.org) return render_to_response('videos_index.html', context)
def videos_index_html(course): """ Returns an HTML page to display previous video uploads and allow new ones """ is_video_transcript_enabled = VideoTranscriptEnabledFlag.feature_enabled(course.id) context = { 'context_course': course, 'image_upload_url': reverse_course_url('video_images_handler', unicode(course.id)), 'video_handler_url': reverse_course_url('videos_handler', unicode(course.id)), 'encodings_download_url': reverse_course_url('video_encodings_download', unicode(course.id)), 'default_video_image_url': _get_default_video_image_url(), 'previous_uploads': _get_index_videos(course), 'concurrent_upload_limit': settings.VIDEO_UPLOAD_PIPELINE.get('CONCURRENT_UPLOAD_LIMIT', 0), 'video_supported_file_formats': VIDEO_SUPPORTED_FILE_FORMATS.keys(), 'video_upload_max_file_size': VIDEO_UPLOAD_MAX_FILE_SIZE_GB, 'video_image_settings': { 'video_image_upload_enabled': WAFFLE_SWITCHES.is_enabled(VIDEO_IMAGE_UPLOAD_ENABLED), 'max_size': settings.VIDEO_IMAGE_SETTINGS['VIDEO_IMAGE_MAX_BYTES'], 'min_size': settings.VIDEO_IMAGE_SETTINGS['VIDEO_IMAGE_MIN_BYTES'], 'max_width': settings.VIDEO_IMAGE_MAX_WIDTH, 'max_height': settings.VIDEO_IMAGE_MAX_HEIGHT, 'supported_file_formats': settings.VIDEO_IMAGE_SUPPORTED_FILE_FORMATS }, 'is_video_transcript_enabled': is_video_transcript_enabled, 'active_transcript_preferences': None, 'transcript_credentials': None, 'transcript_available_languages': get_all_transcript_languages(), 'video_transcript_settings': { 'transcript_download_handler_url': reverse('transcript_download_handler'), 'transcript_upload_handler_url': reverse('transcript_upload_handler'), 'transcript_delete_handler_url': reverse_course_url('transcript_delete_handler', unicode(course.id)), 'trancript_download_file_format': Transcript.SRT } } if is_video_transcript_enabled: context['video_transcript_settings'].update({ 'transcript_preferences_handler_url': reverse_course_url( 'transcript_preferences_handler', unicode(course.id) ), 'transcript_credentials_handler_url': reverse_course_url( 'transcript_credentials_handler', unicode(course.id) ), 'transcription_plans': get_3rd_party_transcription_plans(), }) context['active_transcript_preferences'] = get_transcript_preferences(unicode(course.id)) # Cached state for transcript providers' credentials (org-specific) context['transcript_credentials'] = get_transcript_credentials_state_for_org(course.id.org) return render_to_response('videos_index.html', context)
def get_all_transcript_languages(): """ Returns all possible languages for transcript. """ third_party_transcription_languages = {} transcription_plans = get_3rd_party_transcription_plans() cielo_fidelity = transcription_plans[ TranscriptProvider.CIELO24]['fidelity'] # Get third party transcription languages. third_party_transcription_languages.update( transcription_plans[TranscriptProvider.THREE_PLAY_MEDIA]['languages']) third_party_transcription_languages.update( cielo_fidelity['MECHANICAL']['languages']) third_party_transcription_languages.update( cielo_fidelity['PREMIUM']['languages']) third_party_transcription_languages.update( cielo_fidelity['PROFESSIONAL']['languages']) # Return combined system settings and 3rd party transcript languages. return dict(settings.ALL_LANGUAGES, **third_party_transcription_languages)
def get_all_transcript_languages(): """ Returns all possible languages for transcript. """ third_party_transcription_languages = {} transcription_plans = get_3rd_party_transcription_plans() cielo_fidelity = transcription_plans[TranscriptProvider.CIELO24]['fidelity'] # Get third party transcription languages. third_party_transcription_languages.update(transcription_plans[TranscriptProvider.THREE_PLAY_MEDIA]['languages']) third_party_transcription_languages.update(cielo_fidelity['MECHANICAL']['languages']) third_party_transcription_languages.update(cielo_fidelity['PREMIUM']['languages']) third_party_transcription_languages.update(cielo_fidelity['PROFESSIONAL']['languages']) all_languages_dict = dict(settings.ALL_LANGUAGES, **third_party_transcription_languages) # Return combined system settings and 3rd party transcript languages. all_languages = [] for key, value in sorted(all_languages_dict.iteritems(), key=lambda (k, v): v): all_languages.append({ 'language_code': key, 'language_text': value }) return all_languages
def validate_transcript_preferences(provider, cielo24_fidelity, cielo24_turnaround, three_play_turnaround, video_source_language, preferred_languages): """ Validate 3rd Party Transcription Preferences. Arguments: provider: Transcription provider cielo24_fidelity: Cielo24 transcription fidelity. cielo24_turnaround: Cielo24 transcription turnaround. three_play_turnaround: 3PlayMedia transcription turnaround. video_source_language: Source/Speech language of the videos that are going to be submitted to the Providers. preferred_languages: list of language codes. Returns: validated preferences or a validation error. """ error, preferences = None, {} # validate transcription providers transcription_plans = get_3rd_party_transcription_plans() if provider in transcription_plans.keys(): # Further validations for providers if provider == TranscriptProvider.CIELO24: # Validate transcription fidelity if cielo24_fidelity in transcription_plans[provider]['fidelity']: # Validate transcription turnaround if cielo24_turnaround not in transcription_plans[provider]['turnaround']: error = u'Invalid cielo24 turnaround {}.'.format(cielo24_turnaround) return error, preferences # Validate transcription languages supported_languages = transcription_plans[provider]['fidelity'][cielo24_fidelity]['languages'] if video_source_language not in supported_languages: error = u'Unsupported source language {}.'.format(video_source_language) return error, preferences if not len(preferred_languages) or not (set(preferred_languages) <= set(supported_languages.keys())): error = u'Invalid languages {}.'.format(preferred_languages) return error, preferences # Validated Cielo24 preferences preferences = { 'video_source_language': video_source_language, 'cielo24_fidelity': cielo24_fidelity, 'cielo24_turnaround': cielo24_turnaround, 'preferred_languages': preferred_languages, } else: error = u'Invalid cielo24 fidelity {}.'.format(cielo24_fidelity) elif provider == TranscriptProvider.THREE_PLAY_MEDIA: # Validate transcription turnaround if three_play_turnaround not in transcription_plans[provider]['turnaround']: error = u'Invalid 3play turnaround {}.'.format(three_play_turnaround) return error, preferences # Validate transcription languages valid_translations_map = transcription_plans[provider]['translations'] if video_source_language not in valid_translations_map.keys(): error = u'Unsupported source language {}.'.format(video_source_language) return error, preferences valid_target_languages = valid_translations_map[video_source_language] if not len(preferred_languages) or not (set(preferred_languages) <= set(valid_target_languages)): error = u'Invalid languages {}.'.format(preferred_languages) return error, preferences # Validated 3PlayMedia preferences preferences = { 'three_play_turnaround': three_play_turnaround, 'video_source_language': video_source_language, 'preferred_languages': preferred_languages, } else: error = u'Invalid provider {}.'.format(provider) return error, preferences
def validate_transcript_preferences(provider, cielo24_fidelity, cielo24_turnaround, three_play_turnaround, video_source_language, preferred_languages): """ Validate 3rd Party Transcription Preferences. Arguments: provider: Transcription provider cielo24_fidelity: Cielo24 transcription fidelity. cielo24_turnaround: Cielo24 transcription turnaround. three_play_turnaround: 3PlayMedia transcription turnaround. video_source_language: Source/Speech language of the videos that are going to be submitted to the Providers. preferred_languages: list of language codes. Returns: validated preferences or a validation error. """ error, preferences = None, {} # validate transcription providers transcription_plans = get_3rd_party_transcription_plans() if provider in transcription_plans.keys(): # Further validations for providers if provider == TranscriptProvider.CIELO24: # Validate transcription fidelity if cielo24_fidelity in transcription_plans[provider]['fidelity']: # Validate transcription turnaround if cielo24_turnaround not in transcription_plans[provider]['turnaround']: error = 'Invalid cielo24 turnaround {}.'.format(cielo24_turnaround) return error, preferences # Validate transcription languages supported_languages = transcription_plans[provider]['fidelity'][cielo24_fidelity]['languages'] if video_source_language not in supported_languages: error = 'Unsupported source language {}.'.format(video_source_language) return error, preferences if not len(preferred_languages) or not (set(preferred_languages) <= set(supported_languages.keys())): error = 'Invalid languages {}.'.format(preferred_languages) return error, preferences # Validated Cielo24 preferences preferences = { 'video_source_language': video_source_language, 'cielo24_fidelity': cielo24_fidelity, 'cielo24_turnaround': cielo24_turnaround, 'preferred_languages': preferred_languages, } else: error = 'Invalid cielo24 fidelity {}.'.format(cielo24_fidelity) elif provider == TranscriptProvider.THREE_PLAY_MEDIA: # Validate transcription turnaround if three_play_turnaround not in transcription_plans[provider]['turnaround']: error = 'Invalid 3play turnaround {}.'.format(three_play_turnaround) return error, preferences # Validate transcription languages valid_translations_map = transcription_plans[provider]['translations'] if video_source_language not in valid_translations_map.keys(): error = 'Unsupported source language {}.'.format(video_source_language) return error, preferences valid_target_languages = valid_translations_map[video_source_language] if not len(preferred_languages) or not (set(preferred_languages) <= set(valid_target_languages)): error = 'Invalid languages {}.'.format(preferred_languages) return error, preferences # Validated 3PlayMedia preferences preferences = { 'three_play_turnaround': three_play_turnaround, 'video_source_language': video_source_language, 'preferred_languages': preferred_languages, } else: error = 'Invalid provider {}.'.format(provider) return error, preferences