diff --git a/main.py b/main.py index 62dc488..8f2fa09 100644 --- a/main.py +++ b/main.py @@ -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) diff --git a/manga.py b/manga.py index 1a49f4f..b1c8f8d 100644 --- a/manga.py +++ b/manga.py @@ -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()) diff --git a/packager.py b/packager.py index faaeceb..23d9e1b 100644 --- a/packager.py +++ b/packager.py @@ -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) diff --git a/sites/__init__.py b/sites/__init__.py index 3930a83..166a1c9 100644 --- a/sites/__init__.py +++ b/sites/__init__.py @@ -1,3 +1,5 @@ +# sites/__init__.py + from .flamecomics import FlameComics from .mangapill import Mangapill from .provider import Provider diff --git a/sites/flamecomics.py b/sites/flamecomics.py index 98e21e1..a9e492e 100644 --- a/sites/flamecomics.py +++ b/sites/flamecomics.py @@ -1,3 +1,5 @@ +# sites/flamecomics.py + import json import re diff --git a/sites/mangapill.py b/sites/mangapill.py index 5500a30..42fb5ba 100644 --- a/sites/mangapill.py +++ b/sites/mangapill.py @@ -1,3 +1,5 @@ +# sites/mangapill.py + import asyncio import re from typing import TYPE_CHECKING diff --git a/sites/provider.py b/sites/provider.py index 9f3f0dd..8e31410 100644 --- a/sites/provider.py +++ b/sites/provider.py @@ -1,3 +1,5 @@ +# sites/provider.py + from abc import ABC, abstractmethod