예제 #1
0
def scraped_submit_video(request):
    if not (request.REQUEST.get('url') and \
                url_re.match(request.REQUEST['url'])):
        return HttpResponseRedirect(reverse('localtv_submit_video'))

    scraped_data = util.get_scraped_data(request.REQUEST['url'])

    url = scraped_data.get('link', request.REQUEST['url'])
    existing =  models.Video.objects.filter(site=request.sitelocation.site,
                                            website_url=url)
    existing.filter(status=models.VIDEO_STATUS_REJECTED).delete()
    if existing.count():
        return HttpResponseRedirect(reverse('localtv_submit_thanks',
                                                args=[existing[0].id]))
    initial = dict(request.GET.items())
    if request.method == "GET":
        scraped_form = forms.ScrapedSubmitVideoForm(initial=initial,
                                                    scraped_data=scraped_data)

        return render_to_response(
            'localtv/submit_video/scraped.html',
            {'data': scraped_data,
             'form': scraped_form},
            context_instance=RequestContext(request))

    scraped_form = forms.ScrapedSubmitVideoForm(
        request.POST,
        sitelocation=request.sitelocation,
        user=request.user,
        scraped_data=scraped_data)
    return _submit_finish(scraped_form,
            'localtv/submit_video/scraped.html',
            {'data': scraped_data,
             'form': scraped_form},
            context_instance=RequestContext(request))
예제 #2
0
파일: util.py 프로젝트: Zojax/mirocommunity
    def generate_video_model(self, site, status=models.VIDEO_STATUS_ACTIVE):
        scraped_data = get_scraped_data(self.website_url)
        self.name = scraped_data.get('title', self.name)
        self.description = scraped_data.get('description', self.description)
        self.file_url = scraped_data.get('file_url', self.file_url)
        self.embed_code = scraped_data.get('embed_code', self.embed_code)
        self.flash_enclosure_url = scraped_data.get('flash_enclosure_url',
                                                    self.flash_enclosure_url)
        self.website_url = scraped_data.get('link', self.website_url)

        if scraped_data.get('tags'):
            tags = get_or_create_tags(scraped_data['tags'])
        elif self.tags:
            tags = get_or_create_tags([tag['name'] for tag in
                                       self.tags['objects']['all']])
        else:
            tags = []

        video = models.Video(
            name=self.name,
            site=site,
            description=self.description,
            file_url=self.file_url,
            when_submitted=datetime.datetime.now(),
            when_approved=datetime.datetime.now(),
            status=status,
            website_url=self.website_url,
            thumbnail_url=self.thumbnail_url,
            embed_code=self.embed_code,
            flash_enclosure_url=self.flash_enclosure_url,
            when_published=self.publish_date,
            video_service_user=self.video_service_user,
            video_service_url=self.video_service_url)

        video.try_to_get_file_url_data()
        video.save()
        video.tags = tags
        video.save()
        if video.thumbnail_url:
            video.save_thumbnail()

        return video
예제 #3
0
def embedrequest_submit_video(request):
    if not (request.REQUEST.get('url') and \
                url_re.match(request.REQUEST['url'])):
        return HttpResponseRedirect(reverse('localtv_submit_video'))

    url = request.REQUEST['url']
    existing =  models.Video.objects.filter(site=request.sitelocation.site,
                                            website_url=url)
    existing.filter(status=models.VIDEO_STATUS_REJECTED).delete()
    if existing.count():
        return HttpResponseRedirect(reverse('localtv_submit_thanks',
                                                args=[existing[0].id]))

    scraped_data = util.get_scraped_data(request.REQUEST['url']) or {}
    initial = {
        'url': url,
        'name': scraped_data.get('title', ''),
        'description': scraped_data.get('description', ''),
        'thumbnail': scraped_data.get('thumbnail_url', '')
        }
    if request.method == "GET":
        embed_form = forms.EmbedSubmitVideoForm(initial=initial)

        return render_to_response(
            'localtv/submit_video/embed.html',
            {'form': embed_form},
            context_instance=RequestContext(request))

    embed_form = forms.EmbedSubmitVideoForm(request.POST, request.FILES,
                                            sitelocation=request.sitelocation,
                                            user=request.user)

    return _submit_finish(embed_form,
                          'localtv/submit_video/embed.html',
                          {'form': embed_form},
                          context_instance=RequestContext(request))
예제 #4
0
def embedrequest_submit_video(request):
    if not (request.REQUEST.get('url') and \
                url_re.match(request.REQUEST['url'])):
        return HttpResponseRedirect(reverse('localtv_submit_video'))

    url = request.REQUEST['url']
    existing = models.Video.objects.filter(site=request.sitelocation.site,
                                           website_url=url)
    existing.filter(status=models.VIDEO_STATUS_REJECTED).delete()
    if existing.count():
        return HttpResponseRedirect(
            reverse('localtv_submit_thanks', args=[existing[0].id]))

    scraped_data = util.get_scraped_data(request.REQUEST['url']) or {}
    initial = {
        'url': url,
        'name': scraped_data.get('title', ''),
        'description': scraped_data.get('description', ''),
        'thumbnail': scraped_data.get('thumbnail_url', '')
    }
    if request.method == "GET":
        embed_form = forms.EmbedSubmitVideoForm(initial=initial)

        return render_to_response('localtv/submit_video/embed.html',
                                  {'form': embed_form},
                                  context_instance=RequestContext(request))

    embed_form = forms.EmbedSubmitVideoForm(request.POST,
                                            request.FILES,
                                            sitelocation=request.sitelocation,
                                            user=request.user)

    return _submit_finish(embed_form,
                          'localtv/submit_video/embed.html',
                          {'form': embed_form},
                          context_instance=RequestContext(request))
예제 #5
0
def scraped_submit_video(request):
    if not (request.REQUEST.get('url') and \
                url_re.match(request.REQUEST['url'])):
        return HttpResponseRedirect(reverse('localtv_submit_video'))

    scraped_data = util.get_scraped_data(request.REQUEST['url'])

    url = scraped_data.get('link', request.REQUEST['url'])
    existing = models.Video.objects.filter(site=request.sitelocation.site,
                                           website_url=url)
    existing.filter(status=models.VIDEO_STATUS_REJECTED).delete()
    if existing.count():
        return HttpResponseRedirect(
            reverse('localtv_submit_thanks', args=[existing[0].id]))
    initial = dict(request.GET.items())
    if request.method == "GET":
        scraped_form = forms.ScrapedSubmitVideoForm(initial=initial,
                                                    scraped_data=scraped_data)

        return render_to_response('localtv/submit_video/scraped.html', {
            'data': scraped_data,
            'form': scraped_form
        },
                                  context_instance=RequestContext(request))

    scraped_form = forms.ScrapedSubmitVideoForm(
        request.POST,
        sitelocation=request.sitelocation,
        user=request.user,
        scraped_data=scraped_data)
    return _submit_finish(scraped_form,
                          'localtv/submit_video/scraped.html', {
                              'data': scraped_data,
                              'form': scraped_form
                          },
                          context_instance=RequestContext(request))
예제 #6
0
def submit_video(request):
    if not (request.user_is_admin or \
                request.sitelocation.display_submit_button):
        raise Http404
    url = request.POST.get('url') or request.GET.get('url', '')
    if request.method == "GET" and not url:
        submit_form = forms.SubmitVideoForm()
        return render_to_response(
            'localtv/submit_video/submit.html',
            {'form': submit_form},
            context_instance=RequestContext(request))
    else:
        url = urlparse.urldefrag(url)[0]
        submit_form = forms.SubmitVideoForm({'url': url or ''})
        if submit_form.is_valid():
            existing = models.Video.objects.filter(
                Q(website_url=submit_form.cleaned_data['url']) |
                Q(file_url=submit_form.cleaned_data['url']),
                site=request.sitelocation.site)
            existing.filter(status=models.VIDEO_STATUS_REJECTED).delete()
            if existing.count():
                if request.user_is_admin:
                    # even if the video was rejected, an admin submitting it
                    # should make it approved
                    for v in existing.exclude(
                        status=models.VIDEO_STATUS_ACTIVE):
                        v.user = request.user
                        v.status = models.VIDEO_STATUS_ACTIVE
                        v.when_approved = datetime.datetime.now()
                        v.save()
                    return HttpResponseRedirect(
                        reverse('localtv_submit_thanks',
                                args=[existing[0].pk]))
                else:
                    # pick the first approved video to point the user at
                    videos = existing.filter(
                        status=models.VIDEO_STATUS_ACTIVE)
                    if videos.count():
                        video = videos[0]
                    else:
                        video = None
                    return render_to_response(
                        'localtv/submit_video/submit.html',
                        {'form': forms.SubmitVideoForm(),
                         'was_duplicate': True,
                         'video': video},
                        context_instance=RequestContext(request))

            scraped_data = util.get_scraped_data(
                submit_form.cleaned_data['url'])

            get_dict = {'url': submit_form.cleaned_data['url']}
            if 'bookmarklet' in request.GET:
                get_dict['bookmarklet'] = '1'
            get_params = urllib.urlencode(get_dict)
            if scraped_data:
                if 'link' in scraped_data and \
                        scraped_data['link'] != get_dict['url']:
                    request.POST = {
                        'url': scraped_data['link'].encode('utf8')}
                    # rerun the view, but with the canonical URL
                    return submit_video(request)

                if (scraped_data.get('embed')
                    or (scraped_data.get('file_url')
                        and not scraped_data.get('file_url_is_flaky'))):
                    return HttpResponseRedirect(
                        reverse('localtv_submit_scraped_video') + '?' +
                        get_params)

            # otherwise if it looks like a video file
            if is_video_url(submit_form.cleaned_data['url']):
                return HttpResponseRedirect(
                    reverse('localtv_submit_directlink_video')
                    + '?' + get_params)
            else:
                return HttpResponseRedirect(
                    reverse('localtv_submit_embedrequest_video')
                    + '?' + get_params)

        else:
            return render_to_response(
                'localtv/submit_video/submit.html',
                {'form': submit_form},
                context_instance=RequestContext(request))
예제 #7
0
def submit_video(request):
    #    import pdb; pdb.set_trace()
    if not (request.user_is_admin or \
                request.sitelocation.display_submit_button):
        raise Http404

    # Extract construction hint, if it exists.
    # This is a hint that plugins can use to slightly change the behavior
    # of the video submission forms.
    construction_hint = (request.POST.get('construction_hint', None)
                         or request.GET.get('construction_hint', None))

    url = request.POST.get('url') or request.GET.get('url', '')
    if request.method == "GET" and not url:
        submit_form = forms.SubmitVideoForm(
            construction_hint=construction_hint)
        return render_to_response('localtv/submit_video/submit.html',
                                  {'form': submit_form},
                                  context_instance=RequestContext(request))
    else:
        url = urlparse.urldefrag(url)[0]
        submit_form = forms.SubmitVideoForm({'url': url or ''})
        if submit_form.is_valid():
            existing = models.Video.objects.filter(
                Q(website_url=submit_form.cleaned_data['url'])
                | Q(file_url=submit_form.cleaned_data['url']),
                site=request.sitelocation.site)
            existing.filter(status=models.VIDEO_STATUS_REJECTED).delete()
            if existing.count():
                if request.user_is_admin:
                    # even if the video was rejected, an admin submitting it
                    # should make it approved
                    for v in existing.exclude(
                            status=models.VIDEO_STATUS_ACTIVE):
                        v.user = request.user
                        v.status = models.VIDEO_STATUS_ACTIVE
                        v.when_approved = datetime.datetime.now()
                        v.save()
                    return HttpResponseRedirect(
                        reverse('localtv_submit_thanks',
                                args=[existing[0].pk]))
                else:
                    # pick the first approved video to point the user at
                    videos = existing.filter(status=models.VIDEO_STATUS_ACTIVE)
                    if videos.count():
                        video = videos[0]
                    else:
                        video = None
                    return render_to_response(
                        'localtv/submit_video/submit.html', {
                            'form':
                            forms.SubmitVideoForm(
                                construction_hint=construction_hint),
                            'was_duplicate':
                            True,
                            'video':
                            video
                        },
                        context_instance=RequestContext(request))

            scraped_data = util.get_scraped_data(
                submit_form.cleaned_data['url'])

            get_dict = {'url': submit_form.cleaned_data['url']}
            if 'construction_hint':
                get_dict['construction_hint'] = construction_hint
            if 'bookmarklet' in request.GET:
                get_dict['bookmarklet'] = '1'
            get_params = urllib.urlencode(get_dict)
            if scraped_data:
                if scraped_data.get('link', None) and \
                        scraped_data['link'] != get_dict['url']:
                    request.POST = {'url': scraped_data['link'].encode('utf8')}
                    # rerun the view, but with the canonical URL
                    return submit_video(request)

                if (scraped_data.get('embed')
                        or (scraped_data.get('file_url')
                            and not scraped_data.get('file_url_is_flaky'))):
                    return HttpResponseRedirect(
                        reverse('localtv_submit_scraped_video') + '?' +
                        get_params)

            # otherwise if it looks like a video file
            if is_video_url(submit_form.cleaned_data['url']):
                return HttpResponseRedirect(
                    reverse('localtv_submit_directlink_video') + '?' +
                    get_params)
            else:
                return HttpResponseRedirect(
                    reverse('localtv_submit_embedrequest_video') + '?' +
                    get_params)

        else:
            return render_to_response('localtv/submit_video/submit.html',
                                      {'form': submit_form},
                                      context_instance=RequestContext(request))