From a14671992c57c9e60b0f7b8329945cfce9d0d78e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Wed, 11 Jun 2025 22:16:38 +0200 Subject: [PATCH] [sexcom] prevent '.css' file downloads (#7632) by detecting homepage redirects and improve redirect handling in general --- gallery_dl/extractor/sexcom.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/gallery_dl/extractor/sexcom.py b/gallery_dl/extractor/sexcom.py index 7fb2ccf1..b50a8b0b 100644 --- a/gallery_dl/extractor/sexcom.py +++ b/gallery_dl/extractor/sexcom.py @@ -66,11 +66,26 @@ class SexcomExtractor(Extractor): url = text.urljoin(self.root, text.unescape(url)) def _parse_pin(self, url): - response = self.request(url, fatal=False) + if "/pin/" in url: + if url[-1] != "/": + url += "/" + elif url[-1] == "/": + url = url[:-1] + + response = self.request(url, fatal=False, allow_redirects=False) + location = response.headers.get("location") + + if location: + if location[0] == "/": + location = self.root + location + if len(location) <= 25: + return self.log.warning( + 'Unable to fetch %s: Redirect to homepage', url) + response = self.request(location, fatal=False) + if response.status_code >= 400: - self.log.warning('Unable to fetch %s ("%s %s")', - url, response.status_code, response.reason) - return None + return self.log.warning('Unable to fetch %s: %s %s', + url, response.status_code, response.reason) if "/pin/" in response.url: return self._parse_pin_legacy(response)