提交 d6af782f 编写于 作者: M Mort Yao

Merge branch 'jackyzy823-develop' into develop

* iQIYI: fix #334 and close #150
* QQ: fix #381
......@@ -3,8 +3,62 @@
__all__ = ['iqiyi_download']
from ..common import *
from uuid import uuid4
from random import random,randint
import json
from math import floor
import hashlib
'''
com.qiyi.player.core.model.def.DefinitonEnum
bid meaning for quality
0 none
1 standard
2 high
3 super
4 suprt-high
5 fullhd
10 4k
96 topspeed
'''
def getVRSXORCode(arg1,arg2):
loc3=arg2 %3
if loc3 == 1:
return arg1^121
if loc3 == 2:
return arg1^72
return arg1^103
def getVrsEncodeCode(vlink):
loc6=0
loc2=''
loc3=vlink.split("-")
loc4=len(loc3)
# loc5=loc4-1
for i in range(loc4-1,-1,-1):
loc6=getVRSXORCode(int(loc3[loc4-i-1],16),i)
loc2+=chr(loc6)
return loc2[::-1]
def getVMS(tvid,vid,uid):
tm=randint(1000,2000)
vmsreq='http://cache.video.qiyi.com/vms?key=fvip&src=p'+"&tvId="+tvid+"&vid="+vid+"&vinfo=1&tm="+str(tm)+"&enc="+hashlib.new('md5',bytes('ts56gh'+str(tm)+tvid,"utf-8")).hexdigest()+"&qyid="+uid+"&tn="+str(random())
return json.loads(get_content(vmsreq))
def getDispathKey(rid):
tp=")(*&^flash@#$%a" #magic from swf
time=json.loads(get_content("http://data.video.qiyi.com/t?tn="+str(random())))["t"]
t=str(int(floor(int(time)/(10*60.0))))
return hashlib.new("md5",bytes(t+tp+rid,"utf-8")).hexdigest()
def iqiyi_download(url, output_dir = '.', merge = True, info_only = False):
gen_uid=uuid4().hex
html = get_html(url)
tvid = r1(r'data-player-tvid="([^"]+)"', html)
......@@ -12,26 +66,46 @@ def iqiyi_download(url, output_dir = '.', merge = True, info_only = False):
assert tvid
assert videoid
info_url = 'http://cache.video.qiyi.com/vj/%s/%s/' % (tvid, videoid)
info = get_html(info_url)
raise NotImplementedError('iqiyi')
from xml.dom.minidom import parseString
doc = parseString(info_xml)
title = doc.getElementsByTagName('title')[0].firstChild.nodeValue
size = int(doc.getElementsByTagName('totalBytes')[0].firstChild.nodeValue)
urls = [n.firstChild.nodeValue for n in doc.getElementsByTagName('file')]
assert urls[0].endswith('.f4v'), urls[0]
for i in range(len(urls)):
temp_url = "http://data.video.qiyi.com/%s" % urls[i].split("/")[-1].split(".")[0] + ".ts"
try:
response = request.urlopen(temp_url)
except request.HTTPError as e:
key = r1(r'key=(.*)', e.geturl())
assert key
urls[i] += "?key=%s" % key
info = getVMS(tvid,videoid,gen_uid)
title = info["data"]["vi"]["vn"]
#for highest qualities
#for http://www.iqiyi.com/v_19rrmmz5yw.html not vp -> np
try:
if not info["data"]["vp"] and info["data"]['vp']["tkl"]=='' :
raise ValueError
except:
log.e("[Error] Do not support for iQIYI VIP video.")
exit(-1)
# assert info["data"]['vp']["tkl"]!=''
bid=0
for i in info["data"]["vp"]["tkl"][0]["vs"]:
if int(i["bid"])<=10 and int(i["bid"])>=bid:
bid=int(i["bid"])
video_links=i["fs"]
#todo support choose quality with cmdline
urls=[]
size=0
for i in video_links:
vlink=i["l"]
# print(vlink)
if not vlink.startswith("/"):
#vlink is encode
vlink=getVrsEncodeCode(vlink)
assert vlink.endswith(".f4v")
size+=i["b"]
key=getDispathKey(vlink.split("/")[-1].split(".")[0])
baseurl=info["data"]["vp"]["du"].split("/")
baseurl.insert(-1,key)
url="/".join(baseurl)+vlink+'?su='+gen_uid+'&client=&z=&bt=&ct=&tn='+str(randint(10000,20000))
urls.append(json.loads(get_content(url))["l"])
#download should be complete in 10 minutes
#because the url is generated before start downloading
#and the key may be expired after 10 minutes
print_info(site_info, title, 'flv', size)
if not info_only:
download_urls(urls, title, 'flv', size, output_dir = output_dir, merge = merge)
......
......@@ -3,7 +3,7 @@
__all__ = ['qq_download']
from ..common import *
import uuid
#QQMUSIC
#SINGLE
#1. http://y.qq.com/#type=song&mid=000A9lMb0iEqwN
......@@ -25,19 +25,36 @@ def qq_download_by_id(id, title=None, output_dir='.', merge=True, info_only=Fals
doc_vl = doc_root.getElementsByTagName('vl')[0]
doc_vi = doc_vl.getElementsByTagName('vi')[0]
fn = doc_vi.getElementsByTagName('fn')[0].firstChild.data
fclip = doc_vi.getElementsByTagName('fclip')[0].firstChild.data
if int(fclip) > 0:
fn = fn[:-4] + "." + fclip + fn[-4:]
# fclip = doc_vi.getElementsByTagName('fclip')[0].firstChild.data
# fc=doc_vi.getElementsByTagName('fc')[0].firstChild.data
fvkey = doc_vi.getElementsByTagName('fvkey')[0].firstChild.data
doc_ul = doc_vi.getElementsByTagName('ul')
url = doc_ul[0].getElementsByTagName('url')[0].firstChild.data
url = url + fn + '?vkey=' + fvkey
_, ext, size = url_info(url)
url = doc_ul[0].getElementsByTagName('url')[1].firstChild.data
# print(i.firstChild.data)
urls=[]
ext=fn[-3:]
size=0
for i in doc.getElementsByTagName("cs"):
size+=int(i.firstChild.data)
# size=sum(map(int,doc.getElementsByTagName("cs")))
locid=str(uuid.uuid4())
for i in doc.getElementsByTagName("ci"):
urls.append(url+fn[:-4] + "." + i.getElementsByTagName("idx")[0].firstChild.data + fn[-4:] + '?vkey=' + fvkey+ '&sdtfrom=v1000&type='+ fn[-3:0] +'&locid=' + locid + "&&level=1&platform=11&br=133&fmt=hd&sp=0")
print(urls)
# if int(fclip) > 0:
# fn = fn[:-4] + "." + fclip + fn[-4:]
# url = url + fn + '?vkey=' + fvkey
# _, ext, size = url_info(url)
print_info(site_info, title, ext, size)
if not info_only:
download_urls([url], title, ext, size, output_dir=output_dir, merge=merge)
download_urls(urls, title, ext, size, output_dir=output_dir, merge=merge)
def qq_download(url, output_dir = '.', merge = True, info_only = False):
if re.match(r'http://v.qq.com/([^\?]+)\?vid', url):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册