示例#1
0
def get_share_video(vid):
    """获取视频分享数据(GET)

    :uri: /share/video/<string:vid>
    :returns: {'video': object, 'hot_videos': list, 'comments': comments,
               'game_url': url, 'app_url': url}
    """
    video = Video.get_one(vid)
    if not video:
        return error.VideoNotExist

    cids = Comment.video_comment_ids(vid, 1, 10)
    comments = [c.format() for c in Comment.get_list(cids)]

    vids = Video.game_hotvideo_ids(str(video.game), 1, 10)
    videos = [v.format() for v in Video.get_list(vids)]

    video = video.format()

    _from = request.values.get('ywfrom', None)
    mgyxdt_url = 'http://g.10086.cn/s/clientd/?t=GH_JFDX'
    game_url = video['game'][
        'url'] if _from != 'miguyouxidating' else mgyxdt_url

    app_url = "http://video.cmgame.com/userfiles/wapapp/mgyw.apk"
    app_url = app_url if _from != 'miguyouxidating' else '#'

    return dict(video=video,
                hot_videos=videos,
                comments=comments,
                game_url=game_url,
                app_url=app_url)
示例#2
0
def show_channel_videos():
    """
    栏目频道视频列表
    :uri: /show/channel/videos
    :param: channel_id
    :param: page
    :param: nbr
    :return: {'videos': <Video>list, 'end_page': bool}
    """
    params = request.values
    channel_id = params.get('channel_id')
    page = int(params.get('page', 1))
    nbr = int(params.get('nbr', 10))

    if channel_id is None:
        return error.InvalidArguments

    channel = ShowChannel.get_one(channel_id)
    if not channel:
        return error.ShowChannelNotExist

    vids = Video.show_channel_ids(channel_id, page, nbr)
    videos = [v.format() for v in Video.get_list(vids)]

    return {'videos': videos, 'end_page': len(vids) != nbr}
示例#3
0
def latest_video():
    """获取最新视频 (GET)

    :uri: /videos/current/
    :param maxs: 最后时间, 0代表当前时间, 无此参数按page来分页
    :param page: 页码
    :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))

    videos = list()
    vids = list()
    while len(videos) < pagesize:
        vids = Video.latest_video_ids(page, pagesize, maxs)
        ex_fields = ['is_favored', '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}
示例#4
0
def editor_videos():
    """
    获取小编推荐视频(GET)

    :uri: /videos/editor_videos
    :return: {'videos': <Video>list}
    """

    _ids = EditorVideo.all_editor_video_ids()
    videos = Video.get_list(_ids)

    videos = [video.format() for video in videos] if videos else []

    return {'videos': videos}
示例#5
0
def topic_videos():
    """获取专题所有视频(GET)

    :uri: /videos/topic_videos
    :param: topic_id: 专题ID
    :param maxs: 最后时间, 0代表当前时间, 无此参数按page来分页
    :param page: 页码(数据可能有重复, 建议按照maxs分页)
    :param nbr: 每页数量
    :return: {'videos': <Video>list, 'end_page': bool, 'maxs': timestamp}
    """
    tid = request.values.get('topic_id', None)
    maxs = request.values.get('maxs', None)
    maxs = time.time() if maxs is not None and int(
        float(maxs)) == 0 else maxs and float(maxs)
    page = int(request.values.get('page', 1))
    pagesize = int(request.values.get('nbr', 10))

    if not tid:
        return error.InvalidArguments

    topic = VideoTopic.get_one(tid)
    if not topic:
        return error.VideoTopicNotExist
    topic = topic.format()

    videos = list()
    vids = list()
    while len(videos) < pagesize:
        vids = TopicVideo.topic_video_ids(tid, 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 = TopicVideo.get_by_ship(vids[-1], tid) if vids else None
            maxs = obj.create_at if obj else 1000
            if len(vids) < pagesize:
                break
        else:
            break

    return {
        'videos': videos,
        'topic': topic,
        'end_page': len(vids) != pagesize,
        'maxs': maxs
    }
示例#6
0
def game_videos(gid):
    """获取游戏的视频 (GET)

    :uri: /games/<string:gid>/videos
    :param maxs: 最后时间, 0代表当前时间, 无此参数按page来分页
    :param page: 页码(数据可能有重复, 建议按照maxs分页)
    :param nbr: 每页数量
    :param orderby: 排序方式 ('create_at': 创建时间, 'vv':播放次数)
    :returns: {'videos': list, 'end_page': bool, 'maxs': timestamp}
    """
    params = request.values
    orderby = params.get('orderby', 'create_at')
    maxs = params.get('maxs', None)
    if orderby == 'vv':
        maxs = 10000000 if maxs is not None and int(
            maxs) == 0 else maxs and int(maxs)
    else:
        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))

    videos = list()
    vids = list()
    while len(videos) < pagesize:
        if orderby == 'vv':
            vids = Video.game_hotvideo_ids(gid, page, pagesize, maxs)
        else:
            vids = Video.game_video_ids(gid, 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
            if orderby == 'vv':
                maxs = obj.vv if obj else -1
            else:
                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}
示例#7
0
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}
示例#8
0
def migu_game_popular_videos(bid):
    """获取游戏热门视频 (GET)

    :uri: /migu/games/<string:bid>/popular/
    :param page: 页码
    :param nbr: 每页数量
    :returns: {'videos': list, 'end_page': bool}
    """
    params = request.values
    page = int(params.get('page', 1))
    pagesize = int(params.get('nbr', 10))
    game = Game.get_by_bid(bid)
    if not game:
        return error.GameNotExist
    vids = Video.game_hotvideo_ids(str(game._id), page, pagesize)
    videos = [v.format() for v in Video.get_list(vids)]
    ret = {'videos': videos, 'end_page': len(vids) != pagesize}
    return ret
示例#9
0
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}
示例#10
0
def category_videos():
    """获取游戏下某个视频分类的所有视频(GET)

    :uri: /videos/category_videos
    :param: category_id: 分类ID
    :param: game_id: 游戏ID
    :param maxs: 最后时间, 0代表当前时间, 无此参数按page来分页
    :param page: 页码(数据可能有重复, 建议按照maxs分页)
    :param nbr: 每页数量
    :return: {'videos': <Video>list, 'end_page': bool, 'maxs': timestamp}
    """
    cid = request.values.get('category_id', None)
    gid = request.values.get('game_id', None)
    maxs = request.values.get('maxs', None)
    maxs = time.time() if maxs is not None and int(
        float(maxs)) == 0 else maxs and float(maxs)
    page = int(request.values.get('page', 1))
    pagesize = int(request.values.get('nbr', 10))

    if not cid or not gid:
        return error.InvalidArguments

    videos = list()
    vids = list()
    while len(videos) < pagesize:
        vids = CategoryVideo.category_game_video_ids(cid, gid, 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}
示例#11
0
def sub_game_videos(uid):
    """获取用户已订阅游戏的视频 (GET)

    :uri: /users/<string:uid>/subscriptions
    :returns: {'videos': list}
    """
    gids = UserSubGame.sub_game_ids(uid)
    games = Game.get_list(gids)
    ret = []
    for game in games:
        vids = Video.game_video_ids(str(game._id), 1, 4, time.time())
        ex_fields = [
            'is_favored', 'is_liked', 'author__is_followed', 'game__subscribed'
        ]
        videos = [
            v.format(exclude_fields=ex_fields) for v in Video.get_list(vids)
        ]
        ret.append({'game': game.format(), 'videos': videos})
    return {'videos': ret}
示例#12
0
def game_popular_videos(gid):
    """获取游戏人气视频 (GET)

    :uri: /games/<string:gid>/videos
    :param page: 页码
    :param nbr: 每页数量
    :returns: {'videos': list, 'end_page': bool}
    """
    params = request.values
    page = int(params.get('page', 1))
    pagesize = int(params.get('nbr', 10))

    videos = list()
    vids = Video.game_hotvideo_ids(gid, page, pagesize)
    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)])
    return {'videos': videos, 'end_page': len(vids) != pagesize}
示例#13
0
def tags_videos(cid):
    """获取标签下所有视频 (GET)

    :uri: /tags/<string:tid>/videos
    :uri migu: /migu/tags/<string:tid>/videos/
    :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))
    gids = CategoryGame.category_game_ids(cid)
    gids = [ObjectId(_gid) for _gid in gids]

    videos = list()
    vids = list()
    while len(videos) < pagesize:
        vids = Video.games_video_ids(gids, 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}
示例#14
0
def user_followings_videos(uid):
    """获取用户偶像的视频 (GET&LOGIN)

    :uri: /users/<string:uid>/followings/videos
    :param maxs: 最后时间, 0代表当前时间, 无此参数按page来分页
    :param page: 页码(数据可能有重复, 建议按照maxs分页)
    :param nbr: 每页数量
    :returns: {'videos': list, 'end_page': bool, 'maxs': timestamp}
    """
    params = request.values
    user = request.authed_user
    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)
    uids = FriendShip.following_ids(str(user._id))
    uids = [ObjectId(_uid) for _uid in uids]

    videos = list()
    vids = list()
    while len(videos) < pagesize:
        vids = Video.users_video_ids(uids, gid, page, pagesize, maxs)
        ex_fields = ['is_favored', '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]) 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}
示例#15
0
def favor_videos(uid):
    """获取用户收藏的视频 (GET)

    :uri: /users/<string:uid>/favors
    :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))

    videos = list()
    vids = list()
    while len(videos) < pagesize:
        vids = UserFaverVideo.faver_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 = UserFaverVideo.get_by_ship(uid, vids[-1]) 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}
示例#16
0
def compete_videos(aid):
    """获取可参赛视频(GET&LOGIN)

    :uri: /activity/<string:aid>/compete_videos
    :param page: 页数
    :param nbr: 每页数量
    :return: {'videos': list, 'max_video': int, 'end_page': bool}
    """
    params = request.values
    user = request.authed_user
    page = int(params.get('page', 1))
    pagesize = int(params.get('nbr', 10))

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

    activity_videos = ActivityVideo.user_compete_video_ids(aid, str(user._id))
    avids = [a['video_id'] for a in activity_videos]

    videos = list()
    gids = GameActivity.game_activity_ids(aid)
    gids = [ObjectId(_gid) for _gid in gids]

    vids = Video.activity_video_ids(str(user._id), pagesize, page, gids,
                                    activity_config)
    vids = [vid for vid in vids]
    videos.extend([v.format() for v in Video.get_list(vids)])
    # 允许参赛最大视频数
    max_video = activity_config.max_video - len(avids)

    return {
        'videos': videos,
        'end_page': len(vids) != pagesize,
        'max_video': max_video
    }
示例#17
0
def migu_elite_video():
    """获取精选视频 (GET)

    :uri: /migu/videos/elite/
    :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))

    videos = list()
    vids = list()
    while len(videos) < pagesize:
        vids = Video.elite_video_ids(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.release_time if obj else 1000
            if len(vids) < pagesize:
                break
        else:
            break

    return {'videos': videos, 'end_page': len(vids) != pagesize, 'maxs': maxs}
示例#18
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
    }
示例#19
0
def home():
    """获取首页信息 (GET)

    :uri: /home
    :param os: 平台
    :param channels: 渠道(可选)
    :param version_code: 版本号
    :returns: {'banners': list, 'categories': list,
               'sub_games': list, 'hot_games': list,
               'hot_lives': list}
    """
    user = request.authed_user
    ret = dict()

    # banner广告
    params = request.values
    os = params.get('os', None)
    channels = params.get('channels', None)
    version_code = int(params.get('version_code', 0))

    no_gamefy = False  # 不返回游戏风云视频及内容
    if not os or not version_code:
        no_gamefy = True
    elif (os == 'ios' and version_code < 5920) or (os == 'android'
                                                   and version_code < 416):
        no_gamefy = True

    uid = None
    province = None
    if user:
        uid = str(user._id)
        phone = str(user.phone)

        if user.province:
            province = user.province

        if not user.province and util.is_mobile_phone(phone):
            province = Migu.get_user_info_by_account_name(phone)
            if not isinstance(province, error.ApiError):
                user.update_model({'$set': {'province': province}})
            else:
                province = None
    banners = list()
    _ids = Banner.all_banner_ids()
    for b in Banner.get_list(_ids):
        if b.os and b.os != os:
            continue
        if (b.version_code_mix and b.version_code_mix > version_code) or \
                (b.version_code_max and b.version_code_max < version_code):
            continue
        if channels and b.channels and channels not in b.channels:
            continue
        if b.login == 'login' and (not uid
                                   or not b.user_in_group(str(b.group), uid)):
            continue
        if b.province and province and province not in b.province:
            continue
        banners.append(b.format())

    if version_code == 0 and not banners:
        _ids = Banner.all_banners_by_version()
        banners = [b.format() for b in Banner.get_list(_ids)]
    ret['banners'] = banners

    support_cates = ['video', 'game', 'user', 'show-video']
    if no_gamefy:
        support_cates.pop(-1)
    categories = []
    cate_ids = HomeCategory.all_category_ids()
    cates = HomeCategory.get_list(cate_ids)
    for cate in cates:
        ids = HomeCategoryConfig.category_object_ids(str(cate._id))
        if not ids or cate.ctype not in support_cates:
            continue
        _category = cate.format()
        if cate.ctype in ['video', 'show-video']:
            ex_fields = [
                'is_favored', 'is_liked', 'author__is_followed',
                'game__subscribed'
            ]
            if no_gamefy:
                _category['objects'] = [
                    v.format(exclude_fields=ex_fields)
                    for v in Video.get_list(ids) if v.author
                ]
            else:
                _category['objects'] = [
                    v.format(exclude_fields=ex_fields)
                    for v in Video.get_list(ids)
                ]
        elif cate.ctype == 'game':
            ex_fields = ['subscribed']
            _category['objects'] = [
                g.format(exclude_fields=ex_fields) for g in Game.get_list(ids)
            ]
        elif cate.ctype == 'user':
            ex_fields = ['is_followed']
            _category['objects'] = [
                u.format(exclude_fields=ex_fields) for u in User.get_list(ids)
            ]
        _category['objects'] = _category['objects'][:4]
        categories.append(_category)
    ret['categories'] = categories

    # 兼容老版本
    ret['hottest_of_today'] = []

    # 热门直播
    all_lives = Xlive.get_all_lives()
    hot_lives = all_lives[:4] if len(all_lives) >= 4 else all_lives[:2]
    hot_lives = hot_lives if len(hot_lives) > 1 else []
    ret['hot_lives'] = [Xlive.format(l) for l in hot_lives]

    # 用户已订阅游戏
    sub_game_ids = []
    if user:
        sub_game_ids = UserSubGame.sub_game_ids(str(user._id))
        tmp = []
        for game_id in sub_game_ids:
            ex_fields = [
                'is_favored', 'is_liked', 'author__is_followed',
                'game__subscribed'
            ]
            vids = GameRecommendVideo.game_video_ids(game_id) or []
            videos = [
                v.format(exclude_fields=ex_fields)
                for v in Video.get_list(vids)
            ]
            # 补齐4个人气视频
            if len(videos) < 4:
                hot_vids = Video.game_hotvideo_ids(game_id, 1, 4)
                for _vid in hot_vids:
                    if len(videos) == 4:
                        break
                    if _vid in vids:
                        continue
                    v = Video.get_one(_vid, check_online=True)
                    v and videos.append(v.format(exclude_fields=ex_fields))
            if videos:
                tmp.append({'game': videos[0]['game'], 'videos': videos})
    else:
        tmp = list()
    ret['sub_games'] = tmp

    # 热门游戏
    gids = HotGame.hot_game_ids()
    # 去掉用户已订阅游戏
    gids = [gid for gid in gids if gid not in sub_game_ids]
    tmp = []
    for game_id in gids:
        ex_fields = [
            'is_favored', 'is_liked', 'author__is_followed', 'game__subscribed'
        ]
        vids = GameRecommendVideo.game_video_ids(game_id) or []
        videos = [
            v.format(exclude_fields=ex_fields) for v in Video.get_list(vids)
        ]
        # 补齐4个人气视频
        if len(videos) < 4:
            hot_vids = Video.game_hotvideo_ids(game_id, 1, 4)
            for _vid in hot_vids:
                if len(videos) == 4:
                    break
                if _vid in vids:
                    continue
                v = Video.get_one(_vid, check_online=True)
                v and videos.append(v.format(exclude_fields=ex_fields))
        if videos:
            tmp.append({'game': videos[0]['game'], 'videos': videos})
    ret['hot_games'] = tmp

    return ret
示例#20
0
def share_page(vid):
    video = Video.get_one(vid)
    if not video:
        abort(404)

    cids = Comment.video_comment_ids(vid, 1, 10)
    comments = [c.format() for c in Comment.get_list(cids)]

    vids = Video.game_hotvideo_ids(str(video.game), 1, 10)
    recommend_videos = [v.format() for v in Video.get_list(vids)]

    video = video.format()
    _from = request.values.get('ywfrom', None)
    mgyxdt_url = 'http://g.10086.cn/s/clientd/?t=GH_JFDX'
    download_url = video['game'][
        'url'] if _from != 'miguyouxidating' else mgyxdt_url
    video_dict = {
        "nick_name": video['author'] and video['author']['nickname'],
        "user_logo": video['author'] and video['author']['logo'],
        "title": video['title'],
        "description": video['title'],
        "created_time": stamp_str(video['create_at']),
        "url": str(video['url']),
        "image_url": str(video['cover']),
        "favour": video.get("like_count", "0"),
        "comment": video['comment_count'],
        "vv": video['vv'],
        "game_download_url": download_url,
        "game_logo": video['game'] and video['game']['icon'],
        "game_name": video['game'] and video['game']['name'],
        "game_description": video['game'] and video['game']['description'],
        "game_video_count": video['game'] and video['game']['video_count'],
        "app_logo": video['game']['icon'],
    }

    comments_list = []
    for c in comments:
        comments_list.append({
            "nick_name":
            c['author'] and c['author']['nickname'],
            "user_icon":
            c['author'] and c['author']['logo'],
            "created_at":
            stamp_str(c['create_at']),
            "content":
            c['content'],
            "favour":
            c['like']
        })

    recommend_videos_list = []
    for v in recommend_videos:
        recommend_videos_list.append({
            "share_url": v['share_url'],
            "title": v['title'],
            "image_url": v['cover'],
            "video_id": v['video_id'],
            "vv": v['vv']
        })

    return render_template("share.html",
                           static_url=app.config['STATIC_URL'],
                           video=video_dict,
                           comments=comments_list,
                           recommends=recommend_videos_list,
                           ywfrom=_from)
示例#21
0
def share_top_videos():
    """
    获取分享页视频(GET)

    :uri: /videos/share_top_videos
    :return: {'videos': <Video>list}
    """
    video_id = request.values.get('video_id', None)
    user_id = request.values.get('user_id', None)

    result = []
    if user_id:
        lives = Xlive.get_user_lives(user_id)
        live = lives[0] if lives else None

        if live:
            game_id = live['game_id']
        else:
            _ids = Event.get_history_live(user_id)
            _id = _ids[0] if _ids else None
            live = Event.get_event(_id) if _id else None
            game_id = live.game_id if live else None

        # 获取正在生成的回放视频
        event_ids = Redis.keys(pattern='task:l2v*')
        if event_ids:
            for event_id in event_ids:
                event_id = event_id[9:]
                live = Xlive.get_event(event_id)
                if live['user_id'] != user_id:
                    continue

                if live['game_id'] != game_id:
                    continue

                if len(result) >= 4:
                    continue

                result.append(live)

        if len(result) < 4:
            pagesize = 4 - len(result)

            video_ids = Video.game_userlive_video_ids(user_id, game_id, 1,
                                                      pagesize)

            videos = Video.get_list(video_ids)

            videos = [video.format() for video in videos] if videos else []

            result += videos

    if video_id:
        video = Video.get_one(video_id)
        if video:
            video = video.format()

        game = video['game'] if video else None

        game_id = game['game_id'] if game else None

        video_ids = Video.game_nolive_video_ids(game_id, 1, 4)

        videos = Video.get_list(video_ids)

        result = [
            video.format() for video in videos
            if video.format()['event_id'] is None
        ] if videos else []

    return {'videos': result}