From 06b7edd6d51c459c1cf0f848c5fd6e34ecf43ffe Mon Sep 17 00:00:00 2001 From: Alexander Graf Date: Mon, 20 Aug 2018 10:37:51 +0200 Subject: [PATCH] --no-pictures flag to not download post pictures Closes #131. --- docs/cli-options.rst | 6 +++++ instaloader/__main__.py | 7 +++++ instaloader/instaloader.py | 54 ++++++++++++++++++++++---------------- 3 files changed, 44 insertions(+), 23 deletions(-) diff --git a/docs/cli-options.rst b/docs/cli-options.rst index 6694676..537bd18 100644 --- a/docs/cli-options.rst +++ b/docs/cli-options.rst @@ -35,6 +35,12 @@ automatically **finds it by its unique ID** and renames the folder likewise. Do not download profile picture. +.. option:: --no-pictures + + Do not download post pictures. Cannot be used together with + :option:`--fast-update`. Implies :option:`--no-video-thumbnails`, does not + imply :option:`--no-videos`. + .. option:: --no-videos, -V Do not download videos. diff --git a/instaloader/__main__.py b/instaloader/__main__.py index ee4ed70..ffd6d3d 100644 --- a/instaloader/__main__.py +++ b/instaloader/__main__.py @@ -230,6 +230,9 @@ def main(): help='Only download profile picture.') g_what.add_argument('--no-profile-pic', action='store_true', help='Do not download profile picture.') + g_what.add_argument('--no-pictures', action='store_true', + help='Do not download post pictures. Cannot be used together with --fast-update. ' + 'Implies --no-video-thumbnails, does not imply --no-videos.') g_what.add_argument('-V', '--no-videos', action='store_true', help='Do not download videos.') g_what.add_argument('--no-video-thumbnails', action='store_true', @@ -349,8 +352,12 @@ def main(): raise SystemExit("--no-captions and --post-metadata-txt or --storyitem-metadata-txt given; " "That contradicts.") + if args.no_pictures and args.fast_update: + raise SystemExit('--no-pictures and --fast-update cannot be used together.') + loader = Instaloader(sleep=not args.no_sleep, quiet=args.quiet, user_agent=args.user_agent, dirname_pattern=args.dirname_pattern, filename_pattern=args.filename_pattern, + download_pictures=not args.no_pictures, download_videos=not args.no_videos, download_video_thumbnails=not args.no_video_thumbnails, download_geotags=args.geotags, download_comments=args.comments, save_metadata=not args.no_metadata_json, diff --git a/instaloader/instaloader.py b/instaloader/instaloader.py index 8d171ed..fa5b4ed 100644 --- a/instaloader/instaloader.py +++ b/instaloader/instaloader.py @@ -80,6 +80,7 @@ class Instaloader: :param user_agent: :option:`--user-agent` :param dirname_pattern: :option:`--dirname-pattern`, default is ``{target}`` :param filename_pattern: :option:`--filename-pattern`, default is ``{date_utc}_UTC`` + :param download_pictures: not :option:`--no-pictures` :param download_videos: not :option:`--no-videos` :param download_video_thumbnails: not :option:`--no-video-thumbnails` :param download_geotags: :option:`--geotags` @@ -102,6 +103,7 @@ class Instaloader: user_agent: Optional[str] = None, dirname_pattern: Optional[str] = None, filename_pattern: Optional[str] = None, + download_pictures=True, download_videos: bool = True, download_video_thumbnails: bool = True, download_geotags: bool = True, @@ -118,6 +120,7 @@ class Instaloader: # configuration parameters self.dirname_pattern = dirname_pattern or "{target}" self.filename_pattern = filename_pattern or "{date_utc}_UTC" + self.download_pictures = download_pictures self.download_videos = download_videos self.download_video_thumbnails = download_video_thumbnails self.download_geotags = download_geotags @@ -133,11 +136,15 @@ class Instaloader: def anonymous_copy(self): """Yield an anonymous, otherwise equally-configured copy of an Instaloader instance; Then copy its error log.""" new_loader = Instaloader(self.context.sleep, self.context.quiet, self.context.user_agent, self.dirname_pattern, - self.filename_pattern, self.download_videos, self.download_video_thumbnails, - self.download_geotags, self.download_comments, self.save_metadata, - self.compress_json, self.post_metadata_txt_pattern, - self.storyitem_metadata_txt_pattern, self.context.graphql_count_per_slidingwindow, - self.context.max_connection_attempts) + self.filename_pattern, download_pictures=self.download_pictures, + download_videos=self.download_videos, + download_video_thumbnails=self.download_video_thumbnails, + download_geotags=self.download_geotags, download_comments=self.download_comments, + save_metadata=self.save_metadata, compress_json=self.compress_json, + post_metadata_txt_pattern=self.post_metadata_txt_pattern, + storyitem_metadata_txt_pattern=self.storyitem_metadata_txt_pattern, + graphql_rate_limit=self.context.graphql_count_per_slidingwindow, + max_connection_attempts=self.context.max_connection_attempts) new_loader.context.query_timestamps = self.context.query_timestamps yield new_loader self.context.error_log.extend(new_loader.context.error_log) @@ -343,25 +350,26 @@ class Instaloader: # Download the image(s) / video thumbnail and videos within sidecars if desired downloaded = False - if post.typename == 'GraphSidecar': - edge_number = 1 - for sidecar_node in post.get_sidecar_nodes(): - # Download picture or video thumbnail - if not sidecar_node.is_video or self.download_video_thumbnails is True: - downloaded |= self.download_pic(filename=filename, url=sidecar_node.display_url, - mtime=post.date_local, filename_suffix=str(edge_number)) - # Additionally download video if available and desired - if sidecar_node.is_video and self.download_videos is True: - downloaded |= self.download_pic(filename=filename, url=sidecar_node.video_url, - mtime=post.date_local, filename_suffix=str(edge_number)) - edge_number += 1 - elif post.typename == 'GraphImage': - downloaded = self.download_pic(filename=filename, url=post.url, mtime=post.date_local) - elif post.typename == 'GraphVideo': - if self.download_video_thumbnails is True: + if self.download_pictures: + if post.typename == 'GraphSidecar': + edge_number = 1 + for sidecar_node in post.get_sidecar_nodes(): + # Download picture or video thumbnail + if not sidecar_node.is_video or self.download_video_thumbnails is True: + downloaded |= self.download_pic(filename=filename, url=sidecar_node.display_url, + mtime=post.date_local, filename_suffix=str(edge_number)) + # Additionally download video if available and desired + if sidecar_node.is_video and self.download_videos is True: + downloaded |= self.download_pic(filename=filename, url=sidecar_node.video_url, + mtime=post.date_local, filename_suffix=str(edge_number)) + edge_number += 1 + elif post.typename == 'GraphImage': downloaded = self.download_pic(filename=filename, url=post.url, mtime=post.date_local) - else: - self.context.error("Warning: {0} has unknown typename: {1}".format(post, post.typename)) + elif post.typename == 'GraphVideo': + if self.download_video_thumbnails is True: + downloaded = self.download_pic(filename=filename, url=post.url, mtime=post.date_local) + else: + self.context.error("Warning: {0} has unknown typename: {1}".format(post, post.typename)) # Save caption if desired metadata_string = _ArbitraryItemFormatter(post).format(self.post_metadata_txt_pattern).strip()