Add Mega-Debrid account info check (web scraping)

Scrapes the Mega-Debrid profile page to display username, premium status,
remaining days, and loyalty points. New "Account prüfen" button in Settings > Accounts.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Sucukdeluxe
2026-03-03 14:06:19 +01:00
co-authored by Claude Opus 4.6
parent ac479bb023
commit e6ec1ed755
10 changed files with 113 additions and 2 deletions
+47
View File
@@ -1,3 +1,4 @@
import { ProviderAccountInfo } from "../shared/types";
import { UnrestrictedLink } from "./realdebrid";
import { compactErrorText, filenameFromUrl, sleep } from "./utils";
@@ -15,6 +16,7 @@ const LOGIN_URL = "https://www.mega-debrid.eu/index.php?form=login";
const DEBRID_URL = "https://www.mega-debrid.eu/index.php?form=debrid";
const DEBRID_AJAX_URL = "https://www.mega-debrid.eu/index.php?ajax=debrid&json";
const DEBRID_REFERER = "https://www.mega-debrid.eu/index.php?page=debrideur&lang=de";
const PROFILE_URL = "https://www.mega-debrid.eu/index.php?page=profil";
function normalizeLink(link: string): string {
return link.trim().toLowerCase();
@@ -264,6 +266,51 @@ export class MegaWebFallback {
}, signal);
}
public async getAccountInfo(): Promise<ProviderAccountInfo> {
return this.runExclusive(async () => {
const creds = this.getCredentials();
if (!creds.login.trim() || !creds.password.trim()) {
return { provider: "megadebrid", username: "", accountType: "", daysRemaining: null, loyaltyPoints: null, error: "Login/Passwort nicht konfiguriert" };
}
try {
if (!this.cookie || Date.now() - this.cookieSetAt > 20 * 60 * 1000) {
await this.login(creds.login, creds.password);
}
const res = await fetch(PROFILE_URL, {
method: "GET",
headers: {
"User-Agent": "Mozilla/5.0",
Cookie: this.cookie,
Referer: DEBRID_REFERER
},
signal: AbortSignal.timeout(30000)
});
const html = await res.text();
const usernameMatch = html.match(/<a[^>]*id=["']user_link["'][^>]*><span>([^<]+)<\/span>/i);
const username = usernameMatch?.[1]?.trim() || "";
const typeMatch = html.match(/(Premiumuser|Freeuser)\s*-\s*(\d+)\s*Tag/i);
const accountType = typeMatch?.[1] || "Unbekannt";
const daysRemaining = typeMatch?.[2] ? parseInt(typeMatch[2], 10) : null;
const pointsMatch = html.match(/(\d+)\s*Treuepunkte/i);
const loyaltyPoints = pointsMatch?.[1] ? parseInt(pointsMatch[1], 10) : null;
if (!username && !typeMatch) {
this.cookie = "";
return { provider: "megadebrid", username: "", accountType: "", daysRemaining: null, loyaltyPoints: null, error: "Profil konnte nicht gelesen werden (Session ungültig?)" };
}
return { provider: "megadebrid", username, accountType, daysRemaining, loyaltyPoints };
} catch (err) {
return { provider: "megadebrid", username: "", accountType: "", daysRemaining: null, loyaltyPoints: null, error: compactErrorText(err) };
}
});
}
public invalidateSession(): void {
this.cookie = "";
this.cookieSetAt = 0;