Skip to content

Commit

Permalink
fix #349
Browse files Browse the repository at this point in the history
  • Loading branch information
RicterZ committed Jan 11, 2025
1 parent 13b584a commit 803957b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
4 changes: 4 additions & 0 deletions nhentai/constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,12 @@ def get_nhentai_home() -> str:

IMAGE_URL = f'{urlparse(BASE_URL).scheme}://i.{urlparse(BASE_URL).hostname}/galleries'
IMAGE_URL_MIRRORS = [
f'{urlparse(BASE_URL).scheme}://i1.{urlparse(BASE_URL).hostname}',
f'{urlparse(BASE_URL).scheme}://i2.{urlparse(BASE_URL).hostname}',
f'{urlparse(BASE_URL).scheme}://i3.{urlparse(BASE_URL).hostname}',
f'{urlparse(BASE_URL).scheme}://i4.{urlparse(BASE_URL).hostname}',
f'{urlparse(BASE_URL).scheme}://i5.{urlparse(BASE_URL).hostname}',
f'{urlparse(BASE_URL).scheme}://i6.{urlparse(BASE_URL).hostname}',
f'{urlparse(BASE_URL).scheme}://i7.{urlparse(BASE_URL).hostname}',
]

Expand Down
16 changes: 10 additions & 6 deletions nhentai/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ async def fiber(self, tasks):
for completed_task in asyncio.as_completed(tasks):
try:
result = await completed_task
logger.info(f'{result[1]} download completed')
if result[1]:
logger.info(f'{result[1]} download completed')
else:
logger.warning(f'{result[1]} download failed, return value {result[0]}')
except Exception as e:
logger.error(f'An error occurred: {e}')

Expand Down Expand Up @@ -85,11 +88,11 @@ async def download(self, url, folder='', filename='', retried=0, proxy=None, len

if not await self.save(filename, response):
logger.error(f'Can not download image {url}')
return 1, None
return 1, url

except (httpx.HTTPStatusError, httpx.TimeoutException, httpx.ConnectError) as e:
if retried < 3:
logger.info(f'Download {filename} failed, retrying({retried + 1}) times...')
logger.warning(f'Download {filename} failed, retrying({retried + 1}) times...')
return await self.download(
url=url,
folder=folder,
Expand All @@ -98,7 +101,8 @@ async def download(self, url, folder='', filename='', retried=0, proxy=None, len
proxy=proxy,
)
else:
return 0, None
logger.warning(f'Download {filename} failed with 3 times retried, skipped')
return 0, url

except NHentaiImageNotExistException as e:
os.remove(save_file_path)
Expand All @@ -110,10 +114,10 @@ async def download(self, url, folder='', filename='', retried=0, proxy=None, len
logger.error(f"Exception type: {type(e)}")
traceback.print_stack()
logger.critical(str(e))
return 0, None
return 0, url

except KeyboardInterrupt:
return -3, None
return -3, url

return 1, url

Expand Down
8 changes: 6 additions & 2 deletions nhentai/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,12 @@ def doujinshi_parser(id_, counter=0):

ext = []
for i in html.find_all('div', attrs={'class': 'thumb-container'}):
_, ext_name = os.path.basename(i.img.attrs['data-src']).rsplit('.', 1)
ext.append(ext_name)
base_name = os.path.basename(i.img.attrs['data-src'])
ext_name = base_name.split('.')
if len(ext_name) == 2:
ext.append(ext_name[-1])
elif len(ext_name) == 3:
ext.append(ext_name[1])

if not img_id:
logger.critical(f'Tried yo get image id failed of id: {id_}')
Expand Down

0 comments on commit 803957b

Please sign in to comment.