Files
aka paul 597f279e49
Fetch and Save Remote Content / fetch (push) Successful in 39s
Sync Versions to index.json / sync-versions (push) Failing after 54s
update
2026-05-27 20:30:23 +02:00

140 lines
4.3 KiB
JavaScript

async function searchResults(keyword) {
const results = [];
try {
const response = await fetchv2("https://ww1.asia2tv.pw/?s=" + encodeURIComponent(keyword));
const html = await response.text();
const regex = /<div class="box-item">[\s\S]*?<a href="([^"]+)"[^>]*>[\s\S]*?<img[^>]+src="([^"]+)"[^>]*>[\s\S]*?<h3><a[^>]*>(.*?)<\/a><\/h3>/g;
let match;
while ((match = regex.exec(html)) !== null) {
results.push({
title: match[3].trim(),
image: match[2].trim(),
href: match[1].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 descRegex = /<div class="getcontent">\s*<p>([\s\S]*?)<\/p>/i;
const descMatch = html.match(descRegex);
const description = descMatch ? descMatch[1].trim() : "N/A";
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 regex = /<a href="([^"]+)"[^>]*\/>\s*<div class="titlepisode">[^0-9]*([0-9]+)<\/div>/g;
let match;
while ((match = regex.exec(html)) !== null) {
results.push({
href: match[1].trim(),
number: parseInt(match[2], 10)
});
}
return JSON.stringify(results);
} catch (err) {
return JSON.stringify([{
href: "Error",
number: "Error"
}]);
}
}
async function extractStreamUrl(url) {
try {
console.log("Fetching URL: " + url);
const response = await fetchv2(url);
const html = await response.text();
const streams = [];
const okMatch = html.match(/https?:\/\/ok\.ru\/(?:videoembed|video)\/\d+/);
console.log("OK.ru match: " + (okMatch ? okMatch[0] : "none"));
if (okMatch) {
let okUrl = okMatch[0].replace("/video/", "/videoembed/");
console.log("Fetching OK.ru Embed: " + okUrl);
const okResp = await fetchv2(okUrl);
const okHtml = await okResp.text();
let hlsUrl = null;
const optionsMatch = okHtml.match(/data-options="([^"]+)"/);
if (optionsMatch) {
try {
const optionsJson = optionsMatch[1].replace(/&quot;/g, '"');
const options = JSON.parse(optionsJson);
const metadata = JSON.parse(options.flashvars.metadata);
hlsUrl = metadata.hlsManifestUrl;
} catch (e) {
console.log("Failed parsing OK.ru JSON metadata");
}
}
if (!hlsUrl) {
const match = okHtml.match(/hlsManifestUrl.*?(https.*?.m3u8.*?)(?:\\\\&quot;|\\&quot;|&quot;|"|\\")/);
if (match) hlsUrl = match[1];
}
console.log("HLS match: " + (hlsUrl ? "Found" : "Not Found"));
if (hlsUrl) {
hlsUrl = hlsUrl
.replace(/\\u0026/g, "&")
.replace(/&amp;/g, "&")
.replace(/\\\//g, "/");
if (hlsUrl.startsWith("//")) hlsUrl = "https:" + hlsUrl;
console.log("Final HLS URL: " + hlsUrl);
streams.push({
title: "OK.ru",
streamUrl: hlsUrl,
headers: { "Referer": "https://ok.ru/" }
});
}
}
return JSON.stringify({
streams: streams,
subtitle: ""
});
} catch (err) {
console.log("Error in extractStreamUrl: " + err.message);
return JSON.stringify({ streams: [], subtitle: "" });
}
}