Exemplo n.º 1
0
def create(request):
    if request.method == 'POST':
        video_form = VideoForm(request.POST)
        if video_form.is_valid():
            owner = request.user if request.user.is_authenticated() else None
            parsed_url = urlparse(video_form.cleaned_data['video_url'])
            if 'youtube.com' in parsed_url.netloc:
                yt_video_id = parse_qs(parsed_url.query)['v'][0]
                video, created = Video.objects.get_or_create(
                                    youtube_videoid=yt_video_id,
                                    defaults={'owner': owner,
                                              'video_type': VIDEO_TYPE_YOUTUBE})
            else:
                video, created = Video.objects.get_or_create(
                                    video_url=video_form.cleaned_data['video_url'],
                                    defaults={'owner': owner,
                                              'video_type': VIDEO_TYPE_HTML5})
            if created:
                # TODO: log to activity feed
                pass
            if not video.owner or video.owner == request.user or video.allow_community_edits:
                return HttpResponseRedirect('{0}?autosub=true'.format(reverse(
                        'videos:video', kwargs={'video_id':video.video_id})))
            else:
                # TODO: better error page?
                return HttpResponse('You are not allowed to add transcriptions to this video.')
    else:
        video_form = VideoForm()
    return render_to_response('videos/create.html', locals(),
                              context_instance=RequestContext(request))
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
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))
Exemplo n.º 4
0
def create(request):
    if request.method == 'POST':
        video_form = VideoForm(request.POST, label_suffix="")
        if video_form.is_valid():
            owner = request.user if request.user.is_authenticated() else None
            video_url = video_form.cleaned_data['video_url']
            try:
                video, created = Video.get_or_create_for_url(video_url, owner)
            except VidscraperError:
                vidscraper_error = True
                return render_to_response('videos/create.html', locals(),
                              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''')
            return redirect(video)        
            #if not video.owner or video.owner == request.user or video.allow_community_edits:
            #    return HttpResponseRedirect('{0}?autosub=true'.format(reverse(
            #            'videos:video', kwargs={'video_id':video.video_id})))
            #else:
            #    # TODO: better error page?
            #    return HttpResponse('You are not allowed to add transcriptions to this video.')
    else:
        video_form = VideoForm(label_suffix="")
    return render_to_response('videos/create.html', locals(),
                              context_instance=RequestContext(request))
Exemplo n.º 5
0
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)
Exemplo n.º 6
0
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)
Exemplo n.º 7
0
def video_add(request):
    if request.method == 'POST':
        form = VideoForm(request.POST)

        if form.is_valid():
            video = form.save()
            data = {'video': video, 'form': VideoForm()}
            return render('videos/video_add_success.html', data)

    data = {'form': VideoForm()}
    return render(request, 'videos/video_add.html')
Exemplo n.º 8
0
    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())
Exemplo n.º 9
0
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))
Exemplo n.º 10
0
def create(request):
    if request.method == 'POST':
        video_form = VideoForm(request.POST, label_suffix="")
        if video_form.is_valid():
            video_url = video_form.cleaned_data['video_url']
            try:
                video, created = Video.get_or_create_for_url(video_url)
            except (VidscraperError, RequestError):
                vidscraper_error = True
                return render_to_response('videos/create.html', locals(),
                              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''')
            return redirect(video)
    else:
        video_form = VideoForm(label_suffix="")
    return render_to_response('videos/create.html', locals(),
                              context_instance=RequestContext(request))
Exemplo n.º 11
0
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'''))
        return redirect(video.video_link())
    return render_to_response('videos/create.html', context,
                              context_instance=RequestContext(request))
Exemplo n.º 12
0
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))
Exemplo n.º 13
0
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))
Exemplo n.º 14
0
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))
Exemplo n.º 15
0
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})
Exemplo n.º 16
0
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})
Exemplo n.º 17
0
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})
Exemplo n.º 18
0
def add_video(request):
    """
    Create a new Video for the user
    """
    if request.method == 'POST':
        form = VideoForm(request.POST, request.FILES)
        if form.is_valid():
            video = form.save(commit=False)
            video.created_by = request.user
            video.modified_by = request.user
            video.slug = slugify(video.title)
            video.save()
            # we need to save authors in extra step because they are manytomany
            form.save_m2m()
            request.user.message_set.create(
                    message='Your video has been saved.')
            return HttpResponseRedirect(reverse('videos_video_detail',args=[video.id]))
    else:
        form = VideoForm()

    return render_to_response(
                'videos/video_add.html',
                locals(),
                context_instance=RequestContext(request))
Exemplo n.º 19
0
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)