-
-
Save lopespm/6a2dc5cf291edc2c47e5da68a55c3227 to your computer and use it in GitHub Desktop.
Steam CD Key Batch query
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const assert = require('assert'); | |
const async = require('async'); | |
const fs = require('fs'); | |
let request = require('request'); | |
const FileCookieStore = require('tough-cookie-filestore'); | |
if (!fs.existsSync('cookies.json')) { fs.writeFileSync('cookies.json', '{}');} | |
let j = request.jar(new FileCookieStore('cookies.json')); | |
request = request.defaults({ jar : j }); | |
// Fill cookie string here by grabbing it from a request in Chrome | |
// Should look like 'sessionid=c7...; steamLogin=2...; ...' | |
let cookies_from_browser = 'fill=me; in=please'; // Make sure not to check this in | |
let cookie_url = 'https://partner.steamgames.com'; | |
cookies_from_browser.split('; ').forEach(function (cookie) { | |
j.setCookie(cookie, cookie_url); | |
}); | |
function queryKeys(next) { | |
let keys = fs.readFileSync('keys.csv', 'utf8').split('\n').map(function (s) { | |
return s.trim(); | |
}); | |
let out = []; | |
async.eachSeries(keys, function (key, next) { | |
if (!key) { | |
console.log(''); | |
out.push(''); | |
return next(); | |
} | |
let url = `https://partner.steamgames.com/querycdkey/cdkey?cdkey=${key}&method=Query`; | |
request(url, function (err, resp, body) { | |
if (!body) { | |
console.log(resp, err); | |
} | |
let result = body.split('<h2>Activation Details</h2>')[1]; | |
if (!result && !err) { | |
fs.writeFileSync('out.html', body); | |
console.log('Error quering CD Key, check out.html to see the response returned from Steamworks,'); | |
console.log(' if it is a login page, your cookies_from_browser string is probably invalid'); | |
process.exit(-1); | |
} | |
assert(result); | |
result = result.split('</table>')[0]; | |
result = result.match(/<td>.*<\/td>/g); | |
result = result.map(function (line) { | |
return line.replace(/<[^>]*>/g, ''); | |
}); | |
let line = [key, (result[0] === 'Activated') ? '"' + result[1] + '"' : result[0]].join('\t'); | |
console.log(line); | |
out.push(line); | |
next(); | |
}); | |
}, function (err) { | |
fs.writeFileSync('out.tsv', out.join('\n')); | |
next(err); | |
}); | |
} | |
queryKeys(function (err) { | |
if (err) { | |
throw err; | |
} else { | |
console.log('Done.'); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"dependencies": { | |
"async": "^2.4.1", | |
"request": "^2.81.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment