Exemplo n.º 1
0
def get_musicinfo_byno(mno):
    if not mno:
        return None
    result = []
    nos = []
    key = get_musicinfo_key(mno)
    ret = redis_cli.get(key)
    if ret:
        ret = json.loads(ret)
    if isinstance(ret, dict):
        return ret
    #TODO: seek music nos in redis cache at first
    url = cloud_API + '/MusicService.aspx?op=getmusicinfobynos&depot=0&nos=%s' % mno
    print url
    try:
        res = request_json(url, method='GET')
        session = {}
        if res['code'] == 1:
            if not res['result']:
                #已经下线的歌曲,偶有还可以下载的情况,但是拿不到信息
                logger.error(
                    "Failed to get musicinfo (no:%s), possible song has deleted on cloud side"
                    % mno)
                return None
            m = res['result']['matches'][0]
            key = get_musicinfo_key(m['Music_No'])
            redis_cli.set(key, json.dumps(m))
            redis_cli.expire(key, 3600 * 24 * 7)
            return m
    except Exception as ex:
        logger.error(traceback.format_exc())

    if not res['code'] == 1:
        print res['msg']
    return None
Exemplo n.º 2
0
 def geto2oadcaption(self):
     url = '%s/ad/caption/%s' % (AppSet().O2OAPI, tsServiceTask.get_ktvid())
     #url = "http://api.stage.ktvsky.com/ad/caption/1";
     jsonres = request_json(url, timeout=10, method='GET')
     logger.debug("get o2o ad caption, url:%s result: %s" % (url, jsonres))
     if "errcode" in jsonres and jsonres['errcode'] == 200:
         return jsonres
     return None
Exemplo n.º 3
0
def get_download_limit():
    ses = get_cloud_session()
    url = ktv_90_API + '/cdn/downspeed?dogname=%s' % ses['dog']
    res = request_json(url, method='GET')
    if res['code'] == 1:
        return res['data']
    else:
        print "get download limit: %s" % res
    return None
Exemplo n.º 4
0
    def get_ktvinfo_bydog(self):
        try:
            ktvinfo = None
            dname = self.hw_dogname()
            #print("dogname: %s" % dname)
            if dname == '':
                return None

            url = CloudAPI(
            ).KtvInfoURL + "/ktvservice.aspx?op=getktvbydog&dogname=" + urllib.quote(
                dname)
            result = request_json(url, timeout=10, method='GET')
            #print ('result=%s' % result)
            logger.debug("get ktvinfo: %s, result: %s" % (url, result))
            if result and str(result['code']) == '1':
                if isinstance(result['result'], dict):
                    ktvinfo = result['result']['matches'][0]
                    ktvinfo['dogname'] = dname
        except Exception as ex:
            logging.error(traceback.format_exc())
            return None

        try:
            url = CloudAPI(
            ).Alter90URL + "/KtvAppService.aspx?op=getstorejson&dogname=" + urllib.quote(
                dname) + "&storeid=" + str(ktvinfo['StoreId'])
            dic_res = request_json(url, timeout=10, method='GET')
            if dic_res and str(dic_res['code']) == '1':
                if isinstance(dic_res['result'], dict):
                    result = dic_res['result']['matches']
                    logger.debug("getstoreJson: result:%s" % result)
                    for item in result:
                        ktvinfo['mtype'] = item['ModuleType']
                        ktvinfo['projectver'] = item['ProjectVer']
                        ktvinfo['updatetime'] = item['StoreUpdateTime']
                        ktvinfo['allow_del_song'] = item['IsAllowDelSong']
                        ktvinfo['work_update'] = item["StoreIsWorkingUpdate"]
        except Exception as e:
            logger.error(traceback.format_exc())
            return None

        return ktvinfo
Exemplo n.º 5
0
    def getWallPagersNew(self):
        dicResult = {}
        url = "{0}/ad/policy/{1}".format(self.O2OAPI,
                                         tsServiceTask.get_ktvid())

        logger.debug(url)
        res_dict = request_json(url, timeout=10, method='GET')
        horizon_pos = {}
        verticle_pos = {}
        if res_dict:
            if 'errcode' in res_dict.keys():
                if int(res_dict['errcode']) == 200:
                    hstr = []
                    vstr = []
                    if 'ad_pos' in res_dict.keys():
                        ad_pos = res_dict['ad_pos']
                        if ad_pos:
                            if 'horizon_lock_screen' in ad_pos.keys():
                                horizon_pos = ad_pos['horizon_lock_screen']
                                if horizon_pos:
                                    hstr = horizon_pos["ad"]
                            if 'verticle_lock_screen' in ad_pos.keys():
                                verticle_pos = ad_pos['verticle_lock_screen']
                                if verticle_pos:
                                    vstr = verticle_pos["ad"]
                    if 'ad_info' in res_dict.keys():
                        array_obj = res_dict["ad_info"]
                        for adinfo in array_obj:
                            ad_dict = adinfo
                            if ad_dict["type"].lower(
                            ) == "image" and ".bmp" in ad_dict["url"]:
                                type = 0
                                if len(hstr) > 0:
                                    for arrayh in hstr:
                                        if str(arrayh) == str(ad_dict["ad"]):
                                            type = 0
                                            break
                                if len(vstr) > 0:
                                    for arrayh in hstr:
                                        if str(arrayh) == str(ad_dict["ad"]):
                                            type = 1
                                            break
                                info = self.WallpaperInfo()
                                info['paper_name'] = ad_dict["md5"]
                                info['paper_id'] = ad_dict["ad"]
                                info['paper_sort'] = ad_dict["ad"]
                                info['paper_bagtype'] = type
                                info['paper_url'] = ad_dict["url"]
                                info['monitor_url'] = ad_dict["monitor_url"]
                                if not type in dicResult.keys():
                                    dicResult[type] = []
                                dicResult[type].append(info)
        return dicResult
Exemplo n.º 6
0
 def geto2oadinfolist(self):
     url = "%s/ad/policy/%s" % (self.O2OAPI1, tsServiceTask.get_ktvid())
     jsonres = request_json(url, timeout=10, method='GET')
     logger.debug("geto2oadinfolist: url:%s \nresult:%s\n" % (url, jsonres))
     ad = self.o2oad()
     if jsonres and 'errcode' in jsonres and jsonres['errcode'] == 200:
         if "ad_pos" in jsonres.keys():
             ad_pos = jsonres['ad_pos']
             if "start" in ad_pos.keys():
                 ad['start_action'] = self.parseo2oaction(ad_pos["start"])
             if "mv" in ad_pos.keys():
                 ad['mv_action'] = self.parseo2oaction(ad_pos["mv"])
             if "end" in ad_pos.keys():
                 ad['end_action'] = self.parseo2oaction(ad_pos["end"])
             if "no_song" in ad_pos.keys():
                 ad['nosong_action'] = self.parseo2oaction(
                     ad_pos["no_song"])
             if "horizon_lock_screen" in ad_pos.keys():
                 ad['horizon_action'] = self.parseo2oaction(
                     ad_pos["horizon_lock_screen"])
             if "verticle_lock_screen" in ad_pos.keys():
                 ad['verticle_action'] = self.parseo2oaction(
                     ad_pos["verticle_lock_screen"])
             if "redpack" in ad_pos.keys():
                 ad['redpack_action'] = self.parseo2oaction(
                     ad_pos["redpack"])
             if "7000plus" in ad_pos.keys():
                 ad['redpack_action'] = self.parseo2oaction(
                     ad_pos["7000plus"])
         if "ad_info" in jsonres.keys():
             ad_info = jsonres["ad_info"]
             if ad_info:
                 for item in ad_info:
                     mo2oad = self.o2oad_tvinfo()
                     mo2oad['id'] = item['ad']
                     mo2oad['url'] = item['url']
                     mo2oad['url2'] = item['url2']
                     mo2oad['url2'] = item['url2']
                     if item["type"].lower() == 'video':
                         mo2oad['type'] = 0
                     elif item["type"].lower() == 'gif':
                         mo2oad['type'] = 1
                     else:
                         mo2oad['type'] = 2
                     mo2oad['typestr'] = item["type"]
                     mo2oad['time'] = item['time']
                     mo2oad['monitor_url'] = []
                     mo2oad['md5'] = item['md5']
                     for mstr in item["monitor_url"]:
                         mo2oad['monitor_url'].append(mstr)
                     ad['ad_dict'].append(mo2oad)
         return ad
Exemplo n.º 7
0
    def getNewModule(self, m_ver, bagtype, appver):
        self.dogname = tsServiceTask.get_dogname()
        self.ktvid = tsServiceTask.get_ktvid()
        if not self.dogname or not self.ktvid:
            logger.error("Failed to get dogname or ktvinfo")
            return False
        
        logger.debug("getnewmodule")
        #获取模板信息
        if self.lk == 1 or self.lk == 2:
            url = "%s/module_verservice.aspx?op=getmoduleverjson&version=%s&"\
                    "dogname=%s&bagtype=%s&storeId=%s&type=v2&appver=%s&lk=%d"\
                    % (self.songlist, m_ver, urllib.quote(self.dogname), bagtype, self.ktvid, appver, self.lk)
        else:
            url = "%s/module_verservice.aspx?op=getmoduleverjson&version=%s&"\
                    "dogname=%s&bagtype=%s&storeId=%s&type=v2&appver=%s"\
                    % (self.songlist, m_ver, urllib.quote(self.dogname), bagtype, self.ktvid, appver)

        logger.debug(url)
        dic_res = request_json(url, timeout=10, method='GET')
        arrver=[]
        if dic_res and str(dic_res['code']) == '1':
            if isinstance(dic_res['result'], dict):
                mresult = dic_res['result']['matches']
                var = self.KtvModule_Ver()
                if len(mresult) > 0:
                    for item in mresult:
                        var['id'] = item['Id']
                        var['msgtime'] = item['MsgTime']
                        var['version'] = item['Version']
                        var['fileurl'] = item['FileUrl']
                        var['desc'] = item['Desc']
                        var['addtime'] = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
                        var['needun'] = 0
                        var['revision'] = item['ReVision']
                        var['bagtype'] = item['BagType']
                        var['unpath'] = ""
                        var['name'] = item['Name']
                        var['isshow'] = item['IsShow']
                        var['id'] = item['Id']
                        var['isuse'] = 1
                        var['vertype'] = item['VerType']
                        var['isdefault'] = item['IsDefault']
                        arrver.append(var)
                return arrver
        return arrver
Exemplo n.º 8
0
    def cloud_hello(self):
        '''
        通过歌曲编号,得到下载路径
        '''
        try:
            if not self.ktvinfo:
                self.ktvinfo = KTVInfo.get_ktvinfo()
                if not self.ktvinfo:
                    return False
            sinfo = get_cloud_session()
            if isinstance(sinfo, dict):
                self.validkey = sinfo['validkey']
            else:
                logger.error("Failed to get current login session")
                return False

            params = {'appid': self.app_id,
                    'appver': self.app_ver,
                    'username': self.username,
                    'userid': self.userid,
                    'dogname': self.ktvinfo['dogname'],
                    'storeid': self.ktvinfo['StoreId'],
                    'op': 'hello',
                    'validkey': self.validkey,
                    'utime': int(time.time())}

            qerystr = gen_sign_for_kcloud(params, '', self.sec_key)
            login_path = self.cloud_API_S + '/OpenService.aspx?' + qerystr

            res = request_json(login_path)
            if res['code'] == 1:
                if isinstance(res['result'], dict) and 'matches' in res['result'].keys():
                    self.validkey = res['result']['matches'][0]['validkey']
                    sinfo['validkey'] = self.validkey
                    set_cloud_session(sinfo)
                else:
                    return False
            else:
                if res:
                    logger.error("Failed to say hello: %d - %s" % (res['code'], res['msg']))
                return False
        except Exception as ex:
            logger.error(traceback.format_exc())
        return False
Exemplo n.º 9
0
    def cloud_login_msg(self):
        '''
        登录
        '''
        try:
            msg = '登录失败'
            if not (self.username and self.passwd):
                self.get_auth_info()
                if not (self.username and self.passwd):
                    return False, '未设置用户名或密码'

            if not self.ktvinfo:
                #Try get ktvinfo again
                self.ktvinfo = KTVInfo.get_ktvinfo()
                if not self.ktvinfo:
                    logger.error("cannot get ktvinfo: %s" % self.ktvinfo)
                    return False, '未得到有效的KTV信息'
            params = {'appid': self.app_id,
                    'appver': self.app_ver,
                    'dogname': self.ktvinfo['dogname'],
                    'op': 'linuxlogin',
                    'password': self.passwd,
                    'username': self.username,
                    'utime': int(time.time())}

            qerystr = gen_sign_for_kcloud(params, '', self.sec_key)
            login_path = self.cloud_API_S + '/OpenService.aspx?' + qerystr

            res = request_json(login_path)
            msg = res['msg']
            if res['code'] == 2:
                session = res['result']['matches'][0]
                session['dog'] = self.ktvinfo['dogname']
                set_cloud_session(session)
                return True, msg
            else:
                if res:
                    logger.error("Failed to say hello: %d - %s" % (res['code'], res['msg']))
        except Exception as ex:
            logger.error(traceback.format_exc())
            msg = str(ex)
        return False, msg
Exemplo n.º 10
0
def get_cloudmusic_url(mno, dtype=0):
    #https://kcloud.v2.service.ktvdaren.com/MusicService.aspx?appid=ebf0694982384de46e363e74f2c623ed&appver=4.0.0.76&dogname=&filetype=0&musicno=7650021&op=getmusicdownurl&storeid=87832&type=2&userid=17779&username=cx90hcs&utime=1497493237&validkey=ebc9e4378f4dc098368f4492143c06ce&sign=681b1bf04e409d9287c72b68a408a89a&downtyp=0&boxver=5.0.0.72
    ses = get_cloud_session()

    int_t = int(time.time())

    params = {
        'appid': app_id,
        'appver': app_ver,
        'dogname': ses['dog'],
        'filetype': 0,  #0或1:歌曲 2:资料 3:电影 4:任务
        'musicno': mno,
        'op': 'getmusicdownurl',
        'storeid': ses['storeid'],
        'userid': ses['uid'],
        'username': ses['uname'],
        'validkey': ses['validkey'],
        'type': 2,
        'utime': int_t
    }

    qerystr = gen_sign_for_kcloud(params, '', sec_key)
    url = cloud_API_S + '/MusicService.aspx?' + qerystr
    #'downtype': dtype,
    url += "&downtype=%d&boxver=%s&clientid=1" % (dtype, box_ver)
    print(url)

    res = request_json(url, method='GET')
    if res['code'] == 1:
        minfo = res['result']['matches'][0]
        redis_cli.set(get_cloudfile_key(mno), json.dumps(minfo))
        redis_cli.expire(get_cloudfile_key(mno), 3600 * 3)
        return minfo
    elif isinstance(res, dict) and res['code'] == -3:
        logger.error(
            u'cannot find this music info from cloud, maybe it has been deleted. musicno: %s'
            % mno)
        delete_music_info(mno)
        return None
    else:
        print "get download url: res: %s" % res
    return None
Exemplo n.º 11
0
 def deploy_res(self, res):
     if not isinstance(res, dict):
         return False
     try:
         if 'task_linuxsavepath' in res.keys():
             if not os.path.exists(res['task_linuxsavepath']):
                 os.makedirs(res['task_linuxsavepath'])
         if 'task_url' in res.keys():
             url = "%s?ktvid=%d&time=%d&karaoikver=&erpver=" % (res['task_url'], self.ktvid, int(time.time()))
             logger.debug('taskname:%s, url:%s' % (res['task_name'], url))
             dic_res = request_json(url, timeout=10, method='GET')
             if not isinstance(dic_res, dict) or int(dic_res['code']) != 1:
                 return False
             dic_res = dic_res['data']
             rlist = dic_res.get('data_source')
             if isinstance(rlist, list):
                 for rf in rlist:
                     fname = os.path.join(res['task_linuxsavepath'], os.path.basename(rf))
                     logger.debug("resource: %s -> %s" % (rf, fname))
                     ret = self.down_res(rf, res['task_linuxsavepath'])
                     if not ret:
                         logger.error("failed to download %s to %s" % (res, fname))
                         return False
             rinfo = dic_res.get('data_info')
             if not rinfo:
                 return False
             if res['task_jsonname'] == 1:
                 info_name = 'data_%d.json' % int(time.time())
             else:
                 info_name = 'data.json'
             fname = os.path.join(res['task_linuxsavepath'], info_name)
             #open(fname, 'w+').write(json.dumps(rinfo))
             codecs.open(fname, 'w+', encoding='utf8').write(rinfo)
         return True
     except Exception as ex:
         logger.error(traceback.format_exc())
     return False
Exemplo n.º 12
0
def get_musicinfo_bylist(mnos):
    result = []
    nos = []
    for mno in mnos:
        key = get_musicinfo_key(mno)
        ret = redis_cli.get(key)
        if ret:
            ret = json.loads(ret)
        if isinstance(ret, dict):
            result.append(ret)
        else:
            nos.append(mno)

    if not nos:
        return result

    #TODO: seek music nos in redis cache at first
    url = cloud_API + '/MusicService.aspx?op=getmusicinfobynos&depot=0&nos=%s' % ','.join(
        nos)
    print url
    try:
        res = request_json(url, method='GET')
        session = {}
        if res['code'] == 1:
            for m in res['result']['matches']:
                result.append(m)
                key = get_musicinfo_key(m['Music_No'])
                redis_cli.set(key, json.dumps(m))
                redis_cli.expire(key, 3600 * 24 * 7)
        return result
    except Exception as ex:
        logger.error(traceback.format_exc())

    if not res['code'] == 1:
        print res['msg']
    return None
Exemplo n.º 13
0
    def do_run(self):
        try:
            self.ktvid = tsServiceTask.get_ktvid()
            b_failed = False
            done_tasks = 0
            cur_time = int(time.time())
            if self.lk == 1:
                url = "%s/task/ktvtasklist?ktvid=%d&time=%d&lk=1" % (self.Ktv90, self.ktvid, cur_time)
            else:
                url = "%s/task/ktvtasklist?ktvid=%d&time=%d" % (self.Ktv90, self.ktvid, cur_time)
            logger.debug(url)
            dic_res = request_json(url, timeout=10, method='GET')
            if isinstance(dic_res, dict) and dic_res['code'] == 1:
                for task in dic_res['list']:
                    task_time = 10000
                    if 'task_time' in task.keys():
                        d = datetime.datetime.strptime(task['task_time'], '%Y-%m-%d %H:%M:%S')
                        task_time = int(time.mktime(d.timetuple()))
                    logger.info('task_name: %s, task_time: %s, time:%s, update:%s' % ( task['task_linuxsavepath'], task['task_time'], task_time, self.last_update))
                    if self.last_update <= task_time:
                        ret = self.deploy_res(task)
                        if not ret:
                            #only record the failed case
                            logger.error('task_name: %s, task_time: %s, time:%s, update:%s' % ( task['task_linuxsavepath'], task['task_time'], task_time, self.last_update))
                            b_failed = True
                        else:
                            done_tasks += 1
                        if task['task_linuxsavepath'].endswith('SongClimax'):
                            if not self.load_climax():
                                logger.error("failed to load climax info to database")
            if not b_failed and done_tasks >= 1:
                #update last_update time if all task successed
                update_setconfig({'climax_update': cur_time})

        except Exception as e:
            logger.error(traceback.format_exc())