Better logging
This commit is contained in:
1 parent
c026685b59
commit
a84f87c906
7 files changed
+41
-21
No files matched your search
@@ -1,3 +1,5 @@
|
|||||||
|
# main.py
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import configparser
|
import configparser
|
||||||
import json
|
import json
|
||||||
@@ -71,14 +73,21 @@ def write_to_cache(manga: Manga) -> None:
|
|||||||
|
|
||||||
def parse_cache(cache: dict) -> list[Manga]:
|
def parse_cache(cache: dict) -> list[Manga]:
|
||||||
if not cache:
|
if not cache:
|
||||||
print("Cache is empty!")
|
print("[yellow]Cache is empty![/yellow]", flush=True)
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
|
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:
|
else:
|
||||||
manga = list()
|
print(f"[red]Failed to parse provider for:[/] {series_name}", flush=True)
|
||||||
for entry in cache.values():
|
|
||||||
manga.append(
|
|
||||||
Manga(parse_provider(s, entry.get("url")), entry.get("cached")) # type: ignore
|
|
||||||
)
|
|
||||||
return manga
|
return manga
|
||||||
|
|
||||||
|
|
||||||
@@ -136,7 +145,12 @@ def main():
|
|||||||
else:
|
else:
|
||||||
list_of_manga = choose_manga()
|
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:
|
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.choose_chapters(args.auto)
|
||||||
manga.download(save_dir)
|
manga.download(save_dir)
|
||||||
write_to_cache(manga)
|
write_to_cache(manga)
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
# manga.py
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import tempfile
|
import tempfile
|
||||||
import xml.etree.ElementTree as XML
|
import xml.etree.ElementTree as XML
|
||||||
@@ -82,12 +84,16 @@ class Manga:
|
|||||||
)
|
)
|
||||||
|
|
||||||
def download(self, save_dir: Path):
|
def download(self, save_dir: Path):
|
||||||
|
series_name = self.info.get('series', 'Unknown')
|
||||||
|
|
||||||
if not self.chapters:
|
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
|
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)
|
chapter_sem = asyncio.Semaphore(8)
|
||||||
image_sem = asyncio.Semaphore(40)
|
image_sem = asyncio.Semaphore(40)
|
||||||
|
|
||||||
@@ -95,16 +101,6 @@ class Manga:
|
|||||||
async with aiohttp.ClientSession(
|
async with aiohttp.ClientSession(
|
||||||
headers=self.site.headers, connector=connector
|
headers=self.site.headers, connector=connector
|
||||||
) as session:
|
) 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 def download_and_zip(chapter):
|
||||||
async with chapter_sem:
|
async with chapter_sem:
|
||||||
chapter_nr = chapter.get("nr")
|
chapter_nr = chapter.get("nr")
|
||||||
@@ -120,7 +116,7 @@ class Manga:
|
|||||||
zip_files(self.slug, chapter, all_files, save_dir)
|
zip_files(self.slug, chapter, all_files, save_dir)
|
||||||
|
|
||||||
self.cached.append(chapter_nr)
|
self.cached.append(chapter_nr)
|
||||||
p.update(task, advance=1)
|
print(f" [green]✓ Finished:[/] {series_name} Ch. {chapter_nr:g}", flush=True)
|
||||||
|
|
||||||
await asyncio.gather(
|
await asyncio.gather(
|
||||||
*(download_and_zip(ch) for ch in self.chapters)
|
*(download_and_zip(ch) for ch in self.chapters)
|
||||||
|
|||||||
+4
-2
@@ -1,10 +1,12 @@
|
|||||||
|
# packager.py
|
||||||
|
|
||||||
import zipfile
|
import zipfile
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
def zip_files(slug, chapter: dict, files: list[Path], save_dir: Path):
|
def zip_files(slug, chapter: dict, files: list[Path], save_dir: Path):
|
||||||
save_dir.joinpath(slug).mkdir(exist_ok=True)
|
save_dir.joinpath(slug).mkdir(parents=True, exist_ok=True)
|
||||||
filename = save_dir.joinpath(slug).joinpath(f"{slug} Ch.{chapter.get('nr'):g}.cbz") # type: ignore
|
filename = save_dir.joinpath(slug).joinpath(f"{slug} Ch.{chapter.get('nr'):g}.cbz")
|
||||||
with zipfile.ZipFile(filename, "w") as zf:
|
with zipfile.ZipFile(filename, "w") as zf:
|
||||||
for file in files:
|
for file in files:
|
||||||
zf.write(file, file.name)
|
zf.write(file, file.name)
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
# sites/__init__.py
|
||||||
|
|
||||||
from .flamecomics import FlameComics
|
from .flamecomics import FlameComics
|
||||||
from .mangapill import Mangapill
|
from .mangapill import Mangapill
|
||||||
from .provider import Provider
|
from .provider import Provider
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
# sites/flamecomics.py
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
# sites/mangapill.py
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import re
|
import re
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
# sites/provider.py
|
||||||
|
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user