From 6bb089cca65a715af24f8bad1a0d232c7019354c Mon Sep 17 00:00:00 2001 From: MillenniumEarl Date: Mon, 9 Nov 2020 17:53:29 +0100 Subject: [PATCH] Ignore games with no JSON-LD --- app/example.js | 4 ++-- app/index.js | 1 + app/scripts/scraper.js | 12 ++++++++---- package-lock.json | 2 +- package.json | 2 +- 5 files changed, 13 insertions(+), 8 deletions(-) diff --git a/app/example.js b/app/example.js index 0fa3752..6d44e0d 100644 --- a/app/example.js +++ b/app/example.js @@ -22,9 +22,9 @@ main(); async function main() { // Local variables const gameList = [ + "Four Elements Trainer", "corrupted kingdoms", - "summertime saga", - "brothel king" + "summertime saga" ]; // Log in the platform diff --git a/app/index.js b/app/index.js index 4b64b43..4d22a99 100644 --- a/app/index.js +++ b/app/index.js @@ -122,6 +122,7 @@ module.exports.getGameData = async function (name, mod) { for (const url of urls) { // Start looking for information const info = await scraper.getGameInfo(url); + if(!info) continue; results.push(info); } return results; diff --git a/app/scripts/scraper.js b/app/scripts/scraper.js index 5f62127..76da12b 100644 --- a/app/scripts/scraper.js +++ b/app/scripts/scraper.js @@ -14,7 +14,7 @@ const f95Selector = require("./constants/css-selector.js"); * Get information from the game's main page. * @param {String} url URL of the game/mod to extract data from * @return {Promise} Complete information about the game you are - * looking for + * looking for or `null` if is impossible to parse information */ module.exports.getGameInfo = async function (url) { shared.logger.info("Obtaining game info"); @@ -32,8 +32,12 @@ module.exports.getGameInfo = async function (url) { const src = extractPreviewSource(body); const changelog = extractChangelog(mainPost); const structuredData = extractStructuredData(body); - const parsedInfos = parseMainPostText(structuredData["description"]); - const overview = getOverview(structuredData["description"], prefixesData.mod); + + // Sometimes the JSON-LD are not set, especially in low-profile game + if(!structuredData) return null; + + const parsedInfos = parseMainPostText(structuredData.description); + const overview = getOverview(structuredData.description, prefixesData.mod); // Obtain the updated URL const redirectUrl = await getUrlRedirect(url); @@ -302,7 +306,7 @@ function extractStructuredData(body) { // Return only the data of the game if (json["@type"] === "Book") return json; }).get(); - return json[0] ? json[0] : null; + return json.lenght !== 0 ? json[0] : null; } /** diff --git a/package-lock.json b/package-lock.json index 53b0e3a..fefaa31 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "f95api", - "version": "1.5.0", + "version": "1.6.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 92f8833..09f2a5f 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "main": "./app/index.js", "name": "f95api", - "version": "1.6.0", + "version": "1.6.1", "author": { "name": "Millennium Earl" },