From da8c982608c9308765e0960e08fc28cccb74b215 Mon Sep 17 00:00:00 2001 From: Mort Yao Date: Wed, 8 Aug 2018 16:21:49 +0200 Subject: [PATCH] [twitter] fix #2609 --- src/you_get/extractors/twitter.py | 50 +++++++++++-------------------- 1 file changed, 17 insertions(+), 33 deletions(-) diff --git a/src/you_get/extractors/twitter.py b/src/you_get/extractors/twitter.py index 9cc3c5c7..8ed400db 100644 --- a/src/you_get/extractors/twitter.py +++ b/src/you_get/extractors/twitter.py @@ -64,42 +64,26 @@ def twitter_download(url, output_dir='.', merge=True, info_only=False, **kwargs) output_dir=output_dir) except: # extract video - # always use i/cards or videos url - if not re.match(r'https?://twitter.com/i/', url): - url = r1(r'\s*', vmap) - item_id = i['tweet_id'] - page_title = "{} [{}]".format(screen_name, item_id) - elif 'scribe_playlist_url' in i: - scribe_playlist_url = i['scribe_playlist_url'] - return vine_download(scribe_playlist_url, output_dir, merge=merge, info_only=info_only) + ga_url = 'https://api.twitter.com/1.1/guest/activate.json' + ga_content = post_content(ga_url, headers={'authorization': authorization}) + guest_token = json.loads(ga_content)['guest_token'] - try: - urls = extract_m3u(source) - except: - urls = [source] + api_url = 'https://api.twitter.com/2/timeline/conversation/%s.json?tweet_mode=extended' % item_id + api_content = get_content(api_url, headers={'authorization': authorization, 'x-guest-token': guest_token}) + + info = json.loads(api_content) + variants = info['globalObjects']['tweets'][item_id]['extended_entities']['media'][0]['video_info']['variants'] + variants = sorted(variants, key=lambda kv: kv.get('bitrate', 0)) + urls = [ variants[-1]['url'] ] size = urls_size(urls) - mime, ext = 'video/mp4', 'mp4' + mime, ext = variants[-1]['content_type'], 'mp4' print_info(site_info, page_title, mime, size) if not info_only: