From 73fb7e9a0de7581eb32a0fb5afefd62f5871acbe Mon Sep 17 00:00:00 2001 From: Markil 3 Date: Thu, 27 Nov 2025 17:25:00 -0700 Subject: [PATCH] Adds a URL transform method for overridding --- README.md | 5 +++++ src/comic_download/comic_strip.py | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/README.md b/README.md index e6de10a..707a65d 100644 --- a/README.md +++ b/README.md @@ -6,3 +6,8 @@ The following comics are nativly supported: * XKCD * Existential Comics * Bluesky + +# Installing +This project requires the following dependencies: + +* `libraqm` diff --git a/src/comic_download/comic_strip.py b/src/comic_download/comic_strip.py index 2be9e12..68072bf 100644 --- a/src/comic_download/comic_strip.py +++ b/src/comic_download/comic_strip.py @@ -330,6 +330,17 @@ class ImageRepo(ABC): self.download_data() + def transform_download_url(self, result): + """ + If we need to run extra operations on a request (i.e. a redirect), we + can override this method to handle that before we attempt to extract + image data. If not overridden, this simply returns the original result. + + :param result: The original request result. + :returns: The new request result to use. + """ + return result + def _download_data(self): """ Downloads all images and saves them to temporary files in the #images field. @@ -349,6 +360,8 @@ class ImageRepo(ABC): image_path = NamedTemporaryFile(mode='wb', suffix=str(name), prefix=self.get_identifier_string(), delete = False) result = requests.get(self.image_urls[name], headers=self.download_headers) result.raise_for_status() + # Handles necessary transformations for a URL (i.e., redirections) + result = self.transform_download_url(result) image_path.write(result.content) image_path.close() if type(self.images) == list: