[instagram] use get_content

This commit is contained in:
Mort Yao 2021-07-11 18:41:05 +02:00
parent 3044f5c16a
commit 47bd107686
No known key found for this signature in database
GPG Key ID: 07DA00CB78203251

View File

@ -6,14 +6,14 @@ from ..common import *
def instagram_download(url, output_dir='.', merge=True, info_only=False, **kwargs): def instagram_download(url, output_dir='.', merge=True, info_only=False, **kwargs):
url = r1(r'([^?]*)', url) url = r1(r'([^?]*)', url)
html = get_html(url, faker=True) cont = get_content(url, headers=fake_headers)
vid = r1(r'instagram.com/\w+/([^/]+)', url) vid = r1(r'instagram.com/\w+/([^/]+)', url)
description = r1(r'<meta property="og:title" content="([^"]*)"', html) or \ description = r1(r'<meta property="og:title" content="([^"]*)"', cont) or \
r1(r'<title>\s([^<]*)</title>', html) # with logged-in cookies r1(r'<title>\s([^<]*)</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="([^"]*)"', html) stream = r1(r'<meta property="og:video" content="([^"]*)"', cont)
if stream: if stream:
_, ext, size = url_info(stream) _, ext, size = url_info(stream)
@ -21,14 +21,14 @@ def instagram_download(url, output_dir='.', merge=True, info_only=False, **kwarg
if not info_only: if not info_only:
download_urls([stream], title, ext, size, output_dir, merge=merge) download_urls([stream], title, ext, size, output_dir, merge=merge)
else: else:
data = re.search(r'window\._sharedData\s*=\s*(.*);</script>', html) data = re.search(r'window\._sharedData\s*=\s*(.*);</script>', cont)
try: try:
info = json.loads(data.group(1)) info = json.loads(data.group(1))
post = info['entry_data']['PostPage'][0] post = info['entry_data']['PostPage'][0]
assert post assert post
except: except:
# with logged-in cookies # with logged-in cookies
data = re.search(r'window\.__additionalDataLoaded\(\'[^\']+\',(.*)\);</script>', html) data = re.search(r'window\.__additionalDataLoaded\(\'[^\']+\',(.*)\);</script>', cont)
if data is not None: if data is not None:
log.e('[Warning] Cookies needed.') log.e('[Warning] Cookies needed.')
post = json.loads(data.group(1)) post = json.loads(data.group(1))