-
Notifications
You must be signed in to change notification settings - Fork 263
feat: add lumostories.com parser #2570
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
dteviot
merged 1 commit into
dteviot:ExperimentalTabMode
from
Crn0:feature/LumosStoriesParser
Mar 24, 2026
+143
−0
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
|
|
||
| "use strict"; | ||
|
|
||
| parserFactory.register("lumostories.com", () => new LumosStoriesParer()); | ||
| parserFactory.register("api.lumostories.com", () => new LumosStoriesParer()); | ||
|
|
||
|
|
||
| class LumosStoriesParer extends Parser { | ||
| constructor() { | ||
| super(); | ||
| this.minimumThrottle = 3000; | ||
| } | ||
|
|
||
| /** | ||
| * | ||
| * @returns {"https://api.lumostories.com/api/v1"} | ||
| */ | ||
| getApiBaseUrl() { | ||
| return "https://api.lumostories.com/api/v1"; | ||
| } | ||
|
|
||
| /** | ||
| * @param {HTMLDocument} dom | ||
| * @returns {String} | ||
| */ | ||
| getBookId(dom) { | ||
| //https://lumostories.com/en/story/216/chapters/ | ||
| if (dom.baseURI.endsWith("/chapters/") || dom.baseURI.endsWith("/chapters")) { | ||
| let uriArray = dom.baseURI.split("/").filter(Boolean); | ||
| let id = uriArray[uriArray.length - 2]; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is length - 2 going to work? That assumes there's a trailing '/' when not there, needs to be - 1 Should probably add '/' if not there, then run e.g. let url = dom.baseURI;
if (!url.endsWith("/") {
url += "/"
}
if (dom.baseURI.endsWith("/chapters/"))
...etc
```
Actually, can simplify this and the case of https://lumostories.com/en/story/216/
Whole function can be
````javascript
getBookId(dom) {
return dom.baseURI.split("/")[5];
}
``` |
||
|
|
||
| return id; | ||
| } | ||
| // https://lumostories.com/en/story/216/ | ||
| let uriArray = dom.baseURI.split("/").filter(Boolean); | ||
| let id = uriArray[uriArray.length - 1]; | ||
|
|
||
| return id; | ||
| } | ||
|
|
||
| /** | ||
| * @param {HTMLDocument} dom | ||
| */ | ||
| async getChapterUrls(dom) { | ||
| let id = this.getBookId(dom); | ||
| let book = (await HttpClient.fetchJson(`${this.getApiBaseUrl()}/books/${id}`)).json; | ||
|
|
||
| return book.chapters.map((ch) => ({ | ||
| sourceUrl: `${this.getApiBaseUrl()}/book_chapters/${ch.id}/content?title=${ch.title}`, | ||
| title: `Chapter ${ch.number} - ${ch.title}`, | ||
| newArc: null, | ||
| isIncludeable: new Date() >= new Date(ch.release_date) | ||
| })).reverse(); | ||
| } | ||
|
|
||
| /** | ||
| * @param {HTMLDocument} dom | ||
| */ | ||
| async loadEpubMetaInfo(dom) { | ||
| let id = this.getBookId(dom); | ||
| let book = (await HttpClient.fetchJson(`${this.getApiBaseUrl()}/books/${id}`)).json; | ||
| this.title = book.name; | ||
| this.author = book.author.username; | ||
| this.description = book.summary?.trim(); | ||
| this.subject = book.tags.map((tag) => tag.name).join(", "); | ||
| return; | ||
| } | ||
|
|
||
| extractTitleImpl() { | ||
| return this.title; | ||
| } | ||
|
|
||
| extractAuthor() { | ||
| return this.author; | ||
| } | ||
|
|
||
| extractDescription() { | ||
| return this.description; | ||
| } | ||
|
|
||
| /** | ||
| * @param {HTMLDocument} dom | ||
| */ | ||
| findContent(dom) { | ||
| return dom.querySelector("body"); | ||
| } | ||
|
|
||
| /** | ||
| * @param {HTMLDocument} dom | ||
| */ | ||
| findCoverImageUrl(dom) { | ||
| let title = dom.querySelector("h1").textContent ?? ""; | ||
| let img = dom.querySelector(`img[alt="${title}"]`); | ||
|
|
||
| return img?.src ?? null; | ||
| } | ||
|
|
||
| /** | ||
| * @param {String} url | ||
| */ | ||
| async fetchChapter(url) { | ||
| let search = new URLSearchParams(new URL(url).search); | ||
| let chapterUrl = (await HttpClient.fetchText(url.replace(/\?.*$/, ""))).replaceAll("\"", ""); | ||
| /** @type {HTMLDocument} */ | ||
| let html = (await HttpClient.wrapFetch(chapterUrl)).responseXML; | ||
|
|
||
| let title = search.get("title"); | ||
|
|
||
| if (title) { | ||
| let body = html.querySelector("body"); | ||
|
|
||
| let h1 = html?.createElement("h1"); | ||
|
|
||
| h1.textContent = title; | ||
| body.prepend(h1); | ||
| } | ||
|
|
||
|
|
||
| return html; | ||
| } | ||
|
|
||
| isCustomError(response) { | ||
| const hasError = response?.responseXML.querySelector("error"); | ||
|
|
||
| if (!hasError) return false; | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| setCustomErrorResponse(url, wrapOptions, checkedresponse) { | ||
| if (!checkedresponse?.ok) { | ||
| let newresp = {}; | ||
| newresp.url = url; | ||
| newresp.wrapOptions = wrapOptions; | ||
| newresp.response = {}; | ||
| newresp.response.url = checkedresponse.response.url; | ||
| newresp.response.status = checkedresponse?.status; | ||
| return newresp; | ||
| } | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just noticed it right now, but it looks like I misspelled 'Parser' in this. I will do a quick commit to change this.