mirror of
https://github.com/jo1gi/grawlix.git
synced 2025-12-16 04:09:10 +00:00
parent
f7009f5dd0
commit
651f672e25
@ -7,9 +7,10 @@ from .acsm import Acsm
|
|||||||
from .cbz import Cbz
|
from .cbz import Cbz
|
||||||
from .epub import Epub
|
from .epub import Epub
|
||||||
|
|
||||||
from typing import Callable
|
from typing import Callable, Iterable
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import os
|
import os
|
||||||
|
import platform
|
||||||
|
|
||||||
async def download_book(book: Book, update_func: Callable, template: str) -> None:
|
async def download_book(book: Book, update_func: Callable, template: str) -> None:
|
||||||
"""
|
"""
|
||||||
@ -43,8 +44,35 @@ def format_output_location(book: Book, output_format: OutputFormat, template: st
|
|||||||
:param template: Template for output path
|
:param template: Template for output path
|
||||||
:returns: Output path
|
:returns: Output path
|
||||||
"""
|
"""
|
||||||
values = book.metadata.as_dict()
|
values = { key: remove_unwanted_chars(value) for key, value in book.metadata.as_dict().items() }
|
||||||
return template.format(**values, ext = output_format.extension)
|
path = template.format(**values, ext = output_format.extension)
|
||||||
|
return path
|
||||||
|
|
||||||
|
|
||||||
|
def remove_strings(input: str, strings: Iterable[str]) -> str:
|
||||||
|
"""
|
||||||
|
Remove strings from input
|
||||||
|
|
||||||
|
:param input: the string to remove strings from
|
||||||
|
:param strings: the list of strings to remove from input
|
||||||
|
:returns: input without strinfs
|
||||||
|
"""
|
||||||
|
for c in strings:
|
||||||
|
input = input.replace(c, "")
|
||||||
|
return input
|
||||||
|
|
||||||
|
|
||||||
|
def remove_unwanted_chars(input: str) -> str:
|
||||||
|
"""
|
||||||
|
Remove chars from string that are not supported in output path
|
||||||
|
|
||||||
|
:param input: The string to remove chars from
|
||||||
|
:returns: input without unsupported chars
|
||||||
|
"""
|
||||||
|
if platform.system() == "Windows":
|
||||||
|
return remove_strings(input, "<>:\"/\\|?*")
|
||||||
|
else:
|
||||||
|
return remove_strings(input, "/")
|
||||||
|
|
||||||
|
|
||||||
def get_default_format(book: Book) -> OutputFormat:
|
def get_default_format(book: Book) -> OutputFormat:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user