]> git.lizzy.rs Git - nhentai.git/blobdiff - hentai/dojinshi.py
multithreading download
[nhentai.git] / hentai / dojinshi.py
index 22e5d9d6e8ceb2e79dcd2a6a8724f84c923384ce..0cc214cc320acecce8be18440ff9ffc6ddee9e15 100644 (file)
@@ -1 +1,40 @@
-__author__ = 'ricter'
+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)
\ No newline at end of file