mirror of
https://github.com/vega-org/vega-providers.git
synced 2026-04-17 23:51:44 +00:00
Reapply "feat: add extractors bundled in file refactor stream handling in multiple providers"
This reverts commit ef46918fec.
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import { Stream, ProviderContext } from "../types";
|
||||
import { hubcloudExtractor } from "../extractors/hubcloud";
|
||||
import { gdflixExtractor } from "../extractors/gdflix";
|
||||
|
||||
export const getStream = async function ({
|
||||
link: url,
|
||||
@@ -11,37 +13,61 @@ export const getStream = async function ({
|
||||
signal: AbortSignal;
|
||||
providerContext: ProviderContext;
|
||||
}): Promise<Stream[]> {
|
||||
const headers = providerContext.commonHeaders;
|
||||
const { axios, cheerio, commonHeaders: headers } = providerContext;
|
||||
try {
|
||||
if (type === "movie") {
|
||||
const res = await providerContext.axios.get(url, { headers });
|
||||
const res = await axios.get(url, { headers });
|
||||
const html = res.data;
|
||||
const $ = providerContext.cheerio.load(html);
|
||||
const $ = cheerio.load(html);
|
||||
const link = $('a:contains("HubCloud")').attr("href");
|
||||
url = link || url;
|
||||
}
|
||||
const res = await providerContext.axios.get(url, { headers });
|
||||
let redirectUrl = res.data.match(
|
||||
/<meta\s+http-equiv="refresh"\s+content="[^"]*?;\s*url=([^"]+)"\s*\/?>/i
|
||||
)?.[1];
|
||||
if (url.includes("/archives/")) {
|
||||
|
||||
let redirectUrl = "";
|
||||
try {
|
||||
const res = await axios.get(url, { headers });
|
||||
redirectUrl = res.data.match(
|
||||
/<a\s+[^>]*href="(https:\/\/hubcloud\.[^\/]+\/[^"]+)"/i
|
||||
/<meta\s+http-equiv="refresh"\s+content="[^"]*?;\s*url=([^"]+)"\s*\/?>/i,
|
||||
)?.[1];
|
||||
if (url.includes("/archives/")) {
|
||||
redirectUrl = res.data.match(
|
||||
/<a\s+[^>]*href="(https:\/\/hubcloud\.[^\/]+\/[^"]+)"/i,
|
||||
)?.[1];
|
||||
}
|
||||
} catch (err: any) {
|
||||
console.error("Hubcloud redirect err", err?.message || err);
|
||||
}
|
||||
if (!redirectUrl) {
|
||||
return await providerContext.extractors.hubcloudExtracter(url, signal);
|
||||
if (url.includes("hubcloud")) {
|
||||
console.log(" hubcloud link found in:", url);
|
||||
return await hubcloudExtractor(url, signal, axios, cheerio, headers);
|
||||
} else if (url.includes("gdflix")) {
|
||||
// handle gdflix links
|
||||
console.log("gdflix link found:", url);
|
||||
const gdflixStreams = await gdflixExtractor(
|
||||
url,
|
||||
signal,
|
||||
axios,
|
||||
cheerio,
|
||||
headers,
|
||||
);
|
||||
return gdflixStreams;
|
||||
}
|
||||
}
|
||||
const res2 = await providerContext.axios.get(redirectUrl, { headers });
|
||||
console.log("redirectUrl", redirectUrl);
|
||||
const res2 = await axios.get(redirectUrl, { headers });
|
||||
const data = res2.data;
|
||||
const $ = providerContext.cheerio.load(data);
|
||||
const $ = cheerio.load(data);
|
||||
const hubcloudLink = $(".fa-file-download").parent().attr("href");
|
||||
return await providerContext.extractors.hubcloudExtracter(
|
||||
return await hubcloudExtractor(
|
||||
hubcloudLink?.includes("https://hubcloud") ? hubcloudLink : redirectUrl,
|
||||
signal
|
||||
signal,
|
||||
axios,
|
||||
cheerio,
|
||||
headers,
|
||||
);
|
||||
} catch (err) {
|
||||
console.error("Movies Drive err", err);
|
||||
} catch (err: any) {
|
||||
console.error("Movies Drive err", err?.message || err);
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user