Better logging
This commit is contained in:
1 parent
c026685b59
commit
a84f87c906
7 files changed
+59
-39
No files matched your search
@@ -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())
|
||||
|
||||
Reference in new issue
Block a user