#!/usr/bin/env python __all__ = ['twitter_download'] from ..common import * from .universal import * from .vine import vine_download def extract_m3u(source): r1 = get_content(source) s1 = re.findall(r'(/ext_tw_video/.*)', r1) s1 += re.findall(r'(/amplify_video/.*)', r1) r2 = get_content('https://video.twimg.com%s' % s1[-1]) s2 = re.findall(r'(/ext_tw_video/.*)', r2) s2 += re.findall(r'(/amplify_video/.*)', r2) return ['https://video.twimg.com%s' % i for i in s2] def twitter_download(url, output_dir='.', merge=True, info_only=False, **kwargs): if re.match(r'https?://pbs\.twimg\.com', url): universal_download(url, output_dir, merge=merge, info_only=info_only, **kwargs) return if re.match(r'https?://mobile', url): # normalize mobile URL url = 'https://' + match1(url, r'//mobile\.(.+)') if re.match(r'https?://twitter\.com/i/moments/', url): # moments html = get_html(url, faker=True) paths = re.findall(r'data-permalink-path="([^"]+)"', html) for path in paths: twitter_download('https://twitter.com' + path, output_dir=output_dir, merge=merge, info_only=info_only, **kwargs) return html = get_html(url, faker=True) screen_name = r1(r'twitter\.com/([^/]+)', url) or r1(r'data-screen-name="([^"]*)"', html) or \ r1(r'