예제 #1
0
파일: views.py 프로젝트: jama22/channel2
    def get(self, request, id, slug):
        video = get_object_or_404(Video, id=id)
        video.views += 1
        video.save()

        link = VideoLink.objects.create(
            video=video,
            key=binascii.hexlify(os.urandom(32)),
            ip_address=get_request_ip(request),
            created_by=request.user,
        )

        return redirect('video.link', key=link.key, slug=video.slug)
예제 #2
0
파일: views.py 프로젝트: jama22/channel2
    def get(self, request, key, slug):
        link = get_object_or_404(
            VideoLink.objects.select_related('video'),
            key=key,
        )

        if not link.video.file:
            email_alert('[Channel 2] Video File Missing', 'video/video-file-missing-alert.txt', {'video': link.video})
            return self.render_to_response({'message': self.messages['file_missing']})

        if link.ip_address != get_request_ip(request):
            return self.render_to_response({'message': self.messages['ip_address_mistmatch']})

        if timezone.now() - link.created_on > timezone.timedelta(seconds=VIDEO_LINK_EXPIRE):
            return self.render_to_response({'message': self.messages['link_expired']})

        return HttpResponseXAccel(link.video.file, content_type='video/mp4')