From d996807c4e904e8d593fef6d46d0e0e018e2db50 Mon Sep 17 00:00:00 2001 From: "samuele.berlusconi" Date: Wed, 14 Oct 2020 16:04:50 +0200 Subject: [PATCH] Addes last changelog parser --- app/scripts/classes/game-info.js | 6 ++++++ app/scripts/constants/css-selectors.js | 1 + app/scripts/game-scraper.js | 21 +++++++++++++++++++++ app/scripts/game-searcher.js | 5 +++++ test/user-test.js | 2 +- 5 files changed, 34 insertions(+), 1 deletion(-) diff --git a/app/scripts/classes/game-info.js b/app/scripts/classes/game-info.js index 09ea559..f13aedf 100644 --- a/app/scripts/classes/game-info.js +++ b/app/scripts/classes/game-info.js @@ -65,6 +65,11 @@ class GameInfo { * @type Boolean */ this.isMod = false; + /** + * Changelog for the last version. + * @type String + */ + this.changelog = null; /** * Directory containing the local copy of the game * @type String @@ -96,6 +101,7 @@ class GameInfo { lastUpdate: this.lastUpdate, lastPlayed: this.lastPlayed, isMod: this.isMod, + changelog: this.changelog, gameDir: this.gameDir, downloadInfo: this.downloadInfo, }; diff --git a/app/scripts/constants/css-selectors.js b/app/scripts/constants/css-selectors.js index f36ecff..8b268c3 100644 --- a/app/scripts/constants/css-selectors.js +++ b/app/scripts/constants/css-selectors.js @@ -28,4 +28,5 @@ module.exports = Object.freeze({ DOWNLOAD_LINKS_CONTAINER: 'span[style="font-size: 18px"]', SEARCH_THREADS_RESULTS_BODY: "div.contentRow-main", SEARCH_THREADS_MEMBERSHIP: "li > a:not(.username)", + THREAD_LAST_CHANGELOG: "div.bbCodeBlock-content > div:first-of-type", }); diff --git a/app/scripts/game-scraper.js b/app/scripts/game-scraper.js index 92a553b..57c7a8d 100644 --- a/app/scripts/game-scraper.js +++ b/app/scripts/game-scraper.js @@ -46,6 +46,7 @@ module.exports.getGameInfo = async function (browser, url) { let structuredText = await getMainPostStructuredText(page); let overview = getOverview(structuredText, info.isMod); let parsedInfos = parseConversationPage(structuredText); + let changelog = getLastChangelog(page); // Fill in the GameInfo element with the information obtained info.name = await title; @@ -280,6 +281,26 @@ async function parsePrefixes(page, info) { return info; } +/** + * @private + * Get the last changelog available for the game. + * @param {puppeteer.Page} page Page containing the changelog + * @returns {String} Changelog for the last version + */ +async function getLastChangelog(page) { + // Gets the first post, where are listed all the game's informations + let post = (await page.$$(selectors.THREAD_POSTS))[0]; + + let spoiler = await post.$(selectors.THREAD_LAST_CHANGELOG); + let changelogHTML = await page.evaluate( + /* istanbul ignore next */ + (e) => e.innerText, + spoiler + ); + let parsedText = HTMLParser.parse(changelogHTML).structuredText; + return parsedText; +} + /** * @private * Get game download links for different platforms. diff --git a/app/scripts/game-searcher.js b/app/scripts/game-searcher.js index bf1a5ef..d34f97c 100644 --- a/app/scripts/game-searcher.js +++ b/app/scripts/game-searcher.js @@ -8,6 +8,7 @@ const shared = require("./shared.js"); const constURLs = require("./constants/urls.js"); const selectors = require("./constants/css-selectors.js"); const { preparePage } = require("./puppeteer-helper.js"); +const { isF95URL } = require("./urls-helper.js"); /** * @protected @@ -116,6 +117,10 @@ async function getThreadURL(page, handle) { (e) => e.querySelector("a").href, handle ); + + // Some game already have a full URL + if (isF95URL(relativeURLThread)) return relativeURLThread; + let urlThread = new URL(relativeURLThread, constURLs.F95_BASE_URL).toString(); return urlThread; } diff --git a/test/user-test.js b/test/user-test.js index 8e56a77..fd6236f 100644 --- a/test/user-test.js +++ b/test/user-test.js @@ -18,7 +18,7 @@ async function main() { if (loginResult.success) { await loadF95BaseData(); - let gameData = await getGameData("brothel king", false); + let gameData = await getGameData("queen's brothel", false); console.log(gameData); // let userData = await getUserData();