mirror of
https://github.com/soimort/you-get.git
synced 2025-01-23 21:45:02 +03:00
[instagram] fix extraction
This commit is contained in:
parent
a47960f6ed
commit
d661c95480
@ -10,28 +10,18 @@ def instagram_download(url, output_dir='.', merge=True, info_only=False, **kwarg
|
|||||||
|
|
||||||
vid = r1(r'instagram.com/\w+/([^/]+)', url)
|
vid = r1(r'instagram.com/\w+/([^/]+)', url)
|
||||||
description = r1(r'<meta property="og:title" content="([^"]*)"', cont) or \
|
description = r1(r'<meta property="og:title" content="([^"]*)"', cont) or \
|
||||||
r1(r'<title>\s([^<]*)</title>', cont) # with logged-in cookies
|
r1(r'<title>([^<]*)</title>', cont) # with logged-in cookies
|
||||||
title = "{} [{}]".format(description.replace("\n", " "), vid)
|
title = "{} [{}]".format(description.replace("\n", " "), vid)
|
||||||
|
|
||||||
stream = r1(r'<meta property="og:video" content="([^"]*)"', cont)
|
appId = r1(r'"appId":"(\d+)"', cont)
|
||||||
if stream:
|
media_id = r1(r'"media_id":"(\d+)"', cont)
|
||||||
_, ext, size = url_info(stream)
|
|
||||||
|
|
||||||
print_info(site_info, title, ext, size)
|
api_url = 'https://i.instagram.com/api/v1/media/%s/info/' % media_id
|
||||||
if not info_only:
|
|
||||||
download_urls([stream], title, ext, size, output_dir, merge=merge)
|
|
||||||
else:
|
|
||||||
data = re.search(r'window\._sharedData\s*=\s*(.*);</script>', cont)
|
|
||||||
try:
|
try:
|
||||||
info = json.loads(data.group(1))
|
api_cont = get_content(api_url, headers={**fake_headers, **{'x-ig-app-id': appId}})
|
||||||
post = info['entry_data']['PostPage'][0]
|
|
||||||
assert post['items']
|
|
||||||
except:
|
except:
|
||||||
# with logged-in cookies
|
log.wtf('[Error] Please specify a cookie file.')
|
||||||
data = re.search(r'window\.__additionalDataLoaded\(\'[^\']+\',(.*)\);</script>', cont)
|
post = json.loads(api_cont)
|
||||||
if data is not None:
|
|
||||||
log.e('[Warning] Cookies needed.')
|
|
||||||
post = json.loads(data.group(1))
|
|
||||||
|
|
||||||
for item in post['items']:
|
for item in post['items']:
|
||||||
code = item['code']
|
code = item['code']
|
||||||
|
Loading…
Reference in New Issue
Block a user