]> git.lizzy.rs Git - nhentai.git/blob - nhentai/doujinshi.py
feature: proxy support
[nhentai.git] / nhentai / doujinshi.py
1 # coding: utf-8
2 from __future__ import print_function
3 from constant import DETAIL_URL, IMAGE_URL
4 from logger import logger
5
6
7 class Doujinshi(object):
8     def __init__(self, name=None, subtitle=None, id=None, img_id=None, ext='jpg', pages=0):
9         self.name = name
10         self.subtitle = subtitle
11         self.id = id
12         self.img_id = img_id
13         self.ext = ext
14         self.pages = pages
15         self.downloader = None
16         self.url = '%s/%d' % (DETAIL_URL, self.id)
17
18     def __repr__(self):
19         return '<Doujinshi: %s>' % self.name
20
21     def show(self):
22         logger.info('Print doujinshi information')
23         print('Doujinshi: %s' % self.name)
24         print('Subtitle: %s' % self.subtitle)
25         print('URL: %s' % self.url)
26         print('Pages: %d' % self.pages)
27
28     def download(self):
29         logger.info('Start download doujinshi: %s' % self.name)
30         if self.downloader:
31             download_queue = []
32             for i in xrange(1, self.pages + 1):
33                 download_queue.append('%s/%d/%d.%s' % (IMAGE_URL, int(self.img_id), i, self.ext))
34             self.downloader.download(download_queue, self.id)
35         else:
36             logger.critical('Downloader has not be loaded')
37
38
39 if __name__ == '__main__':
40     test = Doujinshi(name='test nhentai doujinshi', id=1)
41     print(test)
42     test.show()
43     try:
44         test.download()
45     except Exception as e:
46         print('Exception: %s' % str(e))