mirror of
https://github.com/vega-org/vega-providers.git
synced 2026-04-17 23:51:44 +00:00
fix: Refactor hubcloudExtracter for improved link handling and readability
This commit is contained in:
2
dist/hubcloudExtractor.js
vendored
2
dist/hubcloudExtractor.js
vendored
File diff suppressed because one or more lines are too long
@@ -1,85 +1,147 @@
|
|||||||
import axios from 'axios';
|
import axios from "axios";
|
||||||
import * as cheerio from 'cheerio';
|
import * as cheerio from "cheerio";
|
||||||
import {Stream} from './types';
|
import { Stream } from "./types";
|
||||||
import {headers} from './headers';
|
import { headers } from "./headers";
|
||||||
|
|
||||||
const decode = function (value: string) {
|
const decode = function (value: string) {
|
||||||
if (value === undefined) {
|
if (value === undefined) {
|
||||||
return '';
|
return "";
|
||||||
}
|
}
|
||||||
return atob(value.toString());
|
return atob(value.toString());
|
||||||
};
|
};
|
||||||
|
|
||||||
export async function hubcloudExtracter(link: string, signal: AbortSignal) {
|
export async function hubcloudExtracter(link: string, signal: AbortSignal) {
|
||||||
try {
|
try {
|
||||||
console.log('hubcloudExtracter', link);
|
console.log("hubcloudExtracter", link);
|
||||||
const baseUrl = link.split('/').slice(0, 3).join('/');
|
const baseUrl = link.split("/").slice(0, 3).join("/");
|
||||||
const streamLinks: Stream[] = [];
|
const streamLinks: Stream[] = [];
|
||||||
const vLinkRes = await axios(`${link}`, { headers, signal });
|
const vLinkRes = await axios(`${link}`, { headers, signal });
|
||||||
const vLinkText = vLinkRes.data;
|
const vLinkText = vLinkRes.data;
|
||||||
const $vLink = cheerio.load(vLinkText);
|
const $vLink = cheerio.load(vLinkText);
|
||||||
const vLinkRedirect = vLinkText.match(/var\s+url\s*=\s*'([^']+)';/) || [];
|
const vLinkRedirect = vLinkText.match(/var\s+url\s*=\s*'([^']+)';/) || [];
|
||||||
let vcloudLink =
|
let vcloudLink =
|
||||||
decode(vLinkRedirect[1]?.split('r=')?.[1]) ||
|
decode(vLinkRedirect[1]?.split("r=")?.[1]) ||
|
||||||
vLinkRedirect[1] ||
|
vLinkRedirect[1] ||
|
||||||
$vLink('.fa-file-download.fa-lg').parent().attr('href') ||
|
$vLink(".fa-file-download.fa-lg").parent().attr("href") ||
|
||||||
link;
|
link;
|
||||||
console.log('vcloudLink', vcloudLink);
|
console.log("vcloudLink", vcloudLink);
|
||||||
if (vcloudLink?.startsWith('/')) {
|
if (vcloudLink?.startsWith("/")) {
|
||||||
vcloudLink = `${baseUrl}${vcloudLink}`;
|
vcloudLink = `${baseUrl}${vcloudLink}`;
|
||||||
console.log('New vcloudLink', vcloudLink);
|
console.log("New vcloudLink", vcloudLink);
|
||||||
}
|
}
|
||||||
const vcloudRes = await fetch(vcloudLink, {
|
const vcloudRes = await fetch(vcloudLink, {
|
||||||
headers,
|
headers,
|
||||||
signal,
|
signal,
|
||||||
redirect: 'follow',
|
redirect: "follow",
|
||||||
});
|
});
|
||||||
const $ = cheerio.load(await vcloudRes.text());
|
const $ = cheerio.load(await vcloudRes.text());
|
||||||
// console.log('vcloudRes', $.text());
|
// console.log('vcloudRes', $.text());
|
||||||
|
|
||||||
const linkClass = $('.btn-success.btn-lg.h6,.btn-danger,.btn-secondary');
|
const linkClass = $(".btn-success.btn-lg.h6,.btn-danger,.btn-secondary");
|
||||||
for (const element of linkClass) {
|
for (const element of linkClass) {
|
||||||
const itm = $(element);
|
const itm = $(element);
|
||||||
let link = itm.attr('href') || '';
|
let link = itm.attr("href") || "";
|
||||||
if (link?.includes('.dev') && !link?.includes('/?id=')) {
|
|
||||||
streamLinks.push({server: 'Cf Worker', link: link, type: 'mkv'});
|
switch (true) {
|
||||||
}
|
case link?.includes(".dev") && !link?.includes("/?id="):
|
||||||
if (link?.includes('pixeld')) {
|
streamLinks.push({ server: "Cf Worker", link: link, type: "mkv" });
|
||||||
if (!link?.includes('api')) {
|
break;
|
||||||
const token = link.split('/').pop();
|
|
||||||
const baseUrl = link.split('/').slice(0, -2).join('/');
|
case link?.includes("pixeld"):
|
||||||
|
if (!link?.includes("api")) {
|
||||||
|
const token = link.split("/").pop();
|
||||||
|
const baseUrl = link.split("/").slice(0, -2).join("/");
|
||||||
link = `${baseUrl}/api/file/${token}?download`;
|
link = `${baseUrl}/api/file/${token}?download`;
|
||||||
}
|
}
|
||||||
streamLinks.push({server: 'Pixeldrain', link: link, type: 'mkv'});
|
streamLinks.push({ server: "Pixeldrain", link: link, type: "mkv" });
|
||||||
}
|
break;
|
||||||
if (link?.includes('hubcloud') || link?.includes('/?id=')) {
|
|
||||||
|
case link?.includes("hubcloud") || link?.includes("/?id="):
|
||||||
try {
|
try {
|
||||||
const newLinkRes = await axios.head(link, {headers, signal});
|
const newLinkRes = await fetch(link, {
|
||||||
const newLink =
|
method: "HEAD",
|
||||||
newLinkRes.request?.responseURL?.split('link=')?.[1] || link;
|
headers,
|
||||||
streamLinks.push({server: 'hubcloud', link: newLink, type: 'mkv'});
|
signal,
|
||||||
} catch (error) {
|
redirect: "manual",
|
||||||
console.log('hubcloudExtracter error in hubcloud link: ', error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (link?.includes('cloudflarestorage')) {
|
|
||||||
streamLinks.push({server: 'CfStorage', link: link, type: 'mkv'});
|
|
||||||
}
|
|
||||||
if (link?.includes('fastdl')) {
|
|
||||||
streamLinks.push({server: 'FastDl', link: link, type: 'mkv'});
|
|
||||||
}
|
|
||||||
if (link.includes('hubcdn')) {
|
|
||||||
streamLinks.push({
|
|
||||||
server: 'HubCdn',
|
|
||||||
link: link,
|
|
||||||
type: 'mkv',
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Check if response is a redirect (301, 302, etc.)
|
||||||
|
let newLink = link;
|
||||||
|
if (newLinkRes.status >= 300 && newLinkRes.status < 400) {
|
||||||
|
newLink = newLinkRes.headers.get("location") || link;
|
||||||
|
} else if (newLinkRes.url && newLinkRes.url !== link) {
|
||||||
|
// Fallback: check if URL changed (redirect was followed)
|
||||||
|
newLink = newLinkRes.url;
|
||||||
|
} else {
|
||||||
|
newLink = newLinkRes.headers.get("location") || link;
|
||||||
|
}
|
||||||
|
if (newLink.includes("googleusercontent")) {
|
||||||
|
newLink = newLink.split("?link=")[1];
|
||||||
|
} else {
|
||||||
|
const newLinkRes2 = await fetch(newLink, {
|
||||||
|
method: "HEAD",
|
||||||
|
headers,
|
||||||
|
signal,
|
||||||
|
redirect: "manual",
|
||||||
|
});
|
||||||
|
|
||||||
|
// Check if response is a redirect
|
||||||
|
if (newLinkRes2.status >= 300 && newLinkRes2.status < 400) {
|
||||||
|
newLink =
|
||||||
|
newLinkRes2.headers.get("location")?.split("?link=")[1] ||
|
||||||
|
newLink;
|
||||||
|
} else if (newLinkRes2.url && newLinkRes2.url !== newLink) {
|
||||||
|
// Fallback: URL changed due to redirect
|
||||||
|
newLink = newLinkRes2.url.split("?link=")[1] || newLinkRes2.url;
|
||||||
|
} else {
|
||||||
|
newLink =
|
||||||
|
newLinkRes2.headers.get("location")?.split("?link=")[1] ||
|
||||||
|
newLink;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log('streamLinks', streamLinks);
|
|
||||||
|
streamLinks.push({
|
||||||
|
server: "hubcloud",
|
||||||
|
link: newLink,
|
||||||
|
type: "mkv",
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.log("hubcloudExtracter error in hubcloud link: ", error);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case link?.includes("cloudflarestorage"):
|
||||||
|
streamLinks.push({ server: "CfStorage", link: link, type: "mkv" });
|
||||||
|
break;
|
||||||
|
|
||||||
|
case link?.includes("fastdl") || link?.includes("fsl."):
|
||||||
|
streamLinks.push({ server: "FastDl", link: link, type: "mkv" });
|
||||||
|
break;
|
||||||
|
|
||||||
|
case link.includes("hubcdn") && !link.includes("/?id="):
|
||||||
|
streamLinks.push({
|
||||||
|
server: "HubCdn",
|
||||||
|
link: link,
|
||||||
|
type: "mkv",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
if (link?.includes(".mkv")) {
|
||||||
|
const serverName =
|
||||||
|
link
|
||||||
|
.match(/^(?:https?:\/\/)?(?:www\.)?([^\/]+)/i)?.[1]
|
||||||
|
?.replace(/\./g, " ") || "Unknown";
|
||||||
|
streamLinks.push({ server: serverName, link: link, type: "mkv" });
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("streamLinks", streamLinks);
|
||||||
return streamLinks;
|
return streamLinks;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log('hubcloudExtracter error: ', error);
|
console.log("hubcloudExtracter error: ", error);
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user