예제 #1
0
def del_client(session, client):
    c = Client.query.filter(Client.session_id == session, Client.id == client).first()

    db_session.delete(c)
    db_session.commit()

    return "", 200
예제 #2
0
def new_video(session):
    data = request.get_json()

    if "url" not in data or "forced" not in data:
        return error(errcodes.missing_parameters)

    v = Video.query.filter(Video.session_id == session,
            Video.url == data["url"]).first()
    if v is not None:
        return error(errcodes.resource_exists)

    v = Video(
            url=data["url"],
            forced=data["forced"],
            session_id=session,
    )

    # client validator
    if "client_id" in data:
        c = Client.query.filter(Client.session_id == session,
                Client.id == data["client_id"]).first()

        if c is None:
            return error(errcodes.not_found)

        v.client_id = c.id

        vcnt = Video.query.filter(Video.session_id == session,
                Video.client_id == data["client_id"]).count()
        ccnt = Client.query.filter(Client.session_id == session).count()

        if c.blocked:
            return error(errcodes.forbidden_temp)
        elif ccnt > 1 and vcnt >= 3:
            # block user
            c.blocked = True

            # add changes to db
            db_session.add(c)
            db_session.commit()

            return error(errcodes.forbidden_temp)

    def metafetcher(db_session, v):
        extract = NameExtractor(v.url).extract()
        v.title, v.related_url = extract
        db_session.add(v)
        db_session.commit()
    Thread(target=metafetcher, args=(db_session, v)).start()

    return jsonify(v.to_dict())
예제 #3
0
def del_video(session, video):
    v = Video.query.filter(Video.session_id == session, Video.id == video).first()

    db_session.delete(v);

    if v.client_id is not None and v.client.blocked is True:
        vcnt = Video.query.filter(Video.session_id == session,
                Video.client_id == v.client_id).count()
        if vcnt == 0:
            c = Client.query.filter(Client.id == v.client_id).first()
            c.blocked = False
            db_session.add(c)

    db_session.commit();

    return "", 200
예제 #4
0
def new_client(session):
    data = request.get_json()

    if "name" not in data:
        return error(errcodes.missing_parameter)

    c = Client.query.filter(Client.session_id == session, Client.name == data["name"]).first()
    if c is not None:
        return error(errcodes.resource_exists)

    c = Client(
            session_id=session,
            name=data["name"]
    )

    db_session.add(c)
    try:
        db_session.commit()
    except:
        return error(errcodes.internal)

    return jsonify(c.to_dict())
예제 #5
0
 def metafetcher(db_session, v):
     extract = NameExtractor(v.url).extract()
     v.title, v.related_url = extract
     db_session.add(v)
     db_session.commit()