From f53bdf9ef823dac5a0f91489e3c4b622c8126ade Mon Sep 17 00:00:00 2001 From: Alexander Graf <17130992+aandergr@users.noreply.github.com> Date: Sun, 23 Aug 2020 15:56:15 +0200 Subject: [PATCH] Do not call get_sidecar_nodes() if not needed Do not call Post.get_sidecar_nodes() in download_post() if both --no-pictures and --no-videos are set. --- instaloader/instaloader.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/instaloader/instaloader.py b/instaloader/instaloader.py index 773b51a..bf63a8c 100644 --- a/instaloader/instaloader.py +++ b/instaloader/instaloader.py @@ -514,15 +514,16 @@ class Instaloader: # Download the image(s) / video thumbnail and videos within sidecars if desired downloaded = True if post.typename == 'GraphSidecar': - for edge_number, sidecar_node in enumerate(post.get_sidecar_nodes(), start=1): - if self.download_pictures and (not sidecar_node.is_video or self.download_video_thumbnails): - # Download sidecar picture or video thumbnail (--no-pictures implies --no-video-thumbnails) - downloaded &= self.download_pic(filename=filename, url=sidecar_node.display_url, - mtime=post.date_local, filename_suffix=str(edge_number)) - if sidecar_node.is_video and self.download_videos: - # Download sidecar video if desired - downloaded &= self.download_pic(filename=filename, url=sidecar_node.video_url, - mtime=post.date_local, filename_suffix=str(edge_number)) + if self.download_pictures or self.download_videos: + for edge_number, sidecar_node in enumerate(post.get_sidecar_nodes(), start=1): + if self.download_pictures and (not sidecar_node.is_video or self.download_video_thumbnails): + # Download sidecar picture or video thumbnail (--no-pictures implies --no-video-thumbnails) + downloaded &= self.download_pic(filename=filename, url=sidecar_node.display_url, + mtime=post.date_local, filename_suffix=str(edge_number)) + if sidecar_node.is_video and self.download_videos: + # Download sidecar video if desired + downloaded &= self.download_pic(filename=filename, url=sidecar_node.video_url, + mtime=post.date_local, filename_suffix=str(edge_number)) elif post.typename == 'GraphImage': # Download picture if self.download_pictures: