-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from hydralauncher/feature/adding-how-long-to-…
…beat-integration feat: adding how long to beat integration
- Loading branch information
Showing
24 changed files
with
407 additions
and
72 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
semi: true, | ||
trailingComma: "all", | ||
singleQuote: false, | ||
}; |
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import type { GameShop, HowLongToBeatCategory } from "@types"; | ||
import { getHowLongToBeatGame, searchHowLongToBeat } from "@main/services"; | ||
|
||
import { registerEvent } from "../register-event"; | ||
|
||
const getHowLongToBeat = async ( | ||
_event: Electron.IpcMainInvokeEvent, | ||
objectID: string, | ||
_shop: GameShop, | ||
title: string | ||
): Promise<HowLongToBeatCategory[] | null> => { | ||
const response = await searchHowLongToBeat(title); | ||
const game = response.data.find( | ||
(game) => game.profile_steam === Number(objectID) | ||
); | ||
|
||
if (!game) return null; | ||
const howLongToBeat = await getHowLongToBeatGame(String(game.game_id)); | ||
return howLongToBeat; | ||
}; | ||
|
||
registerEvent(getHowLongToBeat, { | ||
name: "getHowLongToBeat", | ||
memoize: true, | ||
}); |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { formatName } from "@main/helpers"; | ||
import axios from "axios"; | ||
import { JSDOM } from "jsdom"; | ||
import { requestWebPage } from "./repack-tracker/helpers"; | ||
import { HowLongToBeatCategory } from "@types"; | ||
|
||
export interface HowLongToBeatResult { | ||
game_id: number; | ||
profile_steam: number; | ||
} | ||
|
||
export interface HowLongToBeatSearchResponse { | ||
data: HowLongToBeatResult[]; | ||
} | ||
|
||
export const searchHowLongToBeat = async (gameName: string) => { | ||
const response = await axios.post( | ||
"https://howlongtobeat.com/api/search", | ||
{ | ||
searchType: "games", | ||
searchTerms: formatName(gameName).split(" "), | ||
searchPage: 1, | ||
size: 100, | ||
}, | ||
{ | ||
headers: { | ||
"User-Agent": | ||
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36", | ||
Referer: "https://howlongtobeat.com/", | ||
}, | ||
}, | ||
); | ||
|
||
return response.data as HowLongToBeatSearchResponse; | ||
}; | ||
|
||
export const getHowLongToBeatGame = async ( | ||
id: string, | ||
): Promise<HowLongToBeatCategory[]> => { | ||
const response = await requestWebPage(`https://howlongtobeat.com/game/${id}`); | ||
|
||
const { window } = new JSDOM(response); | ||
const { document } = window; | ||
|
||
const $ul = document.querySelector(".shadow_shadow ul"); | ||
const $lis = Array.from($ul.children); | ||
|
||
return $lis.map(($li) => { | ||
const title = $li.querySelector("h4").textContent; | ||
const [, accuracyClassName] = Array.from(($li as HTMLElement).classList); | ||
|
||
const accuracy = accuracyClassName.split("time_").at(1); | ||
|
||
return { | ||
title, | ||
duration: $li.querySelector("h5").textContent, | ||
accuracy, | ||
}; | ||
}); | ||
}; |
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
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
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
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
Oops, something went wrong.