Beispiel #1
0
def activity_top(aid):
    """获取结束时获奖视频(手动)

    :uri: activity/<string:aid>/manual/top
    :param page:
    :param nbr:
    :return: {'activity_videos': list, 'end_page': bool}
    """

    params = request.values
    page = int(params.get('page', 1))
    pagesize = int(params.get('nbr', 10))

    activity_videos = list()
    activity_config = ActivityConfig.get_one(str(aid), check_online=False)
    if not activity_config:
        return error.ActivityNotExist

    avids = ActivityVideo.get_manual_top(aid, page, pagesize)
    activity_videos.extend([
        a.format() for a in ActivityVideo.get_list(avids, check_online=False)
    ])
    return {
        'activity_videos': activity_videos,
        'end_page': len(avids) != pagesize
    }
Beispiel #2
0
def activity_top_videos(aid):
    """获取结束时获奖视频

    :uri: activity/<string:aid>/top/videos
    :param page: 页码
    :param nbr: 每页数量
    :returns: {'activity_videos': list, 'end_page': bool, 'activity_config': Object }
    """

    params = request.values
    page = int(params.get('page', 1))
    pagesize = int(params.get('nbr', 10))

    activity_videos = list()
    activity_config = ActivityConfig.get_one(str(aid), check_online=False)
    if not activity_config:
        return error.ActivityNotExist

    avids = ActivityVideo.top_video_end(aid, page, pagesize, activity_config)
    activity_videos.extend([a.format() for a in ActivityVideo.get_list(avids)])
    return {
        'activity_videos': activity_videos,
        'end_page': len(avids) != pagesize,
        'activity_config': activity_config.format()
    }
Beispiel #3
0
def activity_popular_videos(aid):
    """获取人气视频

    :uri: activity/<string:aid>/popular/videos
    :param page: 页码
    :param nbr: 每页数量
    :param device: 终端ID
    :returns: {'activity_videos': list, 'end_page': bool, 'activity_config': Object }
    """

    params = request.values
    page = int(params.get('page', 1))
    pagesize = int(params.get('nbr', 10))

    activity_videos = list()
    activity_config = ActivityConfig.get_one(str(aid), check_online=False)
    if not activity_config:
        return error.ActivityNotExist
    sort = activity_config.sort

    avids = ActivityVideo.popular_video_ids(aid, sort, page, pagesize)
    activity_videos.extend([v.format() for v in ActivityVideo.get_list(avids)])
    return {
        'activity_videos': activity_videos,
        'end_page': len(avids) != pagesize,
        'activity_config': activity_config.format()
    }
Beispiel #4
0
def latest_video(aid):
    """获取最新参赛视频

    :uri: activity/<string:aid>/video/current
    :param maxs: 最后时间, 0代表当前时间
    :param nbr: 每页数量
    :param device: 终端ID
    :returns: {'activity_videos': list, 'end_page': bool, 'activity_config': Object,
               'maxs': timestamp}
    """

    params = request.values
    maxs = params.get('maxs', None)
    maxs = time.time() if maxs is not None and int(
        float(maxs)) == 0 else maxs and float(maxs)
    pagesize = int(params.get('nbr', 10))

    activity_config = ActivityConfig.get_one(aid, check_online=False)
    if not activity_config:
        return error.ActivityNotExist

    avideos = list()
    avids = list()
    while len(avideos) < pagesize:
        avids = ActivityVideo.latest_video_ids(aid, pagesize, maxs)
        avideos.extend([v.format() for v in ActivityVideo.get_list(avids)])
        # 如果按照maxs分页, 不足pagesize个记录则继续查询
        if maxs is not None:
            obj = ActivityVideo.get_one(avids[-1]) if avids else None
            maxs = obj.create_at if obj else 1000
            if len(avids) < pagesize:
                break
        else:
            break
    return {
        'activity_videos': avideos,
        'end_page': len(avids) != pagesize,
        'activity_config': activity_config.format(),
        'maxs': maxs
    }
Beispiel #5
0
def search():
    """搜索 (GET|POST)

    :uri: /search
    :param type: 搜索类型{'all':全部, 'user':用户, 'game':游戏, 'video':视频,
                           'activity_video':活动视频, 'live_number':直播间房号}
    :param keyword: 关键字
    :returns: {'user':list, 'game':list, 'video':list}
    """
    ua = request.headers.get('User-Agent')
    params = request.values
    stype = params.get('type', 'all')
    keyword = params.get('keyword', '')
    keyword = keyword.strip()
    platform = params.get('os')
    version_code = params.get('version_code', 0)

    if not stype or not keyword:
        return error.InvalidArguments

    users = games = videos = activity_videos = lives = list()

    if stype in ['user', 'all']:
        uids = User.search(keyword)
        users = [u.format() for u in User.get_list(uids)]
        users = sorted(users, key=lambda x: x['follower_count'])

    if stype in ['game', 'all']:
        ua_filter = None
        if ua and platform == 'android' and int(version_code) >= 64:
            ua_filter = ua
        gids = Game.search(keyword, ua_filter)
        games = [g.format() for g in Game.get_list(gids, check_online=False)]

    if stype in ['video', 'all']:
        vids = Video.search(keyword)
        videos = [v.format() for v in Video.get_list(vids)]

    if stype in ['activity_video']:
        activity_id = params.get('activity_id', None)
        uids = User.search(keyword)
        _ids = ActivityVideo.get_activity_video_by_authors(uids, activity_id)
        avids = ActivityVideo.search(keyword, activity_id)
        avids.extend(_ids)
        activity_videos = [
            v.format() for v in ActivityVideo.get_list(set(avids))
        ]

    if stype in ['live_number', 'all']:
        uids = User.search_live_number(keyword)
        livers = [u.format() for u in User.get_list(uids)]
        livers = sorted(livers, key=lambda x: x['follower_count'])
        lives_map = {}
        for live in Xlive.get_all_lives():
            lives_map.update({live['user_id']: live})
        lives = list()
        ex_fields = ['user__is_followed', 'game__subscribed']
        for uid in uids:
            uid = str(uid)
            if uid in lives_map:
                ulive = Xlive.format(lives_map[uid], exclude_fields=ex_fields)
                lives.append({'live': ulive, 'user': None})
                continue
            lives.append({'live': None, 'user': User.get_one(uid).format()})

    return {
        'users': users,
        'games': games,
        'videos': videos,
        'activity_videos': activity_videos,
        'lives': lives
    }