Ejemplo n.º 1
0
def do_task(worker, job):
    from wanx.base.log import print_log
    from wanx.base import const
    from wanx.models.video import Video
    from wanx.models.user import User
    from wanx.models.game import Game
    data = job.data
    # 记录日志
    print_log('create_live_video', data)

    data = json.loads(data)
    # 记录日志
    print_log('create_live_video',
              '%s ==========================> Start' % (data['event_id']))

    user = User.get_one(data['user_id'], check_online=False)
    if not user:
        return ''

    game = Game.get_one(data['game_id'], check_online=False)
    if not game:
        return ''

    video_id = Video.get_video_by_event_id(data['event_id'], str(user._id))
    video = Video.get_one(str(video_id), check_online=False)

    if not video:
        video = Video.init()
        video.author = ObjectId(data['user_id'])
        video.game = ObjectId(data['game_id'])
        video.title = data['title']
        video.duration = data['duration']
        video.ratio = data['ratio']
        video.cover = data['cover']
        video.url = data['url']
        video.event_id = data['event_id']
        video.status = const.ONLINE
        video.create_model()
    else:
        data['author'] = ObjectId(data.pop('user_id'))
        data['game'] = ObjectId(data.pop('game_id'))
        video.update_model({'$set': data})

    # 记录日志
    print_log('create_live_video',
              '%s ==========================> Finished' % (data['event_id']))

    from wanx.models.activity import Battle
    battle = Battle.get_live_battle(
        data['user_id'],
        data['title'].decode('unicode-escape').encode('utf-8'), None)
    if battle:
        Battle.set_video_id(battle['_id'], video_id)

    return ''
Ejemplo n.º 2
0
def get_video_id():
    """通过直播间id获取视频(GET)

    :uri: /videos/event_id
    :param: event_id: 直播间id
    :return: {'video': Object}
    """
    uid = request.authed_user and str(request.authed_user._id)
    eid = request.values.get('event_id', None)
    if not eid:
        return error.LiveError("直播间id不存在")

    vid = Video.get_video_by_event_id(eid, uid=uid)
    video = Video.get_one(vid)
    if not video:
        return error.VideoNotExist

    return {'video': video.format()}