解决优酷 客户端无权播放,603

This commit is contained in:
Xiangfang Chen 2017-05-27 16:13:53 +08:00
parent d0a7655727
commit 1d21b66039

View File

@ -53,14 +53,14 @@ class Youku(VideoExtractor):
return result return result
def generate_ep(self, fileid, sid, token): # def generate_ep(self, fileid, sid, token):
ep = parse.quote(base64.b64encode( # ep = parse.quote(base64.b64encode(
''.join(self.__class__.trans_e( # ''.join(self.__class__.trans_e(
self.f_code_2, #use the 86 fcode if using 86 # self.f_code_2, #use the 86 fcode if using 86
sid + '_' + fileid + '_' + token)).encode('latin1')), # sid + '_' + fileid + '_' + token)).encode('latin1')),
safe='~()*!.\'' # safe='~()*!.\''
) # )
return ep # return ep
# Obsolete -- used to parse m3u8 on pl.youku.com # Obsolete -- used to parse m3u8 on pl.youku.com
def parse_m3u8(m3u8): def parse_m3u8(m3u8):
@ -163,8 +163,10 @@ class Youku(VideoExtractor):
self.title = kwargs['title'] self.title = kwargs['title']
else: else:
api_url = 'http://play.youku.com/play/get.json?vid=%s&ct=10' % self.vid # api_url = 'http://play.youku.com/play/get.json?vid=%s&ct=10' % self.vid
api12_url = 'http://play.youku.com/play/get.json?vid=%s&ct=12' % self.vid # api12_url = 'http://play.youku.com/play/get.json?vid=%s&ct=12' % self.vid
api_url = 'https://ups.youku.com/ups/get.json?vid=%s&client_ip=&client_ts=&utid=&ccode=0401' % self.vid
api12_url = 'https://ups.youku.com/ups/get.json?vid=%s&client_ip=&client_ts=&utid=&ccode=0501' % self.vid
try: try:
meta = json.loads(get_content( meta = json.loads(get_content(
@ -203,8 +205,8 @@ class Youku(VideoExtractor):
if not self.title: #86 if not self.title: #86
self.title = data['video']['title'] self.title = data['video']['title']
self.ep = data12['security']['encrypt_string'] # self.ep = data12['security']['encrypt_string']
self.ip = data12['security']['ip'] # self.ip = data12['security']['ip']
if 'stream' not in data and self.password_protected: if 'stream' not in data and self.password_protected:
log.wtf('[Failed] Wrong password.') log.wtf('[Failed] Wrong password.')
@ -274,11 +276,11 @@ class Youku(VideoExtractor):
# Extract stream with the best quality # Extract stream with the best quality
stream_id = self.streams_sorted[0]['id'] stream_id = self.streams_sorted[0]['id']
e_code = self.__class__.trans_e( # e_code = self.__class__.trans_e(
self.f_code_1, # self.f_code_1,
base64.b64decode(bytes(self.ep, 'ascii')) # base64.b64decode(bytes(self.ep, 'ascii'))
) # )
sid, token = e_code.split('_') # sid, token = e_code.split('_')
while True: while True:
try: try:
@ -288,32 +290,34 @@ class Youku(VideoExtractor):
segs = piece['segs'] segs = piece['segs']
seg_count = len(segs) seg_count = len(segs)
for no in range(0, seg_count): for no in range(0, seg_count):
k = segs[no]['key'] cdn_url = segs[no]["cdn_url"]
fileid = segs[no]['fileid'] ksegs += [cdn_url]
if k == -1: # k = segs[no]['key']
# we hit the paywall; stop here # fileid = segs[no]['fileid']
log.w('Skipping %d out of %d segments due to paywall' % # if k == -1:
(seg_count - no, seg_count)) # # we hit the paywall; stop here
break # log.w('Skipping %d out of %d segments due to paywall' %
ep = self.__class__.generate_ep(self, fileid, # (seg_count - no, seg_count))
sid, token) # break
q = parse.urlencode(dict( # ep = self.__class__.generate_ep(self, fileid,
ctype = self.ctype, # sid, token)
ev = 1, # q = parse.urlencode(dict(
K = k, # ctype = self.ctype,
ep = parse.unquote(ep), # ev = 1,
oip = str(self.ip), # K = k,
token = token, # ep = parse.unquote(ep),
yxon = 1 # oip = str(self.ip),
)) # token = token,
u = 'http://k.youku.com/player/getFlvPath/sid/{sid}_00' \ # yxon = 1
'/st/{container}/fileid/{fileid}?{q}'.format( # ))
sid = sid, # u = 'http://k.youku.com/player/getFlvPath/sid/{sid}_00' \
container = self.streams[stream_id]['container'], # '/st/{container}/fileid/{fileid}?{q}'.format(
fileid = fileid, # sid = sid,
q = q # container = self.streams[stream_id]['container'],
) # fileid = fileid,
ksegs += [i['server'] for i in json.loads(get_content(u))] # q = q
# )
# ksegs += [i['server'] for i in json.loads(get_content(u))]
except error.HTTPError as e: except error.HTTPError as e:
# Use fallback stream data in case of HTTP 404 # Use fallback stream data in case of HTTP 404
log.e('[Error] ' + str(e)) log.e('[Error] ' + str(e))