From a53e61116de8a1e503444b587944f227b0711017 Mon Sep 17 00:00:00 2001 From: TheOnlyWayUp Date: Tue, 25 Jun 2024 16:46:45 +0000 Subject: [PATCH 01/13] feat(api): Add image downloading --- src/api/requirements.txt | 3 +++ src/api/src/create_book.py | 24 ++++++++++++++++++++++-- src/api/src/main.py | 6 +++--- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/api/requirements.txt b/src/api/requirements.txt index 06164e5..356667e 100644 --- a/src/api/requirements.txt +++ b/src/api/requirements.txt @@ -9,6 +9,8 @@ asttokens==2.4.1 async-timeout==4.0.3 attrs==23.1.0 backoff==2.2.1 +beautifulsoup4==4.12.3 +bs4==0.0.2 click==8.1.7 comm==0.2.0 debugpy==1.8.0 @@ -48,6 +50,7 @@ pyzmq==25.1.2 rich==13.7.0 six==1.16.0 sniffio==1.3.0 +soupsieve==2.5 stack-data==0.6.3 starlette==0.32.0.post1 tornado==6.4 diff --git a/src/api/src/create_book.py b/src/api/src/create_book.py index a389c7f..85abf08 100644 --- a/src/api/src/create_book.py +++ b/src/api/src/create_book.py @@ -6,6 +6,7 @@ import backoff from aiohttp import ClientResponseError from aiohttp_client_cache.session import CachedSession from aiohttp_client_cache import FileBackend +from bs4 import BeautifulSoup headers = { @@ -116,19 +117,38 @@ async def set_cover(book, data): book.set_cover("cover.jpg", await fetch_cover(data["cover"])) -async def add_chapters(book, data): +async def add_chapters(book, data, download_images: bool = False): chapters = [] for part in data["parts"]: content = await fetch_part_content(part["id"]) 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( title=title, - file_name=f"{slugify(title)}.xhtml", + file_name=f"{clean_title}.xhtml", lang=data["language"]["name"], ) + + if download_images: + soup = BeautifulSoup(content, "lxml") + async with CachedSession(cache=cache, headers=headers) as session: + for idx, image in enumerate(soup.find_all("img")): + if not image["src"]: + continue + async with session.get(image["src"]) as response: + img = epub.EpubImage( + media_type="image/jpeg", + content=await response.read(), + file_name=f"static/{clean_title}/{idx}.jpeg", + ) + book.add_item(img) + content = content.replace( + str(image), f'' + ) + chapter.set_content(f"

{title}

" + content) chapters.append(chapter) diff --git a/src/api/src/main.py b/src/api/src/main.py index f639dba..d49126c 100644 --- a/src/api/src/main.py +++ b/src/api/src/main.py @@ -17,7 +17,7 @@ def home(): @app.get("/download/{story_id}") -async def download_book(story_id: int): +async def download_book(story_id: int, download_images: bool = False): data = await retrieve_story(story_id) book = epub.EpubBook() @@ -27,7 +27,7 @@ async def download_book(story_id: int): # print("Metadata Downloaded") # Chapters are downloaded - async for title in add_chapters(book, data): + async for title in add_chapters(book, data, download_images=download_images): # print(f"Part ({title}) downloaded") ... @@ -57,4 +57,4 @@ app.mount("/", StaticFiles(directory=BUILD_PATH), "static") if __name__ == "__main__": import uvicorn - uvicorn.run(app, host="0.0.0.0", port=80) + uvicorn.run(app, host="0.0.0.0", port=1112) From a487a3ed4742b8862c5725fb3ae046fdd9a320a4 Mon Sep 17 00:00:00 2001 From: TheOnlyWayUp Date: Tue, 25 Jun 2024 17:00:24 +0000 Subject: [PATCH 02/13] feat(frontend): Add background pattern from hero patterns --- src/frontend/src/app.html | 8 ++++++++ src/frontend/src/routes/+page.svelte | 6 +++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/frontend/src/app.html b/src/frontend/src/app.html index a338efd..92ca50d 100644 --- a/src/frontend/src/app.html +++ b/src/frontend/src/app.html @@ -28,6 +28,14 @@ %sveltekit.head% + + +
%sveltekit.body%
diff --git a/src/frontend/src/routes/+page.svelte b/src/frontend/src/routes/+page.svelte index e6c7a11..ba95bed 100644 --- a/src/frontend/src/routes/+page.svelte +++ b/src/frontend/src/routes/+page.svelte @@ -3,7 +3,7 @@
-
+

Wattpad Downloader

-

- Download your favourite books as EPUBs with a single click! +

+ Download your favourite books with a single click!

From 8426bfc21d13a3ae63601fb654b08bf71e0f431e Mon Sep 17 00:00:00 2001 From: TheOnlyWayUp Date: Tue, 25 Jun 2024 17:10:57 +0000 Subject: [PATCH 03/13] Add glass effect to main card --- src/frontend/src/routes/+page.svelte | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/frontend/src/routes/+page.svelte b/src/frontend/src/routes/+page.svelte index ba95bed..f13122b 100644 --- a/src/frontend/src/routes/+page.svelte +++ b/src/frontend/src/routes/+page.svelte @@ -4,7 +4,9 @@
-
+

-
+
-
From ce8a22ba5b54f03c0656f9688499d62bec89475a Mon Sep 17 00:00:00 2001 From: TheOnlyWayUp Date: Tue, 25 Jun 2024 17:29:46 +0000 Subject: [PATCH 04/13] fix(frontend): Move bg-pattern to layout --- src/frontend/src/app.html | 10 +--------- src/frontend/src/routes/+layout.svelte | 8 ++++++++ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/frontend/src/app.html b/src/frontend/src/app.html index 92ca50d..15975a2 100644 --- a/src/frontend/src/app.html +++ b/src/frontend/src/app.html @@ -27,15 +27,7 @@ - %sveltekit.head% - - - + %sveltekit.head%
%sveltekit.body%
diff --git a/src/frontend/src/routes/+layout.svelte b/src/frontend/src/routes/+layout.svelte index bde3404..d9b4594 100644 --- a/src/frontend/src/routes/+layout.svelte +++ b/src/frontend/src/routes/+layout.svelte @@ -2,4 +2,12 @@ import "../app.pcss"; + + + + From 507318b7f5972599fbd4aeb8db01c04623e653f6 Mon Sep 17 00:00:00 2001 From: TheOnlyWayUp Date: Tue, 25 Jun 2024 17:30:25 +0000 Subject: [PATCH 05/13] feat(frontend): Add changelog --- src/frontend/src/routes/+page.svelte | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/frontend/src/routes/+page.svelte b/src/frontend/src/routes/+page.svelte index f13122b..5a7042e 100644 --- a/src/frontend/src/routes/+page.svelte +++ b/src/frontend/src/routes/+page.svelte @@ -5,7 +5,7 @@

Wattpad Downloader

-

+

Download your favourite books with a single click!

+
    +
  • 06/24 - 🎉 Image Downloading!
  • +
-
+
Date: Tue, 25 Jun 2024 17:42:39 +0000 Subject: [PATCH 06/13] feat(frontend): Add image download checkbox --- src/frontend/src/routes/+page.svelte | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/frontend/src/routes/+page.svelte b/src/frontend/src/routes/+page.svelte index 5a7042e..4ebb5cb 100644 --- a/src/frontend/src/routes/+page.svelte +++ b/src/frontend/src/routes/+page.svelte @@ -1,5 +1,6 @@
@@ -45,11 +46,21 @@ Download +
From 0802dca6a61027ca2e3cda50ca6fd8f34c2a9a20 Mon Sep 17 00:00:00 2001 From: TheOnlyWayUp Date: Tue, 25 Jun 2024 17:45:40 +0000 Subject: [PATCH 07/13] fix(frontend): Update after-download text --- src/frontend/src/routes/+page.svelte | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/frontend/src/routes/+page.svelte b/src/frontend/src/routes/+page.svelte index 4ebb5cb..d5ffb3e 100644 --- a/src/frontend/src/routes/+page.svelte +++ b/src/frontend/src/routes/+page.svelte @@ -113,11 +113,11 @@

Hi, thanks for using my site! If you found it useful, please consider donating to keep this project alive. + data-umami-event="Star">starring the project to support WattpadDownloader.

You can also join us on discord, where we discuss updates and features. + >, where we release features early and discuss updates.

Please take a look at Date: Tue, 25 Jun 2024 17:57:20 +0000 Subject: [PATCH 08/13] feat(frontend): Add after-download page --- src/frontend/src/routes/+page.svelte | 186 +++++++++++++-------------- 1 file changed, 89 insertions(+), 97 deletions(-) diff --git a/src/frontend/src/routes/+page.svelte b/src/frontend/src/routes/+page.svelte index d5ffb3e..efdd851 100644 --- a/src/frontend/src/routes/+page.svelte +++ b/src/frontend/src/routes/+page.svelte @@ -1,6 +1,7 @@

@@ -8,66 +9,97 @@
-
-

- Wattpad Downloader -

-

- Download your favourite books with a single click! -

-
    -
  • 06/24 - 🎉 Image Downloading!
  • -
-
-
-
-
- - -
- -
- Download -
+
+ (after_download_page = true)}>Download + +
+ + + +
+ {:else} +
+

+ Your download has Started +

+
+

+ If you found this site useful, please consider starring the project to support WattpadDownloader. +

+

+ You can also join us on discord, where we release features early and discuss updates. +

+
+
+ {/if}
@@ -107,46 +139,6 @@ - - - -
{/if}