Skip to content

Commit cf64205

Browse files
committed
eg: fix EG_MOBILE: use page instead of fetch (got html instead of json)
1 parent d7146c3 commit cf64205

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

epic-games.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import path from 'path';
66
import { existsSync, writeFileSync } from 'fs';
77
import { resolve, jsonDb, datetime, filenamify, prompt, confirm, notify, html_game_list, handleSIGINT } from './src/util.js';
88
import { cfg } from './src/config.js';
9-
import { getGames } from './src/epic-games-mobile.js';
9+
import { getMobileGames } from './src/epic-games-mobile.js';
1010

1111
const screenshot = (...a) => resolve(cfg.dir.screenshots, 'epic-games', ...a);
1212

@@ -153,7 +153,7 @@ try {
153153
// https://egs-platform-service.store.epicgames.com/api/v2/public/discover/home?count=10&country=DE&locale=en&platform=android&start=0&store=EGS
154154
if (cfg.eg_mobile) {
155155
console.log('Including mobile games...');
156-
const mobileGames = await getGames();
156+
const mobileGames = await getMobileGames(context);
157157
urls.push(...mobileGames.map(x => x.url));
158158
}
159159

src/epic-games-mobile.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
// following https://github.com/vogler/free-games-claimer/issues/474
22

3-
const get = async (platform = 'android') => { // or ios
4-
const r = await fetch(`https://egs-platform-service.store.epicgames.com/api/v2/public/discover/home?count=10&country=DE&locale=en&platform=${platform}&start=0&store=EGS`);
5-
return await r.json();
3+
const get = async (page, platform = 'android') => { // or ios
4+
await page.goto(`https://egs-platform-service.store.epicgames.com/api/v2/public/discover/home?count=10&country=DE&locale=en&platform=${platform}&start=0&store=EGS`);
5+
const response = await page.innerText('body');
6+
return JSON.parse(response);
67
};
78

89
// $ jq '.data[].topicId' -r
@@ -35,8 +36,8 @@ const get = async (platform = 'android') => { // or ios
3536

3637
const url = s => `https://store.epicgames.com/en-US/p/${s}`;
3738

38-
export const getPlatformGames = async platform => {
39-
const json = await get(platform);
39+
export const getPlatformGames = async (page, platform) => {
40+
const json = await get(page, platform);
4041
const free_game = json.data.filter(x => x.type == 'freeGame')[0];
4142
// console.log(free_game);
4243
return free_game.offers.map(offer => {
@@ -46,6 +47,11 @@ export const getPlatformGames = async platform => {
4647
});
4748
};
4849

49-
export const getGames = async () => [...await getPlatformGames('android'), ...await getPlatformGames('ios')];
50+
export const getMobileGames = async (context) => {
51+
const page = await context.newPage();
52+
const r = [...await getPlatformGames(page, 'android'), ...await getPlatformGames(page, 'ios')];
53+
await page.close();
54+
return r;
55+
};
5056

5157
// console.log(await getGames());

0 commit comments

Comments
 (0)