diff --git a/you_get/downloader/__init__.py b/you_get/downloader/__init__.py index 3d909092..c7a1668a 100644 --- a/you_get/downloader/__init__.py +++ b/you_get/downloader/__init__.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +from .cntv import * from .ku6 import * from .sohu import * from .tudou import * diff --git a/you_get/downloader/cntv.py b/you_get/downloader/cntv.py new file mode 100644 index 00000000..d807ec27 --- /dev/null +++ b/you_get/downloader/cntv.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python + +__all__ = ['cntv_download', 'cntv_download_by_id'] + +from ..common import * + +import json +import re + +def cntv_download_by_id(id, title = None, output_dir = '.', merge = True, info_only = False): + assert id + info = json.loads(get_html('http://vdn.apps.cntv.cn/api/getHttpVideoInfo.do?pid=' + id)) + title = title or info['title'] + video = info['video'] + alternatives = [x for x in video.keys() if x.startswith('chapters')] + assert alternatives in (['chapters'], ['chapters', 'chapters2']), alternatives + chapters = video['chapters2'] if 'chapters2' in video else video['chapters'] + urls = [x['url'] for x in chapters] + ext = r1(r'\.([^.]+)$', urls[0]) + assert ext in ('flv', 'mp4') + size = 0 + for url in urls: + _, _, temp = url_info(url) + size += temp + + print_info(site_info, title, ext, size) + if not info_only: + download_urls(urls, title, ext, size, output_dir = output_dir, merge = merge) + +def cntv_download(url, output_dir = '.', merge = True, info_only = False): + if re.match(r'http://\w+\.cntv\.cn/(\w+/\w+/classpage/video/)?\d+/\d+\.shtml', url): + id = r1(r'(\w+)', get_html(url)) + elif re.match(r'http://xiyou.cntv.cn/v-[\w-]+\.html', url): + id = r1(r'http://xiyou.cntv.cn/v-([\w-]+)\.html', url) + else: + raise NotImplementedError(url) + + cntv_download_by_id(id, output_dir = output_dir, merge = merge, info_only = info_only) + +site_info = "CNTV.com" +download = cntv_download +download_playlist = playlist_not_supported('cntv') diff --git a/you_get/main.py b/you_get/main.py index 69f380ae..87193ecb 100644 --- a/you_get/main.py +++ b/you_get/main.py @@ -16,6 +16,7 @@ def url_to_module(url): k = r1(r'([^.]+)', domain) downloads = { + 'cntv': cntv, 'ku6': ku6, 'sohu': sohu, 'tudou': tudou, @@ -31,7 +32,6 @@ def url_to_module(url): # 'pptv': pptv, # 'iqiyi': iqiyi, # '56': w56, - # 'cntv': cntv, } if k in downloads: return downloads[k]