Cleanup + fix issue where zerochan sometimes couldn't find the image
parent
26b257824e
commit
abda647335
|
|
@ -26,6 +26,7 @@ export default class NeoScraper {
|
||||||
|
|
||||||
for (const engine of this.engines) {
|
for (const engine of this.engines) {
|
||||||
if (ignoreCanImport || engine.canImport(document.location)) {
|
if (ignoreCanImport || engine.canImport(document.location)) {
|
||||||
|
console.log("Using engine: " + engine.name);
|
||||||
res.results.push(engine.scrapeDocument(document));
|
res.results.push(engine.scrapeDocument(document));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -34,10 +35,13 @@ export default class NeoScraper {
|
||||||
if (!this.fallbackEngine) {
|
if (!this.fallbackEngine) {
|
||||||
console.error("NeoScraper.fallbackEngine is unset!");
|
console.error("NeoScraper.fallbackEngine is unset!");
|
||||||
} else {
|
} else {
|
||||||
|
console.log("Using fallback engine");
|
||||||
res.results.push(this.fallbackEngine.scrapeDocument(document));
|
res.results.push(this.fallbackEngine.scrapeDocument(document));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.dir(res);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,14 @@ export class ScrapeResult {
|
||||||
constructor(engine: string) {
|
constructor(engine: string) {
|
||||||
this.engine = engine;
|
this.engine = engine;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tryAddPost(post: ScrapedPost) {
|
||||||
|
if (!post.imageUrl) {
|
||||||
|
console.log(`[${this.engine}] Not adding post because imageUrl is unset!`);
|
||||||
|
} else {
|
||||||
|
this.posts.push(post);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ScrapeResults {
|
export class ScrapeResults {
|
||||||
|
|
|
||||||
|
|
@ -78,9 +78,7 @@ export default class Danbooru implements ScrapeEngine {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (post.imageUrl) {
|
result.tryAddPost(post);
|
||||||
result.posts.push(post);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -135,9 +135,7 @@ export default class Gelbooru implements ScrapeEngine {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (post.imageUrl) {
|
result.tryAddPost(post);
|
||||||
result.posts.push(post);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -88,10 +88,7 @@ export default class Moebooru implements ScrapeEngine {
|
||||||
post.tags.push(tag);
|
post.tags.push(tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
result.tryAddPost(post);
|
||||||
if (post.imageUrl) {
|
|
||||||
result.posts.push(post);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,9 +25,7 @@ export default class Reddit implements ScrapeEngine {
|
||||||
post.imageUrl = (newLinkElements[0] as HTMLAnchorElement).href;
|
post.imageUrl = (newLinkElements[0] as HTMLAnchorElement).href;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (post.imageUrl) {
|
result.tryAddPost(post);
|
||||||
result.posts.push(post);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -74,9 +74,7 @@ export default class SankakuComplex implements ScrapeEngine {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (post.imageUrl) {
|
result.tryAddPost(post);
|
||||||
result.posts.push(post);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -41,9 +41,7 @@ export default class Shimmie2 implements ScrapeEngine {
|
||||||
.map(x => (x as HTMLAnchorElement).innerText.toLowerCase())
|
.map(x => (x as HTMLAnchorElement).innerText.toLowerCase())
|
||||||
.map(x => new ScrapedTag(x));
|
.map(x => new ScrapedTag(x));
|
||||||
|
|
||||||
if (post.imageUrl) {
|
result.tryAddPost(post);
|
||||||
result.posts.push(post);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,9 +33,7 @@ export default class Twitter implements ScrapeEngine {
|
||||||
post.imageUrl = getOriginalImageUrl((mediaImageElements[0] as HTMLImageElement).src);
|
post.imageUrl = getOriginalImageUrl((mediaImageElements[0] as HTMLImageElement).src);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (post.imageUrl) {
|
result.tryAddPost(post);
|
||||||
result.posts.push(post);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,14 @@ export default class Zerochan implements ScrapeEngine {
|
||||||
// Set image url
|
// Set image url
|
||||||
const previewElements = document.getElementsByClassName("preview");
|
const previewElements = document.getElementsByClassName("preview");
|
||||||
if (previewElements.length > 0) {
|
if (previewElements.length > 0) {
|
||||||
|
// The preview element only exists when there is a larger size available. Preview's img element contains a downscaled version.
|
||||||
post.imageUrl = (previewElements[0] as HTMLAnchorElement).href;
|
post.imageUrl = (previewElements[0] as HTMLAnchorElement).href;
|
||||||
|
} else {
|
||||||
|
// When there is no larger version available just use the displayed version.
|
||||||
|
const imgElement = document.querySelector("img[title='No larger size available']") as HTMLImageElement;
|
||||||
|
if (imgElement) {
|
||||||
|
post.imageUrl = imgElement.src;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set rating
|
// Set rating
|
||||||
|
|
@ -59,9 +66,7 @@ export default class Zerochan implements ScrapeEngine {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (post.imageUrl) {
|
result.tryAddPost(post);
|
||||||
result.posts.push(post);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue