Add anihq/anihq.js

This commit is contained in:
aka paul 2025-11-26 22:42:31 +00:00
parent 42f3ec820a
commit 870add0f82

147
anihq/anihq.js Normal file
View file

@ -0,0 +1,147 @@
async function searchResults(keyword) {
const results = [];
try {
const response = await fetchv2("https://anihq.to/search/?s_keyword=" + encodeURIComponent(keyword));
const html = await response.text();
const regex = /<div class="w-full bg-gradient-to-t from-primary to-transparent[^"]*"[\s\S]*?<img src=['"]([^'"]+)['"][^>]*alt=['"]([^'"]+)['"][\s\S]*?<a[^>]+href=['"]([^'"]+)['"][\s\S]*?<\/div>\s*<\/div>/g;
let match;
while ((match = regex.exec(html)) !== null) {
results.push({
title: match[2].trim(),
image: match[1].trim(),
href: match[3].trim()
});
}
return JSON.stringify(results);
} catch (err) {
return JSON.stringify([{
title: "Error",
image: "Error",
href: "Error"
}]);
}
}
async function extractDetails(url) {
try {
const response = await fetchv2(url);
const html = await response.text();
const descMatch = html.match(/<div\s+data-synopsis[^>]*>([\s\S]*?)<\/div>/);
let description = "N/A";
if (descMatch) {
description = descMatch[1]
.trim()
.replace(/<[^>]+>/g, '')
.replace(/\s+/g, ' ')
.trim();
}
return JSON.stringify([{
description: description,
aliases: "N/A",
airdate: "N/A"
}]);
} catch (err) {
return JSON.stringify([{
description: "Error",
aliases: "Error",
airdate: "Error"
}]);
}
}
async function extractEpisodes(url) {
const results = [];
try {
const response = await fetchv2(url);
const html = await response.text();
const watchUrlMatch = html.match(/<a href="([^"]+\/watch\/[^"]+)"/);
if (!watchUrlMatch) {
return JSON.stringify([{
href: url,
number: 1
}]);
}
const watchUrl = watchUrlMatch[1];
const watchResponse = await fetchv2(watchUrl);
const watchHtml = await watchResponse.text();
const episodeRegex = /<a href="([^"]+)"[^>]*class="[^"]*episode-list-item[^"]*"[^>]*data-episode-search-query="(\d+)"[\s\S]*?<span class="episode-list-item-number">\s*(\d+)\s*<\/span>/g;
let match;
while ((match = episodeRegex.exec(watchHtml)) !== null) {
results.push({
href: match[1].trim(),
number: parseInt(match[2], 10)
});
}
if (results.length === 0) {
return JSON.stringify([{
href: watchUrl,
number: 1
}]);
}
return JSON.stringify(results);
} catch (err) {
return JSON.stringify([{
href: "Error: " + err.message,
number: "Error"
}]);
}
}
async function extractStreamUrl(url) {
try {
const response = await fetchv2(url);
const html = await response.text();
const iframeMatch = html.match(/(?:data-lazy-src|src)=["']https:\/\/(anihqq?\.strp2p\.com)\/#([^"']+)["']/);
if (!iframeMatch) {
console.log("No iframe ID found");
return "https://error.org/";
}
const domain = iframeMatch[1];
const videoId = iframeMatch[2];
const apiUrl = `https://${domain}/api/v1/video?id=${videoId}&w=1792&h=1120&r=anihq.to`;
const apiResponse = await fetchv2(apiUrl);
const encodedString = await apiResponse.text();
const hasUppercase = /[A-Z]/.test(encodedString);
let stringToSend;
if (hasUppercase) {
stringToSend = atob(encodedString);
console.log("Decoded string: " + stringToSend);
} else {
stringToSend = encodedString;
console.log("Using encoded string directly (no uppercase found)");
}
const postData = {
text: stringToSend
};
const headers = { "Content-Type": "application/json" };
const response2 = await fetchv2("https://enc-dec.app/api/dec-vidstack", headers, "POST", postData);
const data = await response2.json();
console.log(JSON.stringify(data));
console.log("Final URL: " + data.result.source);
return data.result.cf;
} catch (err) {
console.log("Error: " + err.message);
return "https://error.org/";
}
}