]*\/>\s*[^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(/"/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.*?)(?:\\\\"|\\"|"|"|\\")/);
if (match) hlsUrl = match[1];
}
console.log("HLS match: " + (hlsUrl ? "Found" : "Not Found"));
if (hlsUrl) {
hlsUrl = hlsUrl
.replace(/\\u0026/g, "&")
.replace(/&/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: "" });
}
}