4
0
mirror of https://github.com/RicterZ/nhentai.git synced 2025-05-04 10:26:09 +02:00
2015-04-19 13:13:55 +08:00

40 lines
1.1 KiB
Python

import Queue
from constant import DETAIL_URL, IMAGE_URL
class Dojinshi(object):
def __init__(self, name=None, subtitle=None, id=None, pages=0):
self.name = name
self.subtitle = subtitle
self.id = id
self.pages = pages
self.downloader = None
self.url = '%s/%d' % (DETAIL_URL, self.id)
def __repr__(self):
return '<Dojinshi: %s>' % self.name
def show(self):
print 'Dojinshi: %s' % self.name
print 'Subtitle: %s' % self.subtitle
print 'URL: %s' % self.url
print 'Pages: %d' % self.pages
def download(self):
if self.downloader:
download_queue = Queue.Queue()
for i in xrange(1, self.pages + 1):
download_queue.put('%s/%d/%d.jpg' % (IMAGE_URL, self.id, i))
self.downloader.download(download_queue)
else:
raise Exception('Downloader has not be loaded')
if __name__ == '__main__':
test = Dojinshi(name='test hentai dojinshi', id=1)
print test
test.show()
try:
test.download()
except Exception, e:
print 'Exception: %s' % str(e)