]> git.lizzy.rs Git - nhentai.git/blobdiff - nhentai/doujinshi.py
fix format
[nhentai.git] / nhentai / doujinshi.py
index 88e092538ce55befd6facdf9fcce342cde108950..3dea1044daf2aae62adf82f4f8765242cf732aaf 100644 (file)
@@ -1,13 +1,11 @@
 # coding: utf-8
-from __future__ import print_function, unicode_literals
+
 from tabulate import tabulate
-from future.builtins import range
 
 from nhentai.constant import DETAIL_URL, IMAGE_URL
 from nhentai.logger import logger
 from nhentai.utils import format_filename
 
-
 EXT_MAP = {
     'j': 'jpg',
     'p': 'png',
@@ -27,7 +25,7 @@ class DoujinshiInfo(dict):
 
 
 class Doujinshi(object):
-    def __init__(self, name=None, id=None, img_id=None, ext='', pages=0, **kwargs):
+    def __init__(self, name=None, id=None, img_id=None, ext='', pages=0, name_format='[%i][%a][%t]', **kwargs):
         self.name = name
         self.id = id
         self.img_id = img_id
@@ -36,23 +34,31 @@ class Doujinshi(object):
         self.downloader = None
         self.url = '%s/%d' % (DETAIL_URL, self.id)
         self.info = DoujinshiInfo(**kwargs)
-        self.filename = format_filename('[%s][%s][%s]' % (self.id, self.info.artist, self.name))
 
-    def __repr__(self):
-        return '<Doujinshi: {0}>'.format(self.name)
+        name_format = name_format.replace('%i', str(self.id))
+        name_format = name_format.replace('%a', self.info.artists)
+        name_format = name_format.replace('%t', self.name)
+        name_format = name_format.replace('%s', self.info.subtitle)
+        self.filename = format_filename(name_format)
 
-    def show(self):
-        table = [
+        self.table = [
+            ["Parodies", self.info.parodies],
             ["Doujinshi", self.name],
             ["Subtitle", self.info.subtitle],
-            ["Characters", self.info.character],
-            ["Authors", self.info.artist],
-            ["Language", self.info.language],
+            ["Characters", self.info.characters],
+            ["Authors", self.info.artists],
+            ["Languages", self.info.languages],
             ["Tags", self.info.tags],
             ["URL", self.url],
             ["Pages", self.pages],
         ]
-        logger.info(u'Print doujinshi information of {0}\n{1}'.format(self.id, tabulate(table)))
+
+    def __repr__(self):
+        return '<Doujinshi: {0}>'.format(self.name)
+
+    def show(self):
+
+        logger.info(u'Print doujinshi information of {0}\n{1}'.format(self.id, tabulate(self.table)))
 
     def download(self):
         logger.info('Starting to download doujinshi: %s' % self.name)
@@ -63,7 +69,7 @@ class Doujinshi(object):
                 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]))
+                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)