Пример #1
0
def search_v2():
    try:
        search_term = request.args.get('q')
        raw_html = get_search_results_html(search_term)
        vids = get_videos(raw_html)
        ret_vids = []
        for _ in vids:
            temp = get_video_attrs(_, removeLongResult=False)
            if temp:
                temp['get_url'] = '/api/v2' + temp['get_url']
                temp['stream_url'] = '/api/v2' + temp['stream_url']
                temp['suggest_url'] = temp['get_url'].replace(
                    'v2/g?', 'v1/suggest?', 1)
                ret_vids.append(temp)
        ret_dict = make_search_api_response(search_term, ret_vids,
                                            '/api/v2/search')
    except Exception as e:
        return make_error_response(msg=str(e), endpoint='/api/v2/search')

    return jsonify(ret_dict)
Пример #2
0
def search():
    """
    Search youtube and return results
    """
    try:
        search_term = request.args.get('q')
        raw_html = get_search_results_html(search_term)
        vids = get_videos(raw_html)
        ret_vids = []
        for _ in vids:
            temp = get_video_attrs(_)
            if temp:
                temp['get_url'] = '/api/v1' + temp['get_url']
                temp['stream_url'] = '/api/v1' + temp['stream_url']
                temp['suggest_url'] = temp['get_url'].replace('/g?', '/suggest?', 1)
                ret_vids.append(temp)
        ret_dict = make_search_api_response(search_term, ret_vids, '/api/v1/search')
    except Exception as e:
        logger.info(traceback.format_exc())
        return make_error_response(msg=str(e), endpoint='/api/v1/search')

    return jsonify(ret_dict)