def check_vimeo_status(sender, instance, **kwargs): from video.rest.vimeoPy import VimeoClient if not instance.is_viewable: vimeoClient = VimeoClient(settings.VIMEO_API_KEY, settings.VIMEO_API_SECRET) rsp = vimeoClient.call("vimeo.videos.checkUploadStatus", {"ticket_id": instance.ticket_id} ) if(rsp.attributes['stat'].value=="ok"): data = rsp.getElementsByTagName("ticket")[0] if data.attributes['is_uploading'].nodeValue=="0": if data.attributes['is_uploading'].nodeValue=="0": rsp = vimeoClient.call("vimeo.videos.getThumbnailUrl", {"video_id": instance.external_id, "size":"160x120"} ) thumbnail_url = rsp.getElementsByTagName("thumbnail")[0].childNodes[0].nodeValue instance.thumbnail_url = thumbnail_url instance.is_viewable = True instance.save()
def vimeo_callback(request, template_name='video/vimeo_auth_callback.html'): if(request.GET['frob']): vimeoClient = VimeoClient(settings.VIMEO_API_KEY, settings.VIMEO_API_SECRET) rsp = vimeoClient.call('vimeo.auth.getToken', {'frob': request.GET['frob']}) if(rsp.attributes['stat'].value == 'ok'): token = rsp.getElementsByTagName("token")[0].childNodes[0].nodeValue VimeoToken.objects.all().delete(); vimeoToken = VimeoToken(name="mainAccount", token=token) vimeoToken.save() return render_to_response(template_name, { "success":True }, context_instance=RequestContext(request)) else: return render_to_response(template_name, { "success":False }, context_instance=RequestContext(request))
def vimeo_save_video(request, ticketId): vimeoClient = VimeoClient(settings.VIMEO_API_KEY, settings.VIMEO_API_SECRET) rsp = vimeoClient.call('vimeo.videos.checkUploadStatus', {'ticket_id': ticketId}) if(rsp.attributes['stat'].value=="ok"): id = rsp.getElementsByTagName("ticket")[0].attributes["video_id"].value video = Video(creator= request.user, import_url="http://vimeo.com/"+id, imported=False, thumbnail_url="", title="", ) return render_to_response("video/failed_ticket.html", { }, context_instance=RequestContext(request)) else: return render_to_response("video/failed_ticket.html", { }, context_instance=RequestContext(request))
def upload_video(request, template_name='video/upload.html'): if request.method == 'POST': form = VideoForm(request.POST, request.FILES) if form.is_valid(): vimeoClient = VimeoClient(settings.VIMEO_API_KEY, settings.VIMEO_API_SECRET) tempVideo = open(tempfile.mktemp(".AVI"), 'wb+') for chunk in form.files['video'].chunks(): tempVideo.write(chunk) try: ticked_id = vimeoClient.upload(tempVideo.name) except Exception, inst: mail_admins("Error Uploading Video", "Vimeo Video konnte nicht hochgeladen werden: "\ +str(inst.args)) return render_to_response("video/upload_error.html", { }, context_instance=RequestContext(request)) tempVideo.close() if ticked_id: video_id = vimeoClient.check_upload_status(ticked_id) if video_id: #get thumbnail url rsp = vimeoClient.call("vimeo.videos.getThumbnailUrl", {"video_id": video_id, "size":"160x120"} ) thumbnail_url = rsp.getElementsByTagName("thumbnail")[0]\ .childNodes[0].nodeValue #set the values video = Video(creator=request.user, import_url="http://vimeo.com/"+video_id, was_uploaded=True, is_viewable=False, external_id=video_id, ticket_id=ticked_id, comment=form.cleaned_data['comment'], title=form.cleaned_data['title'], tags=form.cleaned_data['tags'], thumbnail_url=thumbnail_url ) video.save(); rsp = vimeoClient.call("vimeo.videos.setTitle", { "title": form.cleaned_data['title'], "video_id": video_id } ) if(rsp.attributes['stat'].value!="ok"): mail_admins("Error", "Vimeo Titel konnte nicht gesetzt werden:\ Video_id: "+str(video.pk)) rsp = vimeoClient.call("vimeo.videos.setCaption", { "caption": form.cleaned_data['comment'], "video_id": video_id } ) if(rsp.attributes['stat'].value!="ok"): mail_admins("Error", "Vimeo Caption konnte nicht gesetzt werden:\ Video_id: "+str(video.pk)) rsp = vimeoClient.call("vimeo.videos.setPrivacy", {"privacy": "anybody", "video_id": video_id} ) if(rsp.attributes['stat'].value!="ok"): mail_admins("Error", "Vimeo Privacy konnte nicht gesetzt werden:\ Video_id: "+str(video.id)) if form.cleaned_data['tags']: tags = parse_tag_input(video.tags) tags = ",".join(tags) rsp = vimeoClient.call("vimeo.videos.addTags", {"tags": tags, "video_id": video_id} ) if(rsp.attributes['stat'].value!="ok"): mail_admins("Error", "Vimeo Tags konnten nicht gesetzt \ werden: Video_id: "+str(video.id)) return render_to_response("video/upload_success.html", { "video": video, }, context_instance=RequestContext(request)) # an error has occurred return render_to_response("video/upload_error.html", { }, context_instance=RequestContext(request)) else: request.user.message_set.create(message=_("Video '%s' was \ successfully uploaded!") % video.title) return HttpResponseRedirect(reverse('show_video', args=(video.id,)))