diff --git a/src/you_get/extractors/acfun.py b/src/you_get/extractors/acfun.py index d4ddf974..b06e23f4 100644 --- a/src/you_get/extractors/acfun.py +++ b/src/you_get/extractors/acfun.py @@ -21,37 +21,37 @@ def get_srt_lock_json(id): url = 'http://comment.acfun.tv/%s_lock.json' % id return get_html(url) -# def acfun_download_by_vid(vid, title=None, output_dir='.', merge=True, info_only=False): -# info = json.loads(get_html('http://www.acfun.tv/video/getVideo.aspx?id=' + vid)) -# sourceType = info['sourceType'] -# sourceId = info['sourceId'] -# # danmakuId = info['danmakuId'] -# if sourceType == 'sina': -# sina_download_by_vid(sourceId, title, output_dir=output_dir, merge=merge, info_only=info_only) -# elif sourceType == 'youku': -# youku_download_by_vid(sourceId, title=title, output_dir=output_dir, merge=merge, info_only=info_only) -# elif sourceType == 'tudou': -# tudou_download_by_iid(sourceId, title, output_dir=output_dir, merge=merge, info_only=info_only) -# elif sourceType == 'qq': -# qq_download_by_id(sourceId, title, output_dir=output_dir, merge=merge, info_only=info_only) -# elif sourceType == 'letv': -# letvcloud_download_by_vu(sourceId, title, output_dir=output_dir, merge=merge, info_only=info_only) -# else: -# raise NotImplementedError(sourceType) +def acfun_download_by_vid(vid, title=None, output_dir='.', merge=True, info_only=False): + info = json.loads(get_html('http://www.acfun.tv/video/getVideo.aspx?id=' + vid)) + sourceType = info['sourceType'] + sourceId = info['sourceId'] + # danmakuId = info['danmakuId'] + if sourceType == 'sina': + sina_download_by_vid(sourceId, title, output_dir=output_dir, merge=merge, info_only=info_only) + elif sourceType == 'youku': + youku_download_by_vid(sourceId, title=title, output_dir=output_dir, merge=merge, info_only=info_only) + elif sourceType == 'tudou': + tudou_download_by_iid(sourceId, title, output_dir=output_dir, merge=merge, info_only=info_only) + elif sourceType == 'qq': + qq_download_by_id(sourceId, title, output_dir=output_dir, merge=merge, info_only=info_only) + elif sourceType == 'letv': + letvcloud_download_by_vu(sourceId, '2d8c027396', title, output_dir=output_dir, merge=merge, info_only=info_only) + else: + raise NotImplementedError(sourceType) -# if not info_only: -# title = get_filename(title) -# try: -# print('Downloading %s ...\n' % (title + '.cmt.json')) -# cmt = get_srt_json(vid) -# with open(os.path.join(output_dir, title + '.cmt.json'), 'w') as x: -# x.write(cmt) -# # print('Downloading %s ...\n' % (title + '.cmt_lock.json')) -# # cmt = get_srt_lock_json(danmakuId) -# # with open(os.path.join(output_dir, title + '.cmt_lock.json'), 'w') as x: -# # x.write(cmt) -# except: -# pass + if not info_only: + title = get_filename(title) + try: + print('Downloading %s ...\n' % (title + '.cmt.json')) + cmt = get_srt_json(vid) + with open(os.path.join(output_dir, title + '.cmt.json'), 'w') as x: + x.write(cmt) + # print('Downloading %s ...\n' % (title + '.cmt_lock.json')) + # cmt = get_srt_lock_json(danmakuId) + # with open(os.path.join(output_dir, title + '.cmt_lock.json'), 'w') as x: + # x.write(cmt) + except: + pass @@ -62,52 +62,52 @@ def get_srt_lock_json(id): # Sometimes may find C80 but size smaller than C30 -def acfun_download_by_vid(vid, title=None, output_dir='.', merge=True, info_only=False ,**kwargs): - #api example http://jiexi.acfun.info/index.php?vid=1122870 - info = json.loads(get_content("http://jiexi.acfun.info/index.php?vid={}".format(vid))) - assert info["code"] == 200 - assert info["success"] == True +#def acfun_download_by_vid(vid, title=None, output_dir='.', merge=True, info_only=False ,**kwargs): + ###api example http://jiexi.acfun.info/index.php?vid=1122870 + #info = json.loads(get_content("http://jiexi.acfun.info/index.php?vid={}".format(vid))) + #assert info["code"] == 200 + #assert info["success"] == True - support_types = sorted(info["result"].keys(),key= lambda i: int(i[1:])) + #support_types = sorted(info["result"].keys(),key= lambda i: int(i[1:])) - stream_id = None - if "stream_id" in kwargs and kwargs["stream_id"] in support_types: - stream_id = kwargs["stream_id"] - else: - print("Current Video Supports:") - for i in support_types: - if info["result"][i]["totalbytes"] != 0: - print("\t--format",i,":",info["result"][i]["quality"],"size:","%.2f"% (info["result"][i]["totalbytes"] / 1024.0 /1024.0),"MB") - else: - print("\t--format",i,":",info["result"][i]["quality"]) - #because C80 is not the best - if "C80" not in support_types: - stream_id = support_types[-1] - else: - stream_id = support_types[-2] + #stream_id = None + #if "stream_id" in kwargs and kwargs["stream_id"] in support_types: + #stream_id = kwargs["stream_id"] + #else: + #print("Current Video Supports:") + #for i in support_types: + #if info["result"][i]["totalbytes"] != 0: + #print("\t--format",i,":",info["result"][i]["quality"],"size:","%.2f"% (info["result"][i]["totalbytes"] / 1024.0 /1024.0),"MB") + #else: + #print("\t--format",i,":",info["result"][i]["quality"]) + ##because C80 is not the best + #if "C80" not in support_types: + #stream_id = support_types[-1] + #else: + #stream_id = support_types[-2] - urls = [None] * len(info["result"][stream_id]["files"]) - for i in info["result"][stream_id]["files"]: - urls[i["no"]] = i["url"] - ext = info["result"][stream_id]["files"][0]["type"] - size = 0 - for i in urls: - _, _, tmp =url_info(i) - size +=tmp - print_info(site_info, title, ext, size) - print("Format: ",stream_id) - print() + #urls = [None] * len(info["result"][stream_id]["files"]) + #for i in info["result"][stream_id]["files"]: + #urls[i["no"]] = i["url"] + #ext = info["result"][stream_id]["files"][0]["type"] + #size = 0 + #for i in urls: + #_, _, tmp =url_info(i) + #size +=tmp + #print_info(site_info, title, ext, size) + #print("Format: ",stream_id) + #print() - if not info_only: - download_urls(urls, title, ext, size, output_dir = output_dir, merge = merge) - title = get_filename(title) - try: - print('Downloading %s ...\n' % (title + '.cmt.json')) - cmt = get_srt_json(vid) - with open(os.path.join(output_dir, title + '.cmt.json'), 'w') as x: - x.write(cmt) - except: - pass + #if not info_only: + #download_urls(urls, title, ext, size, output_dir = output_dir, merge = merge) + #title = get_filename(title) + #try: + #print('Downloading %s ...\n' % (title + '.cmt.json')) + #cmt = get_srt_json(vid) + #with open(os.path.join(output_dir, title + '.cmt.json'), 'w') as x: + #x.write(cmt) + #except: + #pass def acfun_download(url, output_dir = '.', merge = True, info_only = False ,**kwargs): assert re.match(r'http://[^\.]+.acfun.[^\.]+/\D/\D\D(\d+)', url) diff --git a/src/you_get/extractors/letv.py b/src/you_get/extractors/letv.py index 08b68662..eaf92fbb 100644 --- a/src/you_get/extractors/letv.py +++ b/src/you_get/extractors/letv.py @@ -97,16 +97,20 @@ def letv_download_by_vid(vid,title, output_dir='.', merge=True, info_only=False, if not info_only: download_urls(urls, title, ext, size, output_dir=output_dir, merge=merge) -def letvcloud_download_by_vu(vu, title=None, output_dir='.', merge=True, info_only=False): - str2Hash = 'cfflashformatjsonran0.7214574650861323uu2d8c027396ver2.1vu' + vu + 'bie^#@(%27eib58' +def letvcloud_download_by_vu(vu, uu, title=None, output_dir='.', merge=True, info_only=False): + #ran = float('0.' + str(random.randint(0, 9999999999999999))) # For ver 2.1 + #str2Hash = 'cfflashformatjsonran{ran}uu{uu}ver2.2vu{vu}bie^#@(%27eib58'.format(vu = vu, uu = uu, ran = ran) #Magic!/ In ver 2.1 + argumet_dict ={'cf' : 'flash', 'format': 'json', 'ran': str(int(time.time())), 'uu': str(uu),'ver': '2.2', 'vu': str(vu), } + sign_key = '2f9d6924b33a165a6d8b5d3d42f4f987' #ALL YOUR BASE ARE BELONG TO US + str2Hash = ''.join([i + argumet_dict[i] for i in sorted(argumet_dict)]) + sign_key sign = hashlib.md5(str2Hash.encode('utf-8')).hexdigest() - request_info = urllib.request.Request('http://api.letvcloud.com/gpc.php?&sign='+sign+'&cf=flash&vu='+vu+'&ver=2.1&ran=0.7214574650861323&qr=2&format=json&uu=2d8c027396') + request_info = urllib.request.Request('http://api.letvcloud.com/gpc.php?' + '&'.join([i + '=' + argumet_dict[i] for i in argumet_dict]) + '&sign={sign}'.format(sign = sign)) response = urllib.request.urlopen(request_info) data = response.read() info = json.loads(data.decode('utf-8')) type_available = [] - for i in info['data']['video_info']['media']: - type_available.append({'video_url': info['data']['video_info']['media'][i]['play_url']['main_url'], 'video_quality': int(info['data']['video_info']['media'][i]['play_url']['vtype'])}) + for video_type in info['data']['video_info']['media']: + type_available.append({'video_url': info['data']['video_info']['media'][video_type]['play_url']['main_url'], 'video_quality': int(info['data']['video_info']['media'][video_type]['play_url']['vtype'])}) urls = [base64.b64decode(sorted(type_available, key = lambda x:x['video_quality'])[-1]['video_url']).decode("utf-8")] size = urls_size(urls) ext = 'mp4' @@ -118,10 +122,14 @@ def letvcloud_download(url, output_dir='.', merge=True, info_only=False): for i in url.split('&'): if 'vu=' in i: vu = i[3:] + if 'uu=' in i: + uu = i[3:] if len(vu) == 0: raise ValueError('Cannot get vu!') + if len(uu) == 0: + raise ValueError('Cannot get uu!') title = "LETV-%s" % vu - letvcloud_download_by_vu(vu, title=title, output_dir=output_dir, merge=merge, info_only=info_only) + letvcloud_download_by_vu(vu, uu, title=title, output_dir=output_dir, merge=merge, info_only=info_only) def letv_download(url, output_dir='.', merge=True, info_only=False ,**kwargs): if re.match(r'http://yuntv.letv.com/', url):