Exemplo n.º 1
0
def get_openid_by_uuid(uuid=0, uin=0):
    #need ask them l5.
    udp_client = UDPClient(host='10.239.196.159', port=15000)
    try:
        qt = QtHelper()
        sess = qt.createSessInfo(pb_openid.CMD_TICKETSVR,
                                 pb_openid.SUBCMD_PARSE_ID, 8031, uin)

        req = pb_openid.ParseIdReq()
        req.ids.extend([uuid])

        res = qt.buildSendPkg(sess, req)

        udp_client.sendData(buf=res.serialize())
        bb = udp_client.recvData()

        resp = qt.parseReceivePkg(bb)
        resp.unserialize()
        resp_str = str(buffer(resp.body_str)[:])
        pb_resp = pb_openid.ParseIdRsp()
        pb_resp.ParseFromString(resp_str)

        return pb_resp
    except:
        logger.error('get error:%s' % traceback.format_exc())
    finally:
        udp_client.close()
Exemplo n.º 2
0
def fetch_job(game_id=1007039):
    fetcher.info('start fetch job,gameid:%s...' % game_id)
    host, port = get_router(modid, cmdid)
    if not (host and port):
        print 'l5 get error'
        return

    udp_client = UDPClient(host=host, port=port)
    hero_adjuster = HeroAdjuster(udp_client)
    b = BaseDao()
    video_dao = Video(b)
    batch = 5
    batch_num = 10
    from_num = 0
    try:
        obj_arr = hero_adjuster.adjust(batch=batch,
                                       batch_num=batch_num,
                                       from_num=from_num,
                                       game_id=game_id)
        for item in obj_arr:
            video_dao.add_item(item)
            video_dao.add_video_game(item['vid'], game_id)

        fetcher.info('fetch job finish, game_id:%s' % game_id)
    except:
        fetcher.info('fetch job error:%s, game_id:%s' %
                     (traceback.format_exc(), game_id))
    finally:
        udp_client.close()
        b.close()
Exemplo n.º 3
0
def update_job(game_id=1007039):
    host, port = get_router(modid, cmdid)
    if not (host and port):
        print 'l5 get error'
        return
    b = BaseDao()
    video_dao = Video(b)
    udp_client = UDPClient(host=host, port=port)

    try:
        updater.info('start update job...')
        up = Updater(video_dao, udp_client)
        up.update_url(game_id=game_id)
        updater.info('update job finish.')
    except:
        exstr = traceback.format_exc()
        updater.error('update job error:%s' % exstr)
    finally:
        udp_client.close()
        b.close()
Exemplo n.º 4
0
    def _get_download_url(self, vid, game_id):
        if not (vid and game_id):
            logger.error('need game_id vid')
            return ''
        from lib.config import read_l5_info
        from transport.client import UDPClient
        from l5.get_router import get_router
        from adjuster.adjuster_tool import get_download_info_req

        udp_client = None
        try:
            modid, cmdid = read_l5_info()
            host, port = get_router(modid, cmdid)
            if not (host and port):
                logger.error('l5 get error')
                raise Exception('l5 get error')

            udp_client = UDPClient(host=host, port=port)

            resp = get_download_info_req(vid=vid.encode("utf-8"),
                                         game_id=int(game_id),
                                         udp_client=udp_client)
            if not resp:
                logger.warning('vid:%s download info is null.' % vid)
                return ''
            if len(resp.ul) and len(resp.cl):
                url = resp.ul[0]
                cl = resp.cl[0]
                v_url = '%s%s?vkey=%s' % (url.url, resp.fn, cl.vkey)

                return v_url
        except:
            logger.error(traceback.format_exc())
        finally:
            if udp_client:
                udp_client.close()

        return ''
Exemplo n.º 5
0
def test_my_video():
    from busi.dao.base import BaseDao
    from busi.dao.data import Video

    import time

    t = time.localtime(time.time())
    time1 = time.mktime(time.strptime(time.strftime('%Y-%m-%d 00:00:00',
                                                    t),'%Y-%m-%d %H:%M:%S'))
    #ts = long(time1)
    ts = 1519660800

    modid,cmdid = read_l5_info()
    host,port = get_router(modid, cmdid)
    if not (host and port):
        print 'l5 get error'
        sys.exit(1)
    udp_client = UDPClient(host=host, port=port)
    hero_adjuster = HeroAdjuster(udp_client)
    #resp = get_openid_by_uuid(uuid='LA-o6zB8wQxpM_kk0ns29fqsMh4s3lo')
    #print resp
    b = BaseDao()
    video_dao = Video(b)
    try:
        #obj_arr = hero_adjuster.adjust(game_id=1007039)
        obj_arr, t1, t2 = hero_adjuster.get_my_videos(game_id=1007058,uin=289296918, batch_num=50)
        #obj_arr, t1, t2 = hero_adjuster.get_my_videos(game_id=1007058,openid='o6zB8wT0AIXgl6EFGS2sxzFsWyFg')
        for obj in obj_arr:
            print obj
            #if obj['share_time'] >= ts:
            #    video_dao.add_item(obj)
            #    video_dao.add_video_game(obj['vid'], 1007039)
        print t1, t2
    except:
        print traceback.format_exc()
    finally:
        udp_client.close()
Exemplo n.º 6
0
    def get_videos_by_batch_users(self, batch_num=5, game_ids=None, appid='wx9ce8f64a4c9b3308', uin=0, openids=[], uins=[], ip='', port=0):
        #if not game_ids:
        #    game_ids = [2103041,1007058,1007039,1007044,1007042,1007053,1007060]
        if not (ip and port):
            modid,cmdid = read_l5_info()
            ip,port = get_router(modid, cmdid)

        if not (ip and port):
            logger.error('ip or port is null')
            return []

        udp_client = UDPClient(host=ip, port=port)
        end_sec    = 0
        end_usec   = 0
        obj_arr = []

        try:
            for item in openids:
                uid        = item.get('uid') or ''
                if not uid:
                    continue
                begin_sec  = item.get('begin_sec') or 0
                begin_usec = item.get('begin_usec') or 0

                fetcher.info('get_videos_by_batch_users start, begin_sec:%s,begin_usec:%s,batch_num:%s,openid:%s'%(begin_sec,begin_usec,batch_num,uid))
                buf = self.build_multi_game_send_buf(game_ids=game_ids,
                                                       begin_sec=begin_sec,begin_usec=begin_usec,batch_num=batch_num,
                                                       uin=uin,v_type=0,openid=uid)
                udp_client.sendData(buf=buf)

            for item in uins:
                uid        = item.get('uid') or ''
                if not uid:
                    continue
                begin_sec  = item.get('begin_sec') or 0
                begin_usec = item.get('begin_usec') or 0

                fetcher.info('get_videos_by_batch_users start, begin_sec:%s,begin_usec:%s,batch_num:%s,uin:%s'%(begin_sec,begin_usec,batch_num,uid))
                buf = self.build_multi_game_send_buf(game_ids=game_ids,
                                                       begin_sec=begin_sec,begin_usec=begin_usec,batch_num=batch_num,
                                                       uin=uid,v_type=0)
                udp_client.sendData(buf=buf)

            loops = len(openids) + len(uins)
            while loops > 0:
                uid_datas = {'uid':'','end_sec':0, 'end_usec':0, 'datas':[]}
                loops -= 1
                resp = self.recv_multi_game_resp(udp_client)

                if not resp:
                    fetcher.error('get_videos_by_batch_users error, resp is null')
                    continue
                if resp.result != 0:
                    fetcher.error('get_videos_by_batch_users error, resp.resp is not 0:%s'%resp)
                    continue
                fetcher.info('get:%s %sitems of get_videos_by_batch_users in fact' % (resp.flag,len(resp.video_list)))
                end_sec  = resp.end_sec
                end_usec = resp.end_usec
                flag     = resp.flag

                for info in resp.video_list:
                    v_obj = assemble_v_obj(info, None, appid, flag=False)
                    if not v_obj:
                        continue
                    uid_datas['datas'].append(v_obj)
                uid_datas['end_sec']  = end_sec
                uid_datas['end_usec'] = end_usec
                uid_datas['uid']      = flag
                obj_arr.append(uid_datas)

        except:
            logger.error(traceback.format_exc())
        finally:
            udp_client.close()
            return obj_arr
Exemplo n.º 7
0
            game_id = item['cmd']['game_id']
            merge_info = processor.work(candidates)

            if not (merge_info and merge_info.get('file_path')):
                print 'merge fail, exit'
                sys.exit(1)

            file_path = merge_info.get('file_path')

            up = Uploader(file_path, 'mp4', udp_client)
            up_info = up.upload(addrtype=2, game_id=game_id)

            if up_info['status'] != 0:
                print 'upload merge_file fail'
                sys.exit(1)

            logger.info('sleep.....15s')
            time.sleep(15)
            assemble_obj = assemble(candidates, up_info, udp_client)
            if assemble_obj and valid(assemble_obj):
                #print assemble_obj
                video_dao = Video(b)
                video_dao.add_item(assemble_obj)
                video_dao.add_video_game(assemble_obj['vid'], game_id)

    except:
        print traceback.format_exc()
    finally:
        udp_client.close()
        b.close()