async function searchResults(keyword) { const results = []; try { const response = await fetchv2( "https://witanime.red/?search_param=animes&s=" + encodeURIComponent(keyword) ); const html = await response.text(); const regex = /
([\s\S]*?)<\/p>/i.exec(html); 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 = []; function decryptEpisodeData(encodedData) { const parts = encodedData.split('.'); const encryptedData = atob(parts[0]); const xorKey = atob(parts[1]); let decryptedString = ''; for (let i = 0; i < encryptedData.length; i++) { const decryptedChar = String.fromCharCode( encryptedData.charCodeAt(i) ^ xorKey.charCodeAt(i % xorKey.length) ); decryptedString += decryptedChar; } return JSON.parse(decryptedString); } try { const response = await fetchv2(url); const html = await response.text(); const dataRegex = /var\s+processedEpisodeData\s*=\s*'([^']+)'/; const dataMatch = dataRegex.exec(html); const encodedData = dataMatch ? dataMatch[1] : null; if (encodedData) { const decoded = decryptEpisodeData(encodedData); const addEpisode = (ep) => { const num = parseInt(ep.number, 10); results.push({ href: ep.url, number: isNaN(num) ? 0 : num }); }; if (Array.isArray(decoded)) { decoded.forEach(addEpisode); } else { addEpisode(decoded); } return JSON.stringify(results); } return JSON.stringify(results); } catch (err) { return JSON.stringify([{ href: "Error", number: 0 }]); } } async function extractStreamUrl(url) { try { const response = await fetchv2(url); const html = await response.text(); const servers = a(html); console.log(JSON.stringify(servers)); const priorities = [ "streamwish - fhd", "streamwish", "mp4upload", "playerwish - fhd", "playerwish" ]; let chosenServer = null; for (const provider of priorities) { chosenServer = servers.find(s => s.name.toLowerCase().includes(provider) ); if (chosenServer) break; } if (!chosenServer) { throw new Error("No valid server found"); } const streamUrl = chosenServer.url; const name = chosenServer.name.toLowerCase(); if (name.includes("streamwish")) { const newUrl = "https://hgplaycdn.com/e/" + streamUrl.replace(/^https?:\/\/[^/]+\/e\//, ''); const response = await fetchv2(newUrl); const html = await response.text(); const result = await b(html); return result; } else if (name.includes("mp4upload")) { const response = await fetchv2(streamUrl); const html = await response.text(); const result = await c(html); return result; } else if (name.includes("playerwish")) { const response = await fetchv2(streamUrl); const html = await response.text(); const result = await b(html); return result; } else { throw new Error("Unsupported provider: " + chosenServer.name); } } catch (err) { console.error(err); return "https://files.catbox.moe/avolvc.mp4"; } } function a(html) { try { const zGMatch = html.match(/var _zG="([^"]+)";/); const zHMatch = html.match(/var _zH="([^"]+)";/); if (!zGMatch || !zHMatch) throw new Error("Could not find _zG or _zH in HTML"); const resourceRegistry = JSON.parse(atob(zGMatch[1])); const configRegistry = JSON.parse(atob(zHMatch[1])); const serverNames = {}; const serverLinks = html.matchAll( /]+class="server-link"[^>]+data-server-id="(\d+)"[^>]*>\s*([^<]+)<\/span>/g ); for (const match of serverLinks) { serverNames[match[1]] = match[2].trim(); } const servers = []; for (let i = 0; i < 10; i++) { const resourceData = resourceRegistry[i]; const config = configRegistry[i]; if (!resourceData || !config) continue; let decrypted = resourceData.split('').reverse().join(''); decrypted = decrypted.replace(/[^A-Za-z0-9+/=]/g, ''); let rawUrl = atob(decrypted); const indexKey = atob(config.k); const paramOffset = config.d[parseInt(indexKey, 10)]; rawUrl = rawUrl.slice(0, -paramOffset); servers.push({ id: i, name: serverNames[i] || `Unknown Server ${i}`, url: rawUrl.trim() }); } return servers; } catch (error) { return []; } } async function b(data, url = null) { const obfuscatedScript = data.match(/