diff --git a/src/you_get/common.py b/src/you_get/common.py index 0a79ab98..36be1999 100755 --- a/src/you_get/common.py +++ b/src/you_get/common.py @@ -79,6 +79,24 @@ def match1(text, *patterns): ret.append(match.group(1)) return ret +def matchall(text, patterns): + """Scans through a string for substrings matched some patterns. + + Args: + text: A string to be scanned. + patterns: a list of regex pattern. + + Returns: + a list if matched. empty if not. + """ + + ret = [] + for pattern in patterns: + match = re.findall(pattern, text) + ret += match + + return ret + def launch_player(player, urls): import subprocess import shlex @@ -1011,7 +1029,8 @@ def url_to_module(url): res = conn.getresponse() location = res.getheader('location') if location is None: - raise NotImplementedError(url) + from .extractors import embed + return embed, url else: return url_to_module(location) diff --git a/src/you_get/extractors/embed.py b/src/you_get/extractors/embed.py new file mode 100644 index 00000000..e3a929b4 --- /dev/null +++ b/src/you_get/extractors/embed.py @@ -0,0 +1,51 @@ +__all__ = ['embed_download'] + +from ..common import * + +from .letv import letvcloud_download_by_vu +from .qq import qq_download_by_vid +from .sina import sina_download_by_vid +from .tudou import tudou_download_by_id +from .youku import youku_download_by_vid + +""" +refer to http://open.youku.com/tools +""" +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]+)\'' + ] + +""" +http://www.tudou.com/programs/view/html5embed.action?type=0&code=3LS_URGvl54&lcode=&resourceId=0_06_05_99 +""" +tudou_embed_patterns = [ 'tudou\.com[a-zA-Z0-9\/\?=\&\.\;]+code=([[a-zA-Z0-9_]+)\&' + ] + +""" +refer to http://open.tudou.com/wiki/video/info +""" +tudou_api_patterns = [ ] + +def embed_download(url, output_dir = '.', merge = True, info_only = False ,**kwargs): + content = get_content(url) + found = False + title = match1(content, '