Add more metadata

This commit is contained in:
Joakim Holm 2023-04-07 23:49:57 +02:00
parent aa1eacfd43
commit 0d7fdd04a0
4 changed files with 25 additions and 4 deletions

View File

@ -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),
}

View File

@ -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

View File

@ -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)

View File

@ -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