def event_archive(request, event): if event.status != Event.STATUS_INITIATED: return http.HttpResponseBadRequest( "You can't archive events that are NOT in the state of initiated." ) submissions = VidlySubmission.objects.filter( event=event, url__startswith=event.upload.url ) for vidly_submission in submissions.order_by('-submission_time'): break else: # we haven't sent it in for archive yet upload = event.upload base_url = get_base_url(request) webhook_url = base_url + reverse('new:vidly_media_webhook') video_url = prepare_vidly_video_url(upload.url) tag, error = vidly.add_media( video_url, hd=True, notify_url=webhook_url, # Note that we deliberately don't bother yet to set # token_protection here because we don't yet know if the # event is going to be private or not. # Also, it's much quicker to make screencaptures of videos # that are not token protected on vid.ly. ) # then we need to record that we did this vidly_submission = VidlySubmission.objects.create( event=event, url=video_url, tag=tag, hd=True, submission_error=error or None ) default_template = Template.objects.get(default_archive_template=True) # Do an in place edit in case this started before the fetch_duration # has started. Event.objects.filter(id=event.id).update( template=default_template, template_environment={'tag': tag}, ) create_all_timestamp_pictures.delay(event.id) return { 'tag': vidly_submission.tag, 'error': vidly_submission.submission_error }
def event_archive(request, event): if event.status != Event.STATUS_INITIATED: return http.HttpResponseBadRequest( "You can't archive events that are NOT in the state of initiated.") submissions = VidlySubmission.objects.filter( event=event, url__startswith=event.upload.url) for vidly_submission in submissions.order_by('-submission_time'): break else: # we haven't sent it in for archive yet upload = event.upload base_url = get_base_url(request) webhook_url = base_url + reverse('new:vidly_media_webhook') video_url = prepare_vidly_video_url(upload.url) tag, error = vidly.add_media( video_url, hd=True, notify_url=webhook_url, # Note that we deliberately don't bother yet to set # token_protection here because we don't yet know if the # event is going to be private or not. # Also, it's much quicker to make screencaptures of videos # that are not token protected on vid.ly. ) # then we need to record that we did this vidly_submission = VidlySubmission.objects.create( event=event, url=video_url, tag=tag, hd=True, submission_error=error or None) default_template = Template.objects.get(default_archive_template=True) # Do an in place edit in case this started before the fetch_duration # has started. Event.objects.filter(id=event.id).update( template=default_template, template_environment={'tag': tag}, ) create_all_timestamp_pictures.delay(event.id) return { 'tag': vidly_submission.tag, 'error': vidly_submission.submission_error }
def legacy_video_migration(request): # pragma: no cover """for one off mass vid.ly submission""" class VideoURLError(Exception): pass def redirect_recurse(url): """return the URL only when it's not redirecting. Raise an error on all other statuses >= 400 """ response = requests.head(url) if response.status_code in (301, 302): return redirect_recurse(response.headers['Location']) elif response.status_code >= 400: raise VideoURLError('{} => {}'.format( url, response.status_code )) return url if request.method == 'POST': events = Event.objects.filter(id__in=request.POST.getlist('ids')) template, = Template.objects.filter(default_archive_template=True) for event in events: try: url = event.template_environment['url'] url = redirect_recurse(url) base_url = get_base_url(request) webhook_url = base_url + reverse('manage:vidly_media_webhook') url = prepare_vidly_video_url(url) token_protection = event.privacy != Event.PRIVACY_PUBLIC shortcode, error = vidly.add_media( url, hd=True, token_protection=token_protection, notify_url=webhook_url, ) VidlySubmission.objects.create( event=event, url=url, token_protection=token_protection, hd=True, tag=shortcode, submission_error=error ) event.template_environment = { 'tag': shortcode, } if shortcode: event.template = template event.archive_time = None event.status = Event.STATUS_PROCESSING event.save() videoinfo.fetch_duration( event, video_url=url, save=True, verbose=settings.DEBUG ) if Event.objects.get(id=event.id).duration: create_all_event_pictures.delay( event.id, video_url=url, ) create_all_timestamp_pictures.delay( event.id, video_url=url, ) except Exception as exception: error = str(exception) messages.error( request, 'Failed to submit "{}". Error: {}'.format( event.title, error, ) ) messages.success( request, 'Submitted {} events for Vid.ly processing'.format( events.count() ) ) return redirect('manage:legacy_video_migration') search = request.GET.get('search', 'http://videos.mozilla.org/') if search: events = Event.objects.filter( template_environment__icontains=search ) else: events = Event.objects.none() context = { 'events': events, 'search': search, } return render(request, 'manage/legacy_video_migration.html', context)
def legacy_video_migration(request): # pragma: no cover """for one off mass vid.ly submission""" class VideoURLError(Exception): pass def redirect_recurse(url): """return the URL only when it's not redirecting. Raise an error on all other statuses >= 400 """ response = requests.head(url) if response.status_code in (301, 302): return redirect_recurse(response.headers['Location']) elif response.status_code >= 400: raise VideoURLError('{} => {}'.format(url, response.status_code)) return url if request.method == 'POST': events = Event.objects.filter(id__in=request.POST.getlist('ids')) template, = Template.objects.filter(default_archive_template=True) for event in events: try: url = event.template_environment['url'] url = redirect_recurse(url) base_url = get_base_url(request) webhook_url = base_url + reverse('manage:vidly_media_webhook') url = prepare_vidly_video_url(url) token_protection = event.privacy != Event.PRIVACY_PUBLIC shortcode, error = vidly.add_media( url, hd=True, token_protection=token_protection, notify_url=webhook_url, ) VidlySubmission.objects.create( event=event, url=url, token_protection=token_protection, hd=True, tag=shortcode, submission_error=error) event.template_environment = { 'tag': shortcode, } if shortcode: event.template = template event.archive_time = None event.status = Event.STATUS_PROCESSING event.save() videoinfo.fetch_duration(event, video_url=url, save=True, verbose=settings.DEBUG) if Event.objects.get(id=event.id).duration: create_all_event_pictures.delay( event.id, video_url=url, ) create_all_timestamp_pictures.delay( event.id, video_url=url, ) except Exception as exception: error = str(exception) messages.error( request, 'Failed to submit "{}". Error: {}'.format( event.title, error, )) messages.success( request, 'Submitted {} events for Vid.ly processing'.format(events.count())) return redirect('manage:legacy_video_migration') search = request.GET.get('search', 'http://videos.mozilla.org/') if search: events = Event.objects.filter(template_environment__icontains=search) else: events = Event.objects.none() context = { 'events': events, 'search': search, } return render(request, 'manage/legacy_video_migration.html', context)