Adds a URL transform method for overridding
This commit is contained in:
@@ -6,3 +6,8 @@ The following comics are nativly supported:
|
||||
* XKCD
|
||||
* Existential Comics
|
||||
* Bluesky
|
||||
|
||||
# Installing
|
||||
This project requires the following dependencies:
|
||||
|
||||
* `libraqm`
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user