Addes last changelog parser

pull/21/head
samuele.berlusconi 2020-10-14 16:04:50 +02:00
parent 9ba81d4f83
commit d996807c4e
5 changed files with 34 additions and 1 deletions

View File

@ -65,6 +65,11 @@ class GameInfo {
* @type Boolean * @type Boolean
*/ */
this.isMod = false; this.isMod = false;
/**
* Changelog for the last version.
* @type String
*/
this.changelog = null;
/** /**
* Directory containing the local copy of the game * Directory containing the local copy of the game
* @type String * @type String
@ -96,6 +101,7 @@ class GameInfo {
lastUpdate: this.lastUpdate, lastUpdate: this.lastUpdate,
lastPlayed: this.lastPlayed, lastPlayed: this.lastPlayed,
isMod: this.isMod, isMod: this.isMod,
changelog: this.changelog,
gameDir: this.gameDir, gameDir: this.gameDir,
downloadInfo: this.downloadInfo, downloadInfo: this.downloadInfo,
}; };

View File

@ -28,4 +28,5 @@ module.exports = Object.freeze({
DOWNLOAD_LINKS_CONTAINER: 'span[style="font-size: 18px"]', DOWNLOAD_LINKS_CONTAINER: 'span[style="font-size: 18px"]',
SEARCH_THREADS_RESULTS_BODY: "div.contentRow-main", SEARCH_THREADS_RESULTS_BODY: "div.contentRow-main",
SEARCH_THREADS_MEMBERSHIP: "li > a:not(.username)", SEARCH_THREADS_MEMBERSHIP: "li > a:not(.username)",
THREAD_LAST_CHANGELOG: "div.bbCodeBlock-content > div:first-of-type",
}); });

View File

@ -46,6 +46,7 @@ module.exports.getGameInfo = async function (browser, url) {
let structuredText = await getMainPostStructuredText(page); let structuredText = await getMainPostStructuredText(page);
let overview = getOverview(structuredText, info.isMod); let overview = getOverview(structuredText, info.isMod);
let parsedInfos = parseConversationPage(structuredText); let parsedInfos = parseConversationPage(structuredText);
let changelog = getLastChangelog(page);
// Fill in the GameInfo element with the information obtained // Fill in the GameInfo element with the information obtained
info.name = await title; info.name = await title;
@ -280,6 +281,26 @@ async function parsePrefixes(page, info) {
return 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 * @private
* Get game download links for different platforms. * Get game download links for different platforms.

View File

@ -8,6 +8,7 @@ const shared = require("./shared.js");
const constURLs = require("./constants/urls.js"); const constURLs = require("./constants/urls.js");
const selectors = require("./constants/css-selectors.js"); const selectors = require("./constants/css-selectors.js");
const { preparePage } = require("./puppeteer-helper.js"); const { preparePage } = require("./puppeteer-helper.js");
const { isF95URL } = require("./urls-helper.js");
/** /**
* @protected * @protected
@ -116,6 +117,10 @@ async function getThreadURL(page, handle) {
(e) => e.querySelector("a").href, (e) => e.querySelector("a").href,
handle handle
); );
// Some game already have a full URL
if (isF95URL(relativeURLThread)) return relativeURLThread;
let urlThread = new URL(relativeURLThread, constURLs.F95_BASE_URL).toString(); let urlThread = new URL(relativeURLThread, constURLs.F95_BASE_URL).toString();
return urlThread; return urlThread;
} }

View File

@ -18,7 +18,7 @@ async function main() {
if (loginResult.success) { if (loginResult.success) {
await loadF95BaseData(); await loadF95BaseData();
let gameData = await getGameData("brothel king", false); let gameData = await getGameData("queen's brothel", false);
console.log(gameData); console.log(gameData);
// let userData = await getUserData(); // let userData = await getUserData();