Skip to content

Commit

Permalink
* Added option to specify multiple urls
Browse files Browse the repository at this point in the history
- you can specify downloads for games and also dls for owned games etc
  • Loading branch information
4n4n4s committed Oct 3, 2023
1 parent a2a83eb commit b4bec61
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 34 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ Available options/variables and their default values:
| GOG_NEWSLETTER | 0 | Do not unsubscribe from newsletter after claiming a game if 1. |
| GOG_GIVEAWAY | 1 | Claims giveaway game(s). |
| GOG_FREEGAMES | 0 | Claims other free games that are not demos or prologue games. |
| GOG_FREEGAMES_URL | [freegames_url](https://www.gog.com/en/games?priceRange=0,0&languages=en&order=asc:title&hideDLCs=true&excludeTags=demo&excludeTags=freegame) | URL to get games to claim additionally. You can add filters for language or certain categories that you don't like. |
| GOG_FREEGAMES_URL | [freegames_url](https://www.gog.com/en/games?priceRange=0,0&languages=en&order=asc:title&hideDLCs=true&excludeTags=demo&excludeTags=freegame) | URLs to additional games to claim. Multiple URLs can be added with ";". You can add filters for language, certain categories, DLCs that you like to include or exclude. |


See `config.js` for all options.
Expand Down
68 changes: 35 additions & 33 deletions gog.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,42 +239,44 @@ async function claimGame(url){
}

async function claimFreegames(){
var freegames_url = cfg.gog_freegames_url;
if (freegames_url.includes("&hideOwned=true")) {
freegames_url = freegames_url.replace("&hideOwned=true", "");
}
if (!freegames_url.includes("priceRange=0,0")) {
console.log("Filter for only free games not detected adding it manually.");
freegames_url = freegames_url + "&priceRange=0,0";
}
console.log("claiming freegames from " + freegames_url);

await page.goto(freegames_url, { waitUntil: 'networkidle' });
await page.locator('label[selenium-id="hideOwnedCheckbox"]').click(); // when you add it to url immediately it shows more results
await page.waitForTimeout(2500);
var allLinks = [];
var hasMorePages = true;
do {
const links = await page.locator(".product-tile").all();
const gameUrls = await Promise.all(
links.map(async (game) => {
var urlSlug = await game.getAttribute("href");
return urlSlug;
})
);
for (const url of gameUrls) {
allLinks.push(url);
var freegames_urls = cfg.gog_freegames_url.split(";");
for (var freegames_url of freegames_urls) {
if (freegames_url.includes("&hideOwned=true")) {
freegames_url = freegames_url.replace("&hideOwned=true", "");
}
if (await page.locator('.small-pagination__item--next.disabled').isVisible()){
hasMorePages = false;
console.log("last page");
} else {
await page.locator(".small-pagination__item--next").first().click();
console.log("next page - waiting");
await page.waitForTimeout(5000); // wait until page is loaded it takes some time with filters
if (!freegames_url.includes("priceRange=0,0")) {
console.log("Filter for only free games not detected adding it manually.");
freegames_url = freegames_url + "&priceRange=0,0";
}

} while (hasMorePages);
console.log("collecting freegames from " + freegames_url);

await page.goto(freegames_url, { waitUntil: 'networkidle' });
await page.locator('label[selenium-id="hideOwnedCheckbox"]').click(); // when you add it to url immediately it shows more results
await page.waitForTimeout(2500);
var hasMorePages = true;
do {
const links = await page.locator(".product-tile").all();
const gameUrls = await Promise.all(
links.map(async (game) => {
var urlSlug = await game.getAttribute("href");
return urlSlug;
})
);
for (const url of gameUrls) {
allLinks.push(url);
}
if (await page.locator('.small-pagination__item--next.disabled').isVisible()){
hasMorePages = false;
console.log("last page");
} else {
await page.locator(".small-pagination__item--next").first().click();
console.log("next page - waiting");
await page.waitForTimeout(5000); // wait until page is loaded it takes some time with filters
}

} while (hasMorePages);
}
console.log("Found total games: " + allLinks.length);
allLinks = allLinks.filter(function (str) { return !str.endsWith("_prologue"); });
allLinks = allLinks.filter(function (str) { return !str.endsWith("_demo"); });
Expand Down

0 comments on commit b4bec61

Please sign in to comment.