Example #1
0
def video(request, videoid):
    try:
        video_info = s.getVideoInfo(videoid, True)
    except:
        raise Http404
    comments = None
    for ext in [".mp4", ".flv", ".ogv", ".webm"]:
        if ext in str(os.listdir(settings.MEDIA_ROOT+videoid)):
            break
    user_agent = request.META['HTTP_USER_AGENT'].lower()
    HLS = False
    for a in ['iphone', 'ipad', 'mac os', 'android']:
        if a in user_agent:
            HLS = True
            break
    context = {
        'videoid': videoid,
        'HLS': HLS,
        'ext': ext,
        'vi': video_info,
    }
    _check_login(request, context)
    if video_info[2] and request.session['access_token']:
        wb = sina.Weibo()
        wb.setToken(request.session['access_token'], request.session['expires_in'])
        context['comments'] = wb.getComment(video_info[2])
    context['liked'] = False
    if context['login_id']:
        login_id = int(context['login_id'])
        for v in s.getLikeVideo(login_id, True):
           if videoid == v[0]:
               context['liked'] = True
               break
    return render(request, 'video.html', context)
Example #2
0
def doadd(request):
    if request.session['access_token'] and request.session['expires_in']:
        userid = int(request.POST.get('userid'))
        videotitle = request.POST.get('videotitle').replace("'", "`").encode('utf-8')
        cateid = int(request.POST.get('category'))
        try:
            videopath = request.FILES['videopath']
        except:
            return HttpResponse('<html><head><META HTTP-EQUIV="refresh" CONTENT="3;URL=user/%s"></head>Please choose a video</html>' %userid)
        videoid = s.genFilename()
        videoname = videoid + "." + videopath._get_name().split(".")[1]
        os.system("mv %s /var/ftp/pub/%s;chmod 644 /var/ftp/pub/%s" %(videopath.temporary_file_path(), videoname, videoname))
        if not s.addTitle(userid, videoid, cateid, videotitle):
             return HttpResponse('<html><head><META HTTP-EQUIV="refresh" CONTENT="3;URL=user/%s"></head>Add video title failed\n%s</html>' \
             %(userid, str(userid)+","+videoid+","+videotitle))
        url = s.finishUpload(videoid)
        msg = videotitle + " " + burl + videoid
        snapshot = burl + videoid + "/" + videoid + ".jpeg"
        wb = sina.Weibo()
        wb.setToken(request.session['access_token'], request.session['expires_in'])
        try:
            ret = wb.post(msg, snapshot)
            s.shareVideo(videoid, ret.mid)
            message = "</br>Posted and link video on your weibo successfully"
        except:
            message = "</br>Failed to post on your weibo because of illegal words or snapshot doesnot exist"
        return HttpResponse('''<html><head><META HTTP-EQUIV="refresh" CONTENT="3;URL=user/%s"></head>
        Your video can be watched here: %s,%s</html>''' %(userid, url, message))
    else:
        return redirect('login')
Example #3
0
def addcomment(request):
    nc = request.POST['msg'][:140]
    mid = request.POST['mid']
    if request.session['access_token'] and nc and mid:
        wb = sina.Weibo()
        wb.setToken(request.session['access_token'], request.session['expires_in'])
        try:
            wb.addComment(nc, mid)
            return HttpResponse()
        except:
            pass
    return HttpResponse("Fail to add comment. Make sure thread exist and message legal.")
Example #4
0
def dologin(request):
    logined = 0
    ac = request.POST.get('account')
    pw = request.POST.get('password')
    site = request.POST.get('site')
    if site == 'sina':
        if '@' not in ac:
            ac += '@sina.com'
        wb = sina.Weibo()
        token = wb.auth(ac, pw)
        if token:
            wb.setToken(token[0], token[1])
            nickname, alink = wb.profile()
            logined = 1
    if logined:
        uid = s.loginUser(ac, site, nickname, alink)
        request.session['login_user'] = nickname
        request.session['login_id'] = uid
        request.session['access_token'] = token[0]
        request.session['expires_in'] = token[1]
        return HttpResponse('''<html><head><META HTTP-EQUIV="refresh" CONTENT="3;URL=user/%s"></head>
        You have logined as %s</html>''' %(request.session['login_id'], request.session['login_user']))
    else:
        return HttpResponse('''<html><head><META HTTP-EQUIV="refresh" CONTENT="3;URL=login"></head>login failed</html>''')