-
Notifications
You must be signed in to change notification settings - Fork 86
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
ReLibrary: Fix loading scraping+loading covers when a novel is parsed #1353
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -164,7 +164,19 @@ class ReLibraryPlugin implements Plugin.PluginBase { | |
name = 'Re:Library'; | ||
icon = 'src/en/relibrary/icon.png'; | ||
site = 'https://re-library.com'; | ||
version = '1.0.0'; | ||
version = '1.1.0'; | ||
|
||
imageRequestInit: Plugin.ImageRequestInit = { | ||
headers: { | ||
Referer: ReLibraryPlugin.site, | ||
}, | ||
}; | ||
|
||
private static trim_slashes(url: string): string { | ||
while (url.startsWith('/')) url = url.slice(1); | ||
while (url.endsWith('/')) url = url.slice(0, url.length - 1); | ||
return url; | ||
} | ||
Comment on lines
+175
to
+179
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. be careful, after this changes, novels in popular and search would be treated as new novels (though they were installed) because the path is not same as in the database |
||
|
||
private searchFunc = new FuzzySearch<Plugin.NovelItem>(item => [item.name], { | ||
sort: true, | ||
|
@@ -187,10 +199,15 @@ class ReLibraryPlugin implements Plugin.PluginBase { | |
novel.cover = | ||
loadedCheerio(el) | ||
.find('table > tbody > tr > td > a > img') | ||
.attr('src') || defaultCover; | ||
.attr('src') || | ||
loadedCheerio(el) | ||
.find('table > tbody > tr > td > a > img') | ||
.attr('data-cfsrc') || | ||
defaultCover; | ||
if (novel.path.startsWith(this.site)) { | ||
novel.path = novel.path.slice(this.site.length); | ||
} | ||
novel.path = ReLibraryPlugin.trim_slashes(novel.path); | ||
novels.push(novel as Plugin.NovelItem); | ||
}); | ||
return novels; | ||
|
@@ -210,10 +227,15 @@ class ReLibraryPlugin implements Plugin.PluginBase { | |
novel.cover = | ||
loadedCheerio(el) | ||
.find('.entry-content > table > tbody > tr > td > img') | ||
.attr('src') || defaultCover; | ||
.attr('src') || | ||
loadedCheerio(el) | ||
.find('.entry-table > table > tbody > tr > td > img') | ||
.attr('data-cfsrc') || | ||
defaultCover; | ||
if (novel.path.startsWith(this.site)) { | ||
novel.path = novel.path.slice(this.site.length); | ||
} | ||
novel.path = ReLibraryPlugin.trim_slashes(novel.path); | ||
novels.push(novel as Plugin.NovelItem); | ||
}); | ||
return novels; | ||
|
@@ -236,7 +258,7 @@ class ReLibraryPlugin implements Plugin.PluginBase { | |
|
||
async parseNovel(novelPath: string): Promise<Plugin.SourceNovel> { | ||
const novel: Partial<Plugin.SourceNovel> = { | ||
path: novelPath, | ||
path: ReLibraryPlugin.trim_slashes(novelPath), | ||
}; | ||
// title: .entry-content > header.entry-header > .entry-title | ||
// img: .entry-content > table > tbody > tr > td > img | ||
|
@@ -258,10 +280,16 @@ class ReLibraryPlugin implements Plugin.PluginBase { | |
throw new Error(`Invalid novel for url ${novelPath}`); | ||
|
||
// Find the cover | ||
// | ||
// the data-cfsrc is something I don't understand but after dumping all the imgs on the page it was here and there wasn't any `src` attr | ||
novel.cover = | ||
loadedCheerio('.entry-content > table > tbody > tr > td > img').attr( | ||
loadedCheerio('.entry-content > table > tbody > tr > td > a > img').attr( | ||
'src', | ||
) || defaultCover; | ||
) || | ||
loadedCheerio('.entry-content > table > tbody > tr > td > img').attr( | ||
'data-cfsrc', | ||
) || | ||
defaultCover; | ||
|
||
// Genres in comma separated "list" | ||
novel.genres = (() => { | ||
|
@@ -316,10 +344,10 @@ class ReLibraryPlugin implements Plugin.PluginBase { | |
} | ||
chapters.push({ | ||
name: loadedCheerio(chap_el).text(), | ||
path: chap_path, | ||
path: ReLibraryPlugin.trim_slashes(chap_path), | ||
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. should be |
||
chapterNumber: chapter_idx, | ||
// we KNOW that we can't get the released time (at least without any additional fetches), so set it to null purposfully | ||
releaseTime: null, | ||
releaseTime: undefined, | ||
}); | ||
}); | ||
}); | ||
|
@@ -370,6 +398,7 @@ class ReLibraryPlugin implements Plugin.PluginBase { | |
if (path.startsWith(this.site)) { | ||
path = path.slice(this.site.length); | ||
} | ||
path = ReLibraryPlugin.trim_slashes(path); | ||
novels.push({ name: e.text(), path: path, cover: defaultCover }); | ||
} | ||
}); | ||
|
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.
Should be
this.site
instead? I dont thinksite
is a static attribute