Adds request header functionality and fixes indexing

The headers are useful for working around 401 errors. The indexing changes prevent crashes from tuple identifiers.
This commit is contained in:
2025-08-12 13:12:00 -06:00
parent b204ae5508
commit b15913b4ca

View File

@@ -79,7 +79,7 @@ def get_identifier_string(identifier):
return identifier return identifier
elif type(identifier) == tuple or type(identifier) == list: elif type(identifier) == tuple or type(identifier) == list:
# Check for spaces. Their presence influenced the delimiter string. # Check for spaces. Their presence influenced the delimiter string.
if any(re.search(r'\s', id) for id in identifier): if any(re.search(r'\s', str(id)) for id in identifier):
delimiter = ' - ' delimiter = ' - '
else: else:
delimiter = '-' delimiter = '-'
@@ -100,6 +100,12 @@ class ImageRepo(ABC):
seperately. seperately.
""" """
download_headers = {
"accept-language": "en-US,en;q=0.9",
"dnt": "1",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
}
def __init__(self, identifier, image_type): def __init__(self, identifier, image_type):
""" """
Creates an information repository Creates an information repository
@@ -249,7 +255,7 @@ class ImageRepo(ABC):
for name in iterator: for name in iterator:
logging.info(" Downloading repository %s resource %s", self.get_identifier_string(), name) logging.info(" Downloading repository %s resource %s", self.get_identifier_string(), name)
image_path = NamedTemporaryFile(mode='wb', suffix=str(name), prefix=self.get_identifier_string(), delete = False) image_path = NamedTemporaryFile(mode='wb', suffix=str(name), prefix=self.get_identifier_string(), delete = False)
result = requests.get(self.image_urls[name]) result = requests.get(self.image_urls[name], headers=self.download_headers)
result.raise_for_status() result.raise_for_status()
image_path.write(result.content) image_path.write(result.content)
image_path.close() image_path.close()
@@ -330,8 +336,8 @@ class Comic(ImageRepo, ABC):
""" """
with self._index_lock: with self._index_lock:
if not self.identifier in self.strip_index: if not self.identifier in self.strip_index:
self.strip_index[self.identifier] = {} self.strip_index[self.get_identifier_string()] = {}
self.strip_index[self.identifier][strip.identifier] = strip.get_filename() self.strip_index[self.get_identifier_string()][strip.identifier] = strip.get_filename()
def is_strip_present(self, base_path: Path, suffix: str, identifier) -> bool: def is_strip_present(self, base_path: Path, suffix: str, identifier) -> bool:
""" """
@@ -342,11 +348,11 @@ class Comic(ImageRepo, ABC):
:param identifier: The identifier to check. :param identifier: The identifier to check.
:returns: True if the strip file has been saved. :returns: True if the strip file has been saved.
""" """
if not self.identifier in self.strip_index: if not self.get_identifier_string() in self.strip_index:
return False return False
if not identifier in self.strip_index[self.identifier]: if not identifier in self.strip_index[self.get_identifier_string()]:
return False return False
path = Path(base_path, self.strip_index[self.identifier][identifier] + suffix) path = Path(base_path, self.strip_index[self.get_identifier_string()][identifier] + suffix)
return path.exists() return path.exists()