From aa1ca4ed35b600b8807f71fe7c5103bc6d034d83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Wed, 5 Jun 2019 11:12:10 +0200 Subject: [PATCH] [shopify] skip deleted products (#175) Product pages which return a 4xx status code will now be skipped instead of raising an exception. --- gallery_dl/extractor/shopify.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/gallery_dl/extractor/shopify.py b/gallery_dl/extractor/shopify.py index 159283d8..35895bb6 100644 --- a/gallery_dl/extractor/shopify.py +++ b/gallery_dl/extractor/shopify.py @@ -24,12 +24,12 @@ class ShopifyExtractor(SharedConfigMixin, Extractor): Extractor.__init__(self, match) self.item_url = self.root + match.group(1) - def request(self, url, method="GET", expect=(429, 430), **kwargs): + def request(self, url, method="GET", expect=range(400, 500), **kwargs): tries = 0 kwargs["expect"] = expect while True: response = Extractor.request(self, url, method, **kwargs) - if response.status_code not in expect: + if response.status_code not in (429, 430): return response tries += 1 waittime = 2 ** (tries + 2) @@ -45,8 +45,12 @@ class ShopifyExtractor(SharedConfigMixin, Extractor): headers = {"X-Requested-With": "XMLHttpRequest"} for url in self.products(): - product = self.request( - url + ".json", headers=headers).json()["product"] + response = self.request(url + ".json", headers=headers) + if response.status_code >= 400: + self.log.warning('Skipping %s ("%d: %s")', + url, response.status_code, response.reason) + continue + product = response.json()["product"] del product["image"] for num, image in enumerate(product.pop("images"), 1):