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