From 07d804b047b396063680c3fd67dca431b245778e Mon Sep 17 00:00:00 2001
From: Anh Nhan Nguyen <anhnhan@outlook.com>
Date: Wed, 22 Apr 2020 06:19:12 +0200
Subject: [PATCH] move ComicInfo.xml behind the --comic-info flag

---
 nhentai/cmdline.py | 4 +++-
 nhentai/command.py | 2 +-
 nhentai/utils.py   | 5 +++--
 3 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/nhentai/cmdline.py b/nhentai/cmdline.py
index 9decc88..13a8692 100644
--- a/nhentai/cmdline.py
+++ b/nhentai/cmdline.py
@@ -38,7 +38,7 @@ def banner():
 def cmd_parser():
     parser = OptionParser('\n  nhentai --search [keyword] --download'
                           '\n  NHENTAI=http://h.loli.club nhentai --id [ID ...]'
-                          '\n  nhentai --file [filename]'    
+                          '\n  nhentai --file [filename]'
                           '\n\nEnvironment Variable:\n'
                           '  NHENTAI                 nhentai mirror url')
     # operation options
@@ -95,6 +95,8 @@ def cmd_parser():
                       help='generate a main viewer contain all the doujin in the folder')
     parser.add_option('--cbz', '-C', dest='is_cbz', action='store_true',
                       help='generate Comic Book CBZ File')
+    parser.add_option('--comic-info', dest='write_comic_info', action='store_true',
+                      help='when generating Comic Book CBZ File, also write ComicInfo.xml')
     parser.add_option('--rm-origin-dir', dest='rm_origin_dir', action='store_true', default=False,
                       help='remove downloaded doujinshi dir when generated CBZ file.')
 
diff --git a/nhentai/command.py b/nhentai/command.py
index ff962d7..6f821d3 100644
--- a/nhentai/command.py
+++ b/nhentai/command.py
@@ -109,7 +109,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, options.rm_origin_dir)
+                generate_cbz(options.output_dir, doujinshi, options.rm_origin_dir, options.write_comic_info)
 
         if options.main_viewer:
             generate_main_html(options.output_dir)
diff --git a/nhentai/utils.py b/nhentai/utils.py
index 421abb8..6a22d65 100644
--- a/nhentai/utils.py
+++ b/nhentai/utils.py
@@ -168,10 +168,11 @@ def generate_main_html(output_dir='./'):
         logger.warning('Writing Main Viewer failed ({})'.format(str(e)))
 
 
-def generate_cbz(output_dir='.', doujinshi_obj=None, rm_origin_dir=False):
+def generate_cbz(output_dir='.', doujinshi_obj=None, rm_origin_dir=False, write_comic_info=False):
     if doujinshi_obj is not None:
         doujinshi_dir = os.path.join(output_dir, doujinshi_obj.filename)
-        serialize_comicxml(doujinshi_obj, doujinshi_dir)
+        if write_comic_info:
+            serialize_comicxml(doujinshi_obj, doujinshi_dir)
         cbz_filename = os.path.join(os.path.join(doujinshi_dir, '..'), '{}.cbz'.format(doujinshi_obj.filename))
     else:
         cbz_filename = './doujinshi.cbz'