Exemple #1
0
def api_v2():
    method = request.args.get("method", None)
    success = True
    result = None

    '''
    {'file': {u'md': {u'video:category': u'comedy', u'video:duration': 6287L, u'video:description': u'asdf'}, u'c': -1, u'fs': datetime.datetime(2011, 4, 7, 7, 19, 49), 'name': u'http://www.veoh.com/veohplayer.swf?permalinkId=v19638583pbHaJywJ', u'src': {u'6d25345e0114c0424a06af6c': {u'url': u'http://www.veoh.com/watch/v19638583pbHaJywJ', u'm': 1, u't': 17, u'fn': {u'1361703869': {u'm': 1, u'l': 1}}, u'l': 1}, u'fe6d3bedce035eebe2a1e051': {u'url': u'http://www.veoh.com/veohplayer.swf?permalinkId=v19638583pbHaJywJ', u'm': 1, u't': 17, u'fn': {u'1361703869': {u'm': 1, u'l': 1}}, u'l': 1}}, u'bl': 0, u'tt': 1, u'm': 1, u's': 3, u'ls': datetime.datetime(2011, 4, 7, 7, 19, 49), u'_id': ObjectId('fe6d3bedce035eebe2a1e051'), 'id': '-m077c4DXuvioeBR', u'fn': {u'1361703869': {u'x': u'', 'c': 2, 'tht': 0, u'n': u'asdf'}}, u'ct': 2}, 'view': {'md': {}, 'file_type': 'video', 'source': u'veoh.com', 'url': '-m077c4DXuvioeBR', 'nfn': u'asdf', 'fnx': '', 'sources': {u'veoh.com': {'count': 2, 'join': False, 'tip': u'veoh.com', 'parts': [], 'urls': [u'http://www.veoh.com/watch/v19638583pbHaJywJ', u'http://www.veoh.com/veohplayer.swf?permalinkId=v19638583pbHaJywJ', u'magnet:?dn=asdf&'], 'icon': 'web'}}, 'efn': u'asdf', 'action': 'Download', 'fn': u'asdf', 'fnh': u'<strong>asdf</strong>'}}
    '''

    if method == "search":
        result = []
        files = search_files(request.args["q"], request.args)
        result = [{
            "size": f["file"]["z"] if "z" in f["file"] else 0,
            "type": f["view"]["file_type"],
            "link": url_for("files.download", file_id=f["view"]["url"], _external=True),
            "metadata": {k: (_api_v2_md_parser[k](v) if k in _api_v2_md_parser else v)
                for k, v in f["view"]["md"].iteritems()},
            } for f in (fill_data(file_data) for file_data in filesdb.get_files(get_ids(files), True))]
        success = True

    return jsonify(
        method = method,
        success = success,
        result = result)
Exemple #2
0
def search_ajax():
    arg=dict(request.args)
    query = request.args.get("q", None)
    result = search_files(query, request.args,int(request.args.get("page", 1))) or {"total_found":0,"total":0,"time":0}
    taming, dym = taming_search(query, request.args.get("type", None))
    try:
        tags = tags.next()
    except:
        tags = []

    files = [{
        "size": f["file"]["z"] if "z" in f["file"] else 0,
        "type": f["view"]["file_type"] if "file_type" in f["view"] else None,
        "link": url_for("files.download", file_id=f["view"]["url"], _external=True),
        "metadata": {k: (_api_v2_md_parser[k](v) if k in _api_v2_md_parser else v)
            for k, v in f["view"]["md"].iteritems()},

        "html": render_template('files_ajax/file_ajax.html',file=f)
        } for f in (fill_data(file_data,text=query) for file_data in filesdb.get_files(get_ids(result), True))]

    return jsonify(
        result=result,
        files=files,
        tags=render_template('files_ajax/tags.html',tags=tags),
        no_results=render_template('files_ajax/no_results.html',filters=_filters)
    )
Exemple #3
0
def search():
    '''
    Realiza una búsqueda de archivo
    '''

    # TODO: seguridad en param
    #si no se ha buscado nada se manda al inicio
    query = request.args.get("q", None)
    if not query:
        flash("write_something")
        return redirect(url_for("index.home"))

    #para evitar errores cuando en page no viene un número
    page = request.args.get("page", "1")
    if page.isdigit():
        page = int(page)
    else:
        abort(404)

    g.title = "%s - %s" % (query, g.title)
    results = {"total_found":0,"total":0,"time":0}

    didyoumean = None
    tags = None
    if 0 < page < 101:
        #obtener los tags y el quiso decir
        tags, dym = taming_search(query, request.args.get("type", None))

        #obtener los resultados y sacar la paginación
        profiler.checkpoint(opening=["sphinx"])
        results = search_files(query,request.args,page) or results
        ids = get_ids(results)
        profiler.checkpoint(opening=["mongo"], closing=["sphinx"])
        files_dict = {mid2hex(file_data["_id"]):fill_data(file_data, False, query) for file_data in get_files(ids)}
        profiler.checkpoint(opening=["visited"], closing=["mongo"])
        save_visited(files_dict.values())
        profiler.checkpoint(closing=["visited"])
        files=({"file":files_dict[bin2hex(file_id[0])], "search":file_id} for file_id in ids if bin2hex(file_id[0]) in files_dict)

        # recupera los resultados del taming
        try:
            tags = tags.next()
            didyoumean = dym.next()
        except:
            pass
    else:
        files = ()

    return render_template('files/search.html',
        results=results,
        search=request.args["q"].split(" "),
        files=files,
        pagination=Pagination(page, 10, min(results["total_found"], 1000)),
        didyoumean=didyoumean,
        tags=tags)
Exemple #4
0
def search():
    '''
    Realiza una búsqueda de archivo
    '''
    # TODO: seguridad en param
    #si no se ha buscado nada se manda al inicio
    query = request.args.get("q", None)
    if not query:
        flash("write_something")
        return redirect(url_for("index.home"))

    page = int(request.args.get("page", 1))
    g.title = query+" - "+g.title
    results = {"total_found":0,"total":0,"time":0}

    didyoumean = None
    tags = None
    if 0 < page < 101:
        #obtener los tags y el quiso decir
        taming = taming_search(current_app.config, query, request.args.get("type", None), contextg=g._get_current_object())

        #obtener los resultados y sacar la paginación
        profiler.checkpoint(opening=["sphinx"])
        results = search_files(query,request.args,page) or results
        ids = get_ids(results)
        profiler.checkpoint(opening=["mongo"], closing=["sphinx"])
        files_dict = {mid2hex(file_data["_id"]):fill_data(file_data, False, query) for file_data in get_files(ids)}
        profiler.checkpoint(opening=["visited"], closing=["mongo"])
        save_visited(files_dict.values())
        profiler.checkpoint(closing=["visited"])
        files=(files_dict[bin2hex(file_id[0])] for file_id in ids if bin2hex(file_id[0]) in files_dict)

        # recupera los resultados del taming
        try:
            tags = taming.next()
            didyoumean = taming.next()
        except:
            pass
    else:
        files = ()

    return render_template('files/search.html',
        results=results,
        search=request.args["q"].split(" "),
        files=files,
        pagination=Pagination(page, 10, min(results["total_found"], 1000)),
        didyoumean=didyoumean,
        tags=tags)
Exemple #5
0
def api_v1():
    method = request.args.get("method", None)
    results = ()
    success = False
    try:
        if method == "getSearch":
            files = search_files(request.args["q"], request.args)
            results = enumerate(fill_data(file_data) for file_data in filesdb.get_files(get_ids(files),True))
            success = True
    except BaseException as e:
        logging.debug(e)

    return render_template("api/v1.xml",
        api_method=method,
        results=results,
        success = success
        )