|
|
|
@@ -7,7 +7,7 @@ from tqdm import tqdm
|
|
|
|
from pyfzf.pyfzf import FzfPrompt
|
|
|
|
from pyfzf.pyfzf import FzfPrompt
|
|
|
|
import click
|
|
|
|
import click
|
|
|
|
|
|
|
|
|
|
|
|
import os, subprocess, shlex, logging
|
|
|
|
import os, subprocess, shlex, logging, re
|
|
|
|
import importlib.resources as pkg_resources
|
|
|
|
import importlib.resources as pkg_resources
|
|
|
|
from dataclasses import dataclass
|
|
|
|
from dataclasses import dataclass
|
|
|
|
from typing import List
|
|
|
|
from typing import List
|
|
|
|
@@ -46,7 +46,7 @@ class GBConvert():
|
|
|
|
cleanpages: bool = True,
|
|
|
|
cleanpages: bool = True,
|
|
|
|
):
|
|
|
|
):
|
|
|
|
tocpage = os.path.dirname(url) # ToC website url
|
|
|
|
tocpage = os.path.dirname(url) # ToC website url
|
|
|
|
dir_output = self.getDir()
|
|
|
|
dir_output = self.getDir(url)
|
|
|
|
logger.debug('Downloading to %s, expecting files in in %s', self.dir_download, dir_output)
|
|
|
|
logger.debug('Downloading to %s, expecting files in in %s', self.dir_download, dir_output)
|
|
|
|
author = author
|
|
|
|
author = author
|
|
|
|
title = title
|
|
|
|
title = title
|
|
|
|
@@ -105,8 +105,7 @@ class GBConvert():
|
|
|
|
def create_epub(self, author, title, chapters, dir_output):
|
|
|
|
def create_epub(self, author, title, chapters, dir_output):
|
|
|
|
#TODO --epub-cover-image
|
|
|
|
#TODO --epub-cover-image
|
|
|
|
#TODO toc if it isnt described by <h> tags, e.g. https://www.projekt-gutenberg.org/adlersfe/maskenba/
|
|
|
|
#TODO toc if it isnt described by <h> tags, e.g. https://www.projekt-gutenberg.org/adlersfe/maskenba/
|
|
|
|
filename = f'{title} - {author}.epub'
|
|
|
|
filename = slugify(f'{title} - {author}.epub')
|
|
|
|
logger.debug('Creating epub as "%s"',filename)
|
|
|
|
|
|
|
|
command = f'''pandoc -f html -t epub \
|
|
|
|
command = f'''pandoc -f html -t epub \
|
|
|
|
-o "{filename}" \
|
|
|
|
-o "{filename}" \
|
|
|
|
--reference-location=section \
|
|
|
|
--reference-location=section \
|
|
|
|
@@ -115,6 +114,7 @@ class GBConvert():
|
|
|
|
--metadata author="{author}" \
|
|
|
|
--metadata author="{author}" \
|
|
|
|
--epub-title-page=false \
|
|
|
|
--epub-title-page=false \
|
|
|
|
{" ".join(chapters)} '''
|
|
|
|
{" ".join(chapters)} '''
|
|
|
|
|
|
|
|
logger.debug('Calling "%s"', command)
|
|
|
|
subprocess.run(shlex.split(command), cwd=dir_output, check=True)
|
|
|
|
subprocess.run(shlex.split(command), cwd=dir_output, check=True)
|
|
|
|
return os.path.abspath(os.path.join(dir_output,filename))
|
|
|
|
return os.path.abspath(os.path.join(dir_output,filename))
|
|
|
|
|
|
|
|
|
|
|
|
@@ -160,6 +160,13 @@ def get_all_books() -> List[Book]:
|
|
|
|
books.append(book)
|
|
|
|
books.append(book)
|
|
|
|
return books
|
|
|
|
return books
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def slugify(value, replacement='_'):
|
|
|
|
|
|
|
|
value = re.sub(r'[<>:"/\\|?*\x00-\x1F]', replacement, value)
|
|
|
|
|
|
|
|
# Remove leading/trailing whitespace or dots
|
|
|
|
|
|
|
|
value = value.strip().strip(".")
|
|
|
|
|
|
|
|
# Optionally truncate to safe length (e.g. 255 chars for most filesystems)
|
|
|
|
|
|
|
|
return value[:255] or "untitled"
|
|
|
|
|
|
|
|
|
|
|
|
# run main cli
|
|
|
|
# run main cli
|
|
|
|
@click.command()
|
|
|
|
@click.command()
|
|
|
|
#TODO include images flag
|
|
|
|
#TODO include images flag
|
|
|
|
|