-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
55 additions
and
2 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
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from "./gofile"; | ||
export * from "./qiwi"; | ||
export * from "./datanodes"; | ||
export * from "./mediafire"; |
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,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; | ||
} | ||
} |
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 |
---|---|---|
|
@@ -5,6 +5,7 @@ export enum Downloader { | |
PixelDrain, | ||
Qiwi, | ||
Datanodes, | ||
Mediafire, | ||
} | ||
|
||
export enum DownloadSourceStatus { | ||
|
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