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 myAtob(input) { const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; let str = ''; let buffer = 0; let bits = 0; for (let i = 0; i < input.length; i++) { const char = input.charAt(i); if (char === '=') break; const index = chars.indexOf(char); if (index === -1) continue; buffer = (buffer << 6) | index; bits += 6; if (bits >= 8) { bits -= 8; str += String.fromCharCode((buffer >> bits) & 0xFF); buffer &= (1 << bits) - 1; } } return str; } function decryptEpisodeData(encodedData) { const parts = encodedData.split('.'); const encryptedData = myAtob(parts[0]); const xorKey = myAtob(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; } try { decryptedString = decodeURIComponent(escape(decryptedString)); } catch (e) {} 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) { try { 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); } catch (innerErr) { console.log("Decryption failed, using fallback..."); } } const regex = /openEpisode\('([^']+)'\)[\s\S]*?>[^<]*?(\d+)[^<]*?<\/a>/gi; let match; const seenHrefs = new Set(); while ((match = regex.exec(html)) !== null) { const href = myAtob(match[1]); const number = parseInt(match[2], 10); if (!seenHrefs.has(href)) { results.push({ href: href, number: isNaN(number) ? 0 : number }); seenHrefs.add(href); } } if (results.length === 0) { const fallbackRegex = /openEpisode\('([^']+)'\)/gi; while ((match = fallbackRegex.exec(html)) !== null) { const href = atob(match[1]); if (!seenHrefs.has(href)) { const numMatch = href.match(/-(\d+)\/?$/); const number = numMatch ? parseInt(numMatch[1], 10) : results.length + 1; results.push({ href: href, number: number }); seenHrefs.add(href); } } } 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(/