From 21e8c5d6452b4699b76ab69f9c495c465cb75b39 Mon Sep 17 00:00:00 2001 From: Matt Low Date: Sun, 28 Nov 2021 12:09:39 -0700 Subject: [PATCH] First commit. --- .gitignore | 2 ++ README.md | 33 +++++++++++++++++++++++++++++ index.js | 53 +++++++++++++++++++++++++++++++++++++++++++++++ package-lock.json | 43 ++++++++++++++++++++++++++++++++++++++ package.json | 20 ++++++++++++++++++ 5 files changed, 151 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100755 index.js create mode 100644 package-lock.json create mode 100644 package.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2ff6d6f --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +**/.env* +**/node_modules/* diff --git a/README.md b/README.md new file mode 100644 index 0000000..e847808 --- /dev/null +++ b/README.md @@ -0,0 +1,33 @@ +# steamcmd-app-update + +Outputs one `app_update [-validate]` line per game in your Steam library. + +A useful tool if you intend to automate the fetching of your entire +steam library :) + +# Usage + +Configuration +```sh +## .env + +# Steam API key. +export STEAM_API_KEY= + +# The profile ID to fetch the list of owned games of. +export STEAM_PROFILE_ID= + +# Comma separated list of games to skip +export SKIP_GAMES='Dota 2 Test, Metro Exodus, 1240440' + +# Whether to force game file validation by adding -validate +# Any value = true, unset/empty = false +export FORCE_VALIDATE= +``` + +Execution + +```sh +source .env && node ./index.js +# Or integrate this into your library updating docker container! +``` diff --git a/index.js b/index.js new file mode 100755 index 0000000..6c92999 --- /dev/null +++ b/index.js @@ -0,0 +1,53 @@ +#! /usr/bin/env node + +const STEAM_API_KEY = process.env.STEAM_API_KEY; + +if (!STEAM_API_KEY) { + console.error( + "The STEAM_API_KEY environment variale should contain your Steam API key." + ); + console.error("See: https://steamcommunity.com/dev/apikey"); + process.exit(1); +} + +const steam = new (require("steamapi"))(STEAM_API_KEY); + +const STEAM_PROFILE_ID = process.env.STEAM_PROFILE_ID; + +if (!STEAM_PROFILE_ID) { + console.error("The STEAM_PROFILE_ID environment variable is required."); + process.exit(1); +} + +const skipGames = []; + +if (process.env.SKIP_GAMES) { + process.env.SKIP_GAMES.split(",") + .map((game) => game.trim()) + .forEach((game) => { + skipGames.push(game); + }); +} + +function shouldSkip(gameId, gameTitle) { + return ( + // We could be comparing strings against numbers here, that's fine + skipGames.find((game) => game == gameId || game == gameTitle) !== undefined + ); +} + +const shouldValidate = !!process.env.FORCE_VALIDATE; + +steam.getUserOwnedGames(STEAM_PROFILE_ID).then((games) => + games + .filter((game) => !shouldSkip(game.appID, game.name)) + .sort((a, b) => a.appID - b.appID) + .forEach((game) => { + console.log( + `// ${game.name} - https://store.steampowered.com/app/${game.appID}` + ); + console.log( + `app_update ${game.appID}${shouldValidate ? " -validate" : ""}` + ); + }) +); diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..cd19152 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,43 @@ +{ + "name": "steamcmd-app-update", + "lockfileVersion": 2, + "requires": true, + "packages": { + "": { + "dependencies": { + "steamapi": "^2.1.2" + } + }, + "node_modules/steamapi": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/steamapi/-/steamapi-2.2.0.tgz", + "integrity": "sha512-2UWklLzYQruuUC0a5AUgll1dU91/CWgiAhm/7y+rqc43kbBWereGTtmwo8wr6imjC64iV5893KChXghW0zK8Gg==", + "dependencies": { + "steamid": "^2.0.0" + } + }, + "node_modules/steamid": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/steamid/-/steamid-2.0.0.tgz", + "integrity": "sha512-+BFJMbo+IxzyfovLR37E7APkaNfmrL3S+88T7wTMRHnQ6LBhzEawPnjfWNKM9eUL/dH45j+7vhSX4WaGXoa4/Q==", + "engines": { + "node": ">=12.0.0" + } + } + }, + "dependencies": { + "steamapi": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/steamapi/-/steamapi-2.2.0.tgz", + "integrity": "sha512-2UWklLzYQruuUC0a5AUgll1dU91/CWgiAhm/7y+rqc43kbBWereGTtmwo8wr6imjC64iV5893KChXghW0zK8Gg==", + "requires": { + "steamid": "^2.0.0" + } + }, + "steamid": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/steamid/-/steamid-2.0.0.tgz", + "integrity": "sha512-+BFJMbo+IxzyfovLR37E7APkaNfmrL3S+88T7wTMRHnQ6LBhzEawPnjfWNKM9eUL/dH45j+7vhSX4WaGXoa4/Q==" + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..334f12d --- /dev/null +++ b/package.json @@ -0,0 +1,20 @@ +{ + "dependencies": { + "steamapi": "^2.1.2" + }, + "name": "steamcmd-app-update", + "description": "Outputs one `app_update [-validate]` line per game in your Steam library.", + "version": "1.0.0", + "main": "index.js", + "devDependencies": {}, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [ + "steam", + "steamcmd", + "app_update" + ], + "author": "Matt Low ", + "license": "MIT" +}