diff --git a/nhentai/cmdline.py b/nhentai/cmdline.py index f7f7136..1f4543d 100644 --- a/nhentai/cmdline.py +++ b/nhentai/cmdline.py @@ -67,7 +67,9 @@ def cmd_parser(): help='Don\'t generate HTML') parser.add_option('--cbz', dest='is_cbz', action='store_true', - help='Generate Comic Book CBZ File') + help='Generate Comic Book CBZ File') + parser.add_option('--rm-origin-dir', dest='rm_origin_dir', action='store_true', default=False, + help='Remove downloaded doujinshi dir when generated CBZ file.') try: sys.argv = list(map(lambda x: unicode(x.decode(sys.stdin.encoding)), sys.argv)) diff --git a/nhentai/command.py b/nhentai/command.py index b8bea02..75356cb 100644 --- a/nhentai/command.py +++ b/nhentai/command.py @@ -59,7 +59,7 @@ def main(): if not options.is_nohtml and not options.is_cbz: generate_html(options.output_dir, doujinshi) elif options.is_cbz: - generate_cbz(options.output_dir, doujinshi) + generate_cbz(options.output_dir, doujinshi, options.rm_origin_dir) if not platform.system() == 'Windows': logger.log(15, '🍻 All done.') diff --git a/nhentai/utils.py b/nhentai/utils.py index 618a6ad..8c204cd 100644 --- a/nhentai/utils.py +++ b/nhentai/utils.py @@ -83,25 +83,27 @@ def generate_html(output_dir='.', doujinshi_obj=None): logger.warning('Writen HTML Viewer failed ({})'.format(str(e))) -def generate_cbz(output_dir='.', doujinshi_obj=None): +def generate_cbz(output_dir='.', doujinshi_obj=None, rm_origin_dir=False): if doujinshi_obj is not None: doujinshi_dir = os.path.join(output_dir, format_filename('%s-%s' % (doujinshi_obj.id, doujinshi_obj.name))) - cbz_filename = os.path.join(output_dir, format_filename('%s-%s.cbz' % (doujinshi_obj.id, - doujinshi_obj.name))) + cbz_filename = os.path.join(os.path.join(doujinshi_dir, '..'), '%s.cbz' % doujinshi_obj.id) else: cbz_filename = './doujinshi.cbz' doujinshi_dir = '.' file_list = os.listdir(doujinshi_dir) file_list.sort() - + + logger.info('Writing CBZ file to path: {}'.format(cbz_filename)) with zipfile.ZipFile(cbz_filename, 'w') as cbz_pf: for image in file_list: image_path = os.path.join(doujinshi_dir, image) cbz_pf.write(image_path, image) - - shutil.rmtree(doujinshi_dir, ignore_errors=True) + + if rm_origin_dir: + shutil.rmtree(doujinshi_dir, ignore_errors=True) + logger.log(15, 'Comic Book CBZ file has been write to \'{0}\''.format(doujinshi_dir))