mtkennerly / ludusavi-manifest

Backup info for PC game saves
MIT License
70 stars 13 forks source link

Include GOG ID in manifest #16

Closed sluedecke closed 1 year ago

sluedecke commented 1 year ago

This will help https://github.com/mtkennerly/ludusavi/issues/148 and can be a foundation to build a solid alias database, probably without even using data from gogdb (for most cases). The patch simply collects the "gogcom id" found in the "infobox game" template and adds it to the manifest.

This "gogcom id" maps to what is found in HEROICCONFIG/gog_store/libray.json in most cases and one can use this to map games in a "safe" way to titles from the ludusavi manifest.

But as life isn't, this isn't without exceptions, e.g. "Bioshock 2" comes as a bundle on GOG.com:

I am not shure how to make a "complete" update of all entries and I don't want to burden PCGW with too many requests during testing, but it works fine with npm run recent.

diff --git a/data/schema.strict.yaml b/data/schema.strict.yaml
index b259590..22f3f85 100644
--- a/data/schema.strict.yaml
+++ b/data/schema.strict.yaml
@@ -100,3 +100,8 @@ additionalProperties:
       properties:
         id:
           type: integer
+    gog:
+      type: object
+      properties:
+        id:
+          type: integer
diff --git a/data/schema.yaml b/data/schema.yaml
index 30a6ef7..7eb9585 100644
--- a/data/schema.yaml
+++ b/data/schema.yaml
@@ -81,3 +81,8 @@ additionalProperties:
       properties:
         id:
           type: integer
+    gog:
+      type: object
+      properties:
+        id:
+          type: integer
diff --git a/src/manifest.ts b/src/manifest.ts
index 87e78d9..ab0bf5c 100644
--- a/src/manifest.ts
+++ b/src/manifest.ts
@@ -40,6 +40,9 @@ export interface Game {
     steam?: {
         id?: number
     };
+    gog?: {
+        id?: number
+    };
 }

 export interface Constraint {
@@ -77,6 +80,9 @@ function integrateWikiData(game: Game, cache: WikiGameCache[""]): void {
     if (cache.steam !== undefined) {
         game.steam = { id: cache.steam };
     }
+    if (cache.gog !== undefined) {
+        game.gog = { id: cache.gog };
+    }
     const info = parseTemplates(cache.templates ?? []);
     game.files = info.files;
     game.registry = info.registry;
diff --git a/src/wiki.ts b/src/wiki.ts
index 5383b48..69809b3 100644
--- a/src/wiki.ts
+++ b/src/wiki.ts
@@ -37,6 +37,7 @@ export type WikiGameCache = {
         renamedFrom?: Array<string>,
         templates?: Array<string>,
         steam?: number,
+        gog?: number
     };
 };

@@ -587,6 +588,10 @@ export async function getGame(pageTitle: string, cache: WikiGameCache, client: W
             if (!isNaN(steamId) && steamId > 0) {
                 cache[pageTitle].steam = steamId;
             }
+            const gogId = Number(template.parameters["gogcom id"]);
+            if (!isNaN(gogId) && gogId > 0) {
+                cache[pageTitle].gog = gogId
+            }
         } else if (templateName === "game data/saves" || templateName === "game data/config") {
             const reparsed = parseWiki(template.toString());
             if (reparsed[0].positionalParameters[1]?.length > 0 ?? false) {
mtkennerly commented 1 year ago

Thanks, I think it makes sense to go ahead and do this. Feel free to open a PR :+1:

I am not shure how to make a "complete" update of all entries and I don't want to burden PCGW with too many requests during testing, but it works fine with npm run recent.

No worries. I can do a full run locally after the changes are in.

sluedecke commented 1 year ago

Thanks for considering it! I opened the pull request. Once the data has been updated, it will probably help with https://github.com/mtkennerly/ludusavi/issues/148 and the name finding algorithm.

Looking forward to have even more games covered by ludusavi! :)

mtkennerly commented 1 year ago

All GOG IDs from PCGW have been added now!