Example #1
0
def get_video(request):
    link = request.POST['link']
    if not link[:7] == 'http://':
        link = 'http://%s' % link
    if link.find('youtu.be') != -1:
        link = link.replace('youtu.be/', 'www.youtube.com/watch?v=')
    try:
        search_qs = Video.objects.filter(video_url=link)[0]
    except:
        search_qs = False
    if search_qs:
        payload = dict(success=False, location=search_qs.get_absolute_url())
    else:  # try:
        consumer = oembed.OEmbedConsumer()
        endpoint = get_oembed_end_point(link)
        consumer.addEndpoint(endpoint)
        response = consumer.embed(link)
        result = response.getData()
        result['html'] = update_video_size(result['html'], 500, 280)
        payload = {'success': True, 'data': result}
        #    except:
    #        payload = {'success': False}
    return AjaxLazyAnswer(payload)
Example #2
0
def get_video(request):
    link = request.POST['link']
    if not link[:7] == 'http://':
        link = 'http://%s' % link
    if link.find('youtu.be') != -1:
        link = link.replace('youtu.be/', 'www.youtube.com/watch?v=')
    try:
        search_qs = Video.objects.filter(video_url=link)[0]
    except:
        search_qs = False
    if search_qs:
        payload = dict(success=False, location=search_qs.get_absolute_url())
    else:  # try:
        consumer = oembed.OEmbedConsumer()
        endpoint = get_oembed_end_point(link)
        consumer.addEndpoint(endpoint)
        response = consumer.embed(link)
        result = response.getData()
        result['html'] = update_video_size(result['html'], 500, 280)
        payload = {'success': True, 'data': result}
        #    except:
    #        payload = {'success': False}
    return AjaxLazyAnswer(payload)
Example #3
0
 def form_valid(self, form):
     link = form.cleaned_data.get('video_url')
     if not link[:7] == 'http://':
         link = 'http://%s' % link
     if link.find('youtu.be') != -1:
         link = link.replace('youtu.be/','www.youtube.com/watch?v=')
     consumer = oembed.OEmbedConsumer()
     # TODO: more code security here - big chance to get fatal error
     endpoint = get_oembed_end_point(link)
     #
     consumer.addEndpoint(endpoint)
     response = consumer.embed(link)
     result = response.getData()
     obj = Video()
     obj.embedcode = result['html']
     obj.thumbnail = image_from_url(result['thumbnail_url'])
     if result.has_key('duration'):
         obj.duration = result['duration']
     obj.user = self.request.user
     obj.project_name = form.cleaned_data.get('project_name')
     obj.project_url = form.cleaned_data.get('project_url')
     obj.video_provider = get_video_provider_from_link(form.cleaned_data.get('video_url'))
     obj.publish = True
     obj.description = form.cleaned_data.get('description')
     obj.video_url = link
     obj.save()
     obj.slug = gen_shortcut(obj.id)
     tags = form.cleaned_data.get('tags')
     alltags = Tag.objects.all().filter(name__in=tags)
     for tag in tags:
         obj.tags.add(alltags.get(name=tag))
         obj.save()
     self.success_url = obj.get_absolute_url()
     action.send(self.request.user, verb=_('added the video'), action_type=ACTION_ADDED, target=obj,
         request=self.request)
     return super(VideoAdd, self).form_valid(form)
Example #4
0
 def form_valid(self, form):
     link = form.cleaned_data.get('video_url')
     if not link[:7] == 'http://':
         link = 'http://%s' % link
     if link.find('youtu.be') != -1:
         link = link.replace('youtu.be/', 'www.youtube.com/watch?v=')
     consumer = oembed.OEmbedConsumer()
     # TODO: more code security here - big chance to get fatal error
     endpoint = get_oembed_end_point(link)
     #
     consumer.addEndpoint(endpoint)
     response = consumer.embed(link)
     result = response.getData()
     obj = Video()
     obj.embedcode = result['html']
     obj.thumbnail = image_from_url(result['thumbnail_url'])
     if result.has_key('duration'):
         obj.duration = result['duration']
     obj.user = self.request.user
     obj.project_name = form.cleaned_data.get('project_name')
     obj.project_url = form.cleaned_data.get('project_url')
     obj.video_provider = get_video_provider_from_link(form.cleaned_data.get('video_url'))
     obj.publish = True
     obj.description = form.cleaned_data.get('description')
     obj.video_url = link
     obj.save()
     obj.slug = gen_shortcut(obj.id)
     tags = form.cleaned_data.get('tags')
     alltags = Tag.objects.all().filter(name__in=tags)
     for tag in tags:
         obj.tags.add(alltags.get(name=tag))
         obj.save()
     self.success_url = obj.get_absolute_url()
     action.send(self.request.user, verb=_('added the video'), action_type=ACTION_ADDED, target=obj,
                 request=self.request)
     return super(VideoAdd, self).form_valid(form)