Skip to content
This repository has been archived by the owner on Sep 6, 2024. It is now read-only.

Commit

Permalink
improved gallery handling speed by further reducing hard drive calls
Browse files Browse the repository at this point in the history
  • Loading branch information
9FS committed Nov 15, 2023
1 parent 1a2f050 commit a9b84bc
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ license = "MIT"
name = "x" # can't leave empty because of bug with `poetry install` from poetry.lock file
readme = "readme.md"
repository = "https://github.com/9-FS/2022-10-23-nHentai-to-PDF-Server"
version = "2.3.9"
version = "2.3.10"

[tool.poetry.dependencies]
kfsconfig = "^1.0.0"
Expand Down
6 changes: 4 additions & 2 deletions src/Hentai.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,6 @@ def _get_gallery(cls, nhentai_ID: int, cookies: dict[str, str], headers: dict[st
logging.info(f"\rDownloaded gallery {nhentai_ID} from \"{NHENTAI_GALLERY_API_URL}/{nhentai_ID}\".")

cls.galleries=sorted(cls.galleries, key=lambda gallery: int(gallery["id"])) # sort galleries by ID
if nhentai_ID%10==0: # only save to file roughly every 10 galleries to save time
cls.save_galleries()

return gallery

Expand Down Expand Up @@ -255,6 +253,10 @@ def save_galleries(cls) -> None:
Saves galleries to file.
"""

if len(cls.galleries)==0: # don't save if nothing to save, might prevent overwriting galleries file with uninitialised galleries
return


logging.info(f"Saving galleries in \"{cls.GALLERIES_FILEPATH}\"...")
with open(cls.GALLERIES_FILEPATH, "wt") as galleries_file:
galleries_file.write(json.dumps(cls.galleries, indent=4))
Expand Down
5 changes: 4 additions & 1 deletion src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ def main():
logging.info("--------------------------------------------------")
logging.info(f"{KFSfstr.notation_abs(i+1, 0, round_static=True)}/{KFSfstr.notation_abs(len(hentai_ID_list), 0, round_static=True)} ({KFSfstr.notation_abs((i+1)/(len(hentai_ID_list)), 2, round_static=True)})")

if (i+1)%100==0: # save galleries to file, only every 100 hentai to save time
Hentai.save_galleries()

try:
hentai=Hentai(hentai_ID, cookies, headers) # create hentai object
except ValueError: # if hentai does not exist:
Expand All @@ -67,7 +70,7 @@ def main():
logging.info("--------------------------------------------------")


Hentai.save_galleries() # now save all galleries to file, might not have all saved yet because usually only save roughly every 10 galleries to file
Hentai.save_galleries() # save all galleries to file

logging.info("Deleting leftover image directories...")
for hentai_ID in hentai_ID_list: # attempt final cleanup
Expand Down

0 comments on commit a9b84bc

Please sign in to comment.