Skip to content

Commit

Permalink
fixed download threads not finishing causing the program to stall by …
Browse files Browse the repository at this point in the history
…adding a download timeout
  • Loading branch information
9FS committed Nov 2, 2023
1 parent 2758e1d commit 6c07925
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
20 changes: 16 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ 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/2021-11-15-nHentai-to-PDF"
version = "1.4.1"
version = "1.4.2"

[tool.poetry.dependencies]
kfsconfig = "^1.0.0"
kfsfstr = "^1.0.0"
kfslog = "^1.0.0"
kfsmedia = "^2.1.0"
kfsmedia = "^2.2.0"
python = "^3.11.0"

[tool.poetry.group.dev.dependencies]
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ kfsconfig==1.0.2 ; python_full_version >= "3.11.0" and python_full_version < "4.
kfsfstr==1.1.0 ; python_full_version >= "3.11.0" and python_full_version < "4.0.0"
kfslog==1.0.1 ; python_full_version >= "3.11.0" and python_full_version < "4.0.0"
kfsmath==1.0.1 ; python_full_version >= "3.11.0" and python_full_version < "4.0.0"
kfsmedia==2.1.2 ; python_full_version >= "3.11.0" and python_full_version < "4.0.0"
kfsmedia==2.2.0 ; python_full_version >= "3.11.0" and python_full_version < "4.0.0"
pebble==5.0.3 ; python_full_version >= "3.11.0" and python_full_version < "4.0.0"
pillow==10.1.0 ; python_full_version >= "3.11.0" and python_full_version < "4.0.0"
requests==2.31.0 ; python_full_version >= "3.11.0" and python_full_version < "4.0.0"
urllib3==2.0.7 ; python_full_version >= "3.11.0" and python_full_version < "4.0.0"
7 changes: 4 additions & 3 deletions src/Hentai.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ def download(self, dest_path: str) -> list[PIL.Image.Image]:
pages_URL: list[str]=[] # URL to individual pages to download
PDF: list[PIL.Image.Image] # finished PDF
PDF_filepath: str # where to save downloaded result, ID title pdf, but title maximum 140 characters and without illegal filename characters
TIMEOUT=100 # timeout for downloading images
TITLE_CHARACTERS_FORBIDDEN: str="\\/:*?\"<>|\t\n" # in title forbidden characters


Expand All @@ -221,11 +222,11 @@ def download(self, dest_path: str) -> list[PIL.Image.Image]:
raise KFSmedia.DownloadError(f"Error in {self.download.__name__}{inspect.signature(self.download)}: \"{PDF_filepath}\" already exists as directory. Skipped download.")


while self._give_up==False: # while not giving up: try to download and convert
while self._give_up==False: # while not giving up: try to download and convert
try:
KFSmedia.download_medias(pages_URL, images_filepath) # download images # type:ignore
KFSmedia.download_medias(pages_URL, images_filepath, timeout=TIMEOUT) # download images # type:ignore
except KFSmedia.DownloadError as e:
self._increment_fails(e.args[0]) # increment fails, may trigger giving up
self._increment_fails(e.args[0]) # increment fails, may trigger giving up
continue

try:
Expand Down

0 comments on commit 6c07925

Please sign in to comment.