class CSohuCracker(object): def __init__(self): self._httpcli = HttpDownload() self._format_vid = { "normal": "norVid", "high": "highVid", "super": "superVid", "original": "oriVid" } self._format_vid_linda = { "normal": "nor", "high": "hig", "super": "sup" } self._url_action = "http://hot.vrs.sohu.com/vrs_flash.action?vid=%s" self._url_real = "http://data.vod.itc.cn/?new=%s&mkey=%s&plat=17&prod=app" self._url_action_linda = "http://m.tv.sohu.com/phone_playinfo?vid=%s&site=%s&appid=tv&plat=17&sver=1.0" def get_action(self, vid, site=1): try: if site == 2: resp = self._httpcli.get_data(self._url_action_linda % (vid, site)) resp = resp.decode('gb2312').strip() else: resp = self._httpcli.get_data(self._url_action % vid) if resp: return json.loads(resp) except Exception, e: print e print traceback.format_exc()
class CV1Cracker(object): def __init__(self): self._httpcli = HttpDownload() def crack(self, para): result = {} try: url = self.convert_wurl_to_aurl(para['url']) res = self._httpcli.get_data(url) regex_express = 'source src=\"(.*\.(mp4))\"' regex_pattern = re.compile(regex_express) match_result = regex_pattern.search(res) if match_result: play_url = match_result.groups()[0] format = "normal" formats = [] formats.append(format) segs = {} seg = [] seg.append({"url": play_url, "duration": ""}) segs[format] = seg if segs: result["format"] = formats result["seg"] = segs result["type"] = ParseType.DIRECT result["start"] = "" result["end"] = "" except Exception, e: log.app_log.error(traceback.format_exc()) result = {'error': 1, 'code': ErrorCode.UNKNOWN_ERROR} finally:
class CHunantvCracker(object): def __init__(self): self._api_url = 'http://mobile.api.hunantv.com/v5/video/getSource?appVersion=4.6.7&osType=android&videoId=%s' self._httpcli = HttpDownload() def crack(self, para): result = {} try: if 'cont_id' in para: video_id = cont_id = para['cont_id'] api_url = self._api_url % cont_id resp = self._httpcli.get_data(api_url) if resp: segs = self.entrance_url_parse(resp) if segs: result['start'] = '"info":"' result['end'] = '"' result['seg'] = segs result['format'] = segs.keys() result['type'] = ParseType.CUSTOM else: result = {'error': 1, 'code': ErrorCode.PARSE_ERROR} else: result = {'error': 1, 'code': ErrorCode.NO_RESPONSE} else: result = {'error': 1, 'code': ErrorCode.PARAS_ERROR} except Exception, e: log.app_log.error(traceback.format_exc()) result = {'error': 1, 'code': ErrorCode.UNKNOWN_ERROR} finally:
class CBilibiliCracker(object): def __init__(self): self._httpcli = HttpDownload() self._format_map = {1: 'normal', 2: 'high', 3: 'super'} def build_url(self, cid, quality): # 老接口,用不了了 # url = 'http://interface.bilibili.com/playurl?appkey=f3bb208b3d081dc8&cid=%s&quality=%s' % (cid, quality) # return url appkey = "85eb6835b0a1034e" secretkey = "2ad42749773c441109bdc0191257a664" m1 = md5.new() md5_str = "appkey=%s&cid=%s&quality=%s%s" % (appkey, cid, quality, secretkey) m1.update(md5_str) sign = m1.hexdigest() url = "http://interface.bilibili.com/playurl?appkey=%s&cid=%s&quality=%s&sign=%s" % (appkey, cid, quality, sign) return url def crack(self, para): result = {} try: cid = para['cid'] segs = {} formats = [] # 有bug,默认三种清晰度都有,其实可能会遇到没有的 for i in self._format_map.keys(): url = self.build_url(cid, i) resp = self._httpcli.get_data(url, timeout=5) if resp: doc = etree.fromstring(resp) seg = [] for node in doc.xpath("//video/durl"): length_sel = node.xpath('./length/text()') if length_sel: duration = length_sel[0] url_sel = node.xpath('./url/text()') if url_sel: play_url = url_sel[0] if play_url: seg.append({"url":play_url, "duration": str(int(duration) /1000 if duration else '')}) segs[self._format_map[i]] = seg formats.append(self._format_map[i]) if segs: result["format"] = formats result["seg"] = segs result["type"] = ParseType.DIRECT result["start"] = "" result["end"] = "" except Exception, e: log.app_log.error(traceback.format_exc()) result = {'error': 1, 'code': ErrorCode.NO_RESPONSE} finally:
class CWasuCracker(object): def __init__(self): self._wkey_patterns = [re.compile('\'key\'\s+:\s+\'(\w+)\''), re.compile('_playKey = \'([a-zA-Z0-9+/=]+)\',')] self._ua = 'Mozilla/5.0 (Linux; Android 4.4.2; GT-I9505 Build/JDQ39) AppleWebKit/537.36 (KHTML, like Gecko) Version/1.5 Chrome/28.0.1500.94 Mobile Safari/537.36' self._xml_url = "http://www.wasu.cn/Api/getPlayInfoById/id/%s/datatype/xml" self._enc_url = "http://www.wasu.cn/Api/getVideoUrl/id/%s/key/%s?url=%s" self._httpcli = HttpDownload() self._hdd = {'hd0':'normal', 'hd1':'high', 'hd2':'super'} self._wasuc = CWasuConverter() def crack(self, para): result = {} try: wid = para.get('wid') url = para.get('url') os = para.get('os') aurl = self.get_aurl(url, os) wkey = self.get_wkey(aurl) xurl = self._xml_url % wid sxml = self._httpcli.get_data(xurl) xml = etree.fromstring(sxml) segs_new = {} format_new = [] segs_old = {} format_old = [] for ele in xml.iter('mp4', 'video'): if ele.tag == 'mp4': for hd in ele.iter('hd0', 'hd1', 'hd2'): ft = self.get_format(hd.tag) b64url = hd.text encurl = self.get_encurl(wid, wkey, b64url) if not encurl or re.match('http:.*.mp4', encurl): continue try: decurl = self.get_decurl(encurl) if decurl: decurl += "?version=SWFPlayer_V.4.1.0&vid=%s" %wid except Exception, e: continue segs_new[ft] = [{'url':decurl, 'duration':''}] format_new.append(ft) elif ele.tag == 'video': b64url = ele.text encurl = self.get_encurl(wid, wkey, b64url) if not encurl or re.match('http:.*.mp4', encurl): continue try: decurl = self.get_decurl(encurl) if decurl: decurl += "?version=SWFPlayer_V.4.1.0&vid=%s" %wid except Exception, e: continue ft = self.get_format(self.get_hd(xml.xpath("//bitrate/text()")[0])) segs_old[ft] = [{'url':decurl, 'duration':''}] format_old.append(ft)
class C17173Cracker(object): def __init__(self): self._httpcli = HttpDownload() self._format_map = {1: "normal", 2: "high", 4: "super"} def get_detail(self, video_id): result = None current = int(time.time() * 1000) url = "http://v.17173.com/api/video/vInfo/id/%s?t=%s" % (video_id, current) resp = self._httpcli.get_data(url) if resp: details = json.loads(resp) if details['success'] == 1: result = details['data']['splitInfo'] return result def crack(self, para): result = {} try: video_id = para['videoId'] details = self.get_detail(video_id) formats = [] segs = {} for detail in details: format_17173 = detail['def'] format = self._format_map[format_17173] if not format: log.app_log.error("unknown format: %s" % (format_17173)) formats.append(format) segs[format] = [] infos = detail['info'] for info in infos: duration = info['duration'] url = info['url'][0] segs[format].append({'url': url, 'duration': duration}) if segs: result["format"] = formats result["seg"] = segs result["type"] = ParseType.DIRECT result["start"] = "" result["end"] = "" except Exception, e: log.app_log.error(traceback.format_exc()) result = {'error': 1, 'code': ErrorCode.NO_RESPONSE} finally:
class C56Cracker(object): def __init__(self): self._httpcli = HttpDownload(with_cookie=True) self._url_action = "http://m.tv.sohu.com/phone_playinfo?vid=%s&site=2" self._url_list = "http://data.vod.itc.cn/cdnList?%s&vid=%s_2&prod=flash&rb=1" self._ua = "Mozilla/5.0 (Linux; Android 4.3; Nexus 10 Build/JSS15Q) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2307.2 Safari/537.36" self._formats = {"hig": "high", "nor": "normal", "sup": "super"} def get_action(self, vid): try: resp = self._httpcli.get_data(self._url_action % vid, ua=self._ua) if resp: #return resp return json.loads(resp.decode().encode('utf8')) except Exception, e: print traceback.format_exc()
class CKu6Cracker(object): def __init__(self): self._httpcli = HttpDownload() self._url_action = "http://v.ku6.com/fetch.htm?t=getVideo4Player&vid=%s" self._url_real = "http://data.vod.itc.cn/?new=%s&mkey=%s&plat=17&prod=app" self._format = { u"流 畅": "fluent", u"标 清": "normal", u"高 清": "high", u"超 清": "super" } def get_action(self, vid): try: resp = self._httpcli.get_data(self._url_action % vid, timeout=5) if resp: return json.loads(resp) except Exception, e: log.app_log.error(traceback.format_exc())
class YoukuCracker(object): def __init__(self): self._ctx = PyV8.JSContext() self._ctx.enter() self._httpcli = HttpDownload() #load js self._js = "" base_dir = os.path.abspath(".") filename = base_dir + "/js/youku.js" jsfile = open(filename) #jsfile = open('/tmp/crack_server/cracker/youku.js') try: self._js = jsfile.read() finally: jsfile.close() self._func = self._ctx.eval(self._js) def crack(self, para): #log.app_log.info('%s : %s' % (self.__class__.__name__, json.dumps(para))) result = {} try: tvid = para['yvid'] turl = "http://v.youku.com/player/getPlayList/VideoIDS/" + tvid + "/Pf/4/ctype/12/ev/1" resp = self._httpcli.get_data(turl) if resp: tjresp = json.loads(resp) jresp = tjresp["data"][0] sjresp = json.dumps(jresp) #sjresp = json.dumps(tjresp["data"][0]) res = self._func(sjresp) #print res res_list = res.split(",") type = "" urls_num = 0 tnum = len(res_list) - 2 if tnum >= 1: type = res_list[tnum] urls_num = int(res_list[tnum + 1]) segs = [] if "segs" in jresp and type in jresp["segs"] and len( jresp["segs"][type]) == int(urls_num): i = 0 for i in range(urls_num): seg = {} seg["url"] = res_list[i] seg["duration"] = str( jresp["segs"][type][i]["seconds"]) segs.append(seg) #result["seg"] = {type:segs} #result["format"]=[type] result["seg"] = {'high': segs} result["format"] = ['high'] result["type"] = ParseType.DIRECT result["start"] = "" result["end"] = "" #print json.dumps(resp) except Exception, e: log.app_log.error(traceback.format_exc()) result = {'error': 1, 'code': ErrorCode.NO_RESPONSE} finally:
class CAcfunCracker(object): def __init__(self): self._httpcli = HttpDownload() self._format_map = { '3gphd': 'normal', 'flv': 'normal', 'flvhd': 'high', 'mp4hd': 'high', 'mp4hd2': 'super', 'mp4hd3': 'original' } self.init() def init(self): # get vid, cover, title by content url, args need aid self._content_url = "http://api.aixifan.com/contents/%s" # get sourceId as video_id by plays url, args need vid self._plays_url = "http://api.aixifan.com/plays/%s" # get sign by custom url, args need video_id and refer self._custom_url = "https://api.youku.com/players/custom.json?type=h5&client_id=908a519d032263f8&video_id=%s&embsig=%s&%s" # youku get json url, args need sign self._youku_json_url = "http://play.youku.com/partner/get.json?vid=%s&ct=86&cid=908a519d032263f8&sign=%s" # refer,need by custom url, args need vid, cover, title self._refer = 'http://m.acfun.tv/ykplayer?date=undefined#vid=%s;cover=%s;title=%s&callback=ykv.callbacks.cb_AEFkYaN' self._headers = {} self._headers['deviceType'] = '2' # crack youku self._mk = {'a3': '1z4i', 'a4': '86rv'} self._user_cache = {'a1': 'v', 'a2': 'b'} # _rc4_decrypt_key get from _decrypt_seed self._rc4_decrypt_key = "10ehfkbv" # _rc4_encrypt_key get from _encrypt_seed self._rc4_encrypt_key = "msjv7h2b" type_3gphd = { 'hd': 1, 'key': '3gphd', 'loghd': 4, 'play': True, 'quality': 'mp4', 'suffix': 'mp4' } type_flv = { 'hd': 0, 'key': 'flv', 'loghd': 0, 'play': False, 'quality': 'flv', 'suffix': 'flv' } type_flvhd = { 'hd': 0, 'key': 'flvhd', 'loghd': 0, 'play': False, 'quality': 'flv', 'suffix': 'flv' } type_mp4hd = { 'hd': 1, 'key': 'mp4hd', 'loghd': 1, 'play': True, 'quality': 'mp4', 'suffix': 'mp4' } type_mp4hd2 = { 'hd': 2, 'key': 'mp4hd2', 'loghd': 2, 'play': False, 'quality': 'hd2', 'suffix': 'flv' } type_mp4hd3 = { 'hd': 3, 'key': 'mp4hd3', 'loghd': 3, 'play': False, 'quality': 'hd3', 'suffix': 'flv' } self._stream_types = { '3gphd': type_3gphd, 'flv': type_flv, 'flvhd': type_flvhd, 'mp4hd': type_mp4hd, 'mp4hd2': type_mp4hd2, 'mp4hd3': type_mp4hd3 } self._decrypt_seed = "1z4iogbv" self._encrypt_seed = "86rvailb" self._e = [ 19, 1, 4, 7, 30, 14, 28, 8, 24, 17, 6, 35, 34, 16, 9, 10, 13, 22, 32, 29, 31, 21, 18, 3, 2, 23, 25, 27, 11, 20, 5, 15, 12, 0, 33, 26 ] #not useful, we know rc4_key is always same def get_rc4_key(self, t): n = [] i = 0 length = len(t) while i < length: r = 0 if t[i] >= 'a' and t[i] <= 'z': r = ord(t[i]) - ord('a') else: r = ord(t[i]) - ord('0') + 26 o = 0 while 36 > o: if self._e[o] == r: r = o break o += 1 if r > 25: n.append(str(r - 26)) else: n.append(chr(r + 97)) i += 1 return "".join(n) def get_sid_token(self, base64_str): msg = self.rc4_decrypt(base64_str) if msg: ret = msg.split('_') if len(ret) == 2: self._sid = ret[0] self._token = ret[1] def rc4_decrypt(self, base64_str): encrypt_str = base64.b64decode(base64_str) cipher = ARC4.new(self._rc4_decrypt_key) msg = cipher.decrypt(encrypt_str) return msg def rc4_encrypt(self, src): cipher = ARC4.new(self._rc4_encrypt_key) msg = cipher.encrypt(src) encrypt_str = base64.b64encode(msg) return encrypt_str def get_field_id(self, field_id, seg_num): i = field_id[0:8] r = self.get_hex_string(seg_num) o = field_id[10:] n = i + r + o return n def get_hex_string(self, seg_num): r = hex(seg_num)[2:] if len(r) == 1: r = '0' + r return r def get_ep(self, field_id): src = self._sid + '_' + field_id + '_' + self._token #src = '846191191252886064b76_030020010056CF207CA72D2D9B7D2F958141AE-2EDF-6B01-E970-E557BC2CB3FB_7096' ep = self.rc4_encrypt(src) data = {'ep': ep} ep = urllib.urlencode(data) return ep def parse_path(self, s): n = '' for k, v in s.items(): a = k + '/' + v + '/' n = a + n return n def build_params(self, u): e = [] for k, v in u.items(): n = k + '=' + str(v) e.append(n) return '&'.join(e) def get_mp4_src(self, s, u): i = self.parse_path(s) url = "http://k.youku.com/player/getFlvPath/" + i + self.build_params( u) return url def get_all_urls(self, streams): result = {} for stream in streams: stream_type = self._stream_types[stream['stream_type']] result[stream['stream_type']] = [] st = stream_type['suffix'] stream_field_id = stream['stream_fileid'] segs = stream['segs'] num = 0 for seg in segs: key = seg['key'] seconds = int(seg['total_milliseconds_video']) / 1000 current_field_id = self.get_field_id(stream_field_id, num) sid = self._sid + '_' + self.get_hex_string(num) ep = self.get_ep(current_field_id) ep = ep[3:] s = {'sid': sid, 'fileid': current_field_id, 'st': st} u = { 'K': key, 'hd': stream_type['hd'], 'myp': 0, 'ts': seconds, 'ypp': 0, 'ep': ep, 'ctype': '86', 'ev': 1, 'token': self._token, 'oip': self._oip } url = self.get_mp4_src(s, u) result[stream['stream_type']].append({ "url": url, "duration": seconds }) num += 1 return result def crack(self, para): result = {} try: aid = para['aid'] content_url = self._content_url % (aid) resp = self._httpcli.get_data(content_url, headers=self._headers, timeout=5) if resp: resp_json = json.loads(resp) # bug to do:里面有多个个video的,只取第一个 vid = resp_json['data']['videos'][0]['videoId'] cover = resp_json['data']['cover'] title = resp_json['data']['title'] plays_url = self._plays_url % (vid) resp = self._httpcli.get_data(plays_url, headers=self._headers, timeout=5) if resp: resp_json = json.loads(resp) video_id = resp_json['data']['sourceId'] embsig = resp_json['data']['embsig'] refer = self._refer % (vid, cover, title) data = {'refer': refer.encode('UTF-8')} urlencode_refer = urllib.urlencode(data) custom_url = self._custom_url % (video_id, embsig, urlencode_refer) resp = self._httpcli.get_data(custom_url, timeout=5) if resp: resp_json = json.loads(resp) sign = resp_json['playsign'] youku_json_url = self._youku_json_url % (video_id, sign) resp = self._httpcli.get_data(youku_json_url, timeout=5) if resp: resp_json = json.loads(resp) encrypt_str = resp_json['data']['security'][ 'encrypt_string'] self._oip = resp_json['data']['security']['ip'] self.get_sid_token(encrypt_str) streams = resp_json['data']['stream'] urls = self.get_all_urls(streams) formats = [] segs = {} for k, v in urls.items(): format = self._format_map[k] if not format in formats: formats.append(format) segs[format] = v if segs: result["format"] = formats result["seg"] = segs result["type"] = ParseType.DIRECT result["start"] = "" result["end"] = "" except Exception, e: print e log.app_log.error(traceback.format_exc()) result = {'error': 1, 'code': ErrorCode.NO_RESPONSE} finally:
class CTucaoCracker(object): def __init__(self): self._httpcli = HttpDownload() self._format = 'high' def build_url(self, type, tvid): timestamp = int(time.time()) #暂时发现服务器端没检查key key = "tucao4c35fe3d.cc" url = 'http://api.tucao.tv/api/playurl?type=%s&vid=%s&key=%s&r=%s' % ( type, tvid, key, str(timestamp)) return url def build_result(self, seg): result = {} segs = {} formats = [] segs[self._format] = seg formats.append(self._format) result["format"] = formats result["seg"] = segs result["type"] = ParseType.DIRECT result["start"] = "" result["end"] = "" return result def crack(self, para): result = {} try: extra = para['extra'] ret = urlparse.parse_qs(extra, True) if ret.get('file'): #有播放地址,直接返回 seg = [] seg.append({"url": ret['file'][0], "duration": ''}) result = self.build_result(seg) return result type = ret['type'][0] tvid = ret['vid'][0] url = self.build_url(type, tvid) resp = self._httpcli.get_data(url, timeout=5) if resp: buffer = StringIO(resp) doc = etree.parse(buffer) seg = [] for node in doc.xpath("//video/durl"): duration = '' play_url = '' length_sel = node.xpath('./length/text()') if length_sel: duration = length_sel[0] url_sel = node.xpath('./url/text()') if url_sel: play_url = url_sel[0] if play_url: seg.append({ "url": play_url, "duration": str(int(duration) / 1000) }) if seg: result = self.build_result(seg) except Exception, e: log.app_log.error(traceback.format_exc()) result = {'error': 1, 'code': ErrorCode.NO_RESPONSE} finally:
class CIfengCracker(object): def __init__(self): self._httpcli = HttpDownload() self._format_map = {'VideoPlayUrl': 'normal', 'VideoPlayUrlH': 'high'} self._format_map1 = {'350k': 'normal', '500k': 'high'} def build_url(self, guid): url = 'http://vxml.ifengimg.com/video_info_new/' + guid[ 34] + '/' + guid[34:] + '/' + guid + '.xml' return url def crack(self, para): result = {} try: guid = para['guid'] url = self.build_url(guid) resp = self._httpcli.get_data(url, timeout=5) if resp: buffer = StringIO(resp) doc = etree.parse(buffer) segs = {} formats = [] duration = '' duration_sel = doc.xpath('//PlayList/item/@Duration') if duration_sel: duration = duration_sel[0] nodes = doc.xpath('//PlayList/videos/video[@mediaType="mp4"]') if nodes: for node in nodes: seg = [] format_sel = node.xpath('./@bitrate') url_sel = node.xpath('./@VideoPlayUrl') if format_sel and url_sel: format = self._format_map1[format_sel[0]] seg.append({ "url": url_sel[0], "duration": duration }) segs[format] = seg formats.append(format) else: for af, ff in self._format_map.items(): url_sel = doc.xpath('//PlayList/item/@%s' % (af)) seg = [] if url_sel: seg.append({ "url": url_sel[0], "duration": duration }) segs[ff] = seg formats.append(ff) if segs: result["format"] = formats result["seg"] = segs result["type"] = ParseType.DIRECT result["start"] = "" result["end"] = "" except Exception, e: print e log.app_log.error(traceback.format_exc()) result = {'error': 1, 'code': ErrorCode.NO_RESPONSE} finally:
class CPptvCracker(object): def __init__(self): self._api_url = "http://web-play.pptv.com/webplay3-0-%s.xml?version=4&type=web.fpp" self._real_url = "http://%s/%s/%s?fpp.ver=1.3.0.19&k=%s&type=web.fpp" self._all_format = ['fluent', 'high', 'super', 'original'] #self._all_format = ['fluent', 'high', 'super', 'original', 'original_high'] self._httpcli = HttpDownload() def crack(self, para): result = {} result['seg'] = {} format_list = result['format'] = [] try: pptv_id = para.get('pptv_id', '') if pptv_id: api_url = self._api_url % pptv_id resp = self._httpcli.get_data(api_url) if resp: doc = etree.fromstring(resp) files = doc.xpath( "//file/item[@rid and @bitrate and @height and @width and @ft]" ) file_num = len(files) for f in files: df = f.attrib rid = df.get('rid') bitrate = df.get('bitrate') ft = int(df.get('ft')) if ft >= len(self._all_format): continue format = self._all_format[ft] ipl = doc.xpath("//dt[@ft=%s]/sh" % ft) ip = ipl[ 0].text if ipl else "vod.pplive.com.cust.footprint.net" # 由于抓取到的IP可能是数字地址或域名不固定,统一采用域名 #ip = "vod.pplive.com.cust.footprint.net" keyl = doc.xpath("//dt[@ft=%s]/key" % ft) if not keyl: continue else: key = keyl[0].text sgml = doc.xpath("//dragdata[@ft=%s]/sgm[@no]" % ft) l = [] for sgm in sgml: dseg = sgm.attrib real_url = self._real_url % (ip, dseg['no'], rid, key) dur = dseg.get('dur', '') #dur = str(int(float(dur))) dur = str(dur) l.append({'url': real_url, 'duration': dur}) if not l: continue result['seg'][format] = l format_list.append(format) if not format_list: result = {'error': 1, 'code': ErrorCode.NO_RESPONSE} else: result['start'] = '' result['end'] = '' result['type'] = ParseType.DIRECT else: result = {'error': 1, 'code': ErrorCode.NO_RESPONSE} else: result = {'error': 1, 'code': ErrorCode.PARAS_ERROR} except Exception, e: log.app_log.error(traceback.format_exc()) result = {'error': 1, 'code': ErrorCode.NO_RESPONSE} finally:
class IqiyiSwfDriver(object): ua = 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)' def __init__(self, *args, **kwargs): self.b2f = {1: 'fluent', 2: 'high', 4: 'super', 5: 'original'} # self.salt = "6ab6d0280511493ba85594779759d4ed" self._redis = RedisMgr(cs.redis_ip, cs.redis_port, cs.redis_pwd) self._httpcli = HttpDownload() def parse(self, para): result = {} try: tvid = str(para.get('tvvid', '')) ivid = str(para.get('ivid', '')) # read from redis salt = self._redis.get_data(cs.iqiyi_salt_key) vms = self.get_vms(tvid, ivid, salt) #raw_info = self.http_down(vms) raw_info = self._httpcli.get_data(vms) if not raw_info: result = {'error': 1, 'code': ErrorCode.PARSE_ERROR} else: info = json.loads(raw_info) # 分解拼装 prefix = info["data"]["vp"]["du"] vs = info["data"]["vp"]["tkl"][0]["vs"] segs = {} format_list = [] for v in vs: bid = v.get('bid', '') if not bid in self.b2f.keys(): continue ft = self.b2f[bid] fs = v.get('fs', []) seg = [] for f in fs: tail = f.get('l', '') if not tail.startswith('/'): tail = self.decrypt_tail(tail) if not tail: continue # 过滤掉vip if tail.startswith('/vip'): continue url = prefix + tail duration = str(f['d'] / 1000.0) seg.append({'url': url, 'duration': duration}) if seg: segs[ft] = seg format_list.append(ft) if segs: result['seg'] = segs result['format'] = format_list result['type'] = ParseType.CUSTOM result['start'] = '"l":"' result['end'] = '"' else: result = {'error': 1, 'code': ErrorCode.PARSE_ERROR} except Exception, e: log.app_log.error(traceback.format_exc()) result = {'error': 1, 'code': ErrorCode.NO_RESPONSE} finally: