[twitter] support twitter moments

This commit is contained in:
Mort Yao 2018-04-19 03:22:18 +02:00
parent 029272d140
commit b28d78f71d
No known key found for this signature in database
GPG Key ID: 07DA00CB78203251

View File

@ -18,6 +18,17 @@ def twitter_download(url, output_dir='.', merge=True, info_only=False, **kwargs)
if re.match(r'https?://mobile', url): # normalize mobile URL if re.match(r'https?://mobile', url): # normalize mobile URL
url = 'https://' + match1(url, r'//mobile\.(.+)') url = 'https://' + match1(url, r'//mobile\.(.+)')
if re.match(r'https?://twitter\.com/i/moments/', url): # moments
html = get_html(url)
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) html = get_html(url)
screen_name = r1(r'data-screen-name="([^"]*)"', html) or \ screen_name = r1(r'data-screen-name="([^"]*)"', html) or \
r1(r'<meta name="twitter:title" content="([^"]*)"', html) r1(r'<meta name="twitter:title" content="([^"]*)"', html)
@ -58,7 +69,10 @@ def twitter_download(url, output_dir='.', merge=True, info_only=False, **kwargs)
url = r1(r'<meta\s*property="og:video:url"\s*content="([^"]+)"', html) url = r1(r'<meta\s*property="og:video:url"\s*content="([^"]+)"', html)
if not url: if not url:
url = 'https://twitter.com/i/videos/%s' % item_id url = 'https://twitter.com/i/videos/%s' % item_id
try:
html = get_content(url) html = get_content(url)
except:
return
data_config = r1(r'data-config="([^"]*)"', html) or \ data_config = r1(r'data-config="([^"]*)"', html) or \
r1(r'data-player-config="([^"]*)"', html) r1(r'data-player-config="([^"]*)"', html)