2015-09-03 06:28:43 +03:00
|
|
|
__all__ = ['embed_download']
|
|
|
|
|
2017-08-12 15:57:08 +03:00
|
|
|
import urllib.parse
|
|
|
|
|
2015-09-03 06:28:43 +03:00
|
|
|
from ..common import *
|
|
|
|
|
2016-12-06 07:45:28 +03:00
|
|
|
from .bilibili import bilibili_download
|
2017-09-11 14:23:02 +03:00
|
|
|
from .dailymotion import dailymotion_download
|
2015-11-11 07:17:45 +03:00
|
|
|
from .iqiyi import iqiyi_download_by_vid
|
2016-03-03 23:49:47 +03:00
|
|
|
from .le import letvcloud_download_by_vu
|
2016-03-31 18:42:00 +03:00
|
|
|
from .netease import netease_download
|
2015-09-03 06:28:43 +03:00
|
|
|
from .qq import qq_download_by_vid
|
|
|
|
from .sina import sina_download_by_vid
|
|
|
|
from .tudou import tudou_download_by_id
|
2016-05-19 23:57:48 +03:00
|
|
|
from .vimeo import vimeo_download_by_id
|
2015-11-11 06:20:26 +03:00
|
|
|
from .yinyuetai import yinyuetai_download_by_id
|
2015-09-03 06:28:43 +03:00
|
|
|
from .youku import youku_download_by_vid
|
2017-08-12 15:57:08 +03:00
|
|
|
from . import iqiyi
|
2017-09-05 07:36:50 +03:00
|
|
|
from . import bokecc
|
2015-09-03 06:28:43 +03:00
|
|
|
|
|
|
|
"""
|
|
|
|
refer to http://open.youku.com/tools
|
|
|
|
"""
|
2015-09-03 10:46:29 +03:00
|
|
|
youku_embed_patterns = [ 'youku\.com/v_show/id_([a-zA-Z0-9=]+)',
|
|
|
|
'player\.youku\.com/player\.php/sid/([a-zA-Z0-9=]+)/v\.swf',
|
|
|
|
'loader\.swf\?VideoIDS=([a-zA-Z0-9=]+)',
|
|
|
|
'player\.youku\.com/embed/([a-zA-Z0-9=]+)',
|
|
|
|
'YKU.Player\(\'[a-zA-Z0-9]+\',{ client_id: \'[a-zA-Z0-9]+\', vid: \'([a-zA-Z0-9]+)\''
|
|
|
|
]
|
|
|
|
|
2015-09-03 06:28:43 +03:00
|
|
|
"""
|
|
|
|
http://www.tudou.com/programs/view/html5embed.action?type=0&code=3LS_URGvl54&lcode=&resourceId=0_06_05_99
|
|
|
|
"""
|
2016-11-03 03:44:40 +03:00
|
|
|
tudou_embed_patterns = [ 'tudou\.com[a-zA-Z0-9\/\?=\&\.\;]+code=([a-zA-Z0-9_-]+)\&',
|
2015-12-11 21:31:13 +03:00
|
|
|
'www\.tudou\.com/v/([a-zA-Z0-9_-]+)/[^"]*v\.swf'
|
2015-09-03 10:46:29 +03:00
|
|
|
]
|
2015-09-03 06:28:43 +03:00
|
|
|
|
|
|
|
"""
|
|
|
|
refer to http://open.tudou.com/wiki/video/info
|
|
|
|
"""
|
2015-09-03 10:46:29 +03:00
|
|
|
tudou_api_patterns = [ ]
|
2015-09-03 06:28:43 +03:00
|
|
|
|
2015-11-11 06:20:26 +03:00
|
|
|
yinyuetai_embed_patterns = [ 'player\.yinyuetai\.com/video/swf/(\d+)' ]
|
|
|
|
|
2015-11-11 07:17:45 +03:00
|
|
|
iqiyi_embed_patterns = [ 'player\.video\.qiyi\.com/([^/]+)/[^/]+/[^/]+/[^/]+\.swf[^"]+tvId=(\d+)' ]
|
|
|
|
|
2016-03-31 18:42:00 +03:00
|
|
|
netease_embed_patterns = [ '(http://\w+\.163\.com/movie/[^\'"]+)' ]
|
|
|
|
|
2016-05-19 23:57:48 +03:00
|
|
|
vimeo_embed_patters = [ 'player\.vimeo\.com/video/(\d+)' ]
|
|
|
|
|
2017-09-11 14:23:02 +03:00
|
|
|
dailymotion_embed_patterns = [ 'www\.dailymotion\.com/embed/video/(\w+)' ]
|
|
|
|
|
2016-12-06 07:45:28 +03:00
|
|
|
"""
|
|
|
|
check the share button on http://www.bilibili.com/video/av5079467/
|
|
|
|
"""
|
|
|
|
bilibili_embed_patterns = [ 'static\.hdslb\.com/miniloader\.swf.*aid=(\d+)' ]
|
|
|
|
|
2016-05-19 23:57:48 +03:00
|
|
|
|
2017-08-12 15:57:08 +03:00
|
|
|
'''
|
|
|
|
http://open.iqiyi.com/lib/player.html
|
|
|
|
'''
|
|
|
|
iqiyi_patterns = [r'(?:\"|\')(https?://dispatcher\.video\.qiyi\.com\/disp\/shareplayer\.swf\?.+?)(?:\"|\')',
|
|
|
|
r'(?:\"|\')(https?://open\.iqiyi\.com\/developer\/player_js\/coopPlayerIndex\.html\?.+?)(?:\"|\')']
|
|
|
|
|
2017-09-05 07:36:50 +03:00
|
|
|
bokecc_patterns = [r'bokecc\.com/flash/pocle/player\.swf\?siteid=(.+?)&vid=(.{32})']
|
|
|
|
|
2017-08-12 15:57:08 +03:00
|
|
|
recur_limit = 3
|
|
|
|
|
|
|
|
|
2015-09-03 06:28:43 +03:00
|
|
|
def embed_download(url, output_dir = '.', merge = True, info_only = False ,**kwargs):
|
2016-03-31 18:42:00 +03:00
|
|
|
content = get_content(url, headers=fake_headers)
|
2015-09-03 06:28:43 +03:00
|
|
|
found = False
|
|
|
|
title = match1(content, '<title>([^<>]+)</title>')
|
2016-03-31 18:42:00 +03:00
|
|
|
|
2015-09-03 10:46:29 +03:00
|
|
|
vids = matchall(content, youku_embed_patterns)
|
2015-10-19 04:03:58 +03:00
|
|
|
for vid in set(vids):
|
2015-09-03 06:28:43 +03:00
|
|
|
found = True
|
|
|
|
youku_download_by_vid(vid, title=title, output_dir=output_dir, merge=merge, info_only=info_only)
|
|
|
|
|
2015-09-03 10:46:29 +03:00
|
|
|
vids = matchall(content, tudou_embed_patterns)
|
2015-10-19 04:03:58 +03:00
|
|
|
for vid in set(vids):
|
2015-09-03 06:28:43 +03:00
|
|
|
found = True
|
|
|
|
tudou_download_by_id(vid, title=title, output_dir=output_dir, merge=merge, info_only=info_only)
|
2015-09-03 10:46:29 +03:00
|
|
|
|
2015-11-11 06:20:26 +03:00
|
|
|
vids = matchall(content, yinyuetai_embed_patterns)
|
|
|
|
for vid in vids:
|
|
|
|
found = True
|
|
|
|
yinyuetai_download_by_id(vid, title=title, output_dir=output_dir, merge=merge, info_only=info_only)
|
|
|
|
|
2015-11-11 07:17:45 +03:00
|
|
|
vids = matchall(content, iqiyi_embed_patterns)
|
|
|
|
for vid in vids:
|
|
|
|
found = True
|
|
|
|
iqiyi_download_by_vid((vid[1], vid[0]), title=title, output_dir=output_dir, merge=merge, info_only=info_only)
|
|
|
|
|
2016-03-31 18:42:00 +03:00
|
|
|
urls = matchall(content, netease_embed_patterns)
|
|
|
|
for url in urls:
|
|
|
|
found = True
|
|
|
|
netease_download(url, title=title, output_dir=output_dir, merge=merge, info_only=info_only)
|
|
|
|
|
2016-05-19 23:57:48 +03:00
|
|
|
urls = matchall(content, vimeo_embed_patters)
|
|
|
|
for url in urls:
|
|
|
|
found = True
|
2017-08-12 14:14:18 +03:00
|
|
|
vimeo_download_by_id(url, title=title, output_dir=output_dir, merge=merge, info_only=info_only, referer=url)
|
2016-05-19 23:57:48 +03:00
|
|
|
|
2017-09-11 14:23:02 +03:00
|
|
|
urls = matchall(content, dailymotion_embed_patterns)
|
|
|
|
for url in urls:
|
|
|
|
found = True
|
|
|
|
dailymotion_download(url, title=title, output_dir=output_dir, merge=merge, info_only=info_only)
|
|
|
|
|
2016-12-06 07:45:28 +03:00
|
|
|
aids = matchall(content, bilibili_embed_patterns)
|
|
|
|
for aid in aids:
|
|
|
|
found = True
|
|
|
|
url = 'http://www.bilibili.com/video/av%s/' % aid
|
|
|
|
bilibili_download(url, output_dir=output_dir, merge=merge, info_only=info_only)
|
|
|
|
|
2017-08-12 15:57:08 +03:00
|
|
|
iqiyi_urls = matchall(content, iqiyi_patterns)
|
|
|
|
for url in iqiyi_urls:
|
|
|
|
found = True
|
|
|
|
iqiyi.download(url, output_dir=output_dir, merge=merge, info_only=info_only, **kwargs)
|
|
|
|
|
2017-09-05 07:36:50 +03:00
|
|
|
bokecc_metas = matchall(content, bokecc_patterns)
|
|
|
|
for meta in bokecc_metas:
|
|
|
|
found = True
|
|
|
|
bokecc.bokecc_download_by_id(meta[1], output_dir=output_dir, merge=merge, info_only=info_only, **kwargs)
|
|
|
|
|
2017-08-12 15:57:08 +03:00
|
|
|
if found:
|
|
|
|
return True
|
|
|
|
|
|
|
|
# Try harder, check all iframes
|
|
|
|
if 'recur_lv' not in kwargs or kwargs['recur_lv'] < recur_limit:
|
|
|
|
r = kwargs.get('recur_lv')
|
|
|
|
if r is None:
|
|
|
|
r = 1
|
|
|
|
else:
|
|
|
|
r += 1
|
|
|
|
iframes = matchall(content, [r'<iframe.+?src=(?:\"|\')(.+?)(?:\"|\')'])
|
|
|
|
for iframe in iframes:
|
|
|
|
if not iframe.startswith('http'):
|
|
|
|
src = urllib.parse.urljoin(url, iframe)
|
|
|
|
else:
|
|
|
|
src = iframe
|
|
|
|
found = embed_download(src, output_dir=output_dir, merge=merge, info_only=info_only, recur_lv=r, **kwargs)
|
|
|
|
if found:
|
|
|
|
return True
|
|
|
|
|
|
|
|
if not found and 'recur_lv' not in kwargs:
|
2015-09-03 06:28:43 +03:00
|
|
|
raise NotImplementedError(url)
|
2017-08-12 15:57:08 +03:00
|
|
|
else:
|
|
|
|
return found
|
2015-09-03 06:28:43 +03:00
|
|
|
|
|
|
|
site_info = "any.any"
|
|
|
|
download = embed_download
|
|
|
|
download_playlist = playlist_not_supported('any.any')
|