From 50be89db44e13e7f6409321144c1504a334e33a5 Mon Sep 17 00:00:00 2001 From: RicterZ Date: Sun, 27 Jan 2019 10:06:12 +0800 Subject: [PATCH] fix extension issue #44 --- nhentai/doujinshi.py | 7 +++++-- nhentai/parser.py | 8 +++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/nhentai/doujinshi.py b/nhentai/doujinshi.py index 0dc6faf..6cb17e8 100644 --- a/nhentai/doujinshi.py +++ b/nhentai/doujinshi.py @@ -59,8 +59,11 @@ class Doujinshi(object): if self.downloader: download_queue = [] - for i in range(1, self.pages + 1): - download_queue.append('%s/%d/%d.%s' % (IMAGE_URL, int(self.img_id), i, self.ext)) + if len(self.ext) != self.pages: + logger.warning('Page count and ext count do not equal') + + for i in range(1, min(self.pages, len(self.ext)) + 1): + download_queue.append('%s/%d/%d.%s' % (IMAGE_URL, int(self.img_id), i, self.ext[i-1])) self.downloader.download(download_queue, self.filename) diff --git a/nhentai/parser.py b/nhentai/parser.py index e5b8cd3..2b0f26c 100644 --- a/nhentai/parser.py +++ b/nhentai/parser.py @@ -115,12 +115,18 @@ def doujinshi_parser(id_): doujinshi_cover = html.find('div', attrs={'id': 'cover'}) img_id = re.search('/galleries/([\d]+)/cover\.(jpg|png)$', doujinshi_cover.a.img.attrs['data-src']) + + 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) + if not img_id: logger.critical('Tried yo get image id failed') exit(1) doujinshi['img_id'] = img_id.group(1) - doujinshi['ext'] = img_id.group(2) + doujinshi['ext'] = ext pages = 0 for _ in doujinshi_info.find_all('div', class_=''):