]> git.lizzy.rs Git - nhentai.git/commitdiff
fix extension issue #44
authorRicterZ <ricterzheng@gmail.com>
Sun, 27 Jan 2019 02:06:12 +0000 (10:06 +0800)
committerRicterZ <ricterzheng@gmail.com>
Sun, 27 Jan 2019 02:06:12 +0000 (10:06 +0800)
nhentai/doujinshi.py
nhentai/parser.py

index 0dc6faf64ff7e205b07e06c97b03a9a54bd62313..6cb17e8dacf3eaecf1038ef4c21cb7979a12e195 100644 (file)
@@ -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)
 
index e5b8cd3290f8b125e7f547cfca44e96d3dbd7f35..2b0f26c15bc470e5b1d2652c61e989f87e79c7cc 100644 (file)
@@ -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_=''):