mirror of
https://github.com/alexankitty/Myrient-Search-Engine.git
synced 2026-01-15 08:23:18 -03:00
incremental commit
This commit is contained in:
@@ -215,7 +215,7 @@
|
||||
"Game Boy Advance",
|
||||
"Game Boy Color",
|
||||
"Game Boy",
|
||||
"Gamecube",
|
||||
"GameCube",
|
||||
"Kiosk Video Compact Flash",
|
||||
"Misc",
|
||||
"New Nintendo 3DS",
|
||||
|
||||
@@ -1,3 +1,113 @@
|
||||
import igdb from 'igdb-api-node';
|
||||
import { twitchAccessToken, igdb, request } from "@phalcode/ts-igdb-client";
|
||||
import {
|
||||
fields,
|
||||
or,
|
||||
and,
|
||||
where,
|
||||
whereIn,
|
||||
WhereFlags,
|
||||
WhereInFlags,
|
||||
sort,
|
||||
limit,
|
||||
offset,
|
||||
} from "@phalcode/ts-igdb-client";
|
||||
|
||||
function getMetadata()
|
||||
const twitchSecrets = {
|
||||
client_id: process.env.TWITCH_CLIENT_ID,
|
||||
client_secret: process.env.TWITCH_CLIENT_SECRET,
|
||||
};
|
||||
const accessToken = await twitchAccessToken(twitchSecrets);
|
||||
|
||||
const client = igdb(twitchSecrets.client_id, accessToken);
|
||||
|
||||
const gameFields = [
|
||||
"name",
|
||||
"alternative_names.comment",
|
||||
"alternative_names.name",
|
||||
"cover.image_id",
|
||||
"total_rating",
|
||||
"first_release_date",
|
||||
"summary",
|
||||
"genres.name",
|
||||
"involved_companies.company.name",
|
||||
"involved_companies.developer",
|
||||
"involved_companies.publisher",
|
||||
"involved_companies.supporting",
|
||||
"multiplayer_modes.*",
|
||||
"game_localizations.name",
|
||||
"game_localizations.region",
|
||||
"platforms.name",
|
||||
];
|
||||
|
||||
export async function getMetadata(query) {
|
||||
const data = await client
|
||||
.request("games")
|
||||
.pipe(
|
||||
fields(gameFields),
|
||||
or(...buildOrAndClauses("name", "~", query)),
|
||||
sort("name", "asc")
|
||||
)
|
||||
.execute();
|
||||
return data;
|
||||
}
|
||||
|
||||
function buildOrClauses(field, op, queries) {
|
||||
let orClauses = [];
|
||||
for (let x in queries) {
|
||||
orClauses.push(where(field, op, queries[x], WhereFlags.CONTAINS));
|
||||
}
|
||||
return orClauses;
|
||||
}
|
||||
|
||||
function buildOrAndClauses(field, op, queries) {
|
||||
let orClauses = [];
|
||||
|
||||
for (let x in queries) {
|
||||
let name = queries[x].split(" ");
|
||||
let andClauses = [];
|
||||
for (let y in name) {
|
||||
andClauses.push(where(field, op, name[y], WhereFlags.CONTAINS));
|
||||
}
|
||||
orClauses.push(and(...andClauses));
|
||||
}
|
||||
return orClauses;
|
||||
}
|
||||
|
||||
function normalizeName(filename) {
|
||||
if (!filename) return;
|
||||
return filename
|
||||
.replace(/\.[A-z]{3,3}|\.|&|-|,|v[0-9]+\.[0-9]+|\[.*?\]|\(.*?\)/g, "")
|
||||
.trim();
|
||||
}
|
||||
|
||||
function getBestMatch(filename, data) {
|
||||
const words = filename.split(" ");
|
||||
let bestIndex = null;
|
||||
let bestMatchCount = 0;
|
||||
let lengthDifference = 0;
|
||||
for (let x in data) {
|
||||
let dataWords = data[x].name.split(" ");
|
||||
let matchingWords = 0;
|
||||
for (let y in words) {
|
||||
if (y >= dataWords.length) break;
|
||||
if (words[y] == dataWords[y]) matchingWords++;
|
||||
}
|
||||
let diff = matchingWords - dataWords.length;
|
||||
if (matchingWords > bestMatchCount && diff < lengthDifference) {
|
||||
bestIndex = x;
|
||||
bestMatchCount = matchingWords;
|
||||
lengthDifference = diff
|
||||
}
|
||||
}
|
||||
if(bestIndex != null){
|
||||
return data[bestIndex]
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
let games = await getMetadata([
|
||||
"The Legend of Zelda A Link to the Past",
|
||||
"Super Mario Sunshine",
|
||||
]);
|
||||
console.log(JSON.stringify(games.data, null, 2));
|
||||
//console.log(await getMetadata(games))
|
||||
|
||||
77
package-lock.json
generated
77
package-lock.json
generated
@@ -6,6 +6,7 @@
|
||||
"": {
|
||||
"dependencies": {
|
||||
"@elastic/elasticsearch": "^8.12.2",
|
||||
"@phalcode/ts-igdb-client": "^1.0.22",
|
||||
"compression": "^1.7.4",
|
||||
"cookie-parser": "^1.4.7",
|
||||
"dotenv": "^16.4.5",
|
||||
@@ -13,7 +14,6 @@
|
||||
"express": "^4.21.1",
|
||||
"figlet": "^1.7.0",
|
||||
"i18n": "^0.15.1",
|
||||
"igdb-api-node": "^6.0.5",
|
||||
"innertext": "^1.0.3",
|
||||
"jsdom": "^25.0.1",
|
||||
"jszip": "^3.10.1",
|
||||
@@ -449,6 +449,25 @@
|
||||
"node": ">=8.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@phalcode/ts-apicalypse": {
|
||||
"version": "1.0.22",
|
||||
"resolved": "https://registry.npmjs.org/@phalcode/ts-apicalypse/-/ts-apicalypse-1.0.22.tgz",
|
||||
"integrity": "sha512-1l+2shlUXMsHuvcyLz/kG0VvjErarVCzx1bqJUmu0AHdCeXbDWKd/5bwIzC2Bdjkjk/qg5o3p8Ffb10arQ1oKQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"axios": "^1.4.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@phalcode/ts-igdb-client": {
|
||||
"version": "1.0.22",
|
||||
"resolved": "https://registry.npmjs.org/@phalcode/ts-igdb-client/-/ts-igdb-client-1.0.22.tgz",
|
||||
"integrity": "sha512-UQuWjNXCCtbELOnqAzgoDAw8IAvV/4JqsF3NB1obL8IhDaDOClTK4WxhPmxGwmAyo4YnJyIQnCwmWjUnb2gFSw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@phalcode/ts-apicalypse": "^1.0.22",
|
||||
"axios": "^1.8.2"
|
||||
}
|
||||
},
|
||||
"node_modules/@pkgjs/parseargs": {
|
||||
"version": "0.11.0",
|
||||
"resolved": "https://registry.npmjs.org/@pkgjs/parseargs/-/parseargs-0.11.0.tgz",
|
||||
@@ -614,17 +633,6 @@
|
||||
"arrow2csv": "bin/arrow2csv.js"
|
||||
}
|
||||
},
|
||||
"node_modules/apicalypse": {
|
||||
"version": "1.0.5",
|
||||
"resolved": "https://registry.npmjs.org/apicalypse/-/apicalypse-1.0.5.tgz",
|
||||
"integrity": "sha512-RT6PRNlYrQTrDBdifhlUtww1codmjUH5ZFBxyWS0itkkInzO0z/Xxa8RBV7/TcEOiwIzfkFSt9Hd0Nu3ScVsFQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"axios": "^1.7.3",
|
||||
"better-queue": "^3.8.10",
|
||||
"better-queue-memory": "^1.0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/array-back": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/array-back/-/array-back-3.1.0.tgz",
|
||||
@@ -678,36 +686,6 @@
|
||||
"integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/better-queue": {
|
||||
"version": "3.8.12",
|
||||
"resolved": "https://registry.npmjs.org/better-queue/-/better-queue-3.8.12.tgz",
|
||||
"integrity": "sha512-D9KZ+Us+2AyaCz693/9AyjTg0s8hEmkiM/MB3i09cs4MdK1KgTSGJluXRYmOulR69oLZVo2XDFtqsExDt8oiLA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"better-queue-memory": "^1.0.1",
|
||||
"node-eta": "^0.9.0",
|
||||
"uuid": "^9.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/better-queue-memory": {
|
||||
"version": "1.0.4",
|
||||
"resolved": "https://registry.npmjs.org/better-queue-memory/-/better-queue-memory-1.0.4.tgz",
|
||||
"integrity": "sha512-SWg5wFIShYffEmJpI6LgbL8/3Dqhku7xI1oEiy6FroP9DbcZlG0ZDjxvPdP9t7hTGW40IpIcC6zVoGT1oxjOuA==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/better-queue/node_modules/uuid": {
|
||||
"version": "9.0.1",
|
||||
"resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz",
|
||||
"integrity": "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==",
|
||||
"funding": [
|
||||
"https://github.com/sponsors/broofa",
|
||||
"https://github.com/sponsors/ctavan"
|
||||
],
|
||||
"license": "MIT",
|
||||
"bin": {
|
||||
"uuid": "dist/bin/uuid"
|
||||
}
|
||||
},
|
||||
"node_modules/bluebird": {
|
||||
"version": "3.7.2",
|
||||
"resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.7.2.tgz",
|
||||
@@ -2145,15 +2123,6 @@
|
||||
"node": ">=0.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/igdb-api-node": {
|
||||
"version": "6.0.5",
|
||||
"resolved": "https://registry.npmjs.org/igdb-api-node/-/igdb-api-node-6.0.5.tgz",
|
||||
"integrity": "sha512-rH45b1vJNOusoTt8KkYlqrz4bqBXfH06uezOL+uIPuExyRnbRGNYUSUsGlcIx8YFs0E5U2FmDrlsRqbe9zHhVA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"apicalypse": "^1.0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/immediate": {
|
||||
"version": "3.0.6",
|
||||
"resolved": "https://registry.npmjs.org/immediate/-/immediate-3.0.6.tgz",
|
||||
@@ -2630,12 +2599,6 @@
|
||||
"node": ">=10.5.0"
|
||||
}
|
||||
},
|
||||
"node_modules/node-eta": {
|
||||
"version": "0.9.0",
|
||||
"resolved": "https://registry.npmjs.org/node-eta/-/node-eta-0.9.0.tgz",
|
||||
"integrity": "sha512-mTCTZk29tmX1OGfVkPt63H3c3VqXrI2Kvua98S7iUIB/Gbp0MNw05YtUomxQIxnnKMyRIIuY9izPcFixzhSBrA==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/node-fetch": {
|
||||
"version": "3.3.2",
|
||||
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.3.2.tgz",
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"@elastic/elasticsearch": "^8.12.2",
|
||||
"@phalcode/ts-igdb-client": "^1.0.22",
|
||||
"compression": "^1.7.4",
|
||||
"cookie-parser": "^1.4.7",
|
||||
"dotenv": "^16.4.5",
|
||||
@@ -8,7 +9,6 @@
|
||||
"express": "^4.21.1",
|
||||
"figlet": "^1.7.0",
|
||||
"i18n": "^0.15.1",
|
||||
"igdb-api-node": "^6.0.5",
|
||||
"innertext": "^1.0.3",
|
||||
"jsdom": "^25.0.1",
|
||||
"jszip": "^3.10.1",
|
||||
|
||||
Reference in New Issue
Block a user