mirror of
https://github.com/instaloader/instaloader.git
synced 2024-11-23 18:52:33 +01:00
Remove signatures from profile pic URLs
Fixes #75 as suggested by @e5150.
This commit is contained in:
parent
6f3afd2fa1
commit
541b29b2e9
@ -53,6 +53,10 @@ class QueryReturnedNotFoundException(InstaloaderException):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class QueryReturnedForbiddenException(InstaloaderException):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class ProfileNotExistsException(InstaloaderException):
|
class ProfileNotExistsException(InstaloaderException):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -525,6 +529,9 @@ class Instaloader:
|
|||||||
resp.raw.decode_content = True
|
resp.raw.decode_content = True
|
||||||
shutil.copyfileobj(resp.raw, file)
|
shutil.copyfileobj(resp.raw, file)
|
||||||
else:
|
else:
|
||||||
|
if resp.status_code == 403:
|
||||||
|
# suspected invalid URL signature
|
||||||
|
raise QueryReturnedForbiddenException("403 when accessing {}.".format(url))
|
||||||
if resp.status_code == 404:
|
if resp.status_code == 404:
|
||||||
# 404 not worth retrying.
|
# 404 not worth retrying.
|
||||||
raise QueryReturnedNotFoundException("404 when accessing {}.".format(url))
|
raise QueryReturnedNotFoundException("404 when accessing {}.".format(url))
|
||||||
@ -848,8 +855,11 @@ class Instaloader:
|
|||||||
os.utime(filename, (datetime.now().timestamp(), mtime.timestamp()))
|
os.utime(filename, (datetime.now().timestamp(), mtime.timestamp()))
|
||||||
self._log('geo', end=' ', flush=True)
|
self._log('geo', end=' ', flush=True)
|
||||||
|
|
||||||
def download_profilepic(self, name: str, url: str) -> None:
|
def download_profilepic(self, name: str, profile_metadata: Dict[str, Any]) -> None:
|
||||||
"""Downloads and saves profile pic with given url."""
|
"""Downloads and saves profile pic."""
|
||||||
|
|
||||||
|
url = profile_metadata["user"]["profile_pic_url_hd"] if "profile_pic_url_hd" in profile_metadata["user"] \
|
||||||
|
else profile_metadata["user"]["profile_pic_url"]
|
||||||
|
|
||||||
def _epoch_to_string(epoch: datetime) -> str:
|
def _epoch_to_string(epoch: datetime) -> str:
|
||||||
return epoch.strftime('%Y-%m-%d_%H-%M-%S')
|
return epoch.strftime('%Y-%m-%d_%H-%M-%S')
|
||||||
@ -867,7 +877,12 @@ class Instaloader:
|
|||||||
if os.path.isfile(filename):
|
if os.path.isfile(filename):
|
||||||
self._log(filename + ' already exists')
|
self._log(filename + ' already exists')
|
||||||
return None
|
return None
|
||||||
url = re.sub(r'/s([1-9][0-9]{2})x\1/', '/s2048x2048/', url)
|
url_best = re.sub(r'/s([1-9][0-9]{2})x\1/', '/s2048x2048/', url)
|
||||||
|
url_best = re.sub(r'/vp/[a-f0-9]{32}/[A-F0-9]{8}/', '/', url_best) # remove signature
|
||||||
|
try:
|
||||||
|
self._get_and_write_raw(url_best, filename)
|
||||||
|
except (QueryReturnedForbiddenException, QueryReturnedNotFoundException) as err:
|
||||||
|
self.error('{} Retrying with lower quality version.'.format(err))
|
||||||
self._get_and_write_raw(url, filename)
|
self._get_and_write_raw(url, filename)
|
||||||
os.utime(filename, (datetime.now().timestamp(), date_object.timestamp()))
|
os.utime(filename, (datetime.now().timestamp(), date_object.timestamp()))
|
||||||
self._log('') # log output of _get_and_write_raw() does not produce \n
|
self._log('') # log output of _get_and_write_raw() does not produce \n
|
||||||
@ -1341,7 +1356,7 @@ class Instaloader:
|
|||||||
# Download profile picture
|
# Download profile picture
|
||||||
if profile_pic or profile_pic_only:
|
if profile_pic or profile_pic_only:
|
||||||
with self._error_catcher('Download profile picture of {}'.format(name)):
|
with self._error_catcher('Download profile picture of {}'.format(name)):
|
||||||
self.download_profilepic(name, profile_metadata["user"]["profile_pic_url"])
|
self.download_profilepic(name, profile_metadata)
|
||||||
if profile_pic_only:
|
if profile_pic_only:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user