diff --git a/src/main/services/download/download-manager.ts b/src/main/services/download/download-manager.ts index d3cab967..bdf926f3 100644 --- a/src/main/services/download/download-manager.ts +++ b/src/main/services/download/download-manager.ts @@ -2,7 +2,7 @@ import { Downloader, DownloadError } from "@shared"; import { WindowManager } from "../window-manager"; import { publishDownloadCompleteNotification } from "../notifications"; import type { Download, DownloadProgress, UserPreferences } from "@types"; -import { GofileApi, QiwiApi, DatanodesApi, MediafireApi } from "../hosters"; +import { GofileApi, QiwiApi, DatanodesApi, MediafireApi, PixelDrainApi } from "../hosters"; import { PythonRPC } from "../python-rpc"; import { LibtorrentPayload, @@ -283,11 +283,12 @@ export class DownloadManager { } case Downloader.PixelDrain: { const id = download.uri.split("/").pop(); + const downloadUrl = await PixelDrainApi.getDownloadUrl(id!); return { action: "start", game_id: downloadId, - url: `https://cdn.pd5-gamedriveorg.workers.dev/api/file/${id}`, + url: downloadUrl, save_path: download.downloadPath, }; } diff --git a/src/main/services/hosters/index.ts b/src/main/services/hosters/index.ts index 556897cd..3f3b9ac9 100644 --- a/src/main/services/hosters/index.ts +++ b/src/main/services/hosters/index.ts @@ -2,3 +2,4 @@ export * from "./gofile"; export * from "./qiwi"; export * from "./datanodes"; export * from "./mediafire"; +export * from "./pixeldrain"; diff --git a/src/main/services/hosters/pixeldrain.ts b/src/main/services/hosters/pixeldrain.ts new file mode 100644 index 00000000..7a40fcc7 --- /dev/null +++ b/src/main/services/hosters/pixeldrain.ts @@ -0,0 +1,42 @@ +import axios from "axios"; + +export class PixelDrainApi { + private static readonly browserHeaders = { + "User-Agent": + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36", + Accept: + "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8", + "Accept-Language": "en-US,en;q=0.9", + "Accept-Encoding": "gzip, deflate, br", + DNT: "1", + Connection: "keep-alive", + "Sec-Fetch-Dest": "document", + "Sec-Fetch-Mode": "navigate", + "Sec-Fetch-Site": "none", + "Sec-Fetch-User": "?1", + }; + + public static async getDownloadUrl(fileId: string): Promise { + try { + const response = await axios.get(`https://pd.cybar.xyz/${fileId}`, { + headers: this.browserHeaders, + maxRedirects: 0, + validateStatus: (status) => + status === 301 || status === 302 || status === 200, + }); + + if ( + response.headers.location || + response.status === 301 || + response.status === 302 + ) { + return response.headers.location; + } + + throw new Error(`No redirect URL found (status: ${response.status})`); + } catch (error) { + console.error("Error fetching PixelDrain URL:", error); + throw error; + } + } +}