Exemple #1
0
def apiServiceVideo(id=None):
    funMap = {'GET':db_video.get_all, 'DELETE':''}
    if 'username' in session and request.is_xhr:
        doc_return = {}
        if request.method == 'GET':
            if id == None:
                #doc = request
                db_return = db_video.get_all()
                doc_count = db_video.count()
                for doc in db_return: doc['_id']=doc.eid;
                doc_return = {'count':doc_count,'result':db_return}
                #print doc_return
            else:
                db_return = db_video.get(id)
                db_return['_id']=db_return.eid
                doc_return = {'result':[db_return]}
        elif request.method == 'POST':
            doc = request.get_json(force=True)
            db_video.add_video(doc)
            doc_return = {'result':{'status':'ok'},}
        elif request.method == 'DELETE':
            db_video.remove(id)
            doc_return = {'result':{'status':'ok','_id':id},}
        
        return jsonify(doc_return)
    elif request.is_xhr:
        return "{'result':{'status':'error','message':'login is required'}}"
    else:
        return redirect(url_for('login'))
Exemple #2
0
def download_video_info(video):
    if video['url'] != None:
        try:
            ydl = youtube_dl.YoutubeDL({})
            video_info = ydl.extract_info(video['url'],download=False)
            db_video.add_video(video_info)
            db_queue.remove(video.eid)
        except:
            print 'error in getting video info'