mirror of
				https://github.com/RicterZ/nhentai.git
				synced 2025-10-31 17:49:34 +01:00 
			
		
		
		
	split metadata.json out from html generate function #386
This commit is contained in:
		| @@ -131,6 +131,8 @@ def cmd_parser(): | |||||||
|                       help='generate a metadata file in doujinshi format') |                       help='generate a metadata file in doujinshi format') | ||||||
|     parser.add_option('--regenerate', dest='regenerate', action='store_true', default=False, |     parser.add_option('--regenerate', dest='regenerate', action='store_true', default=False, | ||||||
|                       help='regenerate the cbz or pdf file if exists') |                       help='regenerate the cbz or pdf file if exists') | ||||||
|  |     parser.add_option('--no-metadata', dest='no_metadata', action='store_true', default=False, | ||||||
|  |                       help='don\'t generate metadata json file in doujinshi output path') | ||||||
|  |  | ||||||
|     # nhentai options |     # nhentai options | ||||||
|     parser.add_option('--cookie', type='str', dest='cookie', action='store', |     parser.add_option('--cookie', type='str', dest='cookie', action='store', | ||||||
|   | |||||||
| @@ -15,6 +15,7 @@ from nhentai.doujinshi import Doujinshi | |||||||
| from nhentai.downloader import Downloader | from nhentai.downloader import Downloader | ||||||
| from nhentai.logger import logger | from nhentai.logger import logger | ||||||
| from nhentai.constant import BASE_URL | from nhentai.constant import BASE_URL | ||||||
|  | from nhentai.serializer import serialize_json | ||||||
| from nhentai.utils import generate_html, generate_doc, generate_main_html, generate_metadata_file, \ | from nhentai.utils import generate_html, generate_doc, generate_main_html, generate_metadata_file, \ | ||||||
|     paging, check_cookie, signal_handler, DB, move_to_folder |     paging, check_cookie, signal_handler, DB, move_to_folder | ||||||
|  |  | ||||||
| @@ -115,6 +116,9 @@ def main(): | |||||||
|             if not options.is_nohtml: |             if not options.is_nohtml: | ||||||
|                 generate_html(options.output_dir, doujinshi, template=constant.CONFIG['template']) |                 generate_html(options.output_dir, doujinshi, template=constant.CONFIG['template']) | ||||||
|  |  | ||||||
|  |             if not options.no_metadata: | ||||||
|  |                 generate_doc('json', options.output_dir, doujinshi, options.regenerate) | ||||||
|  |  | ||||||
|             if options.is_cbz: |             if options.is_cbz: | ||||||
|                 generate_doc('cbz', options.output_dir, doujinshi, options.regenerate) |                 generate_doc('cbz', options.output_dir, doujinshi, options.regenerate) | ||||||
|  |  | ||||||
|   | |||||||
| @@ -2,12 +2,11 @@ | |||||||
| import json | import json | ||||||
| import os | import os | ||||||
|  |  | ||||||
| from nhentai.constant import PATH_SEPARATOR | from nhentai.constant import PATH_SEPARATOR, LANGUAGE_ISO | ||||||
| from xml.sax.saxutils import escape | from xml.sax.saxutils import escape | ||||||
| from nhentai.constant import LANGUAGE_ISO |  | ||||||
|  |  | ||||||
|  |  | ||||||
| def serialize_json(doujinshi, output_dir): | def serialize_json(doujinshi, output_dir: str): | ||||||
|     metadata = {'title': doujinshi.name, |     metadata = {'title': doujinshi.name, | ||||||
|                 'subtitle': doujinshi.info.subtitle} |                 'subtitle': doujinshi.info.subtitle} | ||||||
|     if doujinshi.info.favorite_counts: |     if doujinshi.info.favorite_counts: | ||||||
|   | |||||||
| @@ -16,7 +16,7 @@ from requests.structures import CaseInsensitiveDict | |||||||
| from nhentai import constant | from nhentai import constant | ||||||
| from nhentai.constant import PATH_SEPARATOR | from nhentai.constant import PATH_SEPARATOR | ||||||
| from nhentai.logger import logger | from nhentai.logger import logger | ||||||
| from nhentai.serializer import serialize_json, serialize_comic_xml, set_js_database | from nhentai.serializer import serialize_comic_xml, serialize_json, set_js_database | ||||||
|  |  | ||||||
| MAX_FIELD_LENGTH = 100 | MAX_FIELD_LENGTH = 100 | ||||||
| EXTENSIONS = ('.png', '.jpg', '.jpeg', '.gif', '.webp') | EXTENSIONS = ('.png', '.jpg', '.jpeg', '.gif', '.webp') | ||||||
| @@ -142,7 +142,7 @@ def generate_html(output_dir='.', doujinshi_obj=None, template='default'): | |||||||
|     js = readfile(f'viewer/{template}/scripts.js') |     js = readfile(f'viewer/{template}/scripts.js') | ||||||
|  |  | ||||||
|     if doujinshi_obj is not None: |     if doujinshi_obj is not None: | ||||||
|         serialize_json(doujinshi_obj, doujinshi_dir) |         # serialize_json(doujinshi_obj, doujinshi_dir) | ||||||
|         name = doujinshi_obj.name |         name = doujinshi_obj.name | ||||||
|     else: |     else: | ||||||
|         name = {'title': 'nHentai HTML Viewer'} |         name = {'title': 'nHentai HTML Viewer'} | ||||||
| @@ -274,6 +274,9 @@ def generate_doc(file_type='', output_dir='.', doujinshi_obj=None, regenerate=Fa | |||||||
|         except ImportError: |         except ImportError: | ||||||
|             logger.error("Please install img2pdf package by using pip.") |             logger.error("Please install img2pdf package by using pip.") | ||||||
|  |  | ||||||
|  |     elif file_type == 'json': | ||||||
|  |         serialize_json(doujinshi_obj, doujinshi_dir) | ||||||
|  |  | ||||||
|  |  | ||||||
| def format_filename(s, length=MAX_FIELD_LENGTH, _truncate_only=False): | def format_filename(s, length=MAX_FIELD_LENGTH, _truncate_only=False): | ||||||
|     """ |     """ | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user