def migu_user_videos(openid): """获取用户创建的视频 (GET) :uri: /migu/users/<string:openid>/videos/ :param game_id: 咪咕游戏id, 不传取用户所有游戏的视频 :param maxs: 最后时间, 0代表当前时间, 无此参数按page来分页 :param page: 页码(数据可能有重复, 建议按照maxs分页) :param nbr: 每页数量 :returns: {'videos': list, 'end_page': bool, '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) page = int(params.get('page', 1)) pagesize = int(params.get('nbr', 10)) bid = params.get('game_id', None) game = Game.get_by_bid(bid) gid = str(game._id) if game else None user = User.get_platform_user('migu', openid) if not user: return error.UserNotExist uid = str(user._id) videos = list() vids = list() while len(videos) < pagesize: if gid: vids = Video.user_game_video_ids(uid, gid, page, pagesize, maxs) else: vids = Video.user_video_ids(uid, page, pagesize, maxs) for video in Video.get_list(vids): game = Game.get_one(str(video.game)) # 过滤掉不是咪咕大厅游戏(游戏bid字段为空)的视频 if game and game.bid: videos.append(video.format()) # 如果按照maxs分页, 不足pagesize个记录则继续查询 if maxs is not None: obj = Video.get_one(vids[-1], check_online=False) if vids else None maxs = obj.create_at if obj else 1000 if len(vids) < pagesize: break else: break return {'videos': videos, 'end_page': len(vids) != pagesize, 'maxs': maxs}
def user_videos(uid): """获取用户创建的视频 (GET) :uri: /users/<string:uid>/videos :params game_id: 游戏id, 不传取用户所有游戏的视频 :param maxs: 最后时间, 0代表当前时间, 无此参数按page来分页 :param page: 页码(数据可能有重复, 建议按照maxs分页) :param nbr: 每页数量 :returns: {'videos': list, 'end_page': bool, '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) page = int(params.get('page', 1)) pagesize = int(params.get('nbr', 10)) gid = params.get('game_id', None) if gid and not Game.get_one(gid): return error.GameNotExist videos = list() vids = list() while len(videos) < pagesize: if gid: vids = Video.user_game_video_ids(uid, gid, page, pagesize, maxs) else: vids = Video.user_video_ids(uid, page, pagesize, maxs) ex_fields = [ 'is_favored', 'is_liked', 'author__is_followed', 'game__subscribed' ] videos.extend( [v.format(exclude_fields=ex_fields) for v in Video.get_list(vids)]) # 如果按照maxs分页, 不足pagesize个记录则继续查询 if maxs is not None: obj = Video.get_one(vids[-1], check_online=False) if vids else None maxs = obj.create_at if obj else 1000 if len(vids) < pagesize: break else: break return {'videos': videos, 'end_page': len(vids) != pagesize, 'maxs': maxs}