def test_update_media_closed_captions(self, p_urlopen): def mocked_urlopen(request): return StringIO(SAMPLE_MEDIA_UPDATED_XML.strip()) p_urlopen.side_effect = mocked_urlopen # This doesn't return anything but we're only interested in if it # can execute at all without errors. vidly.update_media_closed_captions( 'abc123', 'https://s3.example.com/file.mov', 'https://air.example.com/subs.dfxp', hd=True, )
def event_closed_captions_submit(request, event_id, id): event = get_object_or_404(Event, id=event_id) closedcaptions = get_object_or_404(ClosedCaptions, event=event, id=id) # XXX This might change. Instead of using the same tag as the one # being used, we might use a custom one just for the transcription # service. submission, = VidlySubmission.objects.filter( event=event, tag=event.template_environment['tag'] ) if request.method == 'POST': form = forms.SubmitClosedCaptionsForm(request.POST) if form.is_valid(): file_format = form.cleaned_data['file_format'] base_url = get_base_url(request) public_url = base_url + reverse( 'closedcaptions:download', args=( closedcaptions.filename_hash, closedcaptions.id, event.slug, file_format, ) ) # Send it in vidly.update_media_closed_captions( submission.tag, submission.url, public_url, hd=submission.hd, notify_url=None # XXX improve this some day ) if not closedcaptions.submission_info: closedcaptions.submission_info = {} if not closedcaptions.submission_info.get('submissions'): closedcaptions.submission_info['submissions'] = [] closedcaptions.submission_info['submissions'].append({ 'tag': submission.tag, 'url': submission.url, 'public_url': public_url, 'hd': submission.hd, 'date': timezone.now().isoformat(), }) closedcaptions.save() messages.success( request, '{} submitted for Vid.ly transcoding'.format( public_url ) ) return redirect('manage:event_closed_captions', event.id) else: form = forms.SubmitClosedCaptionsForm() content = closedcaptions.file.read() reader = pycaption.detect_format(content) converter = pycaption.CaptionConverter() converter.read(content, reader()) last_caption = converter.write(LastTimestampWriter()) / 1000000 context = { 'form': form, 'event': closedcaptions.event, 'closedcaptions': closedcaptions, 'last_caption': last_caption, 'submission': submission, } return render(request, 'manage/event_closed_captions_submit.html', context)
def event_closed_captions_submit(request, event_id, id): event = get_object_or_404(Event, id=event_id) closedcaptions = get_object_or_404(ClosedCaptions, event=event, id=id) # XXX This might change. Instead of using the same tag as the one # being used, we might use a custom one just for the transcription # service. submission, = VidlySubmission.objects.filter( event=event, tag=event.template_environment['tag']) if request.method == 'POST': form = forms.SubmitClosedCaptionsForm(request.POST) if form.is_valid(): file_format = form.cleaned_data['file_format'] base_url = get_base_url(request) public_url = base_url + reverse('closedcaptions:download', args=( closedcaptions.filename_hash, closedcaptions.id, event.slug, file_format, )) # Send it in vidly.update_media_closed_captions( submission.tag, submission.url, public_url, hd=submission.hd, notify_url=None # XXX improve this some day ) if not closedcaptions.submission_info: closedcaptions.submission_info = {} if not closedcaptions.submission_info.get('submissions'): closedcaptions.submission_info['submissions'] = [] closedcaptions.submission_info['submissions'].append({ 'tag': submission.tag, 'url': submission.url, 'public_url': public_url, 'hd': submission.hd, 'date': timezone.now().isoformat(), }) closedcaptions.save() messages.success( request, '{} submitted for Vid.ly transcoding'.format(public_url)) return redirect('manage:event_closed_captions', event.id) else: form = forms.SubmitClosedCaptionsForm() content = closedcaptions.file.read() reader = pycaption.detect_format(content) converter = pycaption.CaptionConverter() converter.read(content, reader()) last_caption = converter.write(LastTimestampWriter()) / 1000000 context = { 'form': form, 'event': closedcaptions.event, 'closedcaptions': closedcaptions, 'last_caption': last_caption, 'submission': submission, } return render(request, 'manage/event_closed_captions_submit.html', context)