[instagram] add 'warn-images' & 'warn-videos' options (#8283)

This commit is contained in:
Mike Fährmann
2025-09-24 18:45:17 +02:00
parent 80411585a8
commit 616e3f2dce
3 changed files with 46 additions and 5 deletions

View File

@@ -3428,6 +3428,39 @@ Description
Do not download videos
extractor.instagram.warn-images
-------------------------------
Type
* ``bool``
* ``string``
Default
``true``
Description
Show a warning when downloading images
with a resolution smaller than the `original`.
``true``
Show a warning when at least one dimension
is smaller than the reported `original` resolution
``"all"`` | ``"both"``
Show a warning only when both ``width`` and ``height``
are smaller than the reported `original` resolution
``false``
Do not show a warning
extractor.instagram.warn-videos
-------------------------------
Type
``bool``
Default
``true``
Description
Show a warning when downloading videos with a
`User-Agent <extractor.*.user-agent_>`__
header causing potentially lowered video quality.
extractor.instagram.stories.split
---------------------------------
Type

View File

@@ -455,6 +455,8 @@
"order-posts": "asc",
"previews" : false,
"videos" : true,
"warn-images": true,
"warn-videos": true,
"stories": {
"split": false

View File

@@ -39,7 +39,6 @@ class InstagramExtractor(Extractor):
self.www_claim = "0"
self.csrf_token = util.generate_token()
self._find_tags = util.re(r"#\w+").findall
self._warn_video_ua = True
self._logged_in = True
self._cursor = None
self._user = None
@@ -52,6 +51,12 @@ class InstagramExtractor(Extractor):
else:
self.api = InstagramRestAPI(self)
self._warn_video = True if self.config("warn-videos", True) else False
self._warn_image = (
9 if not (wi := self.config("warn-images", True)) else
1 if wi in ("all", "both") else
0)
def items(self):
self.login()
@@ -239,8 +244,8 @@ class InstagramExtractor(Extractor):
manifest = item.get("video_dash_manifest")
media = video
if self._warn_video_ua:
self._warn_video_ua = False
if self._warn_video:
self._warn_video = False
pattern = text.re(
r"Chrome/\d{3,}\.\d+\.\d+\.\d+(?!\d* Mobile)")
if not pattern.search(self.session.headers["User-Agent"]):
@@ -250,8 +255,9 @@ class InstagramExtractor(Extractor):
video = manifest = None
media = image
if image["width"] < item.get("original_width", 0) or \
image["height"] < item.get("original_height", 0):
if self._warn_image < (
(image["width"] < item.get("original_width", 0)) +
(image["height"] < item.get("original_height", 0))):
self.log.warning(
"%s: Available image resolutions lower than the "
"original (%sx%s < %sx%s). "