you-get/you_get/main.py

56 lines
1.5 KiB
Python
Raw Normal View History

2012-08-31 19:20:38 +04:00
#!/usr/bin/env python
2012-08-20 19:54:03 +04:00
2012-09-01 02:55:45 +04:00
__all__ = ['main', 'any_download', 'any_download_playlist']
2012-08-31 19:20:38 +04:00
from .downloader import *
from .common import *
2012-08-20 19:54:03 +04:00
def url_to_module(url):
site = r1(r'http://([^/]+)/', url)
assert site, 'invalid url: ' + url
if site.endswith('.com.cn'):
site = site[:-3]
domain = r1(r'(\.[^.]+\.[^.]+)$', site)
2012-09-02 05:13:16 +04:00
if not domain:
domain = site
2012-08-20 19:54:03 +04:00
assert domain, 'unsupported url: ' + url
k = r1(r'([^.]+)', domain)
downloads = {
2012-09-01 21:44:06 +04:00
'56': w56,
2012-09-01 23:38:23 +04:00
'acfun': acfun,
2012-09-02 00:02:14 +04:00
'bilibili': bilibili,
2012-09-01 20:35:22 +04:00
'cntv': cntv,
2012-09-25 02:27:28 +04:00
'dailymotion': dailymotion,
2012-09-01 23:03:05 +04:00
'iask': sina,
2012-09-02 17:03:04 +04:00
'ifeng': ifeng,
'iqiyi': iqiyi,
2012-09-02 00:02:14 +04:00
'kankanews': bilibili,
2012-09-01 19:45:30 +04:00
'ku6': ku6,
'pptv': pptv,
2012-09-01 23:03:05 +04:00
'sina': sina,
2012-09-01 14:14:12 +04:00
'sohu': sohu,
2012-08-31 19:20:38 +04:00
'tudou': tudou,
2012-09-02 05:13:16 +04:00
'vimeo': vimeo,
2012-09-01 14:14:12 +04:00
'yinyuetai': yinyuetai,
'youku': youku,
'youtube': youtube,
2012-09-02 00:02:14 +04:00
#TODO
2012-08-20 19:54:03 +04:00
}
if k in downloads:
return downloads[k]
else:
raise NotImplementedError(url)
def any_download(url, output_dir = '.', merge = True, info_only = False):
m = url_to_module(url)
m.download(url, output_dir = output_dir, merge = merge, info_only = info_only)
def any_download_playlist(url, output_dir = '.', merge = True, info_only = False):
m = url_to_module(url)
m.download_playlist(url, output_dir = output_dir, merge = merge, info_only = info_only)
2012-09-01 02:55:45 +04:00
def main():
script_main('you-get', any_download, any_download_playlist)