Ejemplo n.º 1
0
def video(request, video_id):
    video = get_object_or_404(Video, video_id=video_id)
    video.view_count += 1
    video.save()
    # TODO: make this more pythonic, prob using kwargs
    context = widget.js_context(request, video, False, None, False, None, 
                                'autosub' in request.GET)
    context['video'] = video
    context['site'] = Site.objects.get_current()
    return render_to_response('videos/video.html', context,
                              context_instance=RequestContext(request))
Ejemplo n.º 2
0
def embed(request):
    if 'video_id' in request.GET:
        video = models.Video.objects.get(video_id=request.GET['video_id'])
    elif 'youtube_videoid' in request.GET:
        youtube_videoid = request.GET['youtube_videoid']
        try:
            video = models.Video.objects.get(youtube_videoid=youtube_videoid)
        except models.Video.DoesNotExist:
            video = models.Video(video_type=models.VIDEO_TYPE_YOUTUBE,
                                 youtube_videoid=youtube_videoid,
                                 allow_community_edits=False)
            video.save()
    else:
        video_url = request.GET['video_url']
        try:
            video = models.Video.objects.get(video_url=video_url)
        except models.Video.DoesNotExist:
            video = models.Video(video_type=models.VIDEO_TYPE_HTML5,
                                 video_url=video_url,
                                 allow_community_edits=False)
            video.save()
    video.widget_views_count += 1
    video.save()
    
    null_widget = 'null' in request.GET
    debug_js = 'debug_js' in request.GET
    if 'element_id' in request.GET:
        element_id = request.GET['element_id']
    else:
        element_id = None
    if 'autoplay' in request.GET:
        autoplay = request.GET['autoplay']
    else:
        autoplay = None
    return render_to_response('widget/embed.js', 
                              widget.js_context(request, video, 
                                                null_widget, element_id, 
                                                debug_js, autoplay),
                              mimetype="text/javascript",
                              context_instance = RequestContext(request))