]> git.lizzy.rs Git - nhentai.git/commitdiff
Merge branch 'master' of github.com:RicterZ/nhentai
authorRicterZ <ricterzheng@gmail.com>
Mon, 7 Jun 2021 08:48:36 +0000 (16:48 +0800)
committerRicterZ <ricterzheng@gmail.com>
Mon, 7 Jun 2021 08:48:36 +0000 (16:48 +0800)
1  2 
nhentai/utils.py

diff --combined nhentai/utils.py
index 9b2b706fade0d76b5e8bbb46d83b3323236335b7,3364d0d4b675b40b6a13141d47bf9cb170dd18c0..eeae3de694b77d78cb3efccc16189d26aaf9c763
@@@ -10,7 -10,7 +10,7 @@@ import sqlite
  
  from nhentai import constant
  from nhentai.logger import logger
 -from nhentai.serializer import serialize_json, serialize_comicxml, set_js_database
 +from nhentai.serializer import serialize_json, serialize_comic_xml, set_js_database
  
  
  def request(method, url, **kwargs):
@@@ -74,6 -74,13 +74,13 @@@ def generate_html(output_dir='.', douji
      else:
          doujinshi_dir = '.'
  
+     if not os.path.exists(doujinshi_dir):
+         logger.warning('Path \'{0}\' does not exist, creating.'.format(doujinshi_dir))
+         try:
+             os.makedirs(doujinshi_dir)
+         except EnvironmentError as e:
+             logger.critical('{0}'.format(str(e)))
      file_list = os.listdir(doujinshi_dir)
      file_list.sort()
  
@@@ -174,7 -181,7 +181,7 @@@ def generate_cbz(output_dir='.', doujin
      if doujinshi_obj is not None:
          doujinshi_dir = os.path.join(output_dir, doujinshi_obj.filename)
          if write_comic_info:
 -            serialize_comicxml(doujinshi_obj, doujinshi_dir)
 +            serialize_comic_xml(doujinshi_obj, doujinshi_dir)
          cbz_filename = os.path.join(os.path.join(doujinshi_dir, '..'), '{}.cbz'.format(doujinshi_obj.filename))
      else:
          cbz_filename = './doujinshi.cbz'
  def generate_pdf(output_dir='.', doujinshi_obj=None, rm_origin_dir=False):
      try:
          import img2pdf
-         
          """Write images to a PDF file using img2pdf."""
          if doujinshi_obj is not None:
              doujinshi_dir = os.path.join(output_dir, doujinshi_obj.filename)
              shutil.rmtree(doujinshi_dir, ignore_errors=True)
  
          logger.log(15, 'PDF file has been written to \'{0}\''.format(doujinshi_dir))
-         
      except ImportError:
          logger.error("Please install img2pdf package by using pip.")
  
@@@ -246,6 -253,7 +253,6 @@@ def format_filename(s)
      ban_chars = '\\\'/:,;*?"<>|\t'
      filename = s.translate(str.maketrans(ban_chars, ' '*len(ban_chars))).strip()
      filename = ' '.join(filename.split())
 -    print(repr(filename))
  
      while filename.endswith('.'):
          filename = filename[:-1]