diff --git a/app/example.js b/app/example.js index 48eac22..38ef905 100644 --- a/app/example.js +++ b/app/example.js @@ -51,6 +51,6 @@ async function main() { // Extract first game const gamedata = found[0]; - console.log(`Found ${gamedata.name} (${gamedata.version}) by ${gamedata.author}`); + console.log(`Found ${gamedata.name} (${gamedata.version}, ID ${gamedata.id}) by ${gamedata.author}`); } } diff --git a/app/scripts/classes/game-info.js b/app/scripts/classes/game-info.js index 5a6cf4a..f133b90 100644 --- a/app/scripts/classes/game-info.js +++ b/app/scripts/classes/game-info.js @@ -3,6 +3,11 @@ class GameInfo { constructor() { //#region Properties + /** + * Unique ID of the game on the platform. + * @type Number + */ + this.id = -1; /** * Game name * @type String diff --git a/app/scripts/scraper.js b/app/scripts/scraper.js index bf3dd0f..4db77d7 100644 --- a/app/scripts/scraper.js +++ b/app/scripts/scraper.js @@ -40,6 +40,7 @@ module.exports.getGameInfo = async function (url) { // Fill in the GameInfo element with the information obtained const info = new GameInfo(); + info.id = extractIDFromURL(url); info.name = titleData.name; info.author = titleData.author; info.isMod = prefixesData.mod; @@ -353,6 +354,23 @@ function isMod(prefix) { return modPrefixes.includes(prefix.toUpperCase()); } +/** + * @private + * Extracts the game's unique ID from the game's URL. + * @param {String} url Game's URL + * @return {Number} Game's ID + */ +function extractIDFromURL(url) { + // URL are in the format https://f95zone.to/threads/GAMENAME-VERSION-DEVELOPER.ID/ + const splitted = url.split("."); + + // We took the last part (clean it) + const value = splitted.pop().replace("/", "").trim(); + + // Parse and return number + return parseInt(value, 10); +} + /** * @private * Makes an array of strings uppercase.