mirror of
https://github.com/instaloader/instaloader.git
synced 2024-09-11 16:22:24 +02:00
Refactor download_story() into a method
This commit is contained in:
parent
3daaa6fbbc
commit
41a50ffa5a
@ -1025,16 +1025,27 @@ class Instaloader:
|
||||
for item in user_stories["items"]:
|
||||
self._log("[%3i/%3i] " % (count, totalcount), end="", flush=True)
|
||||
count += 1
|
||||
with self._error_catcher('Download story from user {}'.format(name)):
|
||||
downloaded = self.download_story(item, filename_target, name)
|
||||
if fast_update and not downloaded:
|
||||
break
|
||||
|
||||
def download_story(self, item: Dict[str, Any], target: str, profile: str) -> bool:
|
||||
"""Download one user story.
|
||||
|
||||
:param item: Story item, as in story['items'] for story in :meth:`get_stories`
|
||||
:param target: Replacement for {target} in dirname_pattern and filename_pattern
|
||||
:param profile: Owner profile name
|
||||
:return: True if something was downloaded, False otherwise, i.e. file was already there
|
||||
"""
|
||||
|
||||
shortcode = item["code"] if "code" in item else "no_code"
|
||||
date = datetime.fromtimestamp(item["taken_at"])
|
||||
|
||||
dirname = self.dirname_pattern.format(profile=name, target=filename_target)
|
||||
filename = dirname + '/' + self.filename_pattern.format(profile=name, target=filename_target,
|
||||
dirname = self.dirname_pattern.format(profile=profile, target=target)
|
||||
filename = dirname + '/' + self.filename_pattern.format(profile=profile, target=target,
|
||||
date=date,
|
||||
shortcode=shortcode)
|
||||
os.makedirs(os.path.dirname(filename), exist_ok=True)
|
||||
with self._error_catcher('Download story {} from user {}'.format(shortcode, name)):
|
||||
if "image_versions2" in item:
|
||||
url = item["image_versions2"]["candidates"][0]["url"]
|
||||
downloaded = self.download_pic(filename=filename,
|
||||
@ -1060,8 +1071,7 @@ class Instaloader:
|
||||
if location:
|
||||
self.save_location(filename, location, date)
|
||||
self._log()
|
||||
if fast_update and not downloaded:
|
||||
break
|
||||
return downloaded
|
||||
|
||||
def get_feed_posts(self) -> Iterator[Post]:
|
||||
"""Get Posts of the user's feed."""
|
||||
|
Loading…
Reference in New Issue
Block a user