Skip to content

Commit 5b4142d

Browse files
committed
[twitter] fix extraction
1 parent 1c9c0f3 commit 5b4142d

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/you_get/extractors/twitter.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ def extract_m3u(source):
1515
return ['https://video.twimg.com%s' % i for i in s2]
1616

1717
def twitter_download(url, output_dir='.', merge=True, info_only=False, **kwargs):
18+
headers = {
19+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:88.0) Gecko/20100101 Firefox/88.0',
20+
'Accept-Encoding': 'gzip, deflate',
21+
'Accept': '*/*'
22+
}
23+
1824
if re.match(r'https?://pbs\.twimg\.com', url):
1925
universal_download(url, output_dir, merge=merge, info_only=info_only, **kwargs)
2026
return
@@ -52,7 +58,7 @@ def twitter_download(url, output_dir='.', merge=True, info_only=False, **kwargs)
5258
photo_url = photo['url']
5359
title = item_id + '_' + photo_url.split('.')[-2].split('/')[-1]
5460
urls = [ photo_url + ':orig' ]
55-
size = urls_size(urls)
61+
size = urls_size(urls, headers=headers)
5662
ext = photo_url.split('.')[-1]
5763

5864
print_info(site_info, title, ext, size)
@@ -66,12 +72,12 @@ def twitter_download(url, output_dir='.', merge=True, info_only=False, **kwargs)
6672
variants = sorted(variants, key=lambda kv: kv.get('bitrate', 0))
6773
title = item_id + '_' + variants[-1]['url'].split('/')[-1].split('?')[0].split('.')[0]
6874
urls = [ variants[-1]['url'] ]
69-
size = urls_size(urls)
75+
size = urls_size(urls, headers=headers)
7076
mime, ext = variants[-1]['content_type'], 'mp4'
7177

7278
print_info(site_info, title, ext, size)
7379
if not info_only:
74-
download_urls(urls, title, ext, size, output_dir, merge=merge)
80+
download_urls(urls, title, ext, size, output_dir, merge=merge, headers=headers)
7581

7682
# TODO: should we deal with quoted tweets?
7783

0 commit comments

Comments
 (0)