Skip to content

Commit

Permalink
Merge pull request #1420 from Shisuiicaro/Feat/Mediafire-Download
Browse files Browse the repository at this point in the history
Feat: Mediafire Hoster
  • Loading branch information
thegrannychaseroperation authored Feb 1, 2025
2 parents 88184f7 + 77c8362 commit 260fc46
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/main/services/download/download-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from "@main/repository";
import { publishDownloadCompleteNotification } from "../notifications";
import type { DownloadProgress } from "@types";
import { GofileApi, QiwiApi, DatanodesApi } from "../hosters";
import { GofileApi, QiwiApi, DatanodesApi, MediafireApi } from "../hosters";
import { PythonRPC } from "../python-rpc";
import {
LibtorrentPayload,
Expand Down Expand Up @@ -287,6 +287,16 @@ export class DownloadManager {
save_path: game.downloadPath!,
};
}
case Downloader.Mediafire: {
const downloadUrl = await MediafireApi.getDownloadUrl(game.uri!);

return {
action: "start",
game_id: game.id,
url: downloadUrl,
save_path: game.downloadPath!,
};
}
case Downloader.Torrent:
return {
action: "start",
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,3 +1,4 @@
export * from "./gofile";
export * from "./qiwi";
export * from "./datanodes";
export * from "./mediafire";
39 changes: 39 additions & 0 deletions src/main/services/hosters/mediafire.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import axios, { AxiosResponse } from "axios";
import { JSDOM } from "jsdom";

export class MediafireApi {
private static readonly session = axios.create();

public static async getDownloadUrl(mediafireUrl: string): Promise<string> {
const response: AxiosResponse<string> = await this.session.get(
mediafireUrl,
{
headers: {
"User-Agent":
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36",
},
maxRedirects: 0,
validateStatus: (status: number) => status === 200 || status === 302,
}
);

if (response.status === 302) {
const location = response.headers["location"];
if (!location) {
throw new Error("Missing location header in 302 redirect response");
}
return location;
}

const dom = new JSDOM(response.data);
const downloadButton = dom.window.document.querySelector(
"a#downloadButton"
) as HTMLAnchorElement;

if (!downloadButton?.href) {
throw new Error("Download button URL not found in page content");
}

return downloadButton.href;
}
}
1 change: 1 addition & 0 deletions src/renderer/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const DOWNLOADER_NAME = {
[Downloader.PixelDrain]: "PixelDrain",
[Downloader.Qiwi]: "Qiwi",
[Downloader.Datanodes]: "Datanodes",
[Downloader.Mediafire]: "Mediafire",
};

export const MAX_MINUTES_TO_SHOW_IN_PLAYTIME = 120;
1 change: 1 addition & 0 deletions src/shared/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export enum Downloader {
PixelDrain,
Qiwi,
Datanodes,
Mediafire,
}

export enum DownloadSourceStatus {
Expand Down
1 change: 1 addition & 0 deletions src/shared/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export const getDownloadersForUri = (uri: string) => {
if (uri.startsWith("https://pixeldrain.com")) return [Downloader.PixelDrain];
if (uri.startsWith("https://qiwi.gg")) return [Downloader.Qiwi];
if (uri.startsWith("https://datanodes.to")) return [Downloader.Datanodes];
if (uri.startsWith("https://www.mediafire.com")) return [Downloader.Mediafire];

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

0 comments on commit 260fc46

Please sign in to comment.