From 0fad3d9673de9c98fa6c227e50d3652d656286ab Mon Sep 17 00:00:00 2001 From: Mort Yao Date: Sat, 1 Sep 2012 21:38:23 +0200 Subject: [PATCH] add support for AcFun --- you_get/downloader/__init__.py | 1 + you_get/downloader/acfun.py | 60 ++++++++++++++++++++++++++++++++++ you_get/main.py | 2 +- 3 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 you_get/downloader/acfun.py diff --git a/you_get/downloader/__init__.py b/you_get/downloader/__init__.py index 7e27927b..d0f2fd5e 100644 --- a/you_get/downloader/__init__.py +++ b/you_get/downloader/__init__.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +from .acfun import * from .cntv import * from .iqiyi import * from .ku6 import * diff --git a/you_get/downloader/acfun.py b/you_get/downloader/acfun.py new file mode 100644 index 00000000..18052f5e --- /dev/null +++ b/you_get/downloader/acfun.py @@ -0,0 +1,60 @@ +#!/usr/bin/env python + +__all__ = ['acfun_download'] + +from ..common import * + +from .sina import sina_download_by_id +from .tudou import tudou_download_by_iid +from .youku import youku_download_by_id + +import json, re + +def get_srt_json(id): + url = 'http://comment.acfun.tv/%s.json' % id + return get_html(url) + +def qq_download_by_id(id, title = None, output_dir = '.', merge = True, info_only = False): + url = 'http://vsrc.store.qq.com/%s.flv' % id + assert title + _, _, size = url_info(url) + + print_info(site_info, title, 'flv', size) + if not info_only: + download_urls([url], title, 'flv', size, output_dir = output_dir, merge = merge) + +def acfun_download_by_id(id, title = None, output_dir = '.', merge = True, info_only = False): + info = json.loads(get_html('http://www.acfun.tv/api/getVideoByID.aspx?vid=' + id)) + t = info['vtype'] + vid = info['vid'] + if t == 'sina': + sina_download_by_id(vid, title, output_dir = output_dir, merge = merge, info_only = info_only) + elif t == 'youku': + youku_download_by_id(vid, title, output_dir = output_dir, merge = merge, info_only = info_only) + elif t == 'tudou': + tudou_download_by_iid(vid, title, output_dir = output_dir, merge = merge, info_only = info_only) + elif t == 'qq': + qq_download_by_id(vid, title, output_dir = output_dir, merge = merge, info_only = info_only) + else: + raise NotImplementedError(t) + + #srt = get_srt_json(vid) + #with open(title + '.json', 'w') as x: + # x.write(srt) + +def acfun_download(url, output_dir = '.', merge = True, info_only = False): + assert re.match(r'http://www.acfun.tv/v/ac(\d+)', url) + html = get_html(url) + + title = r1(r']*>([^<>]+)', html) + assert title + title = unescape_html(title) + title = escape_file_path(title) + title = title.replace(' - AcFun.tv', '') + + id = r1(r"flashvars = {'id':'(\d+)'", html) + acfun_download_by_id(id, title, output_dir = output_dir, merge = merge, info_only = info_only) + +site_info = "AcFun.tv" +download = acfun_download +download_playlist = playlist_not_supported('acfun') diff --git a/you_get/main.py b/you_get/main.py index b39574ec..81cc8ae4 100644 --- a/you_get/main.py +++ b/you_get/main.py @@ -17,6 +17,7 @@ def url_to_module(url): k = r1(r'([^.]+)', domain) downloads = { '56': w56, + 'acfun': acfun, 'cntv': cntv, 'iask': sina, 'iqiyi': iqiyi, @@ -29,7 +30,6 @@ def url_to_module(url): 'youku': youku, 'youtube': youtube, #TODO: - # 'acfun': acfun, # 'bilibili': bilibili, # 'kankanews': bilibili, }