From 1c124cc7dca2ca4fe4f9601069007c3546899833 Mon Sep 17 00:00:00 2001 From: MrMysterius Date: Sun, 29 Jan 2023 10:45:41 +0100 Subject: [PATCH 01/21] feat: added functions to download a single chapter and get page data --- comic-info.ts | 5 ++-- download.ts | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 3 deletions(-) create mode 100644 download.ts diff --git a/comic-info.ts b/comic-info.ts index caf6127..6fb2383 100644 --- a/comic-info.ts +++ b/comic-info.ts @@ -3,8 +3,7 @@ import { BasicMangaMetadata, Chapter } from "./metadata.ts"; export interface PageInfo { index: number; - width: number; - height: number; + size: number; filename: string; } @@ -47,7 +46,7 @@ export function writeComicInfo(folder_path: string, metadata: BasicMangaMetadata Deno.writeFileSync(FILE_PATH, Encoder.encode(`\t\n`), { create: false, append: true }); for (const page of pages) { - Deno.writeFileSync(FILE_PATH, Encoder.encode(`\t\t\n`), { + Deno.writeFileSync(FILE_PATH, Encoder.encode(`\t\t\n`), { create: false, append: true, }); diff --git a/download.ts b/download.ts new file mode 100644 index 0000000..d2b6e1f --- /dev/null +++ b/download.ts @@ -0,0 +1,82 @@ +import { Chapter } from "./metadata.ts"; +import { PageInfo } from "./comic-info.ts"; +import { join } from "https://deno.land/std@0.174.0/path/mod.ts"; + +const BASE_CHAPTER_URL = "https://mangasee123.com/read-online/"; + +export async function getChapterPage(mangaIndexName: string, chapter: Chapter) { + if (chapter.pretype == 1) { + const res = await fetch(`${BASE_CHAPTER_URL}${mangaIndexName}-chapter-${chapter.main}${chapter.sub != 0 ? chapter.sub : ""}.html`); + return await res.text(); + } else { + const res = await fetch( + `${BASE_CHAPTER_URL}${mangaIndexName}-chapter-${chapter.main}${chapter.sub != 0 ? `.${chapter.sub}` : ""}-index-${chapter.pretype}.html` + ); + return await res.text(); + } +} + +interface ChapterInfo { + Chapter: string; + Page: string; + Directory: string; +} + +export function extractChapterInfo(html_document: string): ChapterInfo | null { + const match = html_document.match(/vm\.CurChapter = (.+);/m); + return JSON.parse(match?.[1] || "") || null; +} + +export function extractHost(html_document: string) { + const match = html_document.match(/vm\.CurPathName = "(.+)";/m); + return match?.[1] || null; +} + +export async function downloadChapter(mangaIndexName: string, chapter: Chapter, folder_path: string): Promise { + const html_document = await getChapterPage(mangaIndexName, chapter); + const chapter_info = extractChapterInfo(html_document); + const host = extractHost(html_document); + + if (chapter_info == null || host == null) return null; + + let chapter_number = ""; + const main_number_string = chapter.main.toString(); + if (main_number_string.length <= 4) { + chapter_number = "0".repeat(4 - main_number_string.length) + main_number_string; + } else { + chapter_number = main_number_string; + } + if (chapter.sub != 0) { + chapter_number += `.${chapter.sub}`; + } + + const DIRECTORY_STRING = chapter_info.Directory != "" ? `${chapter_info.Directory}/` : ""; + const CHAPTER_PREFIX = `${chapter_number}-`; + const BASE_DOWNLOAD_URL = `https://${host}/manga/${mangaIndexName}/${DIRECTORY_STRING}${CHAPTER_PREFIX}`; + + const pages: PageInfo[] = []; + + const page_count = parseInt(chapter_info.Page); + for (let i = 1; i <= page_count; i++) { + let page_number = ""; + const i_string = i.toString(); + if (i_string.length <= 3) { + page_number = "0".repeat(3 - i_string.length) + i_string; + } else { + page_number = i_string; + } + + const res = await fetch(`${BASE_DOWNLOAD_URL}${page_number}.png`); + const file = await Deno.open(join(folder_path, `${i}.png`), { create: true, write: true }); + + await res.body?.pipeTo(file.writable); + try { + file.close(); + } catch (_e) {} + const size = parseInt(res.headers.get("content-length") as string); + + pages.push({ index: i - 1, filename: `${i}.png`, size: size }); + } + + return pages; +} From a777e429f34f426a1a9fdaff25abc0d18faf3a0b Mon Sep 17 00:00:00 2001 From: MrMysterius Date: Mon, 30 Jan 2023 03:01:04 +0100 Subject: [PATCH 02/21] fix: archive function not archiving in the root of the archive #9 --- archive.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/archive.ts b/archive.ts index 7d87b55..64e7334 100644 --- a/archive.ts +++ b/archive.ts @@ -1,10 +1,7 @@ -export async function archive(src_folder: string, archive_name: string): Promise { - const cmd: string[] = ["7z", "a", archive_name]; +import { normalize, posix } from "https://deno.land/std@0.174.0/path/mod.ts"; - for (const file of Deno.readDirSync(src_folder)) { - if (file.isSymlink) continue; - cmd.push(`${src_folder}/${file.name}`); - } +export async function archive(src_folder: string, archive_name: string, delete_src = true): Promise { + const cmd: string[] = ["7z", "a", archive_name, posix.normalize(`.\\${posix.normalize(normalize(`${src_folder}`))}\\*`)]; const process = Deno.run({ cmd, From 5e44d88f9878c93b155c2d8153e237ee9e0b1ab5 Mon Sep 17 00:00:00 2001 From: MrMysterius Date: Mon, 30 Jan 2023 03:01:37 +0100 Subject: [PATCH 03/21] feat: added option which is deault true for deleting the source on archiving --- archive.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/archive.ts b/archive.ts index 64e7334..63e078d 100644 --- a/archive.ts +++ b/archive.ts @@ -9,5 +9,7 @@ export async function archive(src_folder: string, archive_name: string, delete_s stderr: "piped", }); - return (await process.status()).success; + if (!(await process.status()).success) return false; + if (delete_src) Deno.removeSync(src_folder, { recursive: true }); + return true; } From 777913359bc0292a1d9d70bb511a89ad1ded3fce Mon Sep 17 00:00:00 2001 From: MrMysterius Date: Mon, 30 Jan 2023 03:03:40 +0100 Subject: [PATCH 04/21] feat: added raw chapter number string to the chapter structure --- metadata.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/metadata.ts b/metadata.ts index 31dac5b..32e9784 100644 --- a/metadata.ts +++ b/metadata.ts @@ -87,6 +87,7 @@ export interface Chapter { pretype: number; main: number; sub: number; + raw: string; } export async function getChapters(mangaIndexName: string) { @@ -107,6 +108,7 @@ export function extractChapters(html_document: string) { pretype: parseInt(match[1]), main: parseInt(match[2]), sub: parseInt(match[3]), + raw: chapter.Chapter, }); } From cb27a1daae344935bd272efb28ce152d8784e84f Mon Sep 17 00:00:00 2001 From: MrMysterius Date: Mon, 30 Jan 2023 03:06:51 +0100 Subject: [PATCH 05/21] fix: incorporating sub chapter number now in comicinfo #10 --- comic-info.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/comic-info.ts b/comic-info.ts index 6fb2383..9f676e3 100644 --- a/comic-info.ts +++ b/comic-info.ts @@ -29,10 +29,11 @@ export function writeComicInfo(folder_path: string, metadata: BasicMangaMetadata } ); Deno.writeFileSync(FILE_PATH, Encoder.encode(`\t${metadata.title}\n`), { create: false, append: true }); - Deno.writeFileSync(FILE_PATH, Encoder.encode(`\t${chapter_info.main}\n`), { create: false, append: true }); + Deno.writeFileSync(FILE_PATH, Encoder.encode(`\t${chapter_info.main}${chapter_info.sub != 0 ? `.${chapter_info.sub}` : ""}\n`), { + create: false, + append: true, + }); Deno.writeFileSync(FILE_PATH, Encoder.encode(`\t${chapter_info.pretype}\n`), { create: false, append: true }); - if (chapter_info.sub != 0) - Deno.writeFileSync(FILE_PATH, Encoder.encode(`\t${chapter_info.sub}\n`), { create: false, append: true }); Deno.writeFileSync(FILE_PATH, Encoder.encode(`\tDownloaded/Scrapped with Mangasee123 Downloader from MrMysterius\n`), { create: false, append: true, From 13e2b0544bb76cfdef990d65d431e58e1bb29978 Mon Sep 17 00:00:00 2001 From: MrMysterius Date: Mon, 30 Jan 2023 03:08:16 +0100 Subject: [PATCH 06/21] fix: updating progress save and load to more accurately save --- progress.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/progress.ts b/progress.ts index f0716dd..20aab39 100644 --- a/progress.ts +++ b/progress.ts @@ -1,9 +1,10 @@ import { join } from "https://deno.land/std@0.174.0/path/mod.ts"; +import { Chapter } from "./metadata.ts"; interface Progress { - current: number; - start: number; - end: number; + current: Chapter; + start: Chapter; + end: Chapter; } export function saveProgress(target_folder: string, progress: Progress): boolean { From 9cca7b80ec63147a7505e4ee75497c5a1211c0b0 Mon Sep 17 00:00:00 2001 From: MrMysterius Date: Mon, 30 Jan 2023 03:11:23 +0100 Subject: [PATCH 07/21] feat: added function for sorting chapters --- download.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/download.ts b/download.ts index d2b6e1f..7be45c6 100644 --- a/download.ts +++ b/download.ts @@ -80,3 +80,7 @@ export async function downloadChapter(mangaIndexName: string, chapter: Chapter, return pages; } + +export function chaptersSort(chapters: Chapter[]) { + return chapters.sort((a, b) => parseInt(a.raw) - parseInt(b.raw)); +} From 818321eabc436a54714c30f4953bcd30746ad2bb Mon Sep 17 00:00:00 2001 From: MrMysterius Date: Mon, 30 Jan 2023 03:11:45 +0100 Subject: [PATCH 08/21] feat: added function for finding chapter after part chapter --- download.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/download.ts b/download.ts index 7be45c6..13ce1b1 100644 --- a/download.ts +++ b/download.ts @@ -81,6 +81,11 @@ export async function downloadChapter(mangaIndexName: string, chapter: Chapter, return pages; } + +export function findChapter(chapters: Chapter[], search: PartChapter) { + return chapters.filter((chapter) => chapter.pretype == search.pretype && chapter.main == search.main && chapter.sub == search.sub); +} + export function chaptersSort(chapters: Chapter[]) { return chapters.sort((a, b) => parseInt(a.raw) - parseInt(b.raw)); } From 47e54ef42aa563005e9dbae687d48f65d7568fee Mon Sep 17 00:00:00 2001 From: MrMysterius Date: Mon, 30 Jan 2023 03:13:30 +0100 Subject: [PATCH 09/21] feat: added main downloading function for the download command --- download.ts | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/download.ts b/download.ts index 13ce1b1..3ec4b59 100644 --- a/download.ts +++ b/download.ts @@ -81,6 +81,52 @@ export async function downloadChapter(mangaIndexName: string, chapter: Chapter, return pages; } +export async function download( + mangaIndexName: string, + metadata: BasicMangaMetadata, + folder_path: string, + chapters: Chapter[], + start: Chapter, + end: Chapter, + current: Chapter | null = null +) { + const BASE_FOLDER_PATH = join(folder_path, mangaIndexName); + Deno.mkdirSync(BASE_FOLDER_PATH, { recursive: true }); + + if (current == null) current = start; + if (!(findChapter(chapters, current).length > 1)) return false; + + chapters = chaptersSort(chapters); + let init = true; + + for (let chapter of chapters) { + if (chapter.raw != current.raw && init) { + continue; + } + init = false; + + current = chapter; + saveProgress(BASE_FOLDER_PATH, { current: current, start: start, end: end }); + + const CHAPTER_PATH = join(BASE_FOLDER_PATH, `${mangaIndexName}-v${current.pretype}-c${current.main}${current.sub != 0 ? `.${current.sub}` : ""}`); + Deno.mkdirSync(CHAPTER_PATH, { recursive: true }); + const pages = await downloadChapter(mangaIndexName, current, CHAPTER_PATH); + if (pages == null) return false; + + if (!writeComicInfo(CHAPTER_PATH, metadata, current, pages)) return false; + if (!(await archive(CHAPTER_PATH, `${CHAPTER_PATH}.cb7`))) return false; + + if (chapter.raw == end.raw) break; + } + + return true; +} + +export interface PartChapter { + pretype: number; + main: number; + sub: number; +} export function findChapter(chapters: Chapter[], search: PartChapter) { return chapters.filter((chapter) => chapter.pretype == search.pretype && chapter.main == search.main && chapter.sub == search.sub); From fe60e15edde6e6d005cd816851b83d5696bc7ef6 Mon Sep 17 00:00:00 2001 From: MrMysterius Date: Mon, 30 Jan 2023 03:14:00 +0100 Subject: [PATCH 10/21] no message --- download.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/download.ts b/download.ts index 3ec4b59..1e46b25 100644 --- a/download.ts +++ b/download.ts @@ -1,6 +1,9 @@ -import { Chapter } from "./metadata.ts"; +import { BasicMangaMetadata, Chapter } from "./metadata.ts"; import { PageInfo } from "./comic-info.ts"; import { join } from "https://deno.land/std@0.174.0/path/mod.ts"; +import { saveProgress } from "./progress.ts"; +import { writeComicInfo } from "./comic-info.ts"; +import { archive } from "./archive.ts"; const BASE_CHAPTER_URL = "https://mangasee123.com/read-online/"; From 003c561d27b92dbb05909948d1e1747003f0722c Mon Sep 17 00:00:00 2001 From: MrMysterius Date: Mon, 30 Jan 2023 03:14:58 +0100 Subject: [PATCH 11/21] fix: url for manga chapter not being correct with sub numbers --- download.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/download.ts b/download.ts index 1e46b25..0686202 100644 --- a/download.ts +++ b/download.ts @@ -9,7 +9,7 @@ const BASE_CHAPTER_URL = "https://mangasee123.com/read-online/"; export async function getChapterPage(mangaIndexName: string, chapter: Chapter) { if (chapter.pretype == 1) { - const res = await fetch(`${BASE_CHAPTER_URL}${mangaIndexName}-chapter-${chapter.main}${chapter.sub != 0 ? chapter.sub : ""}.html`); + const res = await fetch(`${BASE_CHAPTER_URL}${mangaIndexName}-chapter-${chapter.main}${chapter.sub != 0 ? `.${chapter.sub}` : ""}.html`); return await res.text(); } else { const res = await fetch( From 2ee7e61a459bd03c32b1b32c969902c067a12478 Mon Sep 17 00:00:00 2001 From: MrMysterius Date: Mon, 30 Jan 2023 03:15:32 +0100 Subject: [PATCH 12/21] fix: json parse error crash instead or returning null in extractChapterInfo --- download.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/download.ts b/download.ts index 0686202..286a396 100644 --- a/download.ts +++ b/download.ts @@ -27,7 +27,7 @@ interface ChapterInfo { export function extractChapterInfo(html_document: string): ChapterInfo | null { const match = html_document.match(/vm\.CurChapter = (.+);/m); - return JSON.parse(match?.[1] || "") || null; + return JSON.parse(match?.[1] || "[]") || null; } export function extractHost(html_document: string) { From 014f5eab1283460985a51ce7139ca4b619493785 Mon Sep 17 00:00:00 2001 From: MrMysterius Date: Mon, 30 Jan 2023 03:21:13 +0100 Subject: [PATCH 13/21] refactor: added some space to the search command --- main.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/main.ts b/main.ts index 38f806f..80e5bb7 100644 --- a/main.ts +++ b/main.ts @@ -8,11 +8,15 @@ const ARGS = parse(Deno.args); switch (ARGS._[0] || undefined) { case "search": { if (ARGS._.length <= 1) break; + const results = await searchAnime(ARGS._.slice(1, ARGS._.length).join(" "), parseInt(ARGS.l) || parseInt(ARGS["limit"]) || 5); + for (const result of results) { if (result.score > (parseInt(ARGS.s) || parseInt(ARGS["score-threshold"]) || 0.05)) continue; + let release_year = ""; let chapters_available = ""; + if (!ARGS["no-metadata"] && !ARGS.n) { const metadata = await getBasicMetadata(result.item.i); release_year = metadata?.release_year || ""; From ac0068d29a8602c26d77fef1bb254dfa46536071 Mon Sep 17 00:00:00 2001 From: MrMysterius Date: Mon, 30 Jan 2023 09:35:20 +0100 Subject: [PATCH 14/21] fix: archiving function fix for download function --- archive.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/archive.ts b/archive.ts index 63e078d..7e1ff51 100644 --- a/archive.ts +++ b/archive.ts @@ -1,7 +1,10 @@ import { normalize, posix } from "https://deno.land/std@0.174.0/path/mod.ts"; export async function archive(src_folder: string, archive_name: string, delete_src = true): Promise { - const cmd: string[] = ["7z", "a", archive_name, posix.normalize(`.\\${posix.normalize(normalize(`${src_folder}`))}\\*`)]; + try { + Deno.removeSync(archive_name, { recursive: true }); + } catch (_e) {} + const cmd: string[] = ["7z", "a", archive_name, posix.normalize(`${posix.normalize(normalize(`${src_folder}`))}\\*`)]; const process = Deno.run({ cmd, From 2f884d9c2234843edda033e83744b7e13cad8f9d Mon Sep 17 00:00:00 2001 From: MrMysterius Date: Mon, 30 Jan 2023 09:35:54 +0100 Subject: [PATCH 15/21] build: updated building files --- build_linux.sh | 2 +- build_windows.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build_linux.sh b/build_linux.sh index 3956509..0f9fb01 100644 --- a/build_linux.sh +++ b/build_linux.sh @@ -1,2 +1,2 @@ # Linux -deno compile --allow-net --allow-read --allow-write --allow-env --target x86_64-unknown-linux-gnu --output mangasee-dl main.ts +deno compile --allow-net --allow-read --allow-write --allow-env --allow-run --target x86_64-unknown-linux-gnu --output mangasee-dl main.ts diff --git a/build_windows.sh b/build_windows.sh index 8eba346..7361ab8 100644 --- a/build_windows.sh +++ b/build_windows.sh @@ -1,2 +1,2 @@ # Windows -deno compile --allow-net --allow-read --allow-write --allow-env --target x86_64-pc-windows-msvc --output mangasee-dl.exe main.ts +deno compile --allow-net --allow-read --allow-write --allow-env --allow-run --target x86_64-pc-windows-msvc --output mangasee-dl.exe main.ts From 7147fae3eefdd2485f076baad76f7e111b287932 Mon Sep 17 00:00:00 2001 From: MrMysterius Date: Mon, 30 Jan 2023 09:36:53 +0100 Subject: [PATCH 16/21] feat: changed findChapter to returning the chapter and an index number where it was found --- download.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/download.ts b/download.ts index 286a396..9200e39 100644 --- a/download.ts +++ b/download.ts @@ -97,7 +97,7 @@ export async function download( Deno.mkdirSync(BASE_FOLDER_PATH, { recursive: true }); if (current == null) current = start; - if (!(findChapter(chapters, current).length > 1)) return false; + if (!findChapter(chapters, current)?.chapter) return false; chapters = chaptersSort(chapters); let init = true; @@ -132,7 +132,9 @@ export interface PartChapter { } export function findChapter(chapters: Chapter[], search: PartChapter) { - return chapters.filter((chapter) => chapter.pretype == search.pretype && chapter.main == search.main && chapter.sub == search.sub); + const index = chapters.findIndex((chapter) => chapter.pretype == search.pretype && chapter.main == search.main && chapter.sub == search.sub); + if (index == -1) return null; + return { chapter: chapters[index], index }; } export function chaptersSort(chapters: Chapter[]) { From 8e0d74bae8e65dcadff7a11cc59c5b0b20e46e0a Mon Sep 17 00:00:00 2001 From: MrMysterius Date: Mon, 30 Jan 2023 09:37:33 +0100 Subject: [PATCH 17/21] feat: added function for having a number fixed length --- main.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/main.ts b/main.ts index 80e5bb7..9410f89 100644 --- a/main.ts +++ b/main.ts @@ -34,3 +34,9 @@ switch (ARGS._[0] || undefined) { console.log(Color.red("# No Command Supplied - Aborting #")); break; } + +export function zeroSpaceOut(number: string | number, spaces: number) { + const number_string = number.toString(); + if (number_string.length >= spaces) return number_string; + return "0".repeat(spaces - number_string.length) + number_string; +} From 816e2b28b5795522d228bbfe18fa848b4ed0c84a Mon Sep 17 00:00:00 2001 From: MrMysterius Date: Mon, 30 Jan 2023 09:37:58 +0100 Subject: [PATCH 18/21] feat: added console output for the download with colors --- download.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/download.ts b/download.ts index 9200e39..8b1d7f4 100644 --- a/download.ts +++ b/download.ts @@ -4,6 +4,8 @@ import { join } from "https://deno.land/std@0.174.0/path/mod.ts"; import { saveProgress } from "./progress.ts"; import { writeComicInfo } from "./comic-info.ts"; import { archive } from "./archive.ts"; +import * as Color from "https://deno.land/std@0.174.0/fmt/colors.ts"; +import { zeroSpaceOut } from "./main.ts"; const BASE_CHAPTER_URL = "https://mangasee123.com/read-online/"; @@ -108,16 +110,26 @@ export async function download( } init = false; + Deno.stdout.write( + new TextEncoder().encode(`${Color.green("Downloading: ")} ${Color.blue(`v${chapter.pretype} - c${zeroSpaceOut(chapter.main, 4)}.${chapter.sub}`)}`) + ); + current = chapter; saveProgress(BASE_FOLDER_PATH, { current: current, start: start, end: end }); const CHAPTER_PATH = join(BASE_FOLDER_PATH, `${mangaIndexName}-v${current.pretype}-c${current.main}${current.sub != 0 ? `.${current.sub}` : ""}`); + try { + Deno.removeSync(CHAPTER_PATH, { recursive: true }); + } catch (_e) {} Deno.mkdirSync(CHAPTER_PATH, { recursive: true }); const pages = await downloadChapter(mangaIndexName, current, CHAPTER_PATH); if (pages == null) return false; + Deno.stdout.write(new TextEncoder().encode(`${Color.white(" Done |")} ${Color.yellow("Writing Metadata")}`)); if (!writeComicInfo(CHAPTER_PATH, metadata, current, pages)) return false; + Deno.stdout.write(new TextEncoder().encode(`${Color.white(" Done |")} ${Color.magenta("Archiving")}`)); if (!(await archive(CHAPTER_PATH, `${CHAPTER_PATH}.cb7`))) return false; + Deno.stdout.write(new TextEncoder().encode(`${Color.white(" Done |\n")}`)); if (chapter.raw == end.raw) break; } From 6d0c5f4218a02f92304f57847046a9385243d39d Mon Sep 17 00:00:00 2001 From: MrMysterius Date: Mon, 30 Jan 2023 09:38:21 +0100 Subject: [PATCH 19/21] fix: removed the display of potential error message on loading progress file --- progress.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/progress.ts b/progress.ts index 20aab39..ca97fa8 100644 --- a/progress.ts +++ b/progress.ts @@ -27,8 +27,7 @@ export function loadProgress(target_folder: string) { try { const progress: Progress = JSON.parse(Decoder.decode(Deno.readFileSync(FILE_PATH))); return progress; - } catch (err) { - console.error(err); + } catch (_e) { return undefined; } } From b51e381ecff482e9c35d57455cf10e253ef9525b Mon Sep 17 00:00:00 2001 From: MrMysterius Date: Mon, 30 Jan 2023 09:39:01 +0100 Subject: [PATCH 20/21] fix: added ignore line statements for typescript because of missing type declarations --- metadata.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/metadata.ts b/metadata.ts index 32e9784..ff3b167 100644 --- a/metadata.ts +++ b/metadata.ts @@ -49,12 +49,14 @@ export function extractMetadata(html_document: string) { switch (label?.innerText) { case "Author(s):": { child.querySelectorAll("a").forEach((a) => { + //@ts-ignore property innerText does exist but is not in the Interface/Declaration metadata.authors.push(a.innerText); }); continue; } case "Genre(s):": { child.querySelectorAll("a").forEach((a) => { + //@ts-ignore property innerText does exist but is not in the Interface/Declaration metadata.genres.push(a.innerText); }); continue; From 9cf70c13b02c4ccb4617149c1611bdb77a05a8c3 Mon Sep 17 00:00:00 2001 From: MrMysterius Date: Mon, 30 Jan 2023 09:39:28 +0100 Subject: [PATCH 21/21] feat: added the main download command functionality --- main.ts | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 93 insertions(+), 1 deletion(-) diff --git a/main.ts b/main.ts index 9410f89..d0ef5f9 100644 --- a/main.ts +++ b/main.ts @@ -1,7 +1,10 @@ import { parse } from "https://deno.land/std@0.174.0/flags/mod.ts"; import * as Color from "https://deno.land/std@0.174.0/fmt/colors.ts"; import { searchAnime } from "./search.ts"; -import { getBasicMetadata } from "./metadata.ts"; +import { Chapter, getBasicMetadata, getFullMetadata } from "./metadata.ts"; +import { download, chaptersSort, findChapter } from "./download.ts"; +import { loadProgress } from "./progress.ts"; +import { join } from "https://deno.land/std@0.174.0/path/mod.ts"; const ARGS = parse(Deno.args); @@ -30,6 +33,95 @@ switch (ARGS._[0] || undefined) { } break; } + case "download": { + if (!ARGS._[1]) break; + + const metadata = await getFullMetadata(ARGS._[1] as string); + if (metadata == null) break; + metadata.chapters = chaptersSort(metadata.chapters); + + const progress = loadProgress(join(Deno.cwd(), ARGS._[1] as string)); + const start_part = ARGS.s?.toString().split(".") || ARGS["start"]?.toString().split(".") || null; + const end_part = ARGS.e?.toString().split(".") || ARGS["end"]?.toString().split(".") || null; + + let start: Chapter = { pretype: 0, main: 0, sub: 0, raw: "" }; + let end: Chapter = { pretype: 0, main: 0, sub: 0, raw: "" }; + let current: Chapter = { pretype: 0, main: 0, sub: 0, raw: "" }; + + if (progress != undefined) { + start = progress.start; + end = progress.end; + current = progress.current; + } + + if (start_part != null) { + let c: Chapter = start; + switch (start_part.length) { + case 3: + c = { pretype: start_part[0], main: start_part[1], sub: start_part[2], raw: `${start_part[0]}${zeroSpaceOut(start_part[1], 4)}${start_part[2]}` }; + break; + case 2: + c = { pretype: 1, main: start_part[0], sub: start_part[1], raw: `1${zeroSpaceOut(start_part[0], 4)}${start_part[1]}` }; + break; + case 1: + c = { pretype: 1, main: start_part[0], sub: 0, raw: `1${zeroSpaceOut(start_part[0], 4)}0` }; + break; + } + if (start.raw != c.raw) { + start = c; + current = start; + } + } else if (progress == undefined) { + start = metadata.chapters[0]; + current = metadata.chapters[0]; + } + + if (end_part != null) { + let c = end; + switch (end_part.length) { + case 3: + c = { pretype: end_part[0], main: end_part[1], sub: end_part[2], raw: `${end_part[0]}${zeroSpaceOut(end_part[1], 4)}${end_part[2]}` }; + break; + case 2: + c = { pretype: 1, main: end_part[0], sub: end_part[1], raw: `1${zeroSpaceOut(end_part[0], 4)}${end_part[1]}` }; + break; + case 1: + c = { pretype: 1, main: end_part[0], sub: 0, raw: `1${zeroSpaceOut(end_part[0], 4)}0` }; + break; + } + if (end.raw != c.raw) { + const find_end = findChapter(metadata.chapters, end); + const find_c = findChapter(metadata.chapters, c); + if (find_end == null) { + end = c; + } else if (find_c != null && find_end.index <= find_c.index) { + end = c; + } else if (find_c != null && find_end.index > find_c.index) { + end = c; + current = start; + } + } + } else if (progress == undefined) { + end = metadata.chapters[metadata.chapters.length - 1]; + } + + console.log(Color.green("# Starting Download #")); + console.log(Color.magenta(`Manga: ${metadata.basic.title}`)); + console.log(Color.yellow(`Author(s): ${metadata.basic.authors.join(", ")}`)); + console.log(Color.cyan(`Genre(s): ${metadata.basic.genres.join(", ")}`)); + + console.log(Color.bold("\nFrom:\t\t"), Color.blue(`v${start.pretype} - c${zeroSpaceOut(start.main, 4)}.${start.sub}`)); + console.log(Color.bold("To:\t\t"), Color.brightYellow(`v${end.pretype} - c${zeroSpaceOut(end.main, 4)}.${end.sub}`)); + console.log(Color.bold("Continuing:\t"), Color.brightRed(`v${current.pretype} - c${zeroSpaceOut(current.main, 4)}.${current.sub}`)); + + console.log(Color.gray("\n----------------------------------------")); + + await download(ARGS._[1] as string, metadata.basic, Deno.cwd(), metadata.chapters, start, end, current); + + console.log(Color.green("# Finished Download #")); + + break; + } default: console.log(Color.red("# No Command Supplied - Aborting #")); break;