Better logging

This commit is contained in:
WilliamSoderberg committed 2026-09-11 13:31:43 +02:00 Verified
1 parent c026685b59
commit a84f87c906
7 files changed
+59 -39

No files matched your search

+22 -8
View File
@@ -1,3 +1,5 @@
# main.py
import argparse
import configparser
import json
@@ -71,15 +73,22 @@ def write_to_cache(manga: Manga) -> None:
def parse_cache(cache: dict) -> list[Manga]:
if not cache:
print("Cache is empty!")
print("[yellow]Cache is empty![/yellow]", flush=True)
exit()
else:
manga = list()
for entry in cache.values():
manga.append(
Manga(parse_provider(s, entry.get("url")), entry.get("cached")) # type: ignore
)
return manga
total = len(cache)
print(f"[bold cyan]Found {total} manga in cache. Fetching metadata...[/bold cyan]", flush=True)
manga = []
for idx, (series_name, entry) in enumerate(cache.items(), start=1):
print(f"[{idx}/{total}] Fetching info for: [bold]{series_name}[/bold]...", flush=True)
provider = parse_provider(s, entry.get("url"))
if provider:
manga.append(Manga(provider, entry.get("cached", [])))
else:
print(f"[red]Failed to parse provider for:[/] {series_name}", flush=True)
return manga
def get_cached_manga() -> list[Manga]:
@@ -136,7 +145,12 @@ def main():
else:
list_of_manga = choose_manga()
print(f"[bold green]Starting check/download run for {len(list_of_manga)} manga...[/bold green]", flush=True)
for manga in list_of_manga:
series = manga.info.get("series", "Unknown")
print(f"\n[bold]Checking:[/] {series}", flush=True)
manga.choose_chapters(args.auto)
manga.download(save_dir)
write_to_cache(manga)
+25 -29
View File
@@ -1,3 +1,5 @@
# manga.py
import asyncio
import tempfile
import xml.etree.ElementTree as XML
@@ -82,12 +84,16 @@ class Manga:
)
def download(self, save_dir: Path):
series_name = self.info.get('series', 'Unknown')
if not self.chapters:
print("No new [orange3]Chapter[/] were found...")
print(f" [yellow]↳ No new chapters found for {series_name}.[/yellow]", flush=True)
return
async def process_all_chapters():
print(f" [green]↳ Found {len(self.chapters)} new chapter(s) to download for {series_name}.[/green]", flush=True)
(save_dir / self.slug).mkdir(parents=True, exist_ok=True)
async def process_all_chapters():
chapter_sem = asyncio.Semaphore(8)
image_sem = asyncio.Semaphore(40)
@@ -95,36 +101,26 @@ class Manga:
async with aiohttp.ClientSession(
headers=self.site.headers, connector=connector
) as session:
with Progress(
TextColumn("[progress.description]{task.description}"),
MofNCompleteColumn(),
SpinnerColumn(),
) as p:
task = p.add_task(
f"[bold]Processing [orange3]{self.info.get('series')}[/]",
total=len(self.chapters),
)
async def download_and_zip(chapter):
async with chapter_sem:
chapter_nr = chapter.get("nr")
chapter_temp = Path(temp_dir) / f"ch_{chapter_nr:g}"
chapter_temp.mkdir(parents=True, exist_ok=True)
info_file = self._generateComicInfo(chapter, chapter_temp)
img_urls = chapter.get("images", [])
img_files = await self._async_download_images_internal(
img_urls, chapter_temp, session, image_sem
)
async def download_and_zip(chapter):
async with chapter_sem:
chapter_nr = chapter.get("nr")
chapter_temp = Path(temp_dir) / f"ch_{chapter_nr:g}"
chapter_temp.mkdir(parents=True, exist_ok=True)
info_file = self._generateComicInfo(chapter, chapter_temp)
img_urls = chapter.get("images", [])
img_files = await self._async_download_images_internal(
img_urls, chapter_temp, session, image_sem
)
all_files = [info_file] + [f for f in img_files if f]
zip_files(self.slug, chapter, all_files, save_dir)
all_files = [info_file] + [f for f in img_files if f]
zip_files(self.slug, chapter, all_files, save_dir)
self.cached.append(chapter_nr)
print(f" [green]✓ Finished:[/] {series_name} Ch. {chapter_nr:g}", flush=True)
self.cached.append(chapter_nr)
p.update(task, advance=1)
await asyncio.gather(
*(download_and_zip(ch) for ch in self.chapters)
)
await asyncio.gather(
*(download_and_zip(ch) for ch in self.chapters)
)
with tempfile.TemporaryDirectory(prefix="manga_") as temp_dir:
asyncio.run(process_all_chapters())
+4 -2
View File
@@ -1,10 +1,12 @@
# packager.py
import zipfile
from pathlib import Path
def zip_files(slug, chapter: dict, files: list[Path], save_dir: Path):
save_dir.joinpath(slug).mkdir(exist_ok=True)
filename = save_dir.joinpath(slug).joinpath(f"{slug} Ch.{chapter.get('nr'):g}.cbz") # type: ignore
save_dir.joinpath(slug).mkdir(parents=True, exist_ok=True)
filename = save_dir.joinpath(slug).joinpath(f"{slug} Ch.{chapter.get('nr'):g}.cbz")
with zipfile.ZipFile(filename, "w") as zf:
for file in files:
zf.write(file, file.name)
+2
View File
@@ -1,3 +1,5 @@
# sites/__init__.py
from .flamecomics import FlameComics
from .mangapill import Mangapill
from .provider import Provider
+2
View File
@@ -1,3 +1,5 @@
# sites/flamecomics.py
import json
import re
+2
View File
@@ -1,3 +1,5 @@
# sites/mangapill.py
import asyncio
import re
from typing import TYPE_CHECKING
+2
View File
@@ -1,3 +1,5 @@
# sites/provider.py
from abc import ABC, abstractmethod