def create(request): initial = { 'video_url': request.GET.get('initial_url'), } if request.user.is_authenticated(): if request.method == 'POST': create_form = VideoForm(request.user, data=request.POST, initial=initial) if create_form.is_valid(): video = create_form.video messages.info(request, message=_(u'''Here is the subtitle workspace for your video. You can share the video with friends, or get an embed code for your site. To start new subtitles, click \"Add a new language!\" in the sidebar.''')) if create_form.created: messages.info(request, message=_(u'''Existing subtitles will be imported in a few minutes.''')) return redirect(video.get_absolute_url()) else: create_form = VideoForm(request.user, initial=initial) else: create_form = None data = { 'create_form': create_form } data.update(videos_create_extra_data(request, create_form)) return render(request, videos_create_template(), data)
def create(request, id): course = Course.objects.get(id = id) if request.method == "POST": form = VideoForm(request.POST) if form.is_valid(): f = form.save(commit=False) f.course_id = id f.save() else: form = VideoForm(request.POST) return render(request, 'admin/video/create.html', {'course': course, 'form': form})
def create(request): video_form = VideoForm(request.user, request.POST or None) context = { 'video_form': video_form, 'initial_url': request.GET.get('initial_url'), } if video_form.is_valid(): video = video_form.video messages.info( request, message=_(u'''Here is the subtitle workspace for your video. You can share the video with friends, or get an embed code for your site. To start new subtitles, click \"Add a new language!\" in the sidebar.''')) url_obj = video.videourl_set.filter(primary=True).all()[:1].get() if url_obj.type != 'Y': # Check for all types except for Youtube if not url_obj.effective_url.startswith('https'): messages.warning(request, message=_(u'''You have submitted a video that is served over http. Your browser may display mixed content warnings.''')) if video_form.created: messages.info( request, message=_( u'''Existing subtitles will be imported in a few minutes.''' )) return redirect(video.get_absolute_url()) return render(request, 'videos/create.html', context)
def create(request): video_form = VideoForm(request.user, request.POST or None) context = { 'video_form': video_form, 'youtube_form': AddFromFeedForm(request.user) } if video_form.is_valid(): try: video = video_form.save() except (VidscraperError, RequestError): context['vidscraper_error'] = True return render_to_response('videos/create.html', context, context_instance=RequestContext(request)) messages.info( request, message=_( u'''Here is the subtitle workspace for your video. You can share the video with friends, or get an embed code for your site. To add or improve subtitles, click the button below the video.''')) if video_form.created: messages.info( request, message=_( u'''Existing subtitles will be imported in a few minutes.''' )) return redirect(video.video_link()) return render_to_response('videos/create.html', context, context_instance=RequestContext(request))
def profile(request): if request.method == 'POST': video_form = VideoForm(request.POST or None, request.FILES or None) if video_form.is_valid(): aux = video_form(commit=False) aux.save() my_video = Video.objects.filter(owner=request.user) context = {"video_form": VideoForm, "my_video": my_video} return render(request, "profile.html", context)
def create_from_feed(request): form = AddFromFeedForm(request.user, request.POST or None) if form.is_valid(): form.save() messages.success(request, form.success_message()) return redirect('videos:create') context = {'video_form': VideoForm(), 'feed_form': form, 'from_feed': True} return render_to_response('videos/create.html', context, context_instance=RequestContext(request))
def create_from_feed(request): form = AddFromFeedForm(request.user, request.POST or None) if form.is_valid(): count = form.save() messages.success(request, _(u"%(count)s videos added") % {'count': count}) return redirect('videos:create') context = {'video_form': VideoForm(), 'youtube_form': form} return render_to_response('videos/create.html', context, context_instance=RequestContext(request))
def create(request): form = VideoForm() if request.method == "POST": form.setData(request.POST) if form.is_valid(): form.save() messages.success(request, 'Video Added!') return redirect("video-list") else: print(form.errors) return render(request, "videos/video_form.html", {"form": form})
def update(request, id): video = Video.objects.get(pk=id) form = VideoForm(instance=video) if request.method == "POST": form.setData(request.POST) if form.is_valid(): form.save() messages.success(request, 'Video Saved!') return redirect("video-list") else: print(form.errors) return render(request, "videos/video_form.html", {"form": form})
def _test_urls(self, urls): for url in urls: form = VideoForm(data={"video_url":url}) self.assertTrue(form.is_valid()) video = form.save() video_type = video_type_registrar.video_type_for_url(url) # double check we never confuse video_id with video.id with videoid, sigh model_url = video.get_video_url() if hasattr(video_type, "videoid"): self.assertTrue(video_type.videoid in model_url) # check the pk is never on any of the urls parts for part in model_url.split("/"): self.assertTrue(str(video.pk) != part) self.assertTrue(video.video_id not in model_url) self.assertTrue(Video.objects.filter(videourl__url=model_url).exists())
def create(request): video_form = VideoForm(request.user, request.POST or None) context = { 'video_form': video_form, 'initial_url': request.GET.get('initial_url'), } if video_form.is_valid(): video = video_form.video messages.info(request, message=_(u'''Here is the subtitle workspace for your video. You can share the video with friends, or get an embed code for your site. To start new subtitles, click \"Add a new language!\" in the sidebar.''')) if video_form.created: messages.info(request, message=_(u'''Existing subtitles will be imported in a few minutes.''')) return redirect(video.get_absolute_url()) return render_to_response('videos/create.html', context, context_instance=RequestContext(request))
def create(request): video_form = VideoForm(request.user, request.POST or None) context = { 'video_form': video_form, 'youtube_form': AddFromFeedForm(request.user) } if video_form.is_valid(): try: video = video_form.save() except (VidscraperError, RequestError): context['vidscraper_error'] = True return render_to_response('videos/create.html', context, context_instance=RequestContext(request)) messages.info( request, message=_( u'''Here is the subtitle workspace for your video. You can share the video with friends, or get an embed code for your site. To add or improve subtitles, click the button below the video.''')) url_obj = video.videourl_set.filter(primary=True).all()[:1].get() if url_obj.type != 'Y': # Check for all types except for Youtube if not url_obj.effective_url.startswith('https'): messages.warning(request, message=_(u'''You have submitted a video that is served over http. Your browser may display mixed content warnings.''')) if video_form.created: messages.info( request, message=_( u'''Existing subtitles will be imported in a few minutes.''' )) return redirect(video.get_absolute_url()) return render_to_response('videos/create.html', context, context_instance=RequestContext(request))
def upload_video(request): if request.method == 'POST' and request.FILES['video_file']: video_file = request.FILES['video_file'] user_id = request.user title = request.POST['title'] desc = request.POST['description'] tags = request.POST['tags'] category = request.POST['category'] cat = VideoCategory.objects.get(id=category) vid = Video(video_id=1, uid=user_id, title=title, description=desc, tags=tags, category=cat, videofile='video_file', thumb='img_output_path') vid.save() video_id = vid.pk vid = Video.objects.get(id=video_id) img_output_path = '%s/thumbnails/%s' % (settings.MEDIA_ROOT, video_id) img_output_path_url = '%sthumbnails/%s' % (settings.MEDIA_URL, video_id) vid.video_id = video_id vid.videofile = video_file vid.save() duration = get_video_length(vid.videofile.path) pertime = duration / 20 ff = FFmpeg(inputs={vid.videofile.path: None}, outputs={ img_output_path + '_%d.jpg': ['-vf', 'fps=1/' + str(pertime), '-vframes', '20'] }) ff.run() vid.thumb = img_output_path + '_1.jpg' vid.thumb_url = img_output_path_url + '_1.jpg' vid.duration = duration vid.save() # Proses Tagging list_tags = tags.split(',') list_tags = [i.strip().lower() for i in list_tags] for tg in list_tags: if VideoTag.objects.filter(tag=tg).exists(): current_tag = VideoTag.objects.filter(tag=tg).first() current_tag.videos.add(vid) else: create_tag = VideoTag(uid=user_id, tag=tg) create_tag.save() create_tag.videos.add(vid) vc_list = VideoCategory.objects.all() context = {'vc_list': vc_list} #return render(request, 'upload-video.html', context) else: vc_list = VideoCategory.objects.all() form = VideoForm() context = {'form': form, 'vc_list': vc_list} #return render(request, 'upload-video.html', context) return render(request, 'upload-video.html', context)