mirror of
https://github.com/instaloader/instaloader.git
synced 2024-09-11 16:22:24 +02:00
Replaced usages of shortcode with mediaid
This commit is contained in:
parent
184c521646
commit
715582138b
@ -71,6 +71,10 @@ class LoginRequiredException(NonfatalException):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class InvalidArgumentException(NonfatalException):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class BadCredentialsException(InstaloaderException):
|
class BadCredentialsException(InstaloaderException):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -134,16 +138,14 @@ def get_anonymous_session() -> requests.Session:
|
|||||||
|
|
||||||
def shortcode_to_mediaid(code: str) -> int:
|
def shortcode_to_mediaid(code: str) -> int:
|
||||||
if len(code) > 11:
|
if len(code) > 11:
|
||||||
print("Wrong shortcode \"{0}\", unable to convert to mediaid.".format(code), file = sys.stderr)
|
raise InvalidArgumentException("Wrong shortcode \"{0}\", unable to convert to mediaid.".format(code))
|
||||||
return
|
|
||||||
code = 'A' * (12 - len(code)) + code
|
code = 'A' * (12 - len(code)) + code
|
||||||
return int.from_bytes(b64decode(code.encode(), b'-_'), 'big')
|
return int.from_bytes(b64decode(code.encode(), b'-_'), 'big')
|
||||||
|
|
||||||
|
|
||||||
def mediaid_to_shortcode(mediaid: int) -> str:
|
def mediaid_to_shortcode(mediaid: int) -> str:
|
||||||
if mediaid.bit_length() > 64:
|
if mediaid.bit_length() > 64:
|
||||||
print("Wrong mediaid {0}, unable to convert to shortcode".format(str(mediaid)), file = sys.stderr)
|
raise InvalidArgumentException("Wrong mediaid {0}, unable to convert to shortcode".format(str(mediaid)))
|
||||||
return
|
|
||||||
return b64encode(mediaid.to_bytes(9, 'big'), b'-_').decode().replace('A', ' ').lstrip().replace(' ','A')
|
return b64encode(mediaid.to_bytes(9, 'big'), b'-_').decode().replace('A', ' ').lstrip().replace(' ','A')
|
||||||
|
|
||||||
|
|
||||||
@ -519,7 +521,8 @@ class Instaloader:
|
|||||||
date = node["date"] if "date" in node else node["taken_at_timestamp"]
|
date = node["date"] if "date" in node else node["taken_at_timestamp"]
|
||||||
if '__typename' in node:
|
if '__typename' in node:
|
||||||
if node['__typename'] == 'GraphSidecar':
|
if node['__typename'] == 'GraphSidecar':
|
||||||
sidecar_data = self.session.get('https://www.instagram.com/p/' + node['code'] + '/',
|
sidecar_data = self.session.get('https://www.instagram.com/p/' +
|
||||||
|
mediaid_to_shortcode(int(node['id'])) + '/',
|
||||||
params={'__a': 1}).json()
|
params={'__a': 1}).json()
|
||||||
edge_number = 1
|
edge_number = 1
|
||||||
downloaded = True
|
downloaded = True
|
||||||
@ -553,7 +556,8 @@ class Instaloader:
|
|||||||
self.save_caption(name, date, node["caption"])
|
self.save_caption(name, date, node["caption"])
|
||||||
else:
|
else:
|
||||||
self._log("<no caption>", end=' ', flush=True)
|
self._log("<no caption>", end=' ', flush=True)
|
||||||
node_code = node['shortcode'] if 'shortcode' in node else node['code']
|
node_id = node['id'] if 'id' in node else node['media_id']
|
||||||
|
node_code = mediaid_to_shortcode(int(node_id))
|
||||||
if node["is_video"] and download_videos:
|
if node["is_video"] and download_videos:
|
||||||
video_data = self.get_json('p/' + node_code)
|
video_data = self.get_json('p/' + node_code)
|
||||||
self.download_pic(name,
|
self.download_pic(name,
|
||||||
@ -646,7 +650,8 @@ class Instaloader:
|
|||||||
if max_count is not None and count > max_count:
|
if max_count is not None and count > max_count:
|
||||||
return
|
return
|
||||||
if lookup_username:
|
if lookup_username:
|
||||||
metadata = self.get_node_metadata(node['shortcode'] if 'shortcode' in node else node['code'])
|
node_id = node['id'] if 'id' in node else node['media_id']
|
||||||
|
metadata = self.get_node_metadata(mediaid_to_shortcode(int(node_id)))
|
||||||
pathname = metadata['owner']['username']
|
pathname = metadata['owner']['username']
|
||||||
else:
|
else:
|
||||||
pathname = '#{0}'.format(hashtag)
|
pathname = '#{0}'.format(hashtag)
|
||||||
|
Loading…
Reference in New Issue
Block a user