2012-09-01 23:38:23 +04:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
__all__ = ['acfun_download']
|
|
|
|
|
|
|
|
from ..common import *
|
|
|
|
|
2014-10-31 12:09:12 +03:00
|
|
|
from .letv import letvcloud_download_by_vu
|
2015-06-19 06:46:43 +03:00
|
|
|
from .qq import qq_download_by_vid
|
2013-07-14 19:34:42 +04:00
|
|
|
from .sina import sina_download_by_vid
|
2012-09-01 23:38:23 +04:00
|
|
|
from .tudou import tudou_download_by_iid
|
2014-06-24 05:59:47 +04:00
|
|
|
from .youku import youku_download_by_vid
|
2012-09-01 23:38:23 +04:00
|
|
|
|
|
|
|
import json, re
|
|
|
|
|
|
|
|
def get_srt_json(id):
|
2014-09-18 09:38:50 +04:00
|
|
|
# url = 'http://comment.acfun.tv/%s.json' % id
|
|
|
|
url = 'http://static.comment.acfun.mm111.net/%s' %id
|
2012-09-01 23:38:23 +04:00
|
|
|
return get_html(url)
|
|
|
|
|
2013-12-07 08:28:38 +04:00
|
|
|
def get_srt_lock_json(id):
|
2014-07-19 01:53:48 +04:00
|
|
|
url = 'http://comment.acfun.tv/%s_lock.json' % id
|
2013-12-07 08:28:38 +04:00
|
|
|
return get_html(url)
|
|
|
|
|
2015-09-30 23:03:39 +03:00
|
|
|
def acfun_download_by_vid(vid, title=None, output_dir='.', merge=True, info_only=False, **kwargs):
|
2015-05-28 05:29:49 +03:00
|
|
|
info = json.loads(get_html('http://www.acfun.tv/video/getVideo.aspx?id=' + vid))
|
|
|
|
sourceType = info['sourceType']
|
2015-11-11 03:41:16 +03:00
|
|
|
if 'sourceId' in info: sourceId = info['sourceId']
|
2015-05-28 05:29:49 +03:00
|
|
|
# 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':
|
2015-06-19 06:46:43 +03:00
|
|
|
qq_download_by_vid(sourceId, title, output_dir=output_dir, merge=merge, info_only=info_only)
|
2015-05-28 05:29:49 +03:00
|
|
|
elif sourceType == 'letv':
|
|
|
|
letvcloud_download_by_vu(sourceId, '2d8c027396', title, output_dir=output_dir, merge=merge, info_only=info_only)
|
2015-11-11 03:41:16 +03:00
|
|
|
elif sourceType == 'zhuzhan':
|
|
|
|
videoList = info['videoList']
|
|
|
|
playUrl = videoList[-1]['playUrl']
|
|
|
|
mime, ext, size = url_info(playUrl)
|
|
|
|
print_info(site_info, title, mime, size)
|
|
|
|
if not info_only:
|
|
|
|
download_urls([playUrl], title, ext, size, output_dir, merge=merge)
|
2012-09-01 23:38:23 +04:00
|
|
|
else:
|
2015-05-28 05:29:49 +03:00
|
|
|
raise NotImplementedError(sourceType)
|
2014-02-14 05:20:06 +04:00
|
|
|
|
2012-09-16 12:50:35 +04:00
|
|
|
if not info_only:
|
2014-05-21 04:39:35 +04:00
|
|
|
title = get_filename(title)
|
2013-12-16 15:08:38 +04:00
|
|
|
try:
|
2014-05-29 04:42:57 +04:00
|
|
|
print('Downloading %s ...\n' % (title + '.cmt.json'))
|
2014-09-18 09:38:50 +04:00
|
|
|
cmt = get_srt_json(vid)
|
2013-12-16 15:08:38 +04:00
|
|
|
with open(os.path.join(output_dir, title + '.cmt.json'), 'w') as x:
|
|
|
|
x.write(cmt)
|
2015-05-28 05:29:49 +03:00
|
|
|
# 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)
|
2013-12-16 15:08:38 +04:00
|
|
|
except:
|
|
|
|
pass
|
2015-01-27 18:44:45 +03:00
|
|
|
|
2015-05-28 05:29:49 +03:00
|
|
|
|
|
|
|
|
|
|
|
# decompile from player swf
|
|
|
|
# protected static const VIDEO_PARSE_API:String = "http://jiexi.acfun.info/index.php?vid=";
|
|
|
|
# protected static var VIDEO_RATES_CODE:Array = ["C40","C30","C20","C10"];
|
|
|
|
# public static var VIDEO_RATES_STRING:Array = ["原画","超清","高清","流畅"];
|
2015-11-11 03:41:16 +03:00
|
|
|
# Sometimes may find C80 but size smaller than C30
|
2015-05-28 05:29:49 +03:00
|
|
|
|
|
|
|
|
|
|
|
#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:]))
|
|
|
|
|
|
|
|
#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,"<URL>:",info["result"][i]["quality"],"size:","%.2f"% (info["result"][i]["totalbytes"] / 1024.0 /1024.0),"MB")
|
|
|
|
#else:
|
|
|
|
#print("\t--format",i,"<URL>:",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()
|
|
|
|
|
|
|
|
#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
|
|
|
|
|
2015-09-30 23:03:39 +03:00
|
|
|
def acfun_download(url, output_dir='.', merge=True, info_only=False, **kwargs):
|
2015-01-20 06:39:29 +03:00
|
|
|
assert re.match(r'http://[^\.]+.acfun.[^\.]+/\D/\D\D(\d+)', url)
|
2012-09-01 23:38:23 +04:00
|
|
|
html = get_html(url)
|
2014-02-14 05:20:06 +04:00
|
|
|
|
2014-04-13 15:31:21 +04:00
|
|
|
title = r1(r'<h1 id="txt-title-view">([^<>]+)<', html)
|
2012-09-01 23:38:23 +04:00
|
|
|
title = unescape_html(title)
|
|
|
|
title = escape_file_path(title)
|
2014-02-14 05:20:06 +04:00
|
|
|
assert title
|
|
|
|
|
2014-08-21 17:35:18 +04:00
|
|
|
videos = re.findall("data-vid=\"(\d+)\".*href=\"[^\"]+\".*title=\"([^\"]+)\"", html)
|
2014-02-14 05:20:06 +04:00
|
|
|
if videos is not None:
|
|
|
|
for video in videos:
|
|
|
|
p_vid = video[0]
|
2015-11-11 03:41:16 +03:00
|
|
|
p_title = title + " - " + video[1] if video[1] != '删除标签' else title
|
2015-01-27 18:41:17 +03:00
|
|
|
acfun_download_by_vid(p_vid, p_title, output_dir=output_dir, merge=merge, info_only=info_only ,**kwargs)
|
2012-10-02 02:17:52 +04:00
|
|
|
else:
|
2014-02-14 05:20:06 +04:00
|
|
|
# Useless - to be removed?
|
|
|
|
id = r1(r"src=\"/newflvplayer/player.*id=(\d+)", html)
|
|
|
|
sina_download_by_vid(id, title, output_dir=output_dir, merge=merge, info_only=info_only)
|
2012-09-01 23:38:23 +04:00
|
|
|
|
2014-07-19 01:53:48 +04:00
|
|
|
site_info = "AcFun.tv"
|
2012-09-01 23:38:23 +04:00
|
|
|
download = acfun_download
|
|
|
|
download_playlist = playlist_not_supported('acfun')
|