Fix some video download edge cases (#776)

Fixes unintended sidecar video skipping if --no-pictures is set.

Fixes video download if video thumbnail access fails with 410 error.
This commit is contained in:
Alexander Graf
2020-08-17 18:23:24 +02:00
committed by GitHub
parent 6f57197afb
commit 020d412342

View File

@@ -513,23 +513,24 @@ class Instaloader:
# Download the image(s) / video thumbnail and videos within sidecars if desired # Download the image(s) / video thumbnail and videos within sidecars if desired
downloaded = True downloaded = True
if self.download_pictures:
if post.typename == 'GraphSidecar': if post.typename == 'GraphSidecar':
edge_number = 1 for edge_number, sidecar_node in enumerate(post.get_sidecar_nodes(), start=1):
for sidecar_node in post.get_sidecar_nodes(): if self.download_pictures and (not sidecar_node.is_video or self.download_video_thumbnails):
# Download picture or video thumbnail # Download sidecar picture or video thumbnail (--no-pictures implies --no-video-thumbnails)
if not sidecar_node.is_video or self.download_video_thumbnails is True:
downloaded &= self.download_pic(filename=filename, url=sidecar_node.display_url, downloaded &= self.download_pic(filename=filename, url=sidecar_node.display_url,
mtime=post.date_local, filename_suffix=str(edge_number)) 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:
if sidecar_node.is_video and self.download_videos is True: # Download sidecar video if desired
downloaded &= self.download_pic(filename=filename, url=sidecar_node.video_url, downloaded &= self.download_pic(filename=filename, url=sidecar_node.video_url,
mtime=post.date_local, filename_suffix=str(edge_number)) mtime=post.date_local, filename_suffix=str(edge_number))
edge_number += 1
elif post.typename == 'GraphImage': elif post.typename == 'GraphImage':
# Download picture
if self.download_pictures:
downloaded = self.download_pic(filename=filename, url=post.url, mtime=post.date_local) downloaded = self.download_pic(filename=filename, url=post.url, mtime=post.date_local)
elif post.typename == 'GraphVideo': elif post.typename == 'GraphVideo':
if self.download_video_thumbnails is True: # Download video thumbnail (--no-pictures implies --no-video-thumbnails)
if self.download_pictures and self.download_video_thumbnails:
with self.context.error_catcher("Video thumbnail of {}".format(post)):
downloaded = self.download_pic(filename=filename, url=post.url, mtime=post.date_local) downloaded = self.download_pic(filename=filename, url=post.url, mtime=post.date_local)
else: else:
self.context.error("Warning: {0} has unknown typename: {1}".format(post, post.typename)) self.context.error("Warning: {0} has unknown typename: {1}".format(post, post.typename))
@@ -540,7 +541,7 @@ class Instaloader:
self.save_caption(filename=filename, mtime=post.date_local, caption=metadata_string) self.save_caption(filename=filename, mtime=post.date_local, caption=metadata_string)
# Download video if desired # Download video if desired
if post.is_video and self.download_videos is True: if post.is_video and self.download_videos:
downloaded &= self.download_pic(filename=filename, url=post.video_url, mtime=post.date_local) downloaded &= self.download_pic(filename=filename, url=post.video_url, mtime=post.date_local)
# Download geotags if desired # Download geotags if desired
@@ -548,11 +549,11 @@ class Instaloader:
self.save_location(filename, post.location, post.date_local) self.save_location(filename, post.location, post.date_local)
# Update comments if desired # Update comments if desired
if self.download_comments is True: if self.download_comments:
self.update_comments(filename=filename, post=post) self.update_comments(filename=filename, post=post)
# Save metadata as JSON if desired. # Save metadata as JSON if desired.
if self.save_metadata is not False: if self.save_metadata:
self.save_metadata_json(filename, post) self.save_metadata_json(filename, post)
self.context.log() self.context.log()