From 24856e18ccacd5bc8fb6dc9f8c7ac85057422613 Mon Sep 17 00:00:00 2001 From: Shehryar Date: Mon, 23 Nov 2020 18:13:34 +0400 Subject: [PATCH 1/7] fixed percentage to two decimal places --- main.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.ts b/main.ts index 595dcac..149360b 100644 --- a/main.ts +++ b/main.ts @@ -134,7 +134,7 @@ autoUpdater.on('update-not-available', (event) => { autoUpdater.on('download-progress', (progressObj) => { const downloadSpeed = Math.round((progressObj.bytesPerSecond / 1024) * 100) / 100; - const downloadPercentage = progressObj.percent; + const downloadPercentage = progressObj.percent.toFixed(2); const downloadTransferred = progressObj.transferred; const downloadTotal = progressObj.total; win.webContents.send('download_progress', { From ce17fe62d5f2b7a4fed7c8522142e55994279a12 Mon Sep 17 00:00:00 2001 From: Shehryar Date: Mon, 30 Nov 2020 14:59:29 +0400 Subject: [PATCH 2/7] chapters & UI --- src/app/pages/novel/novel.component.html | 86 +++++++----------------- src/app/pages/novel/novel.component.scss | 20 +++--- src/app/pages/novel/novel.component.ts | 43 +++++++----- src/assets/img/browser-white.svg | 9 +++ src/assets/img/cancel.svg | 2 +- src/assets/img/delete.svg | 2 +- src/assets/img/folder.svg | 2 +- src/assets/img/update.svg | 2 +- 8 files changed, 78 insertions(+), 88 deletions(-) create mode 100644 src/assets/img/browser-white.svg diff --git a/src/app/pages/novel/novel.component.html b/src/app/pages/novel/novel.component.html index 9f56c3e..246d9d0 100644 --- a/src/app/pages/novel/novel.component.html +++ b/src/app/pages/novel/novel.component.html @@ -2,11 +2,7 @@ diff --git a/src/app/pages/novel/novel.component.scss b/src/app/pages/novel/novel.component.scss index 8b3ce4c..f3e23a9 100644 --- a/src/app/pages/novel/novel.component.scss +++ b/src/app/pages/novel/novel.component.scss @@ -8,8 +8,10 @@ flex-direction: row; justify-content: space-between; align-items: center; - height: 30px; margin-bottom: 10px; + background: $secondaryAccent; + border-radius: 3px; + padding: 0.5em; .progressBar { height: 100%; @@ -120,16 +122,18 @@ border-radius: 5px; opacity: 0.3; - background: linear-gradient( - -45deg, - #74ccbc, - rgb(140, 255, 240), - #44beff, - #00a2ff - ); + background: linear-gradient(-45deg, + #74ccbc, + rgb(140, 255, 240), + #44beff, + #00a2ff); background-size: 400% 400%; animation: load 5s ease infinite; } + + .chapters { + margin-top: 2em; + } } } diff --git a/src/app/pages/novel/novel.component.ts b/src/app/pages/novel/novel.component.ts index c676f19..0e42a99 100644 --- a/src/app/pages/novel/novel.component.ts +++ b/src/app/pages/novel/novel.component.ts @@ -1,11 +1,12 @@ import { Component, OnInit } from '@angular/core'; import { Router } from '@angular/router'; -import { novelObj, sourceObj } from 'app/resources/types'; +import { chapterObj, novelObj, sourceObj } from 'app/resources/types'; import { DatabaseService } from 'app/services/database.service'; import { BoxnovelService } from 'app/services/sources/boxnovel.service'; import { SourceManagerService } from 'app/services/sources/source-service-manager.service'; import { sourceService } from 'app/services/sources/sourceService'; import { shell } from 'electron'; +import { readFileSync } from 'fs'; @Component({ selector: 'app-novel', @@ -16,10 +17,11 @@ export class NovelComponent implements OnInit { source: sourceObj = history.state.source; novel: novelObj = history.state.novel; + chapters: chapterObj; service: sourceService = history.state.service; - fromHome: boolean = history.state.fromHome - fromLibrary: boolean = history.state.fromLibrary + fromHome: boolean = history.state.fromHome; + fromLibrary: boolean = history.state.fromLibrary; progress = 0; @@ -31,22 +33,31 @@ export class NovelComponent implements OnInit { constructor(private router: Router, public database: DatabaseService, public sourceManager: SourceManagerService) { if (!this.source) this.source = { - name: "BoxNovel", - link: "https://boxnovel.com", - icon: "assets/img/sources/boxnovel-logo.png" + name: "NovelFull", + link: "https://novelfull.com", + icon: "assets/img/sources/novelfull-logo.png" }; if (!this.novel) this.novel = { - author: "Baby Piggie, 猪宝宝萌萌哒 Baby Piggie, 猪宝宝萌萌哒 Baby Piggie, 猪宝宝萌萌哒 Baby Piggie, 猪宝宝萌萌哒 Baby Piggie, 猪宝宝萌萌哒 Baby Piggie, 猪宝宝萌萌哒 Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years ", - cover: "https://boxnovel.com/wp-content/uploads/2018/10/My-Youth-Began-With-Him-193x278.jpg", - genre: "Romance", - latestChapter: "Chapter 3644 - Birthday Banquet 14 Chapter 3644 - Birthday Banquet 14 Chapter 3644 - Birthday Banquet 14", - totalChapters: 300, - link: "https://boxnovel.com/novel/my-youth-began-with-him-webnovel/", - name: "My Youth Began With Him-Webnovel My Youth Began With Him-Webnovel My Youth Began With Him-Webnovel My Youth Began With Him-Webnovel My Youth Began With Him-Webnovel My Youth Began With Him-Webnovel My Youth Began With Him-Webnovel", - source: "BoxNovel", - summary: "Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years ", - inLibrary: true, + source: "NovelFull", + link: "https://novelfull.com/tales-of-demons-and-gods.html", + name: "Tales of Demons and Gods", + latestChapter: "Chapter 494 - Divine Items", + cover: "https://novelfull.com/uploads/thumbs/tales-of-demons-and-gods-fceee0fee0-2239c49aee6b961904acf173b7e4602a.jpg", + totalChapters: 494, + author: "Mad Snail", + genre: "Fantasy, Xuanhuan, Action, Adventure, Comedy, Harem, Martial Arts, Romance", + summary: "Killed by a Sage Emperor and reborn as his 13 year old self, Nie Li was given a second chance at life. A second chance to change everything and save his loved ones and his beloved city. He shall once again battle with the Sage Emperor to avenge his death and those of his beloved . With the vast knowledge of hundred years of life he accumulated in his previous life, wielding the strongest demon spirits, he shall reach the pinnacle of Martial Arts.\nEnmities of the past will be settled in this new lifetime. “Since I’m back, then in this lifetime, I shall become the King of the Gods that dominate everything. Let everything else tremble beneath my feet!”\n", + downloadedChapters: 494, + folderPath: "A:\\Downloads\\NovelScraper-Library\\Tales of Demons and Gods", downloading: false, + downloaded: true, + isUpdated: true, + inLibrary: true, + state: [] + } + + if (this.novel.downloaded) { + this.chapters = JSON.parse(readFileSync(this.novel.folderPath + "\\chapters.json").toString()); } } diff --git a/src/assets/img/browser-white.svg b/src/assets/img/browser-white.svg new file mode 100644 index 0000000..88ce2a6 --- /dev/null +++ b/src/assets/img/browser-white.svg @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/src/assets/img/cancel.svg b/src/assets/img/cancel.svg index 09475e6..579eed8 100644 --- a/src/assets/img/cancel.svg +++ b/src/assets/img/cancel.svg @@ -1,3 +1,3 @@ - + diff --git a/src/assets/img/delete.svg b/src/assets/img/delete.svg index 2217591..31129d6 100644 --- a/src/assets/img/delete.svg +++ b/src/assets/img/delete.svg @@ -1,3 +1,3 @@ - + diff --git a/src/assets/img/folder.svg b/src/assets/img/folder.svg index 4bf2ee3..642d04a 100644 --- a/src/assets/img/folder.svg +++ b/src/assets/img/folder.svg @@ -1,3 +1,3 @@ - + diff --git a/src/assets/img/update.svg b/src/assets/img/update.svg index b639c18..cadfc3c 100644 --- a/src/assets/img/update.svg +++ b/src/assets/img/update.svg @@ -1,3 +1,3 @@ - + From 897761083b4ad2b22b0b5be37eaaf7f36daf1357 Mon Sep 17 00:00:00 2001 From: Shehryar Date: Mon, 31 May 2021 00:16:58 +0400 Subject: [PATCH 3/7] audit fix --- package.json | 6 +++--- src/tsconfig.spec.json | 31 +++++++++---------------------- 2 files changed, 12 insertions(+), 25 deletions(-) diff --git a/package.json b/package.json index f1e7cdf..03f424e 100644 --- a/package.json +++ b/package.json @@ -64,11 +64,11 @@ "@typescript-eslint/eslint-plugin-tslint": "3.6.0", "@typescript-eslint/parser": "3.6.0", "chai": "4.2.0", - "conventional-changelog-cli": "2.0.34", + "conventional-changelog-cli": "2.1.1", "core-js": "3.6.5", "cross-env": "7.0.2", "electron": "10.4.0", - "electron-builder": "22.8.1", + "electron-builder": "22.11.5", "electron-reload": "1.5.0", "eslint": "7.4.0", "eslint-plugin-import": "2.22.0", @@ -98,7 +98,7 @@ "cloudscraper": "4.6.0", "electron-updater": "4.3.5", "mime": "2.4.6", - "nconf": "0.10.0", + "nconf": "0.11.2", "nodepub": "3.0.1", "request": "2.88.2", "rimraf": "3.0.2", diff --git a/src/tsconfig.spec.json b/src/tsconfig.spec.json index 1f73aaf..fb533bb 100644 --- a/src/tsconfig.spec.json +++ b/src/tsconfig.spec.json @@ -1,24 +1,11 @@ { - "extends": "../tsconfig.base.json", - "compilerOptions": { - "outDir": "../out-tsc/spec", - "module": "commonjs", - "types": [ - "jasmine", - "node" - ] - }, - "files": [ - "test.ts", - "polyfills-test.ts" - ], - "include": [ - "**/*.spec.ts", - "**/*.d.ts" - ], - "exclude": [ - "dist", - "release", - "node_modules" - ] + "extends": "../tsconfig.base.json", + "compilerOptions": { + "outDir": "../out-tsc/spec", + "module": "commonjs", + "types": ["jasmine", "node"] + }, + "files": ["test.ts", "polyfills-test.ts"], + "include": ["**/*.spec.ts", "**/*.d.ts"], + "exclude": ["dist", "release", "node_modules"] } From 49828213cf106c2dac44c119052ff13ae37974b5 Mon Sep 17 00:00:00 2001 From: Shehryar Date: Mon, 31 May 2021 00:36:57 +0400 Subject: [PATCH 4/7] Revert "audit fix" This reverts commit 897761083b4ad2b22b0b5be37eaaf7f36daf1357. --- package.json | 6 +++--- src/tsconfig.spec.json | 31 ++++++++++++++++++++++--------- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 03f424e..f1e7cdf 100644 --- a/package.json +++ b/package.json @@ -64,11 +64,11 @@ "@typescript-eslint/eslint-plugin-tslint": "3.6.0", "@typescript-eslint/parser": "3.6.0", "chai": "4.2.0", - "conventional-changelog-cli": "2.1.1", + "conventional-changelog-cli": "2.0.34", "core-js": "3.6.5", "cross-env": "7.0.2", "electron": "10.4.0", - "electron-builder": "22.11.5", + "electron-builder": "22.8.1", "electron-reload": "1.5.0", "eslint": "7.4.0", "eslint-plugin-import": "2.22.0", @@ -98,7 +98,7 @@ "cloudscraper": "4.6.0", "electron-updater": "4.3.5", "mime": "2.4.6", - "nconf": "0.11.2", + "nconf": "0.10.0", "nodepub": "3.0.1", "request": "2.88.2", "rimraf": "3.0.2", diff --git a/src/tsconfig.spec.json b/src/tsconfig.spec.json index fb533bb..1f73aaf 100644 --- a/src/tsconfig.spec.json +++ b/src/tsconfig.spec.json @@ -1,11 +1,24 @@ { - "extends": "../tsconfig.base.json", - "compilerOptions": { - "outDir": "../out-tsc/spec", - "module": "commonjs", - "types": ["jasmine", "node"] - }, - "files": ["test.ts", "polyfills-test.ts"], - "include": ["**/*.spec.ts", "**/*.d.ts"], - "exclude": ["dist", "release", "node_modules"] + "extends": "../tsconfig.base.json", + "compilerOptions": { + "outDir": "../out-tsc/spec", + "module": "commonjs", + "types": [ + "jasmine", + "node" + ] + }, + "files": [ + "test.ts", + "polyfills-test.ts" + ], + "include": [ + "**/*.spec.ts", + "**/*.d.ts" + ], + "exclude": [ + "dist", + "release", + "node_modules" + ] } From cef99a8f1f6cc272d116c6f68604f06043449e65 Mon Sep 17 00:00:00 2001 From: Shehryar Date: Mon, 31 May 2021 01:36:45 +0400 Subject: [PATCH 5/7] Revert "chapters & UI" This reverts commit ce17fe62d5f2b7a4fed7c8522142e55994279a12. --- src/app/pages/novel/novel.component.html | 86 +++++++++++++++++------- src/app/pages/novel/novel.component.scss | 20 +++--- src/app/pages/novel/novel.component.ts | 43 +++++------- src/assets/img/browser-white.svg | 9 --- src/assets/img/cancel.svg | 2 +- src/assets/img/delete.svg | 2 +- src/assets/img/folder.svg | 2 +- src/assets/img/update.svg | 2 +- 8 files changed, 88 insertions(+), 78 deletions(-) delete mode 100644 src/assets/img/browser-white.svg diff --git a/src/app/pages/novel/novel.component.html b/src/app/pages/novel/novel.component.html index 246d9d0..9f56c3e 100644 --- a/src/app/pages/novel/novel.component.html +++ b/src/app/pages/novel/novel.component.html @@ -2,7 +2,11 @@ diff --git a/src/app/pages/novel/novel.component.scss b/src/app/pages/novel/novel.component.scss index f3e23a9..8b3ce4c 100644 --- a/src/app/pages/novel/novel.component.scss +++ b/src/app/pages/novel/novel.component.scss @@ -8,10 +8,8 @@ flex-direction: row; justify-content: space-between; align-items: center; + height: 30px; margin-bottom: 10px; - background: $secondaryAccent; - border-radius: 3px; - padding: 0.5em; .progressBar { height: 100%; @@ -122,18 +120,16 @@ border-radius: 5px; opacity: 0.3; - background: linear-gradient(-45deg, - #74ccbc, - rgb(140, 255, 240), - #44beff, - #00a2ff); + background: linear-gradient( + -45deg, + #74ccbc, + rgb(140, 255, 240), + #44beff, + #00a2ff + ); background-size: 400% 400%; animation: load 5s ease infinite; } - - .chapters { - margin-top: 2em; - } } } diff --git a/src/app/pages/novel/novel.component.ts b/src/app/pages/novel/novel.component.ts index 0e42a99..c676f19 100644 --- a/src/app/pages/novel/novel.component.ts +++ b/src/app/pages/novel/novel.component.ts @@ -1,12 +1,11 @@ import { Component, OnInit } from '@angular/core'; import { Router } from '@angular/router'; -import { chapterObj, novelObj, sourceObj } from 'app/resources/types'; +import { novelObj, sourceObj } from 'app/resources/types'; import { DatabaseService } from 'app/services/database.service'; import { BoxnovelService } from 'app/services/sources/boxnovel.service'; import { SourceManagerService } from 'app/services/sources/source-service-manager.service'; import { sourceService } from 'app/services/sources/sourceService'; import { shell } from 'electron'; -import { readFileSync } from 'fs'; @Component({ selector: 'app-novel', @@ -17,11 +16,10 @@ export class NovelComponent implements OnInit { source: sourceObj = history.state.source; novel: novelObj = history.state.novel; - chapters: chapterObj; service: sourceService = history.state.service; - fromHome: boolean = history.state.fromHome; - fromLibrary: boolean = history.state.fromLibrary; + fromHome: boolean = history.state.fromHome + fromLibrary: boolean = history.state.fromLibrary progress = 0; @@ -33,31 +31,22 @@ export class NovelComponent implements OnInit { constructor(private router: Router, public database: DatabaseService, public sourceManager: SourceManagerService) { if (!this.source) this.source = { - name: "NovelFull", - link: "https://novelfull.com", - icon: "assets/img/sources/novelfull-logo.png" + name: "BoxNovel", + link: "https://boxnovel.com", + icon: "assets/img/sources/boxnovel-logo.png" }; if (!this.novel) this.novel = { - source: "NovelFull", - link: "https://novelfull.com/tales-of-demons-and-gods.html", - name: "Tales of Demons and Gods", - latestChapter: "Chapter 494 - Divine Items", - cover: "https://novelfull.com/uploads/thumbs/tales-of-demons-and-gods-fceee0fee0-2239c49aee6b961904acf173b7e4602a.jpg", - totalChapters: 494, - author: "Mad Snail", - genre: "Fantasy, Xuanhuan, Action, Adventure, Comedy, Harem, Martial Arts, Romance", - summary: "Killed by a Sage Emperor and reborn as his 13 year old self, Nie Li was given a second chance at life. A second chance to change everything and save his loved ones and his beloved city. He shall once again battle with the Sage Emperor to avenge his death and those of his beloved . With the vast knowledge of hundred years of life he accumulated in his previous life, wielding the strongest demon spirits, he shall reach the pinnacle of Martial Arts.\nEnmities of the past will be settled in this new lifetime. “Since I’m back, then in this lifetime, I shall become the King of the Gods that dominate everything. Let everything else tremble beneath my feet!”\n", - downloadedChapters: 494, - folderPath: "A:\\Downloads\\NovelScraper-Library\\Tales of Demons and Gods", - downloading: false, - downloaded: true, - isUpdated: true, + author: "Baby Piggie, 猪宝宝萌萌哒 Baby Piggie, 猪宝宝萌萌哒 Baby Piggie, 猪宝宝萌萌哒 Baby Piggie, 猪宝宝萌萌哒 Baby Piggie, 猪宝宝萌萌哒 Baby Piggie, 猪宝宝萌萌哒 Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years ", + cover: "https://boxnovel.com/wp-content/uploads/2018/10/My-Youth-Began-With-Him-193x278.jpg", + genre: "Romance", + latestChapter: "Chapter 3644 - Birthday Banquet 14 Chapter 3644 - Birthday Banquet 14 Chapter 3644 - Birthday Banquet 14", + totalChapters: 300, + link: "https://boxnovel.com/novel/my-youth-began-with-him-webnovel/", + name: "My Youth Began With Him-Webnovel My Youth Began With Him-Webnovel My Youth Began With Him-Webnovel My Youth Began With Him-Webnovel My Youth Began With Him-Webnovel My Youth Began With Him-Webnovel My Youth Began With Him-Webnovel", + source: "BoxNovel", + summary: "Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years Seven years ", inLibrary: true, - state: [] - } - - if (this.novel.downloaded) { - this.chapters = JSON.parse(readFileSync(this.novel.folderPath + "\\chapters.json").toString()); + downloading: false, } } diff --git a/src/assets/img/browser-white.svg b/src/assets/img/browser-white.svg deleted file mode 100644 index 88ce2a6..0000000 --- a/src/assets/img/browser-white.svg +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - diff --git a/src/assets/img/cancel.svg b/src/assets/img/cancel.svg index 579eed8..09475e6 100644 --- a/src/assets/img/cancel.svg +++ b/src/assets/img/cancel.svg @@ -1,3 +1,3 @@ - + diff --git a/src/assets/img/delete.svg b/src/assets/img/delete.svg index 31129d6..2217591 100644 --- a/src/assets/img/delete.svg +++ b/src/assets/img/delete.svg @@ -1,3 +1,3 @@ - + diff --git a/src/assets/img/folder.svg b/src/assets/img/folder.svg index 642d04a..4bf2ee3 100644 --- a/src/assets/img/folder.svg +++ b/src/assets/img/folder.svg @@ -1,3 +1,3 @@ - + diff --git a/src/assets/img/update.svg b/src/assets/img/update.svg index cadfc3c..b639c18 100644 --- a/src/assets/img/update.svg +++ b/src/assets/img/update.svg @@ -1,3 +1,3 @@ - + From 1ea376cfd1fc9fe239b2fc5b3bb941daac73d98b Mon Sep 17 00:00:00 2001 From: Shehryar Date: Tue, 1 Jun 2021 03:37:40 +0400 Subject: [PATCH 6/7] control panel ui --- src/app/pages/novel/novel.component.html | 2 +- src/app/pages/novel/novel.component.scss | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/app/pages/novel/novel.component.html b/src/app/pages/novel/novel.component.html index 9f56c3e..fc5a5af 100644 --- a/src/app/pages/novel/novel.component.html +++ b/src/app/pages/novel/novel.component.html @@ -19,7 +19,7 @@

diff --git a/src/app/pages/novel/novel.component.scss b/src/app/pages/novel/novel.component.scss index 8b3ce4c..4ec2e94 100644 --- a/src/app/pages/novel/novel.component.scss +++ b/src/app/pages/novel/novel.component.scss @@ -10,9 +10,12 @@ align-items: center; height: 30px; margin-bottom: 10px; + box-shadow: 0 0 12px rgba(0, 0, 0, 0.2); + border-radius: 5px; + padding: 1.5em 1em; .progressBar { - height: 100%; + height: 30px; background: $primaryFade; overflow: hidden; position: relative; @@ -42,6 +45,10 @@ height: 100%; margin-left: 10px; margin-right: 10px; + + &:last-child { + margin-right: 0; + } } } From 649150f17fee944bfd649ebbeac01be81882edf2 Mon Sep 17 00:00:00 2001 From: Shehryar Date: Thu, 10 Jun 2021 00:35:08 +0400 Subject: [PATCH 7/7] v2.0.5 progress saving --- package.json | 2 +- src/app/services/novel-factory.service.ts | 11 ++- src/app/services/sources/boxnovel.service.ts | 78 +++++++++------- src/app/services/sources/novelfull.service.ts | 88 +++++++++++-------- .../sources/readlightnovel-service.service.ts | 60 +++++++++---- src/app/services/sources/sourceService.ts | 9 +- 6 files changed, 149 insertions(+), 99 deletions(-) diff --git a/package.json b/package.json index f1e7cdf..b15d1be 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "NovelScraper", - "version": "2.0.4", + "version": "2.0.5", "description": "App for downloading novels from pirate sites.", "homepage": "https://github.com/HanaDigital/NovelScraper", "author": { diff --git a/src/app/services/novel-factory.service.ts b/src/app/services/novel-factory.service.ts index fa747a1..b04b376 100644 --- a/src/app/services/novel-factory.service.ts +++ b/src/app/services/novel-factory.service.ts @@ -20,7 +20,7 @@ export class NovelFactoryService { "NovelScraper-Library" ); - constructor(public database: DatabaseService) {} + constructor(public database: DatabaseService) { } async generateEpub( novel: novelObj, @@ -33,7 +33,7 @@ export class NovelFactoryService { await shellJS.mkdir("-p", novelFolder); // Save chapters in a json file and set the novel as download - await this.saveChapters(novel, chapters, novelFolder); + await this.saveChapters(novel, chapters); // Download the cover and get its path const coverPath = await this.downloadCover(novel.cover, novelFolder); @@ -72,9 +72,12 @@ export class NovelFactoryService { // Save chapters to a json file so we don't re-download when updating async saveChapters( novel: novelObj, - chapters: chapterObj[], - novelFolder: string + chapters: chapterObj[] ): Promise { + // Create the folder for storing the novel files + const novelFolder = novel.folderPath; + await shellJS.mkdir("-p", novelFolder); + const chaptersFile = path.join(novelFolder, "chapters.json"); const json = JSON.stringify(chapters, null, 4); writeFile(chaptersFile, json, (err) => { diff --git a/src/app/services/sources/boxnovel.service.ts b/src/app/services/sources/boxnovel.service.ts index aa39592..1f5757b 100644 --- a/src/app/services/sources/boxnovel.service.ts +++ b/src/app/services/sources/boxnovel.service.ts @@ -272,50 +272,62 @@ export class BoxnovelService extends sourceService { chapterNames = chapterNames.slice(update.startIndex); } - // Download each chapter at a time - for (let i = 0; i < chapterLinks.length; i++) { - if (this.database.isCanceled(downloadID)) { - this.database.updateDownloading(novel.link, false); - console.log("Download canceled!"); - return; - } + const totalLength = downloadedChapters.length + chapterLinks.length; + let canceled = false; - const html = await this.getHtml(chapterLinks[i]); - const chapterHtml = html.getElementsByClassName( - "entry-content" - )[0]; - try { - chapterHtml.getElementsByClassName("cha-tit")[0].remove(); // Remove h3 tag from chapter - } catch (error) { - console.log( - "Missing 'cha-tit' class at chapter index " + + try { + // Download each chapter at a time + for (let i = 0; i < chapterLinks.length; i++) { + if (this.database.isCanceled(downloadID)) { + this.database.updateDownloading(novel.link, false); + console.log("Download canceled!"); + canceled = true; + return; + } + + const html = await this.getHtml(chapterLinks[i]); + const chapterHtml = html.getElementsByClassName( + "entry-content" + )[0]; + try { + chapterHtml.getElementsByClassName("cha-tit")[0].remove(); // Remove h3 tag from chapter + } catch (error) { + console.log( + "Missing 'cha-tit' class at chapter index " + i + "and chapter name " + chapterNames[i] - ); - } + ); + } - const chapterTitle = chapterNames[i]; + const chapterTitle = chapterNames[i]; - let chapterBody = "

" + chapterTitle + "

"; - chapterBody += chapterHtml.outerHTML; + let chapterBody = "

" + chapterTitle + "

"; + chapterBody += chapterHtml.outerHTML; - const chapter = this.prepChapter( + const chapter = this.prepChapter(novel, downloadID, chapterTitle, chapterBody, downloadedChapters.length, totalLength); + downloadedChapters.push(chapter); + } + + if (!canceled) this.novelFactory.generateEpub(novel, downloadedChapters, downloadID); + } catch (error) { + canceled = true; + console.error("Error downloading the complete novel. Retry."); + console.error(error); + } + + if (canceled) { + this.novelFactory.saveChapters( novel, - downloadID, - chapterTitle, - chapterBody, - i, - chapterLinks.length + downloadedChapters ); - downloadedChapters.push(chapter); + this.database.cancelDownload(downloadID); + this.database.updateDownloading(novel.link, false); + this.database.updateDownloadedChapters(novel.link, downloadedChapters.length); + this.database.updateDownloaded(novel.link, true); + this.database.updateIsUpdated(novel.link, false); } - this.novelFactory.generateEpub( - novel, - downloadedChapters, - downloadID - ); } catch (error) { this.database.cancelDownload(downloadID); this.database.updateDownloading(novel.link, false); diff --git a/src/app/services/sources/novelfull.service.ts b/src/app/services/sources/novelfull.service.ts index 61cd7b1..b6a8951 100644 --- a/src/app/services/sources/novelfull.service.ts +++ b/src/app/services/sources/novelfull.service.ts @@ -257,9 +257,9 @@ export class NovelfullService extends sourceService { for (let x = 0; x < chapters.length; x++) { chapterLinks.push( "https://novelfull.com" + - chapters[x] - .getElementsByTagName("a")[0] - .getAttribute("href") + chapters[x] + .getElementsByTagName("a")[0] + .getAttribute("href") ); chapterNames.push( chapters[x].getElementsByTagName("a")[0].title @@ -280,53 +280,65 @@ export class NovelfullService extends sourceService { chapterNames = chapterNames.slice(update.startIndex); } - // Download each chapter at a time - for (let i = 0; i < chapterLinks.length; i++) { - if (this.database.isCanceled(downloadID)) { - this.database.updateDownloading(novel.link, false); - console.log("Download canceled!"); - return; - } + const totalLength = downloadedChapters.length + chapterLinks.length; + let canceled = false; - const html = await this.getHtml(chapterLinks[i]); + try { + // Download each chapter at a time + for (let i = 0; i < chapterLinks.length; i++) { + if (this.database.isCanceled(downloadID)) { + this.database.updateDownloading(novel.link, false); + console.log("Download canceled!"); + canceled = true; + return; + } - //////////////////////// [2] YOUR CODE STARTS HERE /////////////////////////////// + const html = await this.getHtml(chapterLinks[i]); - // FIXME: you have the html of the chapter page - // Get the element that wraps all the paragraphs of the chapter - const chapterHtml = html.getElementsByClassName("chapter-c")[0]; + //////////////////////// [2] YOUR CODE STARTS HERE /////////////////////////////// - //////////////////////// YOUR CODE ENDS HERE ///////////////////////////////// + // FIXME: you have the html of the chapter page + // Get the element that wraps all the paragraphs of the chapter + const chapterHtml = html.getElementsByClassName("chapter-c")[0]; - const chapterTitle = chapterNames[i]; + //////////////////////// YOUR CODE ENDS HERE ///////////////////////////////// - let chapterBody = "

" + chapterTitle + "

"; - chapterBody += chapterHtml.outerHTML; + const chapterTitle = chapterNames[i]; - chapterBody = chapterBody.replace( - /\(adsbygoogle = window.adsbygoogle \|\| \[\]\).push\({}\);/g, - "" - ); - chapterBody = chapterBody.replace(/<\/script>/g, ""); - chapterBody = chapterBody.replace(//g, ""); - console.log(chapterBody); + let chapterBody = "

" + chapterTitle + "

"; + chapterBody += chapterHtml.outerHTML; + + chapterBody = chapterBody.replace( + /\(adsbygoogle = window.adsbygoogle \|\| \[\]\).push\({}\);/g, + "" + ); + chapterBody = chapterBody.replace(/<\/script>/g, ""); + chapterBody = chapterBody.replace(//g, ""); + console.log(chapterBody); + + const chapter = this.prepChapter(novel, downloadID, chapterTitle, chapterBody, downloadedChapters.length, totalLength); + downloadedChapters.push(chapter); + } + + if (!canceled) this.novelFactory.generateEpub(novel, downloadedChapters, downloadID); + } catch (error) { + canceled = true; + console.error("Error downloading the complete novel. Retry."); + console.error(error); + } - const chapter = this.prepChapter( + if (canceled) { + this.novelFactory.saveChapters( novel, - downloadID, - chapterTitle, - chapterBody, - i, - chapterLinks.length + downloadedChapters ); - downloadedChapters.push(chapter); + this.database.cancelDownload(downloadID); + this.database.updateDownloading(novel.link, false); + this.database.updateDownloadedChapters(novel.link, downloadedChapters.length); + this.database.updateDownloaded(novel.link, true); + this.database.updateIsUpdated(novel.link, false); } - this.novelFactory.generateEpub( - novel, - downloadedChapters, - downloadID - ); } catch (error) { this.database.cancelDownload(downloadID); this.database.updateDownloading(novel.link, false); diff --git a/src/app/services/sources/readlightnovel-service.service.ts b/src/app/services/sources/readlightnovel-service.service.ts index f896396..005948f 100644 --- a/src/app/services/sources/readlightnovel-service.service.ts +++ b/src/app/services/sources/readlightnovel-service.service.ts @@ -163,35 +163,57 @@ export class ReadlightnovelService extends sourceService { chapterNames = chapterNames.slice(update.startIndex); } - // Download each chapter at a time - for (let i = 0; i < chapterLinks.length; i++) { - if (this.database.isCanceled(downloadID)) { - this.database.updateDownloading(novel.link, false); - console.log('Download canceled!') - return; - } + const totalLength = downloadedChapters.length + chapterLinks.length; + let canceled = false; + + try { + // Download each chapter at a time + for (let i = 0; i < chapterLinks.length; i++) { + if (this.database.isCanceled(downloadID)) { + this.database.updateDownloading(novel.link, false); + console.log('Download canceled!'); + canceled = true; + break; + } + + const html = await this.getHtml(chapterLinks[i]); - const html = await this.getHtml(chapterLinks[i]); + //////////////////////// YOUR CODE STARTS HERE /////////////////////////////// - //////////////////////// YOUR CODE STARTS HERE /////////////////////////////// + // You have the html of the chapter page + // Get the element that wraps all the paragraphs of the chapter + const chapterHtml = html.getElementsByClassName('desc')[0].getElementsByClassName("hidden")[0]; - // You have the html of the chapter page - // Get the element that wraps all the paragraphs of the chapter - const chapterHtml = html.getElementsByClassName('desc')[0].getElementsByClassName("hidden")[0]; + //////////////////////// YOUR CODE ENDS HERE ///////////////////////////////// - //////////////////////// YOUR CODE ENDS HERE ///////////////////////////////// + const chapterTitle = chapterNames[i]; - const chapterTitle = chapterNames[i]; + let chapterBody = "

" + chapterTitle + "

"; + chapterBody += chapterHtml.outerHTML; - let chapterBody = "

" + chapterTitle + "

"; - chapterBody += chapterHtml.outerHTML; + const chapter = this.prepChapter(novel, downloadID, chapterTitle, chapterBody, downloadedChapters.length, totalLength); + downloadedChapters.push(chapter); + } - const chapter = this.prepChapter(novel, downloadID, chapterTitle, chapterBody, i, chapterLinks.length); - downloadedChapters.push(chapter); + if (!canceled) this.novelFactory.generateEpub(novel, downloadedChapters, downloadID); + } catch (error) { + canceled = true; + console.error("Error downloading the complete novel. Retry."); + console.error(error); } - this.novelFactory.generateEpub(novel, downloadedChapters, downloadID); + if (canceled) { + this.novelFactory.saveChapters( + novel, + downloadedChapters + ); + this.database.cancelDownload(downloadID); + this.database.updateDownloading(novel.link, false); + this.database.updateDownloadedChapters(novel.link, downloadedChapters.length); + this.database.updateDownloaded(novel.link, true); + this.database.updateIsUpdated(novel.link, false); + } } catch (error) { this.database.cancelDownload(downloadID); diff --git a/src/app/services/sources/sourceService.ts b/src/app/services/sources/sourceService.ts index 4b50bce..7b57404 100644 --- a/src/app/services/sources/sourceService.ts +++ b/src/app/services/sources/sourceService.ts @@ -13,7 +13,7 @@ export class sourceService { scrollPos: number; - constructor(public database: DatabaseService) {} + constructor(public database: DatabaseService) { } async searchWIthLink( link: string, @@ -23,9 +23,9 @@ export class sourceService { return {}; } - async searchWithName(name: string, source: string): Promise {} + async searchWithName(name: string, source: string): Promise { } - async download(novel: novelObj, downloadID: number): Promise {} + async download(novel: novelObj, downloadID: number): Promise { } update(novel: novelObj, numOfChapters: number): update { if (numOfChapters > novel.totalChapters) { @@ -90,7 +90,8 @@ export class sourceService { const percentage = ((currentPos / destPos) * 100).toFixed(2); this.database.updateDownloadTracker(downloadID, percentage); - console.log(percentage); + + console.log(`Downloaded chapter ${currentPos}`) return { title: title,