From c0695a9d179ba3d06f1e835a92448c5c0119a33e Mon Sep 17 00:00:00 2001
From: Dhanush R <76237496+TheOnlyWayUp@users.noreply.github.com>
Date: Sat, 2 Nov 2024 03:07:41 +0530
Subject: [PATCH] fix(api/images): #14 - Image downloads functional
* fix(api/image_downloads): Replace image url with file path
* fix(api/image_downloads): Add comments
* fix(frontend): Update changelog
---
src/api/src/create_book.py | 8 ++++++--
src/frontend/src/routes/+page.svelte | 2 ++
2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/src/api/src/create_book.py b/src/api/src/create_book.py
index 468468e..0879248 100644
--- a/src/api/src/create_book.py
+++ b/src/api/src/create_book.py
@@ -177,7 +177,6 @@ async def add_chapters(
for cidx, part in enumerate(data["parts"]):
content = await fetch_part_content(part["id"], cookies=cookies)
title = part["title"]
- clean_title = slugify(title)
# Thanks https://eu17.proxysite.com/process.php?d=5VyWYcoQl%2BVF0BYOuOavtvjOloFUZz2BJ%2Fepiusk6Nz7PV%2B9i8rs7cFviGftrBNll%2B0a3qO7UiDkTt4qwCa0fDES&b=1
chapter = epub.EpubHtml(
@@ -188,6 +187,7 @@ async def add_chapters(
if download_images:
soup = BeautifulSoup(content, "lxml")
+
async with (
CachedSession(headers=headers, cache=cache)
if not cookies
@@ -196,6 +196,8 @@ async def add_chapters(
for idx, image in enumerate(soup.find_all("img")):
if not image["src"]:
continue
+ # Find all image tags and filter for those with sources
+
async with session.get(image["src"]) as response:
img = epub.EpubImage(
media_type="image/jpeg",
@@ -203,8 +205,10 @@ async def add_chapters(
file_name=f"static/{cidx}/{idx}.jpeg",
)
book.add_item(img)
+ # Fetch image and pack
+
content = content.replace(
- str(image), f'
'
+ str(image["src"]), f"static/{cidx}/{idx}.jpeg"
)
chapter.set_content(f"