diff --git a/grawlix/book.py b/grawlix/book.py index 9177769..d977823 100644 --- a/grawlix/book.py +++ b/grawlix/book.py @@ -1,5 +1,5 @@ from grawlix import Encryption -from dataclasses import dataclass +from dataclasses import dataclass, field from typing import Optional, Union, TypeVar, Generic @dataclass(slots=True) @@ -7,6 +7,8 @@ class Metadata: """Metadata about a book""" title: str series: Optional[str] = None + authors: list[str] = field(default_factory=list) + language: Optional[str] = None publisher: Optional[str] = None identifier: Optional[str] = None @@ -16,6 +18,8 @@ class Metadata: "series": self.series or "UNKNOWN", "publisher": self.publisher or "UNKNOWN", "identifier": self.identifier or "UNKNOWN", + "language": self.language or "UNKNOWN", + "authors": "; ".join(self.authors), } diff --git a/grawlix/logging.py b/grawlix/logging.py index c935d3a..43b1276 100644 --- a/grawlix/logging.py +++ b/grawlix/logging.py @@ -9,6 +9,14 @@ from dataclasses import dataclass console = Console(stderr=True) +def info(msg: str) -> None: + """ + Print message in log + + :param msg: Message to print + """ + console.print(msg) + def progress(category_name: str, source_name: str, count=1) -> Progress: if count > 1: console.print(f"Downloading [yellow not bold]{count}[/] books in [blue]{category_name}[/] from [magenta]{source_name}[/]") @@ -19,7 +27,8 @@ def progress(category_name: str, source_name: str, count=1) -> Progress: "{task.description}", BarColumn(), "[progress.percentage]{task.percentage:>3.0f}%", - console = console + console = console, + expand = True ) return progress diff --git a/grawlix/output/__init__.py b/grawlix/output/__init__.py index aecb7f0..3585fff 100644 --- a/grawlix/output/__init__.py +++ b/grawlix/output/__init__.py @@ -1,5 +1,6 @@ from grawlix.book import Book, BookData, SingleFile, ImageList, OnlineFile from grawlix.exceptions import GrawlixError +from grawlix.logging import info from .output_format import OutputFormat from .epub import Epub @@ -17,6 +18,9 @@ def download_book(book: Book, update_func: Callable, template: str) -> None: """ output_format = get_default_format(book.data) location = format_output_location(book, output_format, template) + if os.path.exists(location): + info("Skipping - File already exists") + return parent = Path(location).parent if not parent.exists(): os.makedirs(parent) diff --git a/grawlix/sources/saxo.py b/grawlix/sources/saxo.py index 0a3574d..03a2fbf 100644 --- a/grawlix/sources/saxo.py +++ b/grawlix/sources/saxo.py @@ -7,7 +7,7 @@ from .source import Source class Saxo(Source): name: str = "Saxo" match = [ - r"https://(www.)?saxo.(com|dk)/[^/]+/.+\d+$" + r"https://(\w+\.)?saxo.(com|dk)/.+\d+$" ] _authentication_methods = [ "login" ] user_id: str @@ -102,7 +102,11 @@ class Saxo(Source): :param metadata: Metadata response from saxo :returns: Metadata formatted as `grawlix.Metadata` """ - return Metadata(metadata["title"]) + return Metadata( + title = metadata["title"], + authors = [metadata["author"]] if "author" in metadata else [], + language = metadata.get("languageLocalized") + ) @staticmethod