Skip to content

Commit

Permalink
feat: adding support to qiwi
Browse files Browse the repository at this point in the history
  • Loading branch information
thegrannychaseroperation committed Aug 18, 2024
1 parent 76d3fea commit 6c24a52
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 27 deletions.
1 change: 1 addition & 0 deletions src/main/events/torrenting/start-game-download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ const startGameDownload = async (
await downloadQueueRepository.delete({ game: { id: updatedGame!.id } });
await downloadQueueRepository.insert({ game: { id: updatedGame!.id } });

await DownloadManager.cancelDownload(updatedGame!.id);
await DownloadManager.startDownload(updatedGame!);
};

Expand Down
6 changes: 5 additions & 1 deletion src/main/helpers/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import axios from "axios";
import { JSDOM } from "jsdom";
import UserAgent from "user-agents";

export const getSteamAppAsset = (
Expand Down Expand Up @@ -48,13 +49,16 @@ export const sleep = (ms: number) =>
export const requestWebPage = async (url: string) => {
const userAgent = new UserAgent();

return axios
const data = await axios
.get(url, {
headers: {
"User-Agent": userAgent.toString(),
},
})
.then((response) => response.data);

const { window } = new JSDOM(data);
return window.document;
};

export const isPortableVersion = () =>
Expand Down
50 changes: 31 additions & 19 deletions src/main/services/download/download-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { downloadQueueRepository, gameRepository } from "@main/repository";
import { publishDownloadCompleteNotification } from "../notifications";
import { RealDebridDownloader } from "./real-debrid-downloader";
import type { DownloadProgress } from "@types";
import { GofileApi } from "../hosters";
import { GofileApi, QiwiApi } from "../hosters";

Check failure on line 9 in src/main/services/download/download-manager.ts

View workflow job for this annotation

GitHub Actions / lint

Module '"../hosters"' has no exported member 'QiwiApi'.
import { GenericHttpDownloader } from "./generic-http-downloader";

export class DownloadManager {
Expand Down Expand Up @@ -96,26 +96,38 @@ export class DownloadManager {
}

static async startDownload(game: Game) {
if (game.downloader === Downloader.Gofile) {
const id = game!.uri!.split("/").pop();
switch (game.downloader) {
case Downloader.Gofile: {
const id = game!.uri!.split("/").pop();

const token = await GofileApi.authorize();
const downloadLink = await GofileApi.getDownloadLink(id!);
const token = await GofileApi.authorize();
const downloadLink = await GofileApi.getDownloadLink(id!);

GenericHttpDownloader.startDownload(game, downloadLink, {
Cookie: `accountToken=${token}`,
});
} else if (game.downloader === Downloader.PixelDrain) {
const id = game!.uri!.split("/").pop();

await GenericHttpDownloader.startDownload(
game,
`https://pixeldrain.com/api/file/${id}?download`
);
} else if (game.downloader === Downloader.Torrent) {
PythonInstance.startDownload(game);
} else if (game.downloader === Downloader.RealDebrid) {
RealDebridDownloader.startDownload(game);
GenericHttpDownloader.startDownload(game, downloadLink, {
Cookie: `accountToken=${token}`,
});
break;
}
case Downloader.PixelDrain: {
const id = game!.uri!.split("/").pop();

await GenericHttpDownloader.startDownload(
game,
`https://pixeldrain.com/api/file/${id}?download`
);
break;
}
case Downloader.Qiwi: {
const downloadUrl = await QiwiApi.getDownloadUrl(game.uri!);

await GenericHttpDownloader.startDownload(game, downloadUrl);
break;
}
case Downloader.Torrent:
PythonInstance.startDownload(game);
break;
case Downloader.RealDebrid:
RealDebridDownloader.startDownload(game);
}

this.currentDownloader = game.downloader;
Expand Down
1 change: 1 addition & 0 deletions src/main/services/hosters/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from "./gofile";
export * from "./qiwi";

Check failure on line 2 in src/main/services/hosters/index.ts

View workflow job for this annotation

GitHub Actions / lint

Cannot find module './qiwi' or its corresponding type declarations.
6 changes: 1 addition & 5 deletions src/main/services/how-long-to-beat.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import axios from "axios";
import { JSDOM } from "jsdom";
import { requestWebPage } from "@main/helpers";
import { HowLongToBeatCategory } from "@types";
import { formatName } from "@shared";
Expand Down Expand Up @@ -52,10 +51,7 @@ const parseListItems = ($lis: Element[]) => {
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 document = await requestWebPage(`https://howlongtobeat.com/game/${id}`);

const $ul = document.querySelector(".shadow_shadow ul");
if (!$ul) return [];
Expand Down
1 change: 1 addition & 0 deletions src/renderer/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ export const DOWNLOADER_NAME = {
[Downloader.Torrent]: "Torrent",
[Downloader.Gofile]: "Gofile",
[Downloader.PixelDrain]: "PixelDrain",
[Downloader.Qiwi]: "Qiwi",
};
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@ export const hintText = style({
});

export const downloaders = style({
display: "flex",
display: "grid",
gap: `${SPACING_UNIT}px`,
gridTemplateColumns: "repeat(2, 1fr)",
});

export const downloaderOption = style({
flex: "1",
position: "relative",
":only-child": {
gridColumn: "1 / -1",
},
});

export const downloaderIcon = style({
Expand Down
2 changes: 2 additions & 0 deletions src/shared/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export enum Downloader {
Torrent,
Gofile,
PixelDrain,
Qiwi,
}

export enum DownloadSourceStatus {
Expand Down Expand Up @@ -75,6 +76,7 @@ export const getDownloadersForUri = (uri: string) => {
if (uri.startsWith("https://gofile.io")) return [Downloader.Gofile];

if (uri.startsWith("https://pixeldrain.com")) return [Downloader.PixelDrain];
if (uri.startsWith("https://qiwi.gg")) return [Downloader.Qiwi];

if (realDebridHosts.some((host) => uri.startsWith(host)))
return [Downloader.RealDebrid];
Expand Down

0 comments on commit 6c24a52

Please sign in to comment.