add doujinshi folder formatter

This commit is contained in:
RicterZ 2019-05-18 22:13:23 +08:00
parent cf4291d3c2
commit 2c61fd3a3f
4 changed files with 23 additions and 5 deletions

View File

@ -79,6 +79,19 @@ Download your favorites with delay:
nhentai --favorites --download --delay 1
Format output doujinshi folder name:
.. code-block:: bash
nhentai --id 261100 --format '[%i]%s'
Supported doujinshi folder formatter:
- %i: Doujinshi id
- %t: Doujinshi name
- %s: Doujinshi subtitle (translated name)
- %a: Doujinshi authors' name
Other options:

View File

@ -72,7 +72,7 @@ def cmd_parser():
help='uses a proxy, for example: http://127.0.0.1:1080')
parser.add_option('--file', '-f', type='string', dest='file', action='store', help='read gallery IDs from file.')
parser.add_option('--format', type='string', dest='name_format', action='store',
help='format the saved folder name', default='[%i][%n]')
help='format the saved folder name', default='[%i][%a][%t]')
# generate options
parser.add_option('--html', dest='html_viewer', action='store_true',

View File

@ -48,7 +48,7 @@ def main():
if options.delay:
time.sleep(options.delay)
doujinshi_info = doujinshi_parser(id_)
doujinshi_list.append(Doujinshi(**doujinshi_info))
doujinshi_list.append(Doujinshi(name_format=options.name_format, **doujinshi_info))
if not options.is_show:
downloader = Downloader(path=options.output_dir,

View File

@ -27,7 +27,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,7 +36,12 @@ 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))
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 = name_format
def __repr__(self):
return '<Doujinshi: {0}>'.format(self.name)
@ -46,7 +51,7 @@ class Doujinshi(object):
["Doujinshi", self.name],
["Subtitle", self.info.subtitle],
["Characters", self.info.character],
["Authors", self.info.artist],
["Authors", self.info.artists],
["Language", self.info.language],
["Tags", self.info.tags],
["URL", self.url],