Skip to content

Commit

Permalink
[instagram] add 'previews' option (#2135)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed Mar 19, 2022
1 parent 8295bc6 commit f8230dd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
10 changes: 10 additions & 0 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1392,6 +1392,16 @@ Description
You can use ``"all"`` instead of listing all values separately.


extractor.instagram.previews
----------------------------
Type
``bool``
Default
``false``
Description
Download video previews.


extractor.instagram.videos
--------------------------
Type
Expand Down
21 changes: 13 additions & 8 deletions gallery_dl/extractor/instagram.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-

# Copyright 2018-2020 Leonardo Taccari
# Copyright 2018-2021 Mike Fährmann
# Copyright 2018-2022 Mike Fährmann
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
Expand Down Expand Up @@ -43,6 +43,7 @@ def items(self):
self.login()
data = self.metadata()
videos = self.config("videos", True)
previews = self.config("previews", False)
video_headers = {"User-Agent": "Mozilla/5.0"}

for post in self.posts():
Expand All @@ -56,14 +57,18 @@ def items(self):

yield Message.Directory, post
for file in files:
url = file.get("video_url")
if not url:
url = file["display_url"]
elif not videos:
continue
else:
file["_http_headers"] = video_headers
file.update(post)

url = file.get("video_url")
if url:
if videos:
file["_http_headers"] = video_headers
text.nameext_from_url(url, file)
yield Message.Url, url, file
if not previews:
continue

url = file["display_url"]
yield Message.Url, url, text.nameext_from_url(url, file)

def metadata(self):
Expand Down

0 comments on commit f8230dd

Please sign in to comment.