Add new settings
This commit is contained in:
@@ -21,6 +21,8 @@ class Config:
|
||||
self._data['type'] = 'epub,txt'
|
||||
self._data['export_book_template'] = 'exported/<book_name> - <author_name>.<ext>' # noqa: E501
|
||||
self._data['export_chapter_template'] = 'exported/<book_id>/<chapter_id>.txt' # noqa: E501
|
||||
self._data['export_nodownload'] = True
|
||||
self._data['img_cache_dir'] = 'img_cache'
|
||||
self._data['page_size'] = 10
|
||||
self.save()
|
||||
|
||||
@@ -72,6 +74,10 @@ class Config:
|
||||
def export_epub(self):
|
||||
return self.export_type.find('epub') >= 0
|
||||
|
||||
@cached_property
|
||||
def export_nodownload(self):
|
||||
return self.get_arg('export_nodownload', True)
|
||||
|
||||
@cached_property
|
||||
def export_txt(self):
|
||||
return self.export_type.find('txt') >= 0
|
||||
|
||||
22
epub.py
22
epub.py
@@ -360,6 +360,28 @@ class EpubFile:
|
||||
self.EpubList.append(ch)
|
||||
self.epub.spine.append(ch)
|
||||
|
||||
def add_nodownload_chapter(self, chapter, division_name: str):
|
||||
chapter_title = chapter['chapter_title']
|
||||
chapter_id = chapter['chapter_id']
|
||||
ch = epub.EpubHtml(
|
||||
title=f"{chapter_title} (未下载)",
|
||||
file_name=f'ch{chapter_id}.xhtml',
|
||||
lang='zh-CN',
|
||||
uid=f'ch{chapter_id}',
|
||||
)
|
||||
if division_name == '作品相关':
|
||||
ch.is_linear = False
|
||||
ch.content = f'<h1 style="text-align: center;">{chapter_title}</h1>\n<p>本章未下载</p>' # noqa: E501
|
||||
self.epub.add_item(ch)
|
||||
if self.last_division_name != division_name:
|
||||
self.EpubList.append([epub.Link(ch.file_name, division_name), []])
|
||||
self.last_division_name = division_name
|
||||
if isinstance(self.EpubList[-1], list):
|
||||
self.EpubList[-1][-1].append(ch)
|
||||
else:
|
||||
self.EpubList.append(ch)
|
||||
self.epub.spine.append(ch)
|
||||
|
||||
def save_epub_file(self): # save epub file to local
|
||||
# the path to save epub file to local
|
||||
self.epub.toc = self.EpubList
|
||||
|
||||
@@ -100,9 +100,11 @@ def export_book(ncw: NovelCiwei, db: CwmDb, cfg: Config, bn: BooksNew,
|
||||
if cfg.export_epub:
|
||||
epub.add_chapter(chapter, content, division_name)
|
||||
count += 1
|
||||
else:
|
||||
elif cfg.export_nodownload:
|
||||
if cfg.export_txt:
|
||||
txt.write(f"第{chapter_index}章 {chapter_title} (未下载)\n\n") # noqa: E501
|
||||
if cfg.export_epub:
|
||||
epub.add_nodownload_chapter(chapter, division_name)
|
||||
chapter_index += 1
|
||||
print(f'Exported {count} chapters.')
|
||||
finally:
|
||||
|
||||
2
main.py
2
main.py
@@ -3,6 +3,7 @@ from config import Config
|
||||
from db import CwmDb
|
||||
from novelCiwei import NovelCiwei
|
||||
from booksnew import BooksNew
|
||||
from utils import parse_bool
|
||||
|
||||
|
||||
parser = ArgumentParser(description='A tool to export CiWeiMao novel cache.')
|
||||
@@ -19,6 +20,7 @@ parser.add_argument('-t', '--type', help='Export type. Available types: epub, tx
|
||||
parser.add_argument('--ebt', '--export-book-template', help='The template of the exported book. Available key: <ext>, <book_id>, <book_name>, <author_name> eta.') # noqa: E501
|
||||
parser.add_argument('--icd', '--image-cache-dir', help='Path to image cache directory.') # noqa: E501
|
||||
parser.add_argument('-s', '--page-size', help='Maximum size of a page when asking for choices.', type=int) # noqa: E501
|
||||
parser.add_argument('-a', '--export-nodownload', help='export not downloaded chapter when exporting book.', type=parse_bool) # noqa: E501
|
||||
parser.add_argument('action', help='The action to do.', choices=['importkey', 'exportchapter', 'exportbook', 'export', 'ik', 'ec', 'eb', 'e'], nargs='?', default='export') # noqa: E501
|
||||
|
||||
|
||||
|
||||
10
utils.py
10
utils.py
@@ -53,3 +53,13 @@ def ask_choice(cfg: Config, choices: list, prompt='请选择:', fn=None, extra
|
||||
if index < 0 or index >= count:
|
||||
continue
|
||||
return choices[index]
|
||||
|
||||
|
||||
def parse_bool(s: str):
|
||||
if s.lower() in ['y', 'yes', 'true', 't']:
|
||||
return True
|
||||
if s.lower() in ['n', 'no', 'false', 'f']:
|
||||
return False
|
||||
if s.isnumeric():
|
||||
return bool(int(s))
|
||||
raise ValueError(f"Unexpected bool value: {s}")
|
||||
|
||||
Reference in New Issue
Block a user