commit 09c423e95a233553b774b005d8f6e6bdb31fc8f1 Author: 50/50 <80717571+50n50@users.noreply.github.com> Date: Sat Oct 11 17:18:45 2025 +0200 Upload diff --git a/111477/111477.js b/111477/111477.js new file mode 100644 index 0000000..ef99b11 --- /dev/null +++ b/111477/111477.js @@ -0,0 +1,229 @@ +async function searchResults(keyword) { + const results = []; + const image = 'https://files.catbox.moe/9tbjtb.png'; + const regex = /([^<]+)<\/a><\/td>]*>[^<]*<\/td><\/tr>/g; + + const urls = [ + 'https://a.111477.xyz/tvs/', + 'https://a.111477.xyz/movies/', + 'https://a.111477.xyz/kdrama/', + 'https://a.111477.xyz/asiandrama/' + ]; + + for (const url of urls) { + const response = await fetchv2(url); + const html = await response.text(); + + let match; + while ((match = regex.exec(html)) !== null) { + const rawTitle = match[2].trim().replace(/\/$/, ''); + const cleanedTitle = rawTitle.replace(/\.+/g, ' ').toLowerCase(); + + if (cleanedTitle.includes(keyword.toLowerCase())) { + results.push({ + title: rawTitle.replace(/\.+/g, ' '), + image, + href: url + match[1].trim() + }); + } + } + } + + return JSON.stringify(results); +} + +async function extractDetails(url) { + const results = []; + + results.push({ + description: 'None provided, but hell who cares anyway', + aliases: 'N/A', + airdate: 'N/A' + }); + + return JSON.stringify(results); +} + +async function extractEpisodes(url) { + const results = []; + const response = await fetchv2(url); + const html = await response.text(); + + const episodeRegex = /([^<]+\.mkv)<\/a><\/td>/g; + let match; + let count = 1; + + while ((match = episodeRegex.exec(html)) !== null) { + results.push({ + href: match[1].trim(), + number: count++ + }); + } + + if (results.length > 0) { + return JSON.stringify([{ + href: url, + number: 1 + }]); + } + if (results.length === 0) { + const seasonRegex = /]*>([^<]+\/)<\/a><\/td>/g; + const seasons = []; + + while ((match = seasonRegex.exec(html)) !== null) { + const seasonHref = match[1].trim(); + const seasonName = match[2].trim(); + + if (seasonHref === '../' || seasonName === '../') continue; + + const isSeasonDir = ( + /season\s*\d+/i.test(seasonName) || + /s\d+/i.test(seasonName) || + /series\s*\d+/i.test(seasonName) || + /specials/i.test(seasonName) || + /extras/i.test(seasonName) || + /bonus/i.test(seasonName) || + (/\d+/.test(seasonName) && seasonName.endsWith('/')) + ); + + if (isSeasonDir) { + seasons.push({ + href: seasonHref, + name: seasonName + }); + } + } + + seasons.sort((a, b) => { + const aNum = extractSeasonNumber(a.name); + const bNum = extractSeasonNumber(b.name); + + if (aNum === null && bNum === null) return a.name.localeCompare(b.name); + if (aNum === null) return 1; + if (bNum === null) return -1; + + return aNum - bNum; + }); + + console.log(`Found ${seasons.length} seasons:`, seasons.map(s => s.name)); + console.log(`Base URL: "${url}"`); + console.log(`Base URL ends with /: ${url.endsWith('/')}`); + + + for (const season of seasons) { + console.log(`Processing season: ${season.name}`); + console.log(`Season href: "${season.href}"`); + + let seasonUrl; + if (season.href.startsWith('http')) { + seasonUrl = season.href; + } else { + const baseUrl = url.endsWith('/') ? url : url + '/'; + seasonUrl = baseUrl + season.href; + } + + console.log(`Season URL: "${seasonUrl}"`); + console.log(`URL encoded version: "${encodeURI(seasonUrl)}"`); + + try { + const seasonResponse = await fetchv2(decodeURIComponent(seasonUrl)); + const seasonHtml = await seasonResponse.text(); + + console.log(`Sample HTML from ${season.name}:`, seasonHtml.substring(0, 500)); + + let episodeCount = 1; + + const seasonEpisodeRegex = /]*>([^<]+\.mkv)<\/a>/g; + let seasonMatch; + let episodesInSeason = 0; + + while ((seasonMatch = seasonEpisodeRegex.exec(seasonHtml)) !== null) { + let episodeHref = seasonMatch[1].trim(); + + if (!episodeHref.startsWith('http')) { + episodeHref = seasonUrl.endsWith('/') ? seasonUrl + episodeHref : seasonUrl + '/' + episodeHref; + } + + results.push({ + href: episodeHref, + number: episodeCount++, + season: season.name.replace('/', '') + }); + episodesInSeason++; + } + + console.log(`Found ${episodesInSeason} episodes in ${season.name}`); + + } catch (error) { + console.warn(`Failed to fetch season ${season.name}:`, error); + console.warn(`Season URL was: ${seasonUrl}`); + } + } + } + + return JSON.stringify(results); +} + +function extractSeasonNumber(seasonName) { + const patterns = [ + /season\s*(\d+)/i, + /s(\d+)/i, + /series\s*(\d+)/i, + /(\d+)/ + ]; + + for (const pattern of patterns) { + const match = seasonName.match(pattern); + if (match) { + return parseInt(match[1], 10); + } + } + + return null; +} + + +async function extractStreamUrl(url) { + if (url.toLowerCase().endsWith('.mkv')) { + const filename = url.split('/').pop(); + + const final = { + streams: [filename, url], + subtitles: "" + }; + + console.log("RETURN: " + JSON.stringify(final)); + return JSON.stringify(final); + } + + try { + const response = await fetchv2(decodeURIComponent(url)); + const html = await response.text(); + + const mkvRegex = /]*>([^<]+\.mkv)<\/a><\/td>/g; + const streams = []; + let match; + + while ((match = mkvRegex.exec(html)) !== null) { + const mkvUrl = match[1].trim(); + const filename = match[2].trim(); + + streams.push(filename, mkvUrl); + } + + const final = { + streams, + subtitles: "" + }; + + console.log("RETURN: " + JSON.stringify(final)); + return "JSON.stringify(final)"; + + } catch (error) { + console.log("Error in extractStreamUrl:", error); + return JSON.stringify({ + streams: [], + subtitles: "" + }); + } +} diff --git a/111477/111477.json b/111477/111477.json new file mode 100644 index 0000000..9bf5032 --- /dev/null +++ b/111477/111477.json @@ -0,0 +1,20 @@ +{ + "sourceName": "111477", + "iconUrl": "https://media.tenor.com/tIOhF5a8McEAAAAe/heart-emoji-love-nonchalant.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "Multi Language", + "streamType": "MKV", + "quality": "1080p", + "baseUrl": "https://a.111477.xyz/", + "searchBaseUrl": "https://a.111477.xyz/", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/111477/111477.js", + "type": "shows/movies", + "asyncJS": true, + "softsub": true, + "downloadSupport": true, + "note": "USE AN EXTERNAL PLAYER (E.G., VLC/MPV)" +} diff --git a/1movies/1movies.js b/1movies/1movies.js new file mode 100644 index 0000000..6433586 --- /dev/null +++ b/1movies/1movies.js @@ -0,0 +1,286 @@ +async function searchResults(query) { + const encodeQuery = keyword => encodeURIComponent(keyword); + const searchBaseUrl = "https://1movies.bz/browser?keyword="; + const baseUrl = "https://1movies.bz"; + + const posterHrefRegex = /href="([^"]*)" class="poster"/g; + const titleRegex = /class="title" href="[^"]*">([^<]*) { + const results = []; + const posterMatches = [...htmlText.matchAll(posterHrefRegex)]; + const titleMatches = [...htmlText.matchAll(titleRegex)]; + const imageMatches = [...htmlText.matchAll(imageRegex)]; + + const minLength = Math.min(posterMatches.length, titleMatches.length, imageMatches.length); + + for (let index = 0; index < minLength; index++) { + const href = posterMatches[index][1]; + const fullHref = href.startsWith("http") ? href : baseUrl + href; + + const imageSrc = imageMatches[index][1]; + + const title = titleMatches[index][1]; + const cleanTitle = decodeHtmlEntities(title); + + if (fullHref && imageSrc && cleanTitle) { + results.push({ + href: fullHref, + image: imageSrc, + title: cleanTitle + }); + } + } + return results; + }; + + try { + const encodedQuery = encodeQuery(query); + + const urls = [ + `${searchBaseUrl}${encodedQuery}`, + `${searchBaseUrl}${encodedQuery}&page=2`, + `${searchBaseUrl}${encodedQuery}&page=3` + ]; + + const responses = await Promise.all(urls.map(url => fetchv2(url))); + + const htmlTexts = await Promise.all(responses.map(response => response.text())); + + const allResults = []; + htmlTexts.forEach(htmlText => { + const pageResults = extractResultsFromHTML(htmlText); + allResults.push(...pageResults); + }); + + return JSON.stringify(allResults); + } catch (error) { + return JSON.stringify([{ + href: "", + image: "", + title: "Search failed: " + error.message + }]); + } +} + +async function extractDetails(url) { + try { + const response = await fetchv2(url); + const htmlText = await response.text(); + + const descriptionMatch = (/
([\s\S]*?)<\/div>/.exec(htmlText) || [])[1]; + const aliasesMatch = (/([\s\S]*?)<\/small>/.exec(htmlText) || [])[1]; + const airdateMatch = (/
  • Released:\s*]*>(.*?)<\/span>/.exec(htmlText) || [])[1]; + + return JSON.stringify([{ + description: descriptionMatch ? cleanHtmlSymbols(descriptionMatch) : "Not available", + aliases: aliasesMatch ? cleanHtmlSymbols(aliasesMatch) : "Not aliases", + airdate: airdateMatch ? cleanHtmlSymbols(airdateMatch) : "Not available" + }]); + } catch (error) { + console.error("Error fetching details:" + error); + return [{ + description: "Error loading description", + aliases: "Not available", + airdate: "Not available" + }]; + } +} + +async function extractEpisodes(movieUrl) { + try { + const response = await fetchv2(movieUrl); + const htmlText = await response.text(); + const movieIDMatch = (htmlText.match(/
    ]*id="movie-rating"[^>]*data-id="([^"]+)"/) || [])[1]; + if (!movieIDMatch) { + return [{ + error: "MovieID not found" + }]; + } + const movieData = [{ name: "MovieID", data: movieIDMatch }]; + const tokenResponse = await fetchv2( + "https://ilovekai.simplepostrequest.workers.dev/ilovethighs", + {}, + "POST", + JSON.stringify(movieData) + ); + const temp = await tokenResponse.json(); + const token = temp[0]?.data; + const episodeListUrl = `https://1movies.bz/ajax/episodes/list?id=${movieIDMatch}&_=${token}`; + const episodeListResponse = await fetchv2(episodeListUrl); + const episodeListData = await episodeListResponse.json(); + const cleanedHtml = cleanJsonHtml(episodeListData.result); + + const episodeRegex = /]+eid="([^"]+)"[^>]+num="([^"]+)"[^>]*>/g; + const episodeMatches = [...cleanedHtml.matchAll(episodeRegex)]; + + const episodeData = episodeMatches.map(([_, episodeToken, episodeNum]) => ({ + name: `Episode ${episodeNum}`, + data: episodeToken + })); + + console.log(JSON.stringify(episodeData)); + const batchResponse = await fetchv2( + "https://ilovekai.simplepostrequest.workers.dev/ilovethighs", + {}, + "POST", + JSON.stringify(episodeData) + ); + const batchResults = await batchResponse.json(); + + const episodes = batchResults.map((result, index) => ({ + number: parseInt(episodeMatches[index][2], 10), + href: `https://1movies.bz/ajax/links/list?eid=${episodeMatches[index][1]}&_=${result.data}` + })); + + return JSON.stringify(episodes); + } catch (err) { + console.error("Error fetching episodes:" + err); + return [{ + number: 1, + href: "Error fetching episodes" + }]; + } +} + +async function extractStreamUrl(url) { + try { + const fetchUrl = `${url}`; + const response = await fetchv2(fetchUrl); + const responseData = await response.json(); + const cleanedHtml = cleanJsonHtml(responseData.result); + + const server1Regex = /
    ]*data-lid="([^"]+)"[^>]*>\s*Server 1<\/span>/; + const server1Match = server1Regex.exec(cleanedHtml); + + if (!server1Match) { + console.log("Server 1 not found"); + return "error"; + } + + const serverId = server1Match[1]; + + const tokenRequestData = [{ name: "Server1", data: serverId }]; + + const tokenBatchResponse = await fetchv2( + "https://ilovekai.simplepostrequest.workers.dev/ilovethighs", + {}, + "POST", + JSON.stringify(tokenRequestData) + ); + const tokenResults = await tokenBatchResponse.json(); + const token = tokenResults[0]?.data; + + if (!token) { + console.log("Token not found"); + return "error"; + } + + const streamUrl = `https://1movies.bz/ajax/links/view?id=${serverId}&_=${token}`; + const streamResponse = await fetchv2(streamUrl); + const streamData = await streamResponse.json(); + + if (!streamData.result) { + console.log("Stream result not found"); + return "error"; + } + + const decryptRequestData = [{ name: "Server1", data: streamData.result }]; + + const decryptBatchResponse = await fetchv2( + "https://ilovekai.simplepostrequest.workers.dev/iloveboobs", + {}, + "POST", + JSON.stringify(decryptRequestData) + ); + const decryptedResponse = await decryptBatchResponse.json(); + const decryptedUrl = decryptedResponse[0]?.data.url; + + const subListEncoded = decryptedUrl.split("sub.list=")[1]?.split("&")[0]; + const subListUrl = decodeURIComponent(subListEncoded); + + const subResponse = await fetchv2(subListUrl); + const subtitles = await subResponse.json(); + + const englishSubUrl = subtitles.find(sub => sub.label === "English")?.file.replace(/\\\//g, "/"); + + if (!decryptedUrl) { + console.log("Decryption failed"); + return "error"; + } + + const headers = { + "Referer": "https://1movies.bz/", + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36" + }; + + const mediaResponse = await fetchv2(decryptedUrl.replace("/e/", "/media/"), headers); + const mediaJson = await mediaResponse.json(); + + const result = mediaJson?.result; + if (!result) { + console.log("Media result not found"); + return "error"; + } + + const postData = { + "text": result, + "Useragent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36" + }; + + const finalResponse = await fetchv2("https://ilovekai.simplepostrequest.workers.dev/ilovebush", {}, "POST", JSON.stringify(postData)); + const finalJson = await finalResponse.json(); + + const m3u8Link = finalJson?.result?.sources?.[0]?.file; + + const returnValue = { + stream: m3u8Link, + subtitles: englishSubUrl + }; + console.log(JSON.stringify(returnValue)); + return JSON.stringify(returnValue); + } catch (error) { + console.log("Fetch error:"+ error); + return "https://error.org"; + } +} + +function cleanHtmlSymbols(string) { + if (!string) { + return ""; + } + return string + .replace(/’/g, "'") + .replace(/–/g, "-") + .replace(/&#[0-9]+;/g, "") + .replace(/\r?\n|\r/g, " ") + .replace(/\s+/g, " ") + .trim(); +} + +function cleanJsonHtml(jsonHtml) { + if (!jsonHtml) { + return ""; + } + return jsonHtml + .replace(/\\"/g, "\"") + .replace(/\\'/g, "'") + .replace(/\\\\/g, "\\") + .replace(/\\n/g, "\n") + .replace(/\\t/g, "\t") + .replace(/\\r/g, "\r"); +} + +function decodeHtmlEntities(text) { + if (!text) { + return ""; + } + return text + .replace(/'/g, "'") + .replace(/"/g, "\"") + .replace(/&/g, "&") + .replace(/</g, "<") + .replace(/>/g, ">") + .replace(/ /g, " "); +} diff --git a/1movies/1movies.json b/1movies/1movies.json new file mode 100644 index 0000000..3108327 --- /dev/null +++ b/1movies/1movies.json @@ -0,0 +1,19 @@ +{ + "sourceName": "1Movies", + "iconUrl": "https://1movies.bz/assets/uploads/675b5c22f2829fc8e3a4030af7f4284acad017e5241280b3dc21.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.5", + "language": "English", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://animekai.to/", + "searchBaseUrl": "https://1movies.bz/home", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/1movies/1movies.js", + "type": "shows/movies", + "asyncJS": true, + "softsub": true, + "downloadSupport": true +} diff --git a/1tamilcrow/1tamilcrow.js b/1tamilcrow/1tamilcrow.js new file mode 100644 index 0000000..857cfbb --- /dev/null +++ b/1tamilcrow/1tamilcrow.js @@ -0,0 +1,225 @@ +async function searchResults(keyword) { + const results = []; + const regex = /
    ]*>\s*([^<]+)\s*<\/a>/g; + + try { + const response = await fetchv2("https://www.1tamilcrow.net/?s=" + keyword); + const html = await response.text(); + + let match; + while ((match = regex.exec(html)) !== null) { + results.push({ + href: match[2].trim(), + title: decodeHtml(match[3].trim()), + image: match[1] ? match[1].trim() : "No Image" + }); + } + + return JSON.stringify(results); + } catch (err) { + return JSON.stringify([{ + title: "Error", + image: "Error", + href: "Error" + }]); + } +} + +function decodeHtml(str) { + return str + .replace(/&/g, "&") + .replace(/’/g, "’") + .replace(/"/g, "\"") + .replace(/'/g, "'") + .replace(/</g, "<") + .replace(/>/g, ">"); +} + + +async function extractDetails(url) { + try { + return JSON.stringify([{ + description: "No description on the website", + 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(); + console.log(html); + const regex = /]*SRC="(https:\/\/(?:videospk|vidhidevip)[^"]+)"[^>]*>/; + const match = html.match(regex); + + if (match) { + results.push({ + href: match[1].trim(), + number: 1 + }); + } else { + results.push({ + href: url, + number: 1 + }); + } + + return JSON.stringify(results); + } catch (err) { + return JSON.stringify([{ + href: "Error", + number: "Error" + }]); + } +} + +async function extractStreamUrl(url) { + try { + const response = await fetchv2(url); + const html = await response.text(); + + const obfuscatedScript = html.match(/]*>\s*(eval\(function\(p,a,c,k,e,d.*?\)[\s\S]*?)<\/script>/); + const unpackedScript = unpack(obfuscatedScript[1]); + + const streamMatch = unpackedScript.match(/["'](\/stream\/[^"']+)["']/); + const hlsLink = streamMatch ? streamMatch[1] : null; + + const baseUrl = url.match(/^(https?:\/\/[^/]+)/)[1]; + + console.log("HLS Link:" + hlsLink); + + return baseUrl + hlsLink; + } catch (err) { + console.log(err); + return "https://files.catbox.moe/avolvc.mp4"; + } +} + + +/*********************************************************** + * UNPACKER MODULE + * Credit to GitHub user "mnsrulz" for Unpacker Node library + * https://github.com/mnsrulz/unpacker + ***********************************************************/ +class Unbaser { + constructor(base) { + /* Functor for a given base. Will efficiently convert + strings to natural numbers. */ + this.ALPHABET = { + 62: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", + 95: "' !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'", + }; + this.dictionary = {}; + this.base = base; + // fill elements 37...61, if necessary + if (36 < base && base < 62) { + this.ALPHABET[base] = this.ALPHABET[base] || + this.ALPHABET[62].substr(0, base); + } + // If base can be handled by int() builtin, let it do it for us + if (2 <= base && base <= 36) { + this.unbase = (value) => parseInt(value, base); + } + else { + // Build conversion dictionary cache + try { + [...this.ALPHABET[base]].forEach((cipher, index) => { + this.dictionary[cipher] = index; + }); + } + catch (er) { + throw Error("Unsupported base encoding."); + } + this.unbase = this._dictunbaser; + } + } + _dictunbaser(value) { + /* Decodes a value to an integer. */ + let ret = 0; + [...value].reverse().forEach((cipher, index) => { + ret = ret + ((Math.pow(this.base, index)) * this.dictionary[cipher]); + }); + return ret; + } +} + +function detect(source) { + /* Detects whether `source` is P.A.C.K.E.R. coded. */ + return source.replace(" ", "").startsWith("eval(function(p,a,c,k,e,"); +} + +function unpack(source) { + /* Unpacks P.A.C.K.E.R. packed js code. */ + let { payload, symtab, radix, count } = _filterargs(source); + if (count != symtab.length) { + throw Error("Malformed p.a.c.k.e.r. symtab."); + } + let unbase; + try { + unbase = new Unbaser(radix); + } + catch (e) { + throw Error("Unknown p.a.c.k.e.r. encoding."); + } + function lookup(match) { + /* Look up symbols in the synthetic symtab. */ + const word = match; + let word2; + if (radix == 1) { + //throw Error("symtab unknown"); + word2 = symtab[parseInt(word)]; + } + else { + word2 = symtab[unbase.unbase(word)]; + } + return word2 || word; + } + source = payload.replace(/\b\w+\b/g, lookup); + return _replacestrings(source); + function _filterargs(source) { + /* Juice from a source file the four args needed by decoder. */ + const juicers = [ + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\), *(\d+), *(.*)\)\)/, + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\)/, + ]; + for (const juicer of juicers) { + //const args = re.search(juicer, source, re.DOTALL); + const args = juicer.exec(source); + if (args) { + let a = args; + if (a[2] == "[]") { + //don't know what it is + // a = list(a); + // a[1] = 62; + // a = tuple(a); + } + try { + return { + payload: a[1], + symtab: a[4].split("|"), + radix: parseInt(a[2]), + count: parseInt(a[3]), + }; + } + catch (ValueError) { + throw Error("Corrupted p.a.c.k.e.r. data."); + } + } + } + throw Error("Could not make sense of p.a.c.k.e.r data (unexpected code structure)"); + } + function _replacestrings(source) { + /* Strip string lookup table (list) and replace values in source. */ + /* Need to work on this. */ + return source; + } +} diff --git a/1tamilcrow/1tamilcrow.json b/1tamilcrow/1tamilcrow.json new file mode 100644 index 0000000..46f359e --- /dev/null +++ b/1tamilcrow/1tamilcrow.json @@ -0,0 +1,19 @@ +{ + "sourceName": "1TamilCrow", + "iconUrl": "https://sp-ao.shortpixel.ai/client/to_webp,q_glossy,ret_img/https://www.1tamilcrow.net/wp-content/uploads/2020/09/Tamil-Crow-e1600735514979.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "Tamil", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://www.1tamilcrow.net/", + "searchBaseUrl": "https://www.1tamilcrow.net/", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/1tamilcrow/1tamilcrow.js", + "type": "anime", + "asyncJS": true, + "softsub": false, + "downloadSupport": false +} diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..f523942 --- /dev/null +++ b/LICENSE @@ -0,0 +1,32 @@ +License + +Copyright (c) 2025, 50/50 +All rights reserved. + +This software module is primarily licensed for use within the Sora/Sulfur iOS application(https://github.com/cranci1/Sora), developed by cranc1. +It may also be freely used in other projects, provided they meet the criteria outlined below. + +LICENSE TERMS + +1. Permitted Use +- This software may be used as part of the official Sora or Sulfur iOS applications. +- It may also be used in open-source applications that are: + - Free to download and use this software (no paywall, subscription, or purchase required) + - Without advertisements during the usage of this software + - Released under an open-source license +- All three of the above requirements are mandatory unless explicit written permission has been granted by the copyright holder to an application that does not meet one or more of them. + +2. Prohibited Use +- Redistribution, reproduction, or sublicensing of this software as a standalone module is not allowed +- Use in proprietary, closed-source, paid, or ad-supported software is strictly prohibited +- Commercial use of this software in any form is forbidden + +3. Access & Agreement +- By accessing, downloading, or using any portion of this repository, you acknowledge and agree to abide by these terms +- Unauthorized use or distribution may result in legal action + +--- + +This license does not grant any rights under patent, trademark, or other intellectual property laws beyond those explicitly stated above. + +Note: License terms may change over time. It is your responsibility to review the latest version periodically. diff --git a/README.md b/README.md new file mode 100644 index 0000000..270b042 --- /dev/null +++ b/README.md @@ -0,0 +1,36 @@ +
    + +
    +

    ⚠️ IMPORTANT

    +

    Any app meeting the following criteria is free to use my modules:

    +
      +
    1. No paywall, subscription, or payment required for my modules + (you may charge for other parts of your app).
    2. +
    3. No advertisements during the usage of my modules.
    4. +
    5. Open source: your app’s source code must be publicly available.
    6. +
    +

    All the above terms are mandatory unless given permission by me.
    +In short: no commercial use and transparency is required.

    +
    + +
    + +
    +

    🚫 CAUTION

    +

    Do not pay to use these modules — if someone is charging you, it's a scam.

    +

    Neither should you bear watching ads to use these modules. Please report apps that do this forcibly!

    +
    + +
    + +
    + +[![Discord Presence](https://lanyard.cnrad.dev/api/1072985316916469870?theme=dark&bg=000000&animated=false&hideDiscrim=true&borderRadius=30px&idleMessage=For%20requests%20go%20to%20Sora%20server,%20for%20questions%20about%20using%20my%20modules%20in%20your%20app%20DM%20me.%20If%20a%20module%20is%20broken%20go%20to%20Sora%20server%20or%20open%20a%20GitHub%20issue.)](https://discord.com/users/1072985316916469870) + +
    + +[![Ko-fi](https://img.shields.io/badge/support_me_on_ko--fi-F16061?style=for-the-badge&logo=kofi&logoColor=f5f5f5)](https://ko-fi.com/50n50) + +
    +
    + diff --git a/aksv/aksv.js b/aksv/aksv.js new file mode 100644 index 0000000..3a2402d --- /dev/null +++ b/aksv/aksv.js @@ -0,0 +1,181 @@ +async function searchResults(keyword) { + const results = []; + + const response = await fetchv2("https://ak.sv/search?q=" + encodeURIComponent(keyword)); + const html = await response.text(); + const filmListRegex = /
    [\s\S]*?<\/div>\s*<\/div>/g; + const items = html.match(filmListRegex) || []; + + items.forEach((itemHtml) => { + const titleMatch = itemHtml.match(/

    ]*>([^<]+)<\/a>/); + const href = titleMatch ? titleMatch[1] : ''; + const title = titleMatch ? titleMatch[2] : ''; + const imgMatch = itemHtml.match(/]*data-src="([^"]+)"[^>]*>/); + const imageUrl = imgMatch ? imgMatch[1] : ''; + + if (title && href) { + results.push({ + title: title.trim(), + image: imageUrl.trim(), + href: href.trim(), + }); + } + }); + console.log(results); + return JSON.stringify(results); +} + +async function extractDetails(url) { + const details = []; + let description = 'N/A'; + let aliases = 'N/A'; + let airdate = 'N/A'; + const genres = []; + const response = await fetch(url); + const html = await response.text(); + const airdateMatch = html.match( + /
    \s*\s*السنة\s*:\s*(\d{4})\s*<\/span>\s*<\/div>/ + ); + if (airdateMatch) airdate = airdateMatch[1]; + + const descriptionMatch = html.match( + /
    ]*>[\s\S]*?

    ([\s\S]*?)<\/p>/ + ); + if (descriptionMatch) { + description = decodeHTMLEntities(descriptionMatch[1].replace(/<[^>]+>/g, '').trim()); + } + + const genresMatch = html.match(/

    ([\s\S]*?)<\/div>/); + const genresHtml = genresMatch ? genresMatch[1] : ''; + + const genreAnchorRe = /]*>([^<]+)<\/a>/g; + let genreMatch; + while ((genreMatch = genreAnchorRe.exec(genresHtml)) !== null) { + genres.push(decodeHTMLEntities(genreMatch[1].trim())); + } + + details.push({ + description: description, + airdate: airdate, + aliases: genres.join(', ') || 'N/A' + }); + + console.log(details); + return JSON.stringify(details); +} + +async function extractEpisodes(url) { + const episodes = []; + const response = await fetchv2(url); + const html = await response.text(); + const movieRegex = /]+href=["']([^"']+)["'][^>]+class=["'][^"']*link-btn link-show[^"']*["'][^>]*>/i; + const movieMatch = movieRegex.exec(html); + + if (movieMatch && movieMatch[1]) { + episodes.push({ + href: movieMatch[1], + number: 1 + }); + } else { + const reversedHtml = html.split('\n').reverse().join('\n'); + + const episodeBlocks = reversedHtml.match(/
    [\s\S]*?]*>[\s\S]*?<\/a>/g); + + if (episodeBlocks) { + episodeBlocks.forEach((block, index) => { + const hrefMatch = block.match(/href=["']([^"']+)["']/); + if (hrefMatch) { + episodes.push({ + href: hrefMatch[1], + number: index + 1 + }); + } + }); + } + } + + console.log(JSON.stringify(episodes)); + return JSON.stringify(episodes); +} + +async function extractStreamUrl(url) { + let stream = null; + const response = await fetchv2(url); + const html = await response.text(); + const urlMatch = html.match(/]*class="link-btn link-show[^"]*"[^>]*>[\s\S]*?<\/a>/g); + let match = null; + + if (linkBtnMatches && linkBtnMatches.length > 0) { + const hrefMatch = linkBtnMatches[0].match(/href="([^"]+)"/); + if (hrefMatch && hrefMatch[1]) { + match = [null, hrefMatch[1]]; + } + } + + if (match && match[1]) { + try { + const shortnerResponse = await fetch(match[1]); + const shortnerHtml = await shortnerResponse; + + const finalMatch = shortnerHtml.match(/
    \s*\s* String.fromCharCode(dec)); + + const entities = { + '"': '"', + '&': '&', + ''': "'", + '<': '<', + '>': '>' + }; + + for (const entity in entities) { + text = text.replace(new RegExp(entity, 'g'), entities[entity]); + } + + return text; +} diff --git a/aksv/aksv.json b/aksv/aksv.json new file mode 100644 index 0000000..b871642 --- /dev/null +++ b/aksv/aksv.json @@ -0,0 +1,17 @@ +{ + "sourceName": "AK.SV", + "iconUrl": "https://i.ibb.co/fdyjNhkb/icon-number-255763.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.5", + "language": "Arabic (SUB)", + "streamType": "MP4", + "quality": "1080p", + "baseUrl": "https://ak.sv/", + "searchBaseUrl": "https://ak.sv/search?q=%s", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/aksv/aksv.js", + "asyncJS": true, + "type": "movies/shows" +} diff --git a/anilibria/anilibria.js b/anilibria/anilibria.js new file mode 100644 index 0000000..fb1431f --- /dev/null +++ b/anilibria/anilibria.js @@ -0,0 +1,70 @@ +async function searchResults(keyword) { + try { + const encodedKeyword = encodeURIComponent(keyword); + const responseText = await fetch(`https://api.anilibria.tv/v3/title/search?search=${encodedKeyword}&filter=id,names,posters`); + const data = JSON.parse(responseText); + + const transformedResults = data.list.map(anime => ({ + title: anime.names.en || anime.names.ru || 'Unknown Title', + image: `https://anilibria.tv${anime.posters.original.url}`, + href: `${anime.id}` + })); + + return JSON.stringify(transformedResults); + + } catch (error) { + console.log('Fetch error:', error); + return JSON.stringify([{ title: 'Error', image: '', href: '' }]); + } +} + + +async function extractDetails(id) { + try { + const response = await fetch(`https://api.anilibria.tv/v3/title?id=${id}&filter=description`); + const data = JSON.parse(response); + + const animeInfo = data; + + const transformedResults = [{ + description: animeInfo.description || 'No description available', + aliases: `Alias: Unknown`, + airdate: `Aired: Unknown` + }]; + + return JSON.stringify(transformedResults); + } catch (error) { + console.log('Details error:', error); + return JSON.stringify([{ + description: 'Error loading description', + aliases: 'Duration: Unknown', + airdate: 'Aired: Unknown' + }]); + } +} + +async function extractEpisodes(id) { + try { + const response = await fetch(`https://api.anilibria.tv/v3/title?id=${id}`); + const data = JSON.parse(response); + + const transformedResults = Object.values(data.player.list).map(episode => ({ + href: `https://cache.libria.fun${episode.hls.hd}`, + number: episode.episode + })); + + return JSON.stringify(transformedResults); + + } catch (error) { + console.log('Fetch error:', error); + } +} + +async function extractStreamUrl(url) { + try { + return url; + } catch (error) { + console.log('Fetch error:', error); + return null; + } +} diff --git a/anilibria/anilibria.json b/anilibria/anilibria.json new file mode 100644 index 0000000..5836cb6 --- /dev/null +++ b/anilibria/anilibria.json @@ -0,0 +1,17 @@ +{ + "sourceName": "AniLibria", + "iconUrl": "https://github.com/50n50/sources/blob/main/anilibria/icon.png?raw=true", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "Russian", + "streamType": "HLS", + "quality": "720p", + "baseUrl": "https://api.anilibria.tv/", + "searchBaseUrl": "https://api.anilibria.tv/v3/title/search?search=%s", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/anilibria/anilibria.js", + "asyncJS": true, + "type": "anime" +} diff --git a/anilibria/icon.png b/anilibria/icon.png new file mode 100644 index 0000000..f12000c Binary files /dev/null and b/anilibria/icon.png differ diff --git a/anilibria/iconalt.png b/anilibria/iconalt.png new file mode 100644 index 0000000..b15e0a8 Binary files /dev/null and b/anilibria/iconalt.png differ diff --git a/anime-sama/anime-sama.js b/anime-sama/anime-sama.js new file mode 100644 index 0000000..bb9645d --- /dev/null +++ b/anime-sama/anime-sama.js @@ -0,0 +1,340 @@ +async function searchResults(keyword) { + const results = []; + const headers = { + "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8", + "X-Requested-With": "XMLHttpRequest", + "referer": "https://anime-sama.fr/" + }; + + const regex = /]+href="([^"]+)"[\s\S]*?]+src="([^"]+)"[\s\S]*?]*>(.*?)<\/h3>/gi; + + try { + const response = await fetchv2( + "https://anime-sama.fr/template-php/defaut/fetch.php", + headers, + "POST", + `query=${encodeURIComponent(keyword)}` + ); + const html = await response.text(); + + 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 regex = /

    (.*?)<\/p>/is; + const match = regex.exec(html); + + const description = match ? match[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 seasonRegex = /panneauAnime\("([^"]+)",\s*"([^"]+)"\);/g; + let match; + + const seasonUrls = []; + while ((match = seasonRegex.exec(html)) !== null) { + const seasonHref = match[2].trim(); + const fullSeasonUrl = url + '/' + seasonHref; + + seasonUrls.push(fullSeasonUrl); + } + + const seasonPromises = seasonUrls.map(seasonUrl => fetchv2(seasonUrl)); + const seasonResponses = await Promise.all(seasonPromises); + + for (let i = 0; i < seasonResponses.length; i++) { + const seasonResponse = seasonResponses[i]; + const seasonHtml = await seasonResponse.text(); + const seasonUrl = seasonUrls[i]; + + const episodeScriptRegex = /]+src=['"]([^'"]*episodes\.js[^'"]*?)['"][^>]*>/; + const scriptMatch = episodeScriptRegex.exec(seasonHtml); + + if (scriptMatch) { + const episodesSrc = scriptMatch[1].trim(); + const fullEpisodesUrl = seasonUrl + '/' + episodesSrc; + + const episodesResponse = await fetchv2(fullEpisodesUrl); + const episodesJs = await episodesResponse.text(); + + let episodeNumber = 1; + + const oneuploadRegex = /'(https:\/\/oneupload\.to\/[^']+)'/g; + let episodeMatch; + let foundEpisodes = false; + + while ((episodeMatch = oneuploadRegex.exec(episodesJs)) !== null) { + const oneuploadUrl = episodeMatch[1].trim(); + results.push({ + href: oneuploadUrl, + number: episodeNumber + }); + episodeNumber++; + foundEpisodes = true; + } + + if (!foundEpisodes) { + episodeNumber = 1; + const sendvidRegex = /'(https:\/\/sendvid\.com\/[^']+)'/g; + + while ((episodeMatch = sendvidRegex.exec(episodesJs)) !== null) { + const sendvidUrl = episodeMatch[1].trim(); + results.push({ + href: sendvidUrl, + number: episodeNumber + }); + episodeNumber++; + foundEpisodes = true; + } + } + + if (!foundEpisodes) { + episodeNumber = 1; + const smoothpreRegex = /'(https:\/\/smoothpre\.com\/[^']+)'/gi; + + while ((episodeMatch = smoothpreRegex.exec(episodesJs)) !== null) { + const smoothpreUrl = episodeMatch[1].trim(); + results.push({ + href: smoothpreUrl, + number: episodeNumber + }); + episodeNumber++; + foundEpisodes = true; + } + } + + if (!foundEpisodes) { + episodeNumber = 1; + const mp4Regex = /'([^']+\.mp4[^']*)'/g; + + while ((episodeMatch = mp4Regex.exec(episodesJs)) !== null) { + const mp4Url = episodeMatch[1].trim(); + results.push({ + href: mp4Url, + number: episodeNumber + }); + episodeNumber++; + foundEpisodes = true; + } + } + + if (!foundEpisodes && seasonUrl.includes('film')) { + episodeNumber = 1; + const allVideoRegex = /'(https:\/\/[^']+\.(mp4|mkv|avi|mov|webm)[^']*)'/gi; + + while ((episodeMatch = allVideoRegex.exec(episodesJs)) !== null) { + const videoUrl = episodeMatch[1].trim(); + results.push({ + href: videoUrl, + number: 1 + }); + foundEpisodes = true; + break; + } + } + } + } + + return JSON.stringify(results); + } catch (err) { + console.error(err); + return JSON.stringify([{ + href: "Error", + number: "Error" + }]); + } +} + +async function extractStreamUrl(url) { + try { + if (/^https?:\/\/smoothpre\.com/i.test(url)) { + const response = await fetchv2(url); + const html = await response.text(); + const obfuscatedScript = html.match(/]*>\s*(eval\(function\(p,a,c,k,e,d.*?\)[\s\S]*?)<\/script>/); + const unpackedScript = unpack(obfuscatedScript[1]); + + const hls2Match = unpackedScript.match(/"hls2"\s*:\s*"([^"]+)"/); + const hls2Url = hls2Match ? hls2Match[1] : null; + + return hls2Url; + } else if (/^https?:\/\/sendvid\.com/i.test(url)) { + const response = await fetchv2(url); + const html = await response.text(); + const match = html.match(/var\s+video_source\s*=\s*"([^"]+)"/); + const videoUrl = match ? match[1] : null; + + return videoUrl; + } else if (/^https?:\/\/oneupload\.to/i.test(url)) { + const response = await fetchv2(url); + const html = await response.text(); + const match = html.match(/sources:\s*\[\{file:"([^"]+)"\}\]/); + const fileUrl = match ? match[1] : null; + + return fileUrl; + } else if (/\.mp4$/i.test(url)) { + + return url; + } else { + return "https://error.org/"; + } + } catch (err) { + return "https://error.org/"; + } +} + +/*********************************************************** + * UNPACKER MODULE + * Credit to GitHub user "mnsrulz" for Unpacker Node library + * https://github.com/mnsrulz/unpacker + ***********************************************************/ +class Unbaser { + constructor(base) { + /* Functor for a given base. Will efficiently convert + strings to natural numbers. */ + this.ALPHABET = { + 62: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", + 95: "' !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'", + }; + this.dictionary = {}; + this.base = base; + // fill elements 37...61, if necessary + if (36 < base && base < 62) { + this.ALPHABET[base] = this.ALPHABET[base] || + this.ALPHABET[62].substr(0, base); + } + // If base can be handled by int() builtin, let it do it for us + if (2 <= base && base <= 36) { + this.unbase = (value) => parseInt(value, base); + } + else { + // Build conversion dictionary cache + try { + [...this.ALPHABET[base]].forEach((cipher, index) => { + this.dictionary[cipher] = index; + }); + } + catch (er) { + throw Error("Unsupported base encoding."); + } + this.unbase = this._dictunbaser; + } + } + _dictunbaser(value) { + /* Decodes a value to an integer. */ + let ret = 0; + [...value].reverse().forEach((cipher, index) => { + ret = ret + ((Math.pow(this.base, index)) * this.dictionary[cipher]); + }); + return ret; + } +} + +function detect(source) { + /* Detects whether `source` is P.A.C.K.E.R. coded. */ + return source.replace(" ", "").startsWith("eval(function(p,a,c,k,e,"); +} + +function unpack(source) { + /* Unpacks P.A.C.K.E.R. packed js code. */ + let { payload, symtab, radix, count } = _filterargs(source); + if (count != symtab.length) { + throw Error("Malformed p.a.c.k.e.r. symtab."); + } + let unbase; + try { + unbase = new Unbaser(radix); + } + catch (e) { + throw Error("Unknown p.a.c.k.e.r. encoding."); + } + function lookup(match) { + /* Look up symbols in the synthetic symtab. */ + const word = match; + let word2; + if (radix == 1) { + //throw Error("symtab unknown"); + word2 = symtab[parseInt(word)]; + } + else { + word2 = symtab[unbase.unbase(word)]; + } + return word2 || word; + } + source = payload.replace(/\b\w+\b/g, lookup); + return _replacestrings(source); + function _filterargs(source) { + /* Juice from a source file the four args needed by decoder. */ + const juicers = [ + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\), *(\d+), *(.*)\)\)/, + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\)/, + ]; + for (const juicer of juicers) { + //const args = re.search(juicer, source, re.DOTALL); + const args = juicer.exec(source); + if (args) { + let a = args; + if (a[2] == "[]") { + //don't know what it is + // a = list(a); + // a[1] = 62; + // a = tuple(a); + } + try { + return { + payload: a[1], + symtab: a[4].split("|"), + radix: parseInt(a[2]), + count: parseInt(a[3]), + }; + } + catch (ValueError) { + throw Error("Corrupted p.a.c.k.e.r. data."); + } + } + } + throw Error("Could not make sense of p.a.c.k.e.r data (unexpected code structure)"); + } + function _replacestrings(source) { + /* Strip string lookup table (list) and replace values in source. */ + /* Need to work on this. */ + return source; + } +} diff --git a/anime-sama/anime-sama.json b/anime-sama/anime-sama.json new file mode 100644 index 0000000..5c909bb --- /dev/null +++ b/anime-sama/anime-sama.json @@ -0,0 +1,19 @@ +{ + "sourceName": "Anime-Sama", + "iconUrl": "https://cdn.statically.io/gh/Anime-Sama/IMG/img/autres/logo_icon.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.1", + "language": "French", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://anime-sama.fr/", + "searchBaseUrl": "https://anime-sama.fr/", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/anime-sama/anime-sama.js", + "type": "anime", + "asyncJS": true, + "softsub": false, + "downloadSupport": false +} diff --git a/anime3rb/anime3rb.js b/anime3rb/anime3rb.js new file mode 100644 index 0000000..485bae1 --- /dev/null +++ b/anime3rb/anime3rb.js @@ -0,0 +1,228 @@ +function searchResults(html) { + if (typeof html !== 'string') { + console.error('Invalid HTML input: expected a string.'); + return []; + } + + const results = []; + + const titleRegex = /]*>(.*?)<\/h4>/; + const hrefRegex = /]*>/; + const imgRegex = /]*src="([^"]+)"[^>]*>/; + + const itemRegex = /]*>[\s\S]*?<\/a>/g; + const items = html.match(itemRegex) || []; + + items.forEach((itemHtml, index) => { + try { + if (typeof itemHtml !== 'string') { + console.error(`Item ${index} is not a string.`); + return; + } + + const titleMatch = itemHtml.match(titleRegex); + const title = titleMatch?.[1]?.trim() ?? ''; + + const hrefMatch = itemHtml.match(hrefRegex); + const href = hrefMatch?.[1]?.trim() ?? ''; + + const imgMatch = itemHtml.match(imgRegex); + const imageUrl = imgMatch?.[1]?.trim() ?? ''; + + if (title && href) { + results.push({ + title: decodeHTMLEntities(title), + image: imageUrl, + href: href + }); + } else { + console.error(`Missing title or href in item ${index}`); + } + } catch (err) { + console.error(`Error processing item ${index}:`, err); + } + }); + + return results; +} + + +function extractDetails(html) { + const details = []; + + const containerMatch = html.match(/

    \s*((?:

    [\s\S]*?<\/p>\s*)+)<\/div>/); + + let description = ""; + if (containerMatch) { + const pBlock = containerMatch[1]; + + const pRegex = /

    ([\s\S]*?)<\/p>/g; + const matches = [...pBlock.matchAll(pRegex)] + .map(m => m[1].trim()) + .filter(text => text.length > 0); + + description = decodeHTMLEntities(matches.join("\n\n")); + } + + const airdateMatch = html.match(/]*title="([^"]+)">[^<]+<\/td>/); + let airdate = airdateMatch ? airdateMatch[1].trim() : ""; + + const genres = []; + const aliasesMatch = html.match( + /([\s\S]*?)<\/div>/ + ); + const inner = aliasesMatch ? aliasesMatch[1] : ""; + + const anchorRe = /]*class="btn btn-md btn-plain !p-0"[^>]*>([^<]+)<\/a>/g; + let m; + while ((m = anchorRe.exec(inner)) !== null) { + genres.push(m[1].trim()); + } + + if (description && airdate) { + details.push({ + description: description, + aliases: genres.join(", "), + airdate: airdate, + }); + } + + console.log(details); + return details; +} + + +function extractEpisodes(html) { + const episodes = []; + const htmlRegex = /]*href="([^"]*?\/episode\/[^"]*?)"[^>]*>[\s\S]*?الحلقة\s+(\d+)[\s\S]*?<\/a>/gi; + const plainTextRegex = /الحلقة\s+(\d+)/g; + + let matches; + + if ((matches = html.match(htmlRegex))) { + matches.forEach(link => { + const hrefMatch = link.match(/href="([^"]+)"/); + const numberMatch = link.match(/الحلقة\s+(\d+)/); + if (hrefMatch && numberMatch) { + const href = hrefMatch[1]; + const number = numberMatch[1]; + episodes.push({ + href: href, + number: number + }); + } + }); + } + else if ((matches = html.match(plainTextRegex))) { + matches.forEach(match => { + const numberMatch = match.match(/\d+/); + if (numberMatch) { + episodes.push({ + href: null, + number: numberMatch[0] + }); + } + }); + } + + console.log(episodes); + return episodes; +} + +async function extractStreamUrl(html) { + try { + const sourceMatch = html.match(/data-video-source="([^"]+)"/); + let embedUrl = sourceMatch?.[1]?.replace(/&/g, '&'); + if (!embedUrl) return null; + + const cinemaMatch = html.match(/url\.searchParams\.append\(\s*['"]cinema['"]\s*,\s*(\d+)\s*\)/); + const lastMatch = html.match(/url\.searchParams\.append\(\s*['"]last['"]\s*,\s*(\d+)\s*\)/); + const cinemaNum = cinemaMatch ? cinemaMatch[1] : undefined; + const lastNum = lastMatch ? lastMatch[1] : undefined; + + if (cinemaNum) embedUrl += `&cinema=${cinemaNum}`; + if (lastNum) embedUrl += `&last=${lastNum}`; + embedUrl += `&next-image=undefined`; + + console.log('Full embed URL:', embedUrl); + + const response = await fetchv2(embedUrl); + const data = await response.text(); + console.log('Embed page HTML:', data); + + const qualities = extractQualities(data); + + const epMatch = html.match(/[^<]*الحلقة\s*(\d+)[^<]*<\/title>/); + const currentEp = epMatch ? Number(epMatch[1]) : null; + + let nextEpNum, nextDuration, nextSubtitle; + if (currentEp !== null) { + const episodeRegex = new RegExp( + `<a[^>]+href="[^"]+/episode/[^/]+/(\\d+)"[\\s\\S]*?` + + `<span[^>]*>([^<]+)<\\/span>[\\s\\S]*?` + + `<p[^>]*>([^<]+)<\\/p>`, + 'g' + ); + let m; + while ((m = episodeRegex.exec(html)) !== null) { + const num = Number(m[1]); + if (num > currentEp) { + nextEpNum = num; + nextDuration = m[2].trim(); + nextSubtitle = m[3].trim(); + break; + } + } + } + + if (nextEpNum != null) { + embedUrl += `&next-title=${encodeURIComponent(nextDuration)}`; + embedUrl += `&next-sub-title=${encodeURIComponent(nextSubtitle)}`; + } + + const result = { + streams: qualities, + } + + console.log(JSON.stringify(result)); + return JSON.stringify(result); + } catch (err) { + console.error(err); + return null; + } +} + +function extractQualities(html) { + const match = html.match(/var\s+videos\s*=\s*(\[[\s\S]*?\]);/); + if (!match) return []; + + const raw = match[1]; + const regex = /\{\s*src:\s*'([^']+)'\s*[^}]*label:\s*'([^']*)'/g; + const list = []; + let m; + + while ((m = regex.exec(raw)) !== null) { + list.push(m[2], m[1]); + } + + return list; +} + + +function decodeHTMLEntities(text) { + text = text.replace(/&#(\d+);/g, (match, dec) => String.fromCharCode(dec)); + + const entities = { + '"': '"', + '&': '&', + ''': "'", + '<': '<', + '>': '>' + }; + + for (const entity in entities) { + text = text.replace(new RegExp(entity, 'g'), entities[entity]); + } + + return text; +} diff --git a/anime3rb/anime3rb.json b/anime3rb/anime3rb.json new file mode 100644 index 0000000..26270ef --- /dev/null +++ b/anime3rb/anime3rb.json @@ -0,0 +1,17 @@ +{ + "sourceName": "Anime3rb", + "iconUrl": "https://anime3rb.com/favicon/apple-touch-icon.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.2.0", + "language": "Arabic (SUB)", + "streamType": "MP4", + "quality": "1080p - 720p - 360p", + "baseUrl": "https://anime3rb.com/", + "searchBaseUrl": "https://anime3rb.com/search?q=%s", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/anime3rb/anime3rb.js", + "streamAsyncJS": true, + "type": "anime" +} diff --git a/anime3rb/iconalt.png b/anime3rb/iconalt.png new file mode 100644 index 0000000..64d7e6e Binary files /dev/null and b/anime3rb/iconalt.png differ diff --git a/anime4up/anime4up.js b/anime4up/anime4up.js new file mode 100644 index 0000000..41ed367 --- /dev/null +++ b/anime4up/anime4up.js @@ -0,0 +1,165 @@ +async function searchResults(keyword) { + const results = []; + try { + const response = await fetchv2( + "https://ww.anime4up.rest/?search_param=animes&s=" + encodeURIComponent(keyword) + ); + const html = await response.text(); + + const regex = /<div class="anime-card-container">[\s\S]*?<img[^>]+src="([^"]+)"[^>]*alt="([^"]*)"[\s\S]*?<h3><a[^>]*href="([^"]+)"[^>]*>([^<]+)<\/a><\/h3>/gi; + + let match; + while ((match = regex.exec(html)) !== null) { + results.push({ + title: match[4].trim(), + image: match[1].trim().replace('ww.anime4up.rest', 'www.anime4up.rest'), + href: match[3].trim().replace('ww.anime4up.rest', 'www.anime4up.rest') + }); + } + + 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 = /<p class="anime-story">([\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 = []; + + try { + const response = await fetchv2(url); + const html = await response.text(); + + const episodeRegex = /<div class="col-lg-3[^"]*DivEpisodeContainer">([\s\S]*?)<\/div>\s*<\/div>/gi; + let match; + let epNumber = 1; + + while ((match = episodeRegex.exec(html)) !== null) { + const hrefMatch = /<h3><a href="([^"]+)"/i.exec(match[1]); + const href = hrefMatch ? hrefMatch[1].trim() : ""; + results.push({ + href: href, + number: epNumber + }); + epNumber++; + } + + const paginationRegex = /<li\s*><a\s+class="page-numbers"\s+href="[^"]*\/page\/(\d+)\/">(\d+)<\/a><\/li>/gi; + let maxPage = 1; + let paginationMatch; + + while ((paginationMatch = paginationRegex.exec(html)) !== null) { + const pageNum = parseInt(paginationMatch[2]); + if (pageNum > maxPage) { + maxPage = pageNum; + } + } + + if (maxPage > 1) { + const pagePromises = []; + + for (let page = 2; page <= maxPage; page++) { + const pageUrl = `${url}/page/${page}/`; + pagePromises.push(fetchPageEpisodes(pageUrl, epNumber + (page - 2) * getEpisodesPerPage(results.length))); + } + + const pageResults = await Promise.all(pagePromises); + + pageResults.forEach(pageEpisodes => { + results.push(...pageEpisodes); + }); + + results.forEach((episode, index) => { + episode.number = index + 1; + }); + } + + return JSON.stringify(results); + + } catch (err) { + return JSON.stringify([{ + href: "Error", + number: "Error" + }]); + } +} + +async function fetchPageEpisodes(pageUrl, startingEpNumber) { + try { + const response = await fetchv2(pageUrl); + const html = await response.text(); + const episodeRegex = /<div class="col-lg-3[^"]*DivEpisodeContainer">([\s\S]*?)<\/div>\s*<\/div>/gi; + const pageResults = []; + let match; + let epNumber = startingEpNumber; + + while ((match = episodeRegex.exec(html)) !== null) { + const hrefMatch = /<h3><a href="([^"]+)"/i.exec(match[1]); + const href = hrefMatch ? hrefMatch[1].trim() : ""; + pageResults.push({ + href: href, + number: epNumber + }); + epNumber++; + } + + return pageResults; + } catch (err) { + return []; + } +} + +function getEpisodesPerPage(firstPageCount) { + return firstPageCount || 12; +} + +async function extractStreamUrl(url) { + try { + const response = await fetchv2(url); + const html = await response.text(); + + const match = /<a[^>]+data-ep-url="([^"]*uqload\.cx[^"]*)"/i.exec(html); + if (match) { + console.log(match[1].trim()); + const response2 = await fetchv2(match[1].trim()); + const html2 = await response2.text(); + + const match2 = /sources:\s*\[\s*"([^"]+)"\s*\]/i.exec(html2); + const url = match2 ? match2[1] : null; + + + return url; + } + + return "dwd"; + } catch (err) { + console.error(err); + return "https://files.catbox.moe/avolvc.mp4"; + } +} diff --git a/anime4up/anime4up.json b/anime4up/anime4up.json new file mode 100644 index 0000000..c414779 --- /dev/null +++ b/anime4up/anime4up.json @@ -0,0 +1,20 @@ +{ + "sourceName": "Anime4Up", + "iconUrl": "https://ww.anime4up.rest/wp-content/uploads/2019/03/Anime4up-Icon-1.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.1", + "language": "Arabic", + "streamType": "HLS", + "encrypted":true, + "quality": "1080p", + "baseUrl": "https://uqload.cx/", + "searchBaseUrl": "https://uqload.cx/", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/anime4up/anime4up.js", + "type": "anime", + "asyncJS": true, + "softsub": false, + "downloadSupport": true +} diff --git a/animeav1/animeav1.js b/animeav1/animeav1.js new file mode 100644 index 0000000..a2a4bfe --- /dev/null +++ b/animeav1/animeav1.js @@ -0,0 +1,94 @@ +async function searchResults(keyword) { + const results = []; + try { + const response = await fetchv2("https://animeav1.com/catalogo?search=" + encodeURIComponent(keyword)); + const html = await response.text(); + console.log(html); + + const regex = /<article[^>]*class="group\/item[^"]*"[^>]*>[\s\S]*?<img[^>]+src="([^"]+)"[^>]*alt="[^"]*"[^>]*>[\s\S]*?<h3[^>]*class="[^"]*text-lead[^"]*">([^<]+)<\/h3>[\s\S]*?<a[^>]+href="([^"]+)"/g; + + let match; + while ((match = regex.exec(html)) !== null) { + results.push({ + title: match[2].trim(), + image: match[1].trim(), + href: "https://animeav1.com" + match[3].trim() + }); + } + + return JSON.stringify(results); + } catch (err) { + console.error("Search error:", 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 match = html.match(/<div class="entry[^>]*>\s*<p>([\s\S]*?)<\/p>\s*<\/div>/); + const description = match ? match[1].trim() : "N/A"; + + return JSON.stringify([{ + 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="([^"]+\/(\d+))"[^>]*>\s*<span class="sr-only">/g; + let match; + + while ((match = regex.exec(html)) !== null) { + results.push({ + href: "https://animeav1.com" + 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 { + const response = await fetchv2(url); + const html = await response.text(); + + const match = html.match(/url:"(https:\/\/player\.zilla-networks\.com\/play\/[^"]+)"/i); + if (match) { + return match[1].replace("/play/", "/m3u8/"); + } + + return "https://files.catbox.moe/avolvc.mp4"; + } catch (err) { + return "https://files.catbox.moe/avolvc.mp4"; + } +} + + + diff --git a/animeav1/animeav1.json b/animeav1/animeav1.json new file mode 100644 index 0000000..de28a20 --- /dev/null +++ b/animeav1/animeav1.json @@ -0,0 +1,20 @@ +{ + "sourceName": "AnimeAV1", + "iconUrl": "https://animeav1.com/favicon.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.1", + "language": "Spanish", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://animeav1.com/", + "searchBaseUrl": "https://animeav1.com/search?q=%s", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/animeav1/animeav1.js", + "type": "anime", + "asyncJS": true, + "softsub": true, + "downloadSupport": false, + "note": "Use external player." +} diff --git a/animebalkan/animebalkan.js b/animebalkan/animebalkan.js new file mode 100644 index 0000000..37c7558 --- /dev/null +++ b/animebalkan/animebalkan.js @@ -0,0 +1,111 @@ +function preprocessHtml(html) { + //Module specefic, ignore + return html.replace(/\\2605/g, '★'); +} + +function searchResults(html) { + html = preprocessHtml(html); + const results = []; + const baseUrl = "https://animebalkan.org/"; + + const filmListRegex = /<article class="bs"[\s\S]*?<\/article>/g; + const items = html.match(filmListRegex) || []; + + items.forEach((itemHtml) => { + const titleMatch = itemHtml.match(/<h2 itemprop="headline">([^<]+)<\/h2>/); + const hrefMatch = itemHtml.match(/<a[^>]+href="([^"]+)"[^>]*>/); + const imgMatch = itemHtml.match(/<img[^>]+src="([^"]+)"[^>]*>/); + + let title = titleMatch ? titleMatch[1].trim().replace(/–/g, '–') : ''; + const href = hrefMatch ? hrefMatch[1].trim() : ''; + const imageUrl = imgMatch ? imgMatch[1].trim() : ''; + + if (title && href) { + results.push({ + title, + image: imageUrl.startsWith('http') ? imageUrl : baseUrl + imageUrl, + href + }); + } + }); + + return results; +} + + +function extractDetails(html) { + const details = []; + const descriptionMatch = html.match(/<span class="Y2IQFc"[^>]*>([\s\S]*?)<\/span>/); + const airdateMatch = html.match(/<time[^>]*datetime="([^"]+)"/); + + if (descriptionMatch) { + let description = descriptionMatch[1].trim() + .replace(/–/g, '-') + .replace(/—/g, '—') + .replace(/“/g, '"') + .replace(/”/g, '"') + .replace(/…/g, '...') + .replace(/″/g, '"') + .replace(/′/g, "'"); + + let airdate = airdateMatch ? airdateMatch[1].split('T')[0] : ''; + + if (description && airdate) { + details.push({ + description: description, + aliases: 'N/A', + airdate: airdate + }); + } + } + + return details; +} + +function extractEpisodes(html) { + const episodes = []; + const episodeRegex = /<a href="([^"]+)">[^<]*<div class="epl-num">([^<]+)<\/div>/g; + + let match; + while ((match = episodeRegex.exec(html)) !== null) { + const href = match[1]; + let number = match[2]; + + const isMovie = href.includes('film') || + href.includes('movie') || + number.toLowerCase() === 'film'; + + if (isMovie) { + number = '1'; + } + + if (href.includes('epizoda-') || + href.includes('specijalna-epizoda') || + href.includes('-epizoda/') || + href.includes('film') || + href.includes('movie')) { + + episodes.push({ + href: href, + number: number + }); + } + } + + episodes.reverse(); + console.log(episodes); + return episodes; +} + +function extractStreamUrl(html) { + const sourceRegex = /<source\s+[^>]*src="([^"]+)"/; + const match = html.match(sourceRegex); + + if (match) { + console.log(match[1]); + return match[1]; + } else { + console.log("No stream URL found."); + return null; + } +} diff --git a/animebalkan/animebalkan.json b/animebalkan/animebalkan.json new file mode 100644 index 0000000..f665506 --- /dev/null +++ b/animebalkan/animebalkan.json @@ -0,0 +1,16 @@ +{ + "sourceName": "AnimeBalkan", + "iconUrl": "https://i.ibb.co/7tRnVMqY/favicon.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "Croatian", + "streamType": "MP4", + "quality": "720p", + "baseUrl": "https://animebalkan.org//", + "searchBaseUrl": "https://animebalkan.org/?s=%s", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/animebalkan/animebalkan.js", + "type": "anime" +} diff --git a/animebalkan/iconalt.png b/animebalkan/iconalt.png new file mode 100644 index 0000000..071e65b Binary files /dev/null and b/animebalkan/iconalt.png differ diff --git a/animebum/animebum.js b/animebum/animebum.js new file mode 100644 index 0000000..80bb605 --- /dev/null +++ b/animebum/animebum.js @@ -0,0 +1,364 @@ +async function searchResults(keyword) { + const results = []; + try { + const response = await fetchv2("https://www.animebum.net/search?s=" + encodeURIComponent(keyword)); + const html = await response.text(); + + const regex = /<div class="search-results__item[^>]*>[\s\S]*?<a href="([^"]+)"[^>]*><img src="([^"]+)"[^>]*><\/a>[\s\S]*?<h2>([^<]+)<\/h2>/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 regex = /<div class="description scrollV">\s*<p>([\s\S]*?)<\/p>/i; + const match = regex.exec(html); + let description = match ? match[1].trim() : "N/A"; + + description = description.replace(/<[^>]+>/g, ""); + description = description.replace(/&/g, "&") + .replace(/</g, "<") + .replace(/>/g, ">") + .replace(/"/g, '"') + .replace(/'/g, "'") + .replace(/á/g, "á") + .replace(/é/g, "é") + .replace(/í/g, "í") + .replace(/ó/g, "ó") + .replace(/ú/g, "ú") + .replace(/ñ/g, "ñ") + .replace(/ü/g, "ü") + .replace(/“/g, "“") + .replace(/”/g, "”") + .replace(/‘/g, "‘") + .replace(/’/g, "’") + .replace(/¡/g, "¡") + .replace(/¿/g, "¿"); + + + 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 containerMatch = html.match( + /<div class="list-episodies-content">([\s\S]*?)<\/div>/ + ); + + if (!containerMatch) { + return JSON.stringify([{ href: "Not found", number: "N/A" }]); + } + + const containerHtml = containerMatch[1]; + + const regex = /<a[^>]+href="([^"]+)"[^>]*>[\s\S]*?Episodio\s+(\d+)\s*<\/a>/gi; + + let match; + while ((match = regex.exec(containerHtml)) !== 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 { + const response = await fetchv2(url); + const html = await response.text(); + + // Try Filemoon first + const filemoonRegex = /(https:\/\/filemoon\.(?:to|sx)\/e\/[A-Za-z0-9]+\/[^\s"']+)/; + const filemoonMatch = filemoonRegex.exec(html); + + if (filemoonMatch) { + const filemoon = filemoonMatch[1]; + console.log("Filemoon URL found: " + filemoon); + + const headers = { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3", + "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", + "Referer": "https://animebum.net/", + }; + + const filemoonResponse = await fetchv2(filemoon, headers); + const filemoonHtml = await filemoonResponse.text(); + + try { + const streamUrl = await filemoonExtractor(filemoonHtml, "https://animebum.net/"); + if (streamUrl) return streamUrl; + } catch (err) { + console.log("Filemoon extraction error:" + err); + } + } + + const optionRegex = /<ul class="play-list-tabs">([\s\S]*?)<\/ul>/i; + const optionMatch = optionRegex.exec(html); + if (!optionMatch) return null; + + const optionsHtml = optionMatch[1]; + const faireMatch = /<li[^>]*data-id="(\d+)"[^>]*>\s*<a[^>]*title="Faire"/i.exec(optionsHtml); + if (!faireMatch) return null; + + const faireId = parseInt(faireMatch[1], 10); + const videoRegex = new RegExp(`video\\[${faireId}\\]\\s*=\\s*'([^']+)'`); + const videoMatch = videoRegex.exec(html); + if (!videoMatch) return null; + + const iframeHtml = videoMatch[1]; + const srcMatch = /src=["']([^"']+)["']/.exec(iframeHtml); + const streamUrl = srcMatch ? srcMatch[1] : null; + + const responeSome = await fetchv2(streamUrl); + const htmlSome = await responeSome.text(); + + const shareIdMatch = htmlSome.match(/var\s+shareId\s*=\s*"([^"]+)"/); + if (!shareIdMatch) return null; + const shareId = shareIdMatch[1]; + const someUrl = `https://www.amazon.com/drive/v1/shares/${shareId}?resourceVersion=V2&ContentType=JSON&asset=ALL`; + + const shareJsonResp = await fetchv2(someUrl); + const shareJson = await shareJsonResp.json(); + console.log(JSON.stringify(shareJson)); + const nodeId = shareJson.nodeInfo?.id; + if (!nodeId) return null; + + const childrenUrl = `https://www.amazon.com/drive/v1/nodes/${nodeId}/children?resourceVersion=V2&ContentType=JSON&limit=200&sort=%5B%22kind+DESC%22%2C+%22modifiedDate+DESC%22%5D&asset=ALL&tempLink=true&shareId=${shareId}`; + const childrenResp = await fetchv2(childrenUrl); + const childrenData = await childrenResp.json(); + console.log(JSON.stringify(childrenData)); + + const file = childrenData.data.find(item => item.kind === "FILE"); + if (!file) return null; + + return file.tempLink; + + } catch (err) { + console.log("Fetch error:" + err); + return "https://error.org/"; + } +} + + +/* SCHEME START */ +/* {REQUIRED PLUGINS: unbaser} */ + +/** + * @name filemoonExtractor + * @author Cufiy - Inspired by Churly + */ + +async function filemoonExtractor(html, url = null) { + // check if contains iframe, if does, extract the src and get the url + const regex = /<iframe[^>]+src="([^"]+)"[^>]*><\/iframe>/; + const match = html.match(regex); + if (match) { + console.log("Iframe URL: " + match[1]); + const iframeUrl = match[1]; + const iframeResponse = await soraFetch(iframeUrl, { + headers: { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3", + "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", + "Referer": url, + } + }); + console.log("Iframe Response: " + iframeResponse.status); + html = await iframeResponse.text(); + } + // console.log("HTML: " + html); + // get /<script[^>]*>([\s\S]*?)<\/script>/gi + const scriptRegex = /<script[^>]*>([\s\S]*?)<\/script>/gi; + const scripts = []; + let scriptMatch; + while ((scriptMatch = scriptRegex.exec(html)) !== null) { + scripts.push(scriptMatch[1]); + } + // get the script with eval and m3u8 + const evalRegex = /eval\((.*?)\)/; + const m3u8Regex = /m3u8/; + // console.log("Scripts: " + scripts); + const evalScript = scripts.find(script => evalRegex.test(script) && m3u8Regex.test(script)); + if (!evalScript) { + console.log("No eval script found"); + return null; + } + const unpackedScript = unpack(evalScript); + // get the m3u8 url + const m3u8Regex2 = /https?:\/\/[^\s]+master\.m3u8[^\s]*?(\?[^"]*)?/; + const m3u8Match = unpackedScript.match(m3u8Regex2); + if (m3u8Match) { + return m3u8Match[0]; + } else { + console.log("No M3U8 URL found"); + return null; + } +} + + +/* REMOVE_START */ + + +class Unbaser { + constructor(base) { + this.ALPHABET = { + 62: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", + 95: "' !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'", + }; + this.dictionary = {}; + this.base = base; + if (36 < base && base < 62) { + this.ALPHABET[base] = this.ALPHABET[base] || + this.ALPHABET[62].substr(0, base); + } + if (2 <= base && base <= 36) { + this.unbase = (value) => parseInt(value, base); + } + else { + try { + [...this.ALPHABET[base]].forEach((cipher, index) => { + this.dictionary[cipher] = index; + }); + } + catch (er) { + throw Error("Unsupported base encoding."); + } + this.unbase = this._dictunbaser; + } + } + _dictunbaser(value) { + let ret = 0; + [...value].reverse().forEach((cipher, index) => { + ret = ret + ((Math.pow(this.base, index)) * this.dictionary[cipher]); + }); + return ret; + } +} + + +function unpack(source) { + let { payload, symtab, radix, count } = _filterargs(source); + if (count != symtab.length) { + throw Error("Malformed p.a.c.k.e.r. symtab."); + } + let unbase; + try { + unbase = new Unbaser(radix); + } + catch (e) { + throw Error("Unknown p.a.c.k.e.r. encoding."); + } + function lookup(match) { + const word = match; + let word2; + if (radix == 1) { + word2 = symtab[parseInt(word)]; + } + else { + word2 = symtab[unbase.unbase(word)]; + } + return word2 || word; + } + source = payload.replace(/\b\w+\b/g, lookup); + return _replacestrings(source); + function _filterargs(source) { + const juicers = [ + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\), *(\d+), *(.*)\)\)/, + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\)/, + ]; + for (const juicer of juicers) { + const args = juicer.exec(source); + if (args) { + let a = args; + if (a[2] == "[]") { + } + try { + return { + payload: a[1], + symtab: a[4].split("|"), + radix: parseInt(a[2]), + count: parseInt(a[3]), + }; + } + catch (ValueError) { + throw Error("Corrupted p.a.c.k.e.r. data."); + } + } + } + throw Error("Could not make sense of p.a.c.k.e.r data (unexpected code structure)"); + } + function _replacestrings(source) { + return source; + } +} + + +/** + * Uses Sora's fetchv2 on ipad, fallbacks to regular fetch on Windows + * @author ShadeOfChaos + * + * @param {string} url The URL to make the request to. + * @param {object} [options] The options to use for the request. + * @param {object} [options.headers] The headers to send with the request. + * @param {string} [options.method='GET'] The method to use for the request. + * @param {string} [options.body=null] The body of the request. + * + * @returns {Promise<Response|null>} The response from the server, or null if the + * request failed. + */ +async function soraFetch(url, options = { headers: {}, method: 'GET', body: null }) { + try { + return await fetchv2(url, options.headers ?? {}, options.method ?? 'GET', options.body ?? null); + } catch(e) { + try { + return await fetch(url, options); + } catch(error) { + return null; + } + } +} +/* REMOVE_END */ + +/* SCHEME END */ + + + diff --git a/animebum/animebum.json b/animebum/animebum.json new file mode 100644 index 0000000..9d5b184 --- /dev/null +++ b/animebum/animebum.json @@ -0,0 +1,19 @@ +{ + "sourceName": "AnimeBum", + "iconUrl": "https://files.catbox.moe/i96cs1.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "Spanish (DUB/SUB)", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://www.animebum.net/", + "searchBaseUrl": "https://www.animebum.net/", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/animebum/animebum.js", + "type": "Anime", + "asyncJS": true, + "softsub": false, + "downloadSupport": false +} diff --git a/animedefenders/animedefenders.js b/animedefenders/animedefenders.js new file mode 100644 index 0000000..b825765 --- /dev/null +++ b/animedefenders/animedefenders.js @@ -0,0 +1,113 @@ +async function searchResults(keyword) { + const results = []; + try { + const response = await fetchv2("https://animedefenders.me/view/?wd=" + encodeURIComponent(keyword)); + const html = await response.text(); + + const regex = /<a class="vod-item-img shining" href="(.*?)">[\s\S]*?data-original="(.*?)"[\s\S]*?<h3 class="vod-item-title.*?"><a href=".*?">(.*?)<\/a><\/h3>/g; + let match; + while ((match = regex.exec(html)) !== null) { + results.push({ + title: match[3].trim(), + image: match[2].trim(), + href: "https://animedefenders.me" + 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 descriptionRegex = /<div class="detail-desc-content layout-box">\s*<p>(.*?)<\/p>\s*<\/div>/s; + const match = html.match(descriptionRegex); + + let description = "N/A"; + if (match && match[1]) { + description = match[1] + .replace(/<br\s*\/?>/gi, ' ') + .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 regex = /<a class="text-overflow ep" href="([^"]+)">(\d+)<\/a>/g; + let match; + + while ((match = regex.exec(html)) !== null) { + results.push({ + href: "https://animedefenders.me" + match[1].trim(), + number: parseInt(match[2], 10) + }); + } + + return JSON.stringify(results.reverse()); + } catch (err) { + return JSON.stringify([{ + href: "Error", + number: "Error" + }]); + } +} + +async function extractStreamUrl(url) { + try { + const response = await fetchv2(url); + const html = await response.text(); + + const subUrlRegex = /data-url="(https:\/\/ee\.anih1\.top\/bb\/sub[^"]+)"/; + const match = html.match(subUrlRegex); + + if (match && match[1]) { + const subUrl = match[1]; + const headers = { + "Referer": "https://ee.anih1.top", + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36" + }; + + const subResponse = await fetchv2(subUrl, headers); + const subHtml = await subResponse.text(); + + const artplayerRegex = /url:\s*'([^']+\.m3u8)'/; + const artMatch = subHtml.match(artplayerRegex); + + if (artMatch && artMatch[1]) { + return artMatch[1]; + } + } + console.log("No stream URL found"); + return "https://error.org/"; + } catch (err) { + return "https://error.org/"; + } +} diff --git a/animedefenders/animedefenders.json b/animedefenders/animedefenders.json new file mode 100644 index 0000000..1bea437 --- /dev/null +++ b/animedefenders/animedefenders.json @@ -0,0 +1,19 @@ +{ + "sourceName": "AnimeDefenders", + "iconUrl": "https://cdn.jsdelivr.net/gh/756751uosmaqy/vjplayer@main/2fcbd487e5cacb41cbe7802d5ccfc0dc.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "English (SUB)", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://ee.anih1.top", + "searchBaseUrl": "https://ee.anih1.top", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/animedefenders/animedefenders.js", + "type": "anime", + "asyncJS": true, + "softsub": false, + "downloadSupport": false +} diff --git a/animeepisodeseries/animeepisodeseries.js b/animeepisodeseries/animeepisodeseries.js new file mode 100644 index 0000000..1d652ab --- /dev/null +++ b/animeepisodeseries/animeepisodeseries.js @@ -0,0 +1,139 @@ +async function searchResults(keyword) { + const results = []; + try { + const response = await fetchv2("https://animeepisodeseries.com/?s=" + encodeURIComponent(keyword)); + const html = await response.text(); + + const regex = /<a href="([^"]+)"[^>]*>\s*<img[^>]+src="([^"]+)"[^>]*>[\s\S]*?<h2 class="entry-title"><a [^>]+>([^<]+)<\/a><\/h2>/g; + + let match; + while ((match = regex.exec(html)) !== null) { + results.push({ + title: cleanTitle(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 match = html.match(/<p><strong[\s\S]*?>[\s\S]*?Summary:[\s\S]*?<\/strong><br\s*\/?>(.*?)<\/p>/i); + const description = match ? match[1].trim() : "N/A"; + + return JSON.stringify([{ + description: cleanTitle(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 gridMatch = html.match(/<div[^>]+class="[^"]*eael-post-grid[^"]*"[^>]*>([\s\S]*?)<\/div>\s*<div[^>]+class="clearfix">/i); + + + const gridHtml = gridMatch[1]; + + const patterns = [ + /<a[^>]+href="([^"]*?-episode-(\d+)-[^"]*)"/gi, + /<a[^>]+href="([^"]*?-episode-(\d+)(?:-[^"]*)?\/?)"/gi, + /<a[^>]+href="([^"]*?episode(\d+)[^"]*)"/gi, + /<a[^>]+href="([^"]*?ep(\d+)[^"]*)"/gi + ]; + + for (const regex of patterns) { + let match; + while ((match = regex.exec(gridHtml)) !== null) { + const episodeNumber = parseInt(match[2], 10); + + if (!results.find(r => r.number === episodeNumber && r.href === match[1].trim())) { + results.push({ + href: match[1].trim(), + number: episodeNumber + }); + } + } + } + + if (results.length === 0) { + const linkRegex = /<a[^>]+href="([^"]+)"[^>]*title="[^"]*episode[^"]*(\d+)[^"]*"/gi; + let match; + while ((match = linkRegex.exec(gridHtml)) !== null) { + results.push({ + href: match[1].trim(), + number: parseInt(match[2], 10) + }); + } + } + + const uniqueResults = results.reduce((acc, current) => { + const existing = acc.find(item => item.number === current.number); + if (!existing) { + acc.push(current); + } + return acc; + }, []); + + uniqueResults.sort((a, b) => a.number - b.number); + + return JSON.stringify(uniqueResults); + + } catch (err) { + console.error("Error in extractEpisodes:", 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 match = html.match(/<iframe[^>]+src="(https:\/\/www\.4shared\.com\/web\/embed\/file\/[^"]+)"/i); + const video = match ? match[1].trim() : null; + + const response2 = await fetchv2(video); + const html2 = await response2.text(); + + const match2 = html2.match(/<source[^>]+src="([^"]+)"[^>]*type="video\/mp4"/i); + + return match2 ? match2[1].trim() : "dwa"; + } catch (err) { + return "https://files.catbox.moe/avolvc.mp4"; + } +} + +function cleanTitle(title) { + return title + .replace(/’/g, "'") + .replace(/–/g, "-") + .replace(/&#[0-9]+;/g, ""); +} + diff --git a/animeepisodeseries/animeepisodeseries.json b/animeepisodeseries/animeepisodeseries.json new file mode 100644 index 0000000..0481efe --- /dev/null +++ b/animeepisodeseries/animeepisodeseries.json @@ -0,0 +1,20 @@ +{ + "sourceName": "AnimeEpisodeSeries", + "iconUrl": "https://animeepisodeseries.com/wp-content/uploads/2019/10/cropped-anime-episode-1-192x192.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "English (DUB/SUB)", + "streamType": "mp4", + "quality": "1080p", + "baseUrl": "hhttps://animeepisodeseries.com/", + "searchBaseUrl": "https://animeepisodeseries.com/", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/animeepisodeseries/animeepisodeseries.js", + "type": "anime", + "asyncJS": true, + "softsub": false, + "downloadSupport": true, + "note": "Use external player." +} diff --git a/animefhd/animefhd.js b/animefhd/animefhd.js new file mode 100644 index 0000000..56ebd2e --- /dev/null +++ b/animefhd/animefhd.js @@ -0,0 +1,100 @@ +async function searchResults(keyword) { + const results = []; + const response = await fetchv2("https://animefhd.com/?s=" + encodeURIComponent(keyword)); + const html = await response.text(); + const filmListRegex = /<div class="ultAnisContainerItem">[\s\S]*?<\/div>\s*<\/div>/g; + const items = html.match(filmListRegex) || []; + + items.forEach((itemHtml) => { + const titleMatch = itemHtml.match(/<a href="([^"]+)"[^>]*title="([^"]+)"/); + const href = titleMatch ? titleMatch[1] : ''; + const title = titleMatch ? titleMatch[2] : ''; + const imgMatch = itemHtml.match(/<img[^>]*src="([^"]+)"[^>]*>/); + const imageUrl = imgMatch ? imgMatch[1] : ''; + + if (title && href) { + results.push({ + title: title.trim(), + image: imageUrl.trim(), + href: href.trim(), + }); + } + }); + + console.log(results); + return JSON.stringify(results); +} + +async function extractDetails(url) { + const details = []; + const response = await fetchv2(url); + const html = await response.text(); + const descriptionMatch = html.match(/<b>Sinopse:<\/b>\s*<p>\s*([\s\S]*?)\s*<\/p>/); + let description = descriptionMatch ? descriptionMatch[1].trim() : 'N/A'; + + const airdateMatch = html.match(/<b>Ano:<\/b>\s*(\d{4})/); + let airdate = airdateMatch ? airdateMatch[1].trim() : 'N/A'; + + const episodesMatch = html.match(/<b>Episódios:<\/b>\s*(\d+)/); + let aliases = episodesMatch ? episodesMatch[1].trim() : 'N/A'; + + details.push({ + description: description, + alias: "Episódios: " + aliases, + airdate: airdate + }); + + console.log(details); + return JSON.stringify(details); +} + +async function extractEpisodes(url) { + const episodes = []; + const response = await fetchv2(url); + const html = await response.text(); + const episodeMatches = html.match(/<a href="([^"]+)"[^>]*class="list-epi"[^>]*>Episódio (\d+)<\/a>/g); + + if (episodeMatches) { + episodeMatches.forEach(match => { + const hrefMatch = match.match(/href="([^"]+)"/); + const numberMatch = match.match(/Episódio (\d+)/); + + if (hrefMatch && numberMatch) { + episodes.push({ + href: hrefMatch[1], + number: parseInt(numberMatch[1]) + }); + } + }); + } + + console.log(JSON.stringify(episodes)); + return JSON.stringify(episodes); +} + +async function extractStreamUrl(url) { + const response = await fetchv2(url); + const html = await response.text(); + const iframeMatch = html.match(/<iframe[^>]*src="([^"]+)"/); + + if (iframeMatch) { + const streamUrl = iframeMatch[1]; + console.log(streamUrl); + const response = await fetch(streamUrl); + const newHtml = await response; + + const m3u8Match = newHtml.match(/file:\s*'([^']+\.m3u8)'/); + + if (m3u8Match) { + const videoUrl = m3u8Match[1]; + console.log(videoUrl); + return videoUrl; + } else { + console.log("No m3u8 URL found."); + return null; + } + } else { + console.log("No iframe found."); + return null; + } +} diff --git a/animefhd/animefhd.json b/animefhd/animefhd.json new file mode 100644 index 0000000..61a1d14 --- /dev/null +++ b/animefhd/animefhd.json @@ -0,0 +1,17 @@ +{ + "sourceName": "AnimeFHD", + "iconUrl": "https://animefhd.net/wp-content/uploads/2024/12/270.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.2", + "language": "Portuguese (SUB)", + "streamType": "MP4", + "quality": "1080p", + "baseUrl": "https://animefhd.net/", + "searchBaseUrl": "https://animefhd.net/?s=%s", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/animefhd/animefhd.js", + "asyncJS": true, + "type": "anime" +} diff --git a/animeheaven/animeheaven.js b/animeheaven/animeheaven.js new file mode 100644 index 0000000..0d6c4a0 --- /dev/null +++ b/animeheaven/animeheaven.js @@ -0,0 +1,126 @@ +function cleanTitle(title) { + return title + .replace(/’/g, "'") + .replace(/–/g, "-") + .replace(/&#[0-9]+;/g, ""); +} + +async function searchResults(keyword) { + const url = `https://animeheaven.me/fastsearch.php?xhr=1&s=${encodeURIComponent(keyword)}`; + const response = await soraFetch(url); + const html = await response.text(); + const results = []; + + const itemRegex = /<a class='ac' href='([^']+)'>[\s\S]*?<img class='coverimg' src='([^']+)' alt='[^']*'>[\s\S]*?<div class='fastname'>([^<]+)<\/div>/g; + let match; + + while ((match = itemRegex.exec(html)) !== null) { + const href = `https://animeheaven.me${match[1]}`; + const image = `https://animeheaven.me${match[2]}`; + const rawTitle = match[3].trim(); + const title = cleanTitle(rawTitle); + + results.push({ title, image, href }); + } + + console.log(results); + return JSON.stringify(results); +} + +async function extractDetails(url) { + const response = await soraFetch(url); + const html = await response.text(); + const details = []; + + const descriptionMatch = html.match(/<div class='infodes c'>([^<]+)<\/div>/); + let description = descriptionMatch ? descriptionMatch[1] : ''; + + const aliasesMatch = html.match(/<div class='infotitle c'>([^<]+)<\/div>/); + let aliases = aliasesMatch ? aliasesMatch[1] : ''; + + const airdateMatch = html.match(/Year: <div class='inline c2'>([^<]+)<\/div>/); + let airdate = airdateMatch ? airdateMatch[1] : ''; + + if (description && airdate) { + details.push({ + description: description, + aliases: aliases || 'N/A', + airdate: airdate + }); + } + + console.log(details); + return JSON.stringify(details); +} + +async function extractEpisodes(url) { + const response = await soraFetch(url); + const html = await response.text(); + const episodes = []; + + const episodeRegex = /<a[^>]+id="([^"]+)"[^>]*>[\s\S]*?<div class='watch2 bc'[^>]*>(\d+)<\/div>/g; + + let match; + while ((match = episodeRegex.exec(html)) !== null) { + const id = match[1]; + const number = parseInt(match[2], 10); + + if (!isNaN(number)) { + episodes.push({ + href: id, + number: number + }); + } + } + + episodes.reverse(); + + console.log(episodes); + return JSON.stringify(episodes); +} + +async function extractStreamUrl(id) { + if (!_0xCheck()) return 'https://files.catbox.moe/avolvc.mp4'; + + const cookieHeader = `key=${id}`; + const headers = { + Cookie: cookieHeader + }; + + const response = await soraFetch(`https://animeheaven.me/gate.php`, { headers }); + const html = await response.text(); + + const sourceRegex = /<source\s+src=['"]([^"']+\.mp4\?[^"']*)['"]\s+type=['"]video\/mp4['"]/i; + const match = html.match(sourceRegex); + + if (match) { + const streamUrl = match[1].replace(/&/g, '&'); + console.log("Extracted stream URL:", streamUrl); + return streamUrl; + } else { + console.error("Stream URL not found."); + return ""; + } +} + +async function soraFetch(url, options = { headers: {}, method: 'GET', body: null }) { + try { + return await fetchv2(url, options.headers ?? {}, options.method ?? 'GET', options.body ?? null); + } catch(e) { + try { + return await fetch(url, options); + } catch(error) { + return null; + } + } +} + +function _0xCheck() { + var _0x1a = typeof _0xB4F2 === 'function'; + var _0x2b = typeof _0x7E9A === 'function'; + return _0x1a && _0x2b ? (function(_0x3c) { + return _0x7E9A(_0x3c); + })(_0xB4F2()) : !1; +} + +function _0x7E9A(_){return((___,____,_____,______,_______,________,_________,__________,___________,____________)=>(____=typeof ___,_____=___&&___[String.fromCharCode(...[108,101,110,103,116,104])],______=[...String.fromCharCode(...[99,114,97,110,99,105])],_______=___?[...___[String.fromCharCode(...[116,111,76,111,119,101,114,67,97,115,101])]()]:[],(________=______[String.fromCharCode(...[115,108,105,99,101])]())&&_______[String.fromCharCode(...[102,111,114,69,97,99,104])]((_________,__________)=>(___________=________[String.fromCharCode(...[105,110,100,101,120,79,102])](_________))>=0&&________[String.fromCharCode(...[115,112,108,105,99,101])](___________,1)),____===String.fromCharCode(...[115,116,114,105,110,103])&&_____===16&&________[String.fromCharCode(...[108,101,110,103,116,104])]===0))(_)} diff --git a/animeheaven/animeheaven.json b/animeheaven/animeheaven.json new file mode 100644 index 0000000..19feeb5 --- /dev/null +++ b/animeheaven/animeheaven.json @@ -0,0 +1,18 @@ +{ + "sourceName": "AnimeHeaven", + "iconUrl": "https://animeheaven.me/ah_logo.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.5", + "language": "English (SUB)", + "streamType": "HLS", + "quality": "720p", + "baseUrl": "https://animeheaven.me/", + "searchBaseUrl": "https://animeheaven.me/search.php?s=%s", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/animeheaven/animeheaven.js", + "type": "anime", + "asyncJS": true, + "note": "Website was recently hit by a DMCA, so not everything might work right away, please give them time to reupload anime!" +} diff --git a/animeheaven/iconalt.png b/animeheaven/iconalt.png new file mode 100644 index 0000000..ec467b1 Binary files /dev/null and b/animeheaven/iconalt.png differ diff --git a/animekai/dub/animekai.js b/animekai/dub/animekai.js new file mode 100644 index 0000000..134a469 --- /dev/null +++ b/animekai/dub/animekai.js @@ -0,0 +1,307 @@ +async function searchResults(query) { + const encodeQuery = keyword => encodeURIComponent(keyword); + const searchBaseUrl = "https://animekai.to/browser?keyword="; + const baseUrl = "https://animekai.to"; + + const posterHrefRegex = /href="[^"]*" class="poster"/g; + const titleRegex = /class="title"[^>]*title="[^"]*"/g; + const imageRegex = /data-src="[^"]*"/g; + const extractHrefRegex = /href="([^"]*)"/; + const extractImageRegex = /data-src="([^"]*)"/; + const extractTitleRegex = /title="([^"]*)"/; + + try { + const encodedQuery = encodeQuery(query); + const searchUrl = searchBaseUrl + encodedQuery; + const response = await fetchv2(searchUrl); + const htmlText = await response.text(); + + const results = []; + const posterMatches = htmlText.match(posterHrefRegex) || []; + const titleMatches = htmlText.match(titleRegex) || []; + const imageMatches = htmlText.match(imageRegex) || []; + + const minLength = Math.min(posterMatches.length, titleMatches.length, imageMatches.length); + + for (let index = 0; index < minLength; index++) { + const hrefMatch = posterMatches[index].match(extractHrefRegex); + const fullHref = hrefMatch ? + (hrefMatch[1].startsWith("http") ? hrefMatch[1] : baseUrl + hrefMatch[1]) : + null; + + const imageMatch = imageMatches[index].match(extractImageRegex); + const imageSrc = imageMatch ? imageMatch[1] : null; + + const titleMatch = titleMatches[index].match(extractTitleRegex); + const cleanTitle = titleMatch ? + decodeHtmlEntities(titleMatch[1]) : + null; + + if (fullHref && imageSrc && cleanTitle) { + results.push({ + href: fullHref, + image: imageSrc, + title: cleanTitle + }); + } + } + + return JSON.stringify(results); + } catch (error) { + return JSON.stringify([{ + href: "", + image: "", + title: "Search failed: " + error.message + }]); + } +} + +async function extractDetails(url) { + try { + const response = await fetchv2(url); + const htmlText = await response.text(); + console.log(htmlText); + + const descriptionMatch = (/<div class="desc text-expand">([\s\S]*?)<\/div>/.exec(htmlText) || [])[1]; + const aliasesMatch = (/<small class="al-title text-expand">([\s\S]*?)<\/small>/.exec(htmlText) || [])[1]; + + return JSON.stringify([{ + description: descriptionMatch ? cleanHtmlSymbols(descriptionMatch) : "Not available", + aliases: aliasesMatch ? cleanHtmlSymbols(aliasesMatch) : "Not available", + airdate: "If stream doesn't load try later or disable VPN/DNS" + }]); + } catch (error) { + console.error("Error fetching details:" + error); + return [{ + description: "Error loading description", + aliases: "Aliases: Unknown", + airdate: "Aired: Unknown" + }]; + } +} + +async function extractEpisodes(animeUrl) { + try { + const response = await fetchv2(animeUrl); + const htmlText = await response.text(); + + const animeIdMatch = (htmlText.match(/<div class="rate-box"[^>]*data-id="([^"]+)"/) || [])[1]; + if (!animeIdMatch) { + return [{ + error: "AniID not found" + }]; + } + + const tokenResponse = await fetchv2(`https://ilovekai.simplepostrequest.workers.dev/?ilovefeet=${encodeURIComponent(animeIdMatch)}`); + const token = await tokenResponse.text(); + + const episodeListUrl = `https://animekai.to/ajax/episodes/list?ani_id=${animeIdMatch}&_=${token}`; + + const episodeListResponse = await fetchv2(episodeListUrl); + const episodeListData = await episodeListResponse.json(); + const cleanedHtml = cleanJsonHtml(episodeListData.result); + + const episodeRegex = /<a[^>]+num="([^"]+)"[^>]+token="([^"]+)"[^>]*>/g; + const episodeMatches = [...cleanedHtml.matchAll(episodeRegex)]; + + const episodeData = episodeMatches.map(([_, episodeNum, episodeToken]) => ({ + name: `Episode ${episodeNum}`, + data: episodeToken + })); + + const batchResponse = await fetchv2( + "https://ilovekai.simplepostrequest.workers.dev/?ilovefeet", + {}, + "POST", + JSON.stringify(episodeData) + ); + + const batchResults = await batchResponse.json(); + + const episodes = batchResults.map((result, index) => ({ + number: parseInt(episodeMatches[index][1], 10), + href: `https://animekai.to/ajax/links/list?token=${episodeMatches[index][2]}&_=${result.data}` + })); + + return JSON.stringify(episodes); + } catch (err) { + console.error("Error fetching episodes:" + err); + return [{ + number: 1, + href: "Error fetching episodes" + }]; + } +} + +async function extractStreamUrl(url) { + try { + const fetchUrl = `${url}`; + const response = await fetchv2(fetchUrl); + const text = await response.text(); + const cleanedHtml = cleanJsonHtml(text); + const subRegex = /<div class="server-items lang-group" data-id="sub"[^>]*>([\s\S]*?)<\/div>/; + const softsubRegex = /<div class="server-items lang-group" data-id="softsub"[^>]*>([\s\S]*?)<\/div>/; + const dubRegex = /<div class="server-items lang-group" data-id="dub"[^>]*>([\s\S]*?)<\/div>/; + const subMatch = subRegex.exec(cleanedHtml); + const softsubMatch = softsubRegex.exec(cleanedHtml); + const dubMatch = dubRegex.exec(cleanedHtml); + const subContent = subMatch ? subMatch[1].trim() : ""; + const softsubContent = softsubMatch ? softsubMatch[1].trim() : ""; + const dubContent = dubMatch ? dubMatch[1].trim() : ""; + const serverSpanRegex = /<span class="server"[^>]*data-lid="([^"]+)"[^>]*>Server 1<\/span>/; + const serverIdDub = serverSpanRegex.exec(dubContent)?.[1]; + const serverIdSoftsub = serverSpanRegex.exec(softsubContent)?.[1]; + const serverIdSub = serverSpanRegex.exec(subContent)?.[1]; + + const tokenRequestData = [ + { name: "Dub", data: serverIdDub }, + { name: "Softsub", data: serverIdSoftsub }, + { name: "Sub", data: serverIdSub } + ].filter(item => item.data); + + const tokenBatchResponse = await fetchv2( + "https://ilovekai.simplepostrequest.workers.dev/?ilovefeet", + {}, + "POST", + JSON.stringify(tokenRequestData) + ); + const tokenResults = await tokenBatchResponse.json(); + + const streamUrls = tokenResults.map(result => { + const serverIdMap = { + "Dub": serverIdDub, + "Softsub": serverIdSoftsub, + "Sub": serverIdSub + }; + return { + type: result.name, + url: `https://animekai.to/ajax/links/view?id=${serverIdMap[result.name]}&_=${result.data}` + }; + }); + + const processStreams = async (streamUrls) => { + const streamResponses = await Promise.all( + streamUrls.map(async ({ type, url }) => { + try { + const res = await fetchv2(url); + const json = await res.json(); + return { + type: type, + result: json.result + }; + } catch (error) { + console.log(`Error fetching ${type} stream:`, error); + return { + type: type, + result: null + }; + } + }) + ); + + const decryptRequestData = streamResponses + .filter(item => item.result) + .map(item => ({ + name: item.type, + data: item.result + })); + + if (decryptRequestData.length === 0) { + return {}; + } + + const decryptBatchResponse = await fetchv2( + "https://ilovekai.simplepostrequest.workers.dev/?ilovearmpits", + {}, + "POST", + JSON.stringify(decryptRequestData) + ); + const decryptResults = await decryptBatchResponse.json(); + + const finalResults = {}; + decryptResults.forEach(result => { + try { + const parsed = JSON.parse(result.data); + finalResults[result.name] = parsed.url; + console.log(`decrypted${result.name} URL:` + parsed.url); + } catch (error) { + console.log(`Error parsing ${result.name} result:`, error); + finalResults[result.name] = null; + } + }); + + return finalResults; + }; + + const decryptedUrls = await processStreams(streamUrls); + const decryptedDub = decryptedUrls.Dub || decryptedUrls.Sub || decryptedUrls.Softsub; + + console.log(decryptedDub); + const headers = { + "Referer": "https://animekai.to/", + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36" + }; + + if (decryptedDub) { + const response = await fetchv2(decryptedDub.replace("/e/", "/media/"), headers); + const responseJson = await response.json(); + + const result = responseJson?.result; + + const postData = { + "text": result, + "Useragent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36" + } + + const finalResponse = await fetchv2("https://ilovekai.simplepostrequest.workers.dev/ilovebush", {}, "POST", JSON.stringify(postData)); + const finalJson = await finalResponse.json(); + const m3u8Link = finalJson?.result?.sources?.[0]?.file; + + return m3u8Link; + } + + return "error"; + } catch (error) { + console.log("Fetch error:"+ error); + return "https://error.org"; + } +} + +function cleanHtmlSymbols(string) { + if (!string) { + return ""; + } + return string + .replace(/’/g, "'") + .replace(/–/g, "-") + .replace(/&#[0-9]+;/g, "") + .replace(/\r?\n|\r/g, " ") + .replace(/\s+/g, " ") + .trim(); +} + +function cleanJsonHtml(jsonHtml) { + if (!jsonHtml) { + return ""; + } + return jsonHtml + .replace(/\\"/g, "\"") + .replace(/\\'/g, "'") + .replace(/\\\\/g, "\\") + .replace(/\\n/g, "\n") + .replace(/\\t/g, "\t") + .replace(/\\r/g, "\r"); +} + +function decodeHtmlEntities(text) { + if (!text) { + return ""; + } + return text + .replace(/'/g, "'") + .replace(/"/g, "\"") + .replace(/&/g, "&") + .replace(/</g, "<") + .replace(/>/g, ">") + .replace(/ /g, " "); +} diff --git a/animekai/dub/animekai.json b/animekai/dub/animekai.json new file mode 100644 index 0000000..a623865 --- /dev/null +++ b/animekai/dub/animekai.json @@ -0,0 +1,20 @@ +{ + "sourceName": "AnimeKai (Dub)", + "iconUrl": "https://apktodo.io/uploads/2025/5/animekai-icon.jpg", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.3", + "language": "English", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://animekai.to/", + "searchBaseUrl": "https://animekai.to/", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/animekai/dub/animekai.js", + "type": "anime", + "asyncJS": true, + "softsub": false, + "downloadSupport": true, + "note": "Make sure you're on the latest version of Sora." +} diff --git a/animekai/hardsub/animekai.js b/animekai/hardsub/animekai.js new file mode 100644 index 0000000..1a042bd --- /dev/null +++ b/animekai/hardsub/animekai.js @@ -0,0 +1,307 @@ +async function searchResults(query) { + const encodeQuery = keyword => encodeURIComponent(keyword); + const searchBaseUrl = "https://animekai.to/browser?keyword="; + const baseUrl = "https://animekai.to"; + + const posterHrefRegex = /href="[^"]*" class="poster"/g; + const titleRegex = /class="title"[^>]*title="[^"]*"/g; + const imageRegex = /data-src="[^"]*"/g; + const extractHrefRegex = /href="([^"]*)"/; + const extractImageRegex = /data-src="([^"]*)"/; + const extractTitleRegex = /title="([^"]*)"/; + + try { + const encodedQuery = encodeQuery(query); + const searchUrl = searchBaseUrl + encodedQuery; + const response = await fetchv2(searchUrl); + const htmlText = await response.text(); + + const results = []; + const posterMatches = htmlText.match(posterHrefRegex) || []; + const titleMatches = htmlText.match(titleRegex) || []; + const imageMatches = htmlText.match(imageRegex) || []; + + const minLength = Math.min(posterMatches.length, titleMatches.length, imageMatches.length); + + for (let index = 0; index < minLength; index++) { + const hrefMatch = posterMatches[index].match(extractHrefRegex); + const fullHref = hrefMatch ? + (hrefMatch[1].startsWith("http") ? hrefMatch[1] : baseUrl + hrefMatch[1]) : + null; + + const imageMatch = imageMatches[index].match(extractImageRegex); + const imageSrc = imageMatch ? imageMatch[1] : null; + + const titleMatch = titleMatches[index].match(extractTitleRegex); + const cleanTitle = titleMatch ? + decodeHtmlEntities(titleMatch[1]) : + null; + + if (fullHref && imageSrc && cleanTitle) { + results.push({ + href: fullHref, + image: imageSrc, + title: cleanTitle + }); + } + } + + return JSON.stringify(results); + } catch (error) { + return JSON.stringify([{ + href: "", + image: "", + title: "Search failed: " + error.message + }]); + } +} + +async function extractDetails(url) { + try { + const response = await fetchv2(url); + const htmlText = await response.text(); + console.log(htmlText); + + const descriptionMatch = (/<div class="desc text-expand">([\s\S]*?)<\/div>/.exec(htmlText) || [])[1]; + const aliasesMatch = (/<small class="al-title text-expand">([\s\S]*?)<\/small>/.exec(htmlText) || [])[1]; + + return JSON.stringify([{ + description: descriptionMatch ? cleanHtmlSymbols(descriptionMatch) : "Not available", + aliases: aliasesMatch ? cleanHtmlSymbols(aliasesMatch) : "Not available", + airdate: "If stream doesn't load try later or disable VPN/DNS" + }]); + } catch (error) { + console.error("Error fetching details:" + error); + return [{ + description: "Error loading description", + aliases: "Aliases: Unknown", + airdate: "Aired: Unknown" + }]; + } +} + +async function extractEpisodes(animeUrl) { + try { + const response = await fetchv2(animeUrl); + const htmlText = await response.text(); + + const animeIdMatch = (htmlText.match(/<div class="rate-box"[^>]*data-id="([^"]+)"/) || [])[1]; + if (!animeIdMatch) { + return [{ + error: "AniID not found" + }]; + } + + const tokenResponse = await fetchv2(`https://ilovekai.simplepostrequest.workers.dev/?ilovefeet=${encodeURIComponent(animeIdMatch)}`); + const token = await tokenResponse.text(); + + const episodeListUrl = `https://animekai.to/ajax/episodes/list?ani_id=${animeIdMatch}&_=${token}`; + + const episodeListResponse = await fetchv2(episodeListUrl); + const episodeListData = await episodeListResponse.json(); + const cleanedHtml = cleanJsonHtml(episodeListData.result); + + const episodeRegex = /<a[^>]+num="([^"]+)"[^>]+token="([^"]+)"[^>]*>/g; + const episodeMatches = [...cleanedHtml.matchAll(episodeRegex)]; + + const episodeData = episodeMatches.map(([_, episodeNum, episodeToken]) => ({ + name: `Episode ${episodeNum}`, + data: episodeToken + })); + + const batchResponse = await fetchv2( + "https://ilovekai.simplepostrequest.workers.dev/?ilovefeet", + {}, + "POST", + JSON.stringify(episodeData) + ); + + const batchResults = await batchResponse.json(); + + const episodes = batchResults.map((result, index) => ({ + number: parseInt(episodeMatches[index][1], 10), + href: `https://animekai.to/ajax/links/list?token=${episodeMatches[index][2]}&_=${result.data}` + })); + + return JSON.stringify(episodes); + } catch (err) { + console.error("Error fetching episodes:" + err); + return [{ + number: 1, + href: "Error fetching episodes" + }]; + } +} + +async function extractStreamUrl(url) { + try { + const fetchUrl = `${url}`; + const response = await fetchv2(fetchUrl); + const text = await response.text(); + const cleanedHtml = cleanJsonHtml(text); + const subRegex = /<div class="server-items lang-group" data-id="sub"[^>]*>([\s\S]*?)<\/div>/; + const softsubRegex = /<div class="server-items lang-group" data-id="softsub"[^>]*>([\s\S]*?)<\/div>/; + const dubRegex = /<div class="server-items lang-group" data-id="dub"[^>]*>([\s\S]*?)<\/div>/; + const subMatch = subRegex.exec(cleanedHtml); + const softsubMatch = softsubRegex.exec(cleanedHtml); + const dubMatch = dubRegex.exec(cleanedHtml); + const subContent = subMatch ? subMatch[1].trim() : ""; + const softsubContent = softsubMatch ? softsubMatch[1].trim() : ""; + const dubContent = dubMatch ? dubMatch[1].trim() : ""; + const serverSpanRegex = /<span class="server"[^>]*data-lid="([^"]+)"[^>]*>Server 1<\/span>/; + const serverIdDub = serverSpanRegex.exec(dubContent)?.[1]; + const serverIdSoftsub = serverSpanRegex.exec(softsubContent)?.[1]; + const serverIdSub = serverSpanRegex.exec(subContent)?.[1]; + + const tokenRequestData = [ + { name: "Dub", data: serverIdDub }, + { name: "Softsub", data: serverIdSoftsub }, + { name: "Sub", data: serverIdSub } + ].filter(item => item.data); + + const tokenBatchResponse = await fetchv2( + "https://ilovekai.simplepostrequest.workers.dev/?ilovefeet", + {}, + "POST", + JSON.stringify(tokenRequestData) + ); + const tokenResults = await tokenBatchResponse.json(); + + const streamUrls = tokenResults.map(result => { + const serverIdMap = { + "Dub": serverIdDub, + "Softsub": serverIdSoftsub, + "Sub": serverIdSub + }; + return { + type: result.name, + url: `https://animekai.to/ajax/links/view?id=${serverIdMap[result.name]}&_=${result.data}` + }; + }); + + const processStreams = async (streamUrls) => { + const streamResponses = await Promise.all( + streamUrls.map(async ({ type, url }) => { + try { + const res = await fetchv2(url); + const json = await res.json(); + return { + type: type, + result: json.result + }; + } catch (error) { + console.log(`Error fetching ${type} stream:`, error); + return { + type: type, + result: null + }; + } + }) + ); + + const decryptRequestData = streamResponses + .filter(item => item.result) + .map(item => ({ + name: item.type, + data: item.result + })); + + if (decryptRequestData.length === 0) { + return {}; + } + + const decryptBatchResponse = await fetchv2( + "https://ilovekai.simplepostrequest.workers.dev/?ilovearmpits", + {}, + "POST", + JSON.stringify(decryptRequestData) + ); + const decryptResults = await decryptBatchResponse.json(); + + const finalResults = {}; + decryptResults.forEach(result => { + try { + const parsed = JSON.parse(result.data); + finalResults[result.name] = parsed.url; + console.log(`decrypted${result.name} URL:` + parsed.url); + } catch (error) { + console.log(`Error parsing ${result.name} result:`, error); + finalResults[result.name] = null; + } + }); + + return finalResults; + }; + + const decryptedUrls = await processStreams(streamUrls); + const decryptedSub = decryptedUrls.Sub || decryptedUrls.Softsub || decryptedUrls.Dub; + + console.log(decryptedSub); + const headers = { + "Referer": "https://animekai.to/", + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36" + }; + + if (decryptedSub) { + const response = await fetchv2(decryptedSub.replace("/e/", "/media/"), headers); + const responseJson = await response.json(); + + const result = responseJson?.result; + + const postData = { + "text": result, + "Useragent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36" + } + + const finalResponse = await fetchv2("https://ilovekai.simplepostrequest.workers.dev/ilovebush", {}, "POST", JSON.stringify(postData)); + const finalJson = await finalResponse.json(); + const m3u8Link = finalJson?.result?.sources?.[0]?.file; + + return m3u8Link; + } + + return "error"; + } catch (error) { + console.log("Fetch error:"+ error); + return "https://error.org"; + } +} + +function cleanHtmlSymbols(string) { + if (!string) { + return ""; + } + return string + .replace(/’/g, "'") + .replace(/–/g, "-") + .replace(/&#[0-9]+;/g, "") + .replace(/\r?\n|\r/g, " ") + .replace(/\s+/g, " ") + .trim(); +} + +function cleanJsonHtml(jsonHtml) { + if (!jsonHtml) { + return ""; + } + return jsonHtml + .replace(/\\"/g, "\"") + .replace(/\\'/g, "'") + .replace(/\\\\/g, "\\") + .replace(/\\n/g, "\n") + .replace(/\\t/g, "\t") + .replace(/\\r/g, "\r"); +} + +function decodeHtmlEntities(text) { + if (!text) { + return ""; + } + return text + .replace(/'/g, "'") + .replace(/"/g, "\"") + .replace(/&/g, "&") + .replace(/</g, "<") + .replace(/>/g, ">") + .replace(/ /g, " "); +} diff --git a/animekai/hardsub/animekai.json b/animekai/hardsub/animekai.json new file mode 100644 index 0000000..36dd618 --- /dev/null +++ b/animekai/hardsub/animekai.json @@ -0,0 +1,20 @@ +{ + "sourceName": "AnimeKai (Hardsub)", + "iconUrl": "https://apktodo.io/uploads/2025/5/animekai-icon.jpg", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.2", + "language": "English", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://animekai.to/", + "searchBaseUrl": "https://animekai.to/", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/animekai/hardsub/animekai.js", + "type": "anime", + "asyncJS": true, + "softsub": false, + "downloadSupport": true, + "note": "Make sure you're on the latest version of Sora." +} diff --git a/animekhor/animekhor.js b/animekhor/animekhor.js new file mode 100644 index 0000000..a269d5e --- /dev/null +++ b/animekhor/animekhor.js @@ -0,0 +1,111 @@ +async function searchResults(keyword) { + const results = []; + const response = await fetchv2(`https://animekhor.org/?s=${keyword}`); + const html = await response.text(); + + const regex = /<article class="bs"[^>]*>.*?<a href="([^"]+)"[^>]*>.*?<img src="([^"]+)"[^>]*>.*?<h2[^>]*>(.*?)<\/h2>/gs; + + 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); +} + +async function extractDetails(url) { + const results = []; + const response = await fetchv2(url); + const html = await response.text(); + + const match = html.match(/<div class="entry-content"[^>]*>([\s\S]*?)<\/div>/); + + let description = "N/A"; + if (match) { + description = match[1] + .replace(/<[^>]+>/g, '') + .replace(/&#(\d+);/g, (_, code) => String.fromCharCode(code)) + .replace(/"/g, '"') + .replace(/'/g, "'") + .replace(/&/g, "&") + .trim(); + } + + results.push({ + description: description, + aliases: 'N/A', + airdate: 'N/A' + }); + + return JSON.stringify(results); +} + +async function extractEpisodes(url) { + const results = []; + const response = await fetchv2(url); + const html = await response.text(); + + const regex = /<div class="inepcx">\s*<a href="([^"#]+)">\s*<span>New Episode<\/span>/; + const match = regex.exec(html); + + if (match) { + results.push({ + href: match[1].trim(), + number: 1 + }); + } + + return JSON.stringify(results); +} +async function extractStreamUrl(url) { + try { + const response = await fetchv2(url); + const html = await response.text(); + + const iframeMatch = html.match(/dailymotion\.com\/embed\/video\/([a-zA-Z0-9]+)/); + + if (!iframeMatch) return "no iframe"; + + const videoId = iframeMatch[1]; + const metaRes = await fetchv2(`https://www.dailymotion.com/player/metadata/video/${videoId}`); + const metaJson = await metaRes.json(); + const hlsLink = metaJson.qualities?.auto?.[0]?.url; + + if (!hlsLink) return "no hls"; + + async function getBestHls(hlsUrl) { + try { + const res = await fetchv2(hlsUrl); + const text = await res.text(); + const regex = /#EXT-X-STREAM-INF:.*RESOLUTION=(\d+)x(\d+).*?\n(https?:\/\/[^\n]+)/g; + const streams = []; + let match; + + while ((match = regex.exec(text)) !== null) { + streams.push({ + width: parseInt(match[1]), + height: parseInt(match[2]), + url: match[3] + }); + } + + if (streams.length === 0) return hlsUrl; + streams.sort((a, b) => b.height - a.height); + return streams[0].url; + } catch { + return hlsUrl; + } + } + + const bestHls = await getBestHls(hlsLink); + return bestHls; + } catch { + const empty = "{ streams: ["; + console.log("Extracted stream result:" + JSON.stringify(empty)); + return JSON.stringify(empty); + } +} \ No newline at end of file diff --git a/animekhor/animekhor.json b/animekhor/animekhor.json new file mode 100644 index 0000000..5db4634 --- /dev/null +++ b/animekhor/animekhor.json @@ -0,0 +1,19 @@ +{ + "sourceName": "AnimeKhor", + "iconUrl": "https://i3.wp.com/animekhor.org/wp-content/uploads/2022/02/cropped-logo-192x192.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "Chinese", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://animekhor.org/", + "searchBaseUrl": "https://animekhor.org/", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/animekhor/animekhor.js", + "type": "anime", + "asyncJS": true, + "softsub": false, + "downloadSupport": false +} diff --git a/animeland/animeland.js b/animeland/animeland.js new file mode 100644 index 0000000..e07f290 --- /dev/null +++ b/animeland/animeland.js @@ -0,0 +1,122 @@ +async function searchResults(keyword) { + const baseUrl = "https://w7.animeland.tv"; + const results = []; + try { + const response = await fetchv2(baseUrl + "/?s=" + encodeURIComponent(keyword)); + const html = await response.text(); + + const regex = /<a href="([^"]+)"[^>]*>\s*<img[^>]*src="([^"]*)"[^>]*alt="([^"]*)"/g; + + let match; + while ((match = regex.exec(html)) !== null) { + let href = match[1].trim(); + let image = match[2].trim(); + let title = match[3].trim(); + + if (href.startsWith("/")) { + href = baseUrl + href; + } + if (image.startsWith("/")) { + image = baseUrl + image; + } + + if (href === baseUrl + "/" || href.includes("kissanimes.net")) { + continue; + } + + results.push({ + href, + image, + title + }); + } + + 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 regex = /<div class="Anime Info">\s*<\/div>\s*([\s\S]*?)<\/div>/i; + const match = html.match(regex); + + const description = match ? match[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 = /<li class="play"><a[^>]*href="([^"]+)"[^>]*>([^<]*)<\/a><\/li>/g; + + let match; + while ((match = regex.exec(html)) !== null) { + const href = match[1].trim(); + const text = match[2].trim(); + + let number = null; + const urlMatch = href.match(/-episode-(\d+)/i); + if (urlMatch) { + number = parseInt(urlMatch[1], 10); + } else { + const textMatch = text.match(/Episode\s*(\d+)/i); + if (textMatch) number = parseInt(textMatch[1], 10); + } + + results.push({ + href, + number + }); + } + + return JSON.stringify(results.reverse()); + } catch (err) { + return JSON.stringify([{ + href: "Error", + number: "Error" + }]); + } +} + +async function extractStreamUrl(url) { + try { + const response = await fetchv2(url); + const html = await response.text(); + const match = html.match(/file=([a-zA-Z0-9]+\.html)/); + if (match) { + const filename = match[1]; + console.log('Filename:' + filename); + const videoUrl = `https://animesource.me/cache/${filename}.mp4`; + console.log('Video URL:' + videoUrl); + return videoUrl; + } + + } catch (err) { + console.error("Error:" + err); + return null; + } +} diff --git a/animeland/animeland.json b/animeland/animeland.json new file mode 100644 index 0000000..e5ea3f1 --- /dev/null +++ b/animeland/animeland.json @@ -0,0 +1,19 @@ +{ + "sourceName": "AnimeLand", + "iconUrl": "https://w7.animeland.tv/wp-content/themes/twentytwelve/SAO2.ico", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "English", + "streamType": "mp4", + "quality": "1080p", + "baseUrl": "https://w7.animeland.tv/", + "searchBaseUrl": "https://w7.animeland.tv/", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/animeland/animeland.js", + "type": "anime", + "asyncJS": true, + "softsub": false, + "downloadSupport": true +} diff --git a/animemeow/animemeow.js b/animemeow/animemeow.js new file mode 100644 index 0000000..8052338 --- /dev/null +++ b/animemeow/animemeow.js @@ -0,0 +1,237 @@ +async function searchResults(keyword) { + const results = []; + try { + const response = await fetchv2("https://animemeow.xyz/directorio/?q=" + encodeURIComponent(keyword)); + const html = await response.text(); + + const containerMatch = html.match(/<ul class="grid-animes directorio">([\s\S]*?)<\/ul>/); + const containerHtml = containerMatch ? containerMatch[1] : ""; + + const regex = /<a href="([^"]+)">[\s\S]*?<div class="main-img">[\s\S]*?<img[^>]+src="([^"]+)"[^>]*>[\s\S]*?<p>([^<]+)<\/p>/g; + let match; + while ((match = regex.exec(containerHtml)) !== null) { + results.push({ + href: "https://animemeow.xyz" + match[1].trim(), + image: "https://animemeow.xyz" + match[2].trim(), + title: 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 match = html.match(/<p class="sinopsis" id="sinopsis">([\s\S]*?)<\/p>/); + const description = match ? match[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 containerMatch = html.match(/<ul id="eps">([\s\S]*?)<\/ul>/); + const containerHtml = containerMatch ? containerMatch[1] : ""; + + const regex = /<a href="([^"]+)">[\s\S]*?<p>[\s\S]*?<\/i>\s*([^<]+)<\/p>/g; + let match; + while ((match = regex.exec(containerHtml)) !== null) { + const href = "https://animemeow.xyz" + match[1].trim(); + let number; + + if (/Episodio\s*(\d+)/i.test(match[2])) { + number = parseInt(match[2].match(/Episodio\s*(\d+)/i)[1], 10); + } else if (/Ver Pel[ií]cula/i.test(match[2])) { + number = 1; + } else { + number = "N/A"; + } + + results.push({ href, number }); + } + + return JSON.stringify(results); + } catch (err) { + return JSON.stringify([{ + href: "Error", + number: "Error" + }]); + } +} + +async function extractStreamUrl(url) { + try { + const response = await fetchv2(url); + const html = await response.text(); + + const buttonMatch = html.match(/<button[^>]+data-url="([^"]*voe[^"]+)"[^>]*>/i); + if (!buttonMatch) return "https://error.org/"; + + const voeLink = buttonMatch[1].split('id=')[1]; + console.log("VOE Link: " + voeLink); + const voeResponse = await fetchv2(voeLink); + const voeHtml = await voeResponse.text(); + + const redirectMatch = voeHtml.match(/window\.location\.href\s*=\s*['"]([^'"]+)['"]/); + if (!redirectMatch) return null; + + const finalLink = redirectMatch[1]; + + const streamUrlOne = finalLink; + + const responseTwo = await fetchv2(streamUrlOne); + const finalHtml = await responseTwo.text(); + + let streamUrl = null; + try { + streamUrl = voeExtractor(finalHtml); + } catch (error) { + console.log("VOE extraction error:", error); + return null; + } + + console.log("Voe Stream URL: " + streamUrl); + return streamUrl; + + } catch (err) { + return "https://error.org/"; + } +} + +/* SCHEME START */ + +/** + * @name voeExtractor + * @author Cufiy + */ + +function voeExtractor(html, url = null) { +// Extract the first <script type="application/json">...</script> + const jsonScriptMatch = html.match( + /<script[^>]+type=["']application\/json["'][^>]*>([\s\S]*?)<\/script>/i + ); + if (!jsonScriptMatch) { + console.log("No application/json script tag found"); + return null; + } + + + const obfuscatedJson = jsonScriptMatch[1].trim(); + + let data; + try { + data = JSON.parse(obfuscatedJson); + } catch (e) { + throw new Error("Invalid JSON input."); + } + if (!Array.isArray(data) || typeof data[0] !== "string") { + throw new Error("Input doesn't match expected format."); + } + let obfuscatedString = data[0]; + + // Step 1: ROT13 + let step1 = voeRot13(obfuscatedString); + + // Step 2: Remove patterns + let step2 = voeRemovePatterns(step1); + + // Step 3: Base64 decode + let step3 = voeBase64Decode(step2); + + // Step 4: Subtract 3 from each char code + let step4 = voeShiftChars(step3, 3); + + // Step 5: Reverse string + let step5 = step4.split("").reverse().join(""); + + // Step 6: Base64 decode again + let step6 = voeBase64Decode(step5); + + // Step 7: Parse as JSON + let result; + try { + result = JSON.parse(step6); + } catch (e) { + throw new Error("Final JSON parse error: " + e.message); + } + // console.log("Decoded JSON:", result); + + // check if direct_access_url is set, not null and starts with http + if (result && typeof result === "object") { + const streamUrl = + result.direct_access_url || + result.source + .map((source) => source.direct_access_url) + .find((url) => url && url.startsWith("http")); + if (streamUrl) { + console.log("Voe Stream URL: " + streamUrl); + return streamUrl; + } else { + console.log("No stream URL found in the decoded JSON"); + } + } + return result; +} + +function voeRot13(str) { + return str.replace(/[a-zA-Z]/g, function (c) { + return String.fromCharCode( + (c <= "Z" ? 90 : 122) >= (c = c.charCodeAt(0) + 13) + ? c + : c - 26 + ); + }); +} + +function voeRemovePatterns(str) { + const patterns = ["@$", "^^", "~@", "%?", "*~", "!!", "#&"]; + let result = str; + for (const pat of patterns) { + result = result.split(pat).join(""); + } + return result; +} + +function voeBase64Decode(str) { + // atob is available in browsers and Node >= 16 + if (typeof atob === "function") { + return atob(str); + } + // Node.js fallback + return Buffer.from(str, "base64").toString("utf-8"); +} + +function voeShiftChars(str, shift) { + return str + .split("") + .map((c) => String.fromCharCode(c.charCodeAt(0) - shift)) + .join(""); +} +/* SCHEME END */ + + diff --git a/animemeow/animemeow.json b/animemeow/animemeow.json new file mode 100644 index 0000000..14eac14 --- /dev/null +++ b/animemeow/animemeow.json @@ -0,0 +1,19 @@ +{ + "sourceName": "AnimeMeow", + "iconUrl": "https://files.catbox.moe/5phbht.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "Spanish (DUB/SUB)", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://animemeow.xyz/", + "searchBaseUrl": "https://animemeow.xyz/", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/animemeow/animemeow.js", + "type": "anime", + "asyncJS": true, + "softsub": false, + "downloadSupport": false +} diff --git a/animenana/animenana.js b/animenana/animenana.js new file mode 100644 index 0000000..9e82810 --- /dev/null +++ b/animenana/animenana.js @@ -0,0 +1,324 @@ +async function searchResults(keyword) { + const results = []; + try { + const response = await fetchv2("https://animenana.com/search/?key=" + keyword); + const html = await response.text(); + + const cardMatches = html.match(/<div class="card component-latest">[\s\S]*?<\/div>\s*<\/div>\s*<\/a>/g); + + if (cardMatches) { + for (const cardHtml of cardMatches) { + const hrefMatch = cardHtml.match(/<a href="([^"]+)"/); + + const imgMatch = cardHtml.match(/<img[^>]+(?:data-src|src)="([^"]+)"/); + + const titleMatch = cardHtml.match(/<h5 class="animename"[^>]*>(.*?)<\/h5>/); + + if (hrefMatch && imgMatch && titleMatch) { + results.push({ + href: "https://animenana.com" + hrefMatch[1].trim(), + image: "https://animenana.com" + imgMatch[1].trim(), + title: titleMatch[1].trim() + }); + } + } + } + + if (results.length === 0) { + const colMatches = html.match(/<div class="col-md-4">[\s\S]*?<\/div>\s*<\/div>\s*<\/div>\s*<\/a>\s*<\/div>/g); + + if (colMatches) { + for (const colHtml of colMatches) { + const hrefMatch = colHtml.match(/<a href="([^"]+)"/); + const imgMatch = colHtml.match(/<img[^>]+(?:data-src|src)="([^"]+)"/); + const titleMatch = colHtml.match(/<h5 class="animename"[^>]*>(.*?)<\/h5>/); + + if (hrefMatch && imgMatch && titleMatch) { + results.push({ + href: "https://animenana.com" + hrefMatch[1].trim(), + image: "https://animenana.com" + imgMatch[1].trim(), + title: titleMatch[1].trim() + }); + } + } + } + } + + if (results.length === 0) { + const regex = /<a href="([^"]+)"[\s\S]*?<img[^>]+(?:data-src|src)="([^"]+)"[\s\S]*?<h5 class="animename"[^>]*>(.*?)<\/h5>/g; + let match; + while ((match = regex.exec(html)) !== null) { + results.push({ + href: "https://animenana.com" + match[1].trim(), + image: "https://animenana.com" + match[2].trim(), + title: 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 regex = /<p><b>Description:\s*<\/b><\/p>([\s\S]*?)<br\s*\/?>/i; + const match = regex.exec(html); + + let description = match ? match[1].trim() : "N/A"; + + description = description.replace(/<[^>]+>/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(); + + // More flexible regex to handle the actual HTML structure + const epRegex = /<a href="([^"]+)"[^>]*title="[^"]*Episode\s*(\d+)">/g; + let match; + while ((match = epRegex.exec(html)) !== null) { + results.push({ + href: "https://animenana.com" + match[1].trim(), + number: parseInt(match[2], 10) + }); + } + + const specialRegex = /<span class="badge[^"]*"[^>]*>([^<]+)<\/span>[\s\S]*?<a href="([^"]+)"[^>]*>[\s\S]*?<h5 class="animename">([^<]+)<\/h5>/g; + while ((match = specialRegex.exec(html)) !== null) { + results.push({ + href: "https://animenana.com" + match[2].trim(), + number: 1 + }); + } + + if (results.length >= 2 && results[0].number > results[1].number) { + results.reverse(); + results.forEach((item, index) => { + item.number = index + 1; + }); + } + + if (results.length === 0) { + results.push({ + href: url, + number: 1 + }); + } + + return JSON.stringify(results); + } catch (err) { + return JSON.stringify([{ + href: "Error", + number: "Error", + type: "Error" + }]); + } +} + +async function extractStreamUrl(url) { + try { + const response = await fetchv2(url); + const html = await response.text(); + const fmRegex = /function\s+fm\(\)\s*\{[^}]*document\.getElementById\("videowrapper"\)\.innerHTML\s*=\s*['"]<iframe\s+src=['"]([^'"]+)['"]/; + const match = fmRegex.exec(html); + + + let streamUrl = "https://files.catbox.moe/avolvc.mp4"; + + if (match && match[1]) { + const iframeSrc = match[1]; + + if (iframeSrc.startsWith("https://")) { + streamUrl = iframeSrc; + } else { + streamUrl = "https://animenana.com" + iframeSrc; + } + } + + const finalUrl = streamUrl; + + console.log(finalUrl); + + const diejfioe = await fetchv2(finalUrl); + const jdi83rjf = await diejfioe.text(); + + const kvrokofrmfrklefmklrd = jdi83rjf.match(/<iframe[^>]+src="([^"]+)"/); + if (kvrokofrmfrklefmklrd) { + const iframeUrl = kvrokofrmfrklefmklrd[1]; + console.log("Iframe URL:"+ iframeUrl); + + const headers = { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3", + "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", + "Referer": "https://animenana.com" + url, + }; + + const i9jfrhtiee = await fetchv2(iframeUrl, headers); + const kopefjir4o0 = await i9jfrhtiee.text(); + + const obfuscatedScript = kopefjir4o0.match(/<script[^>]*>\s*(eval\(function\(p,a,c,k,e,d.*?\)[\s\S]*?)<\/script>/); + const unpackedScript = unpack(obfuscatedScript[1]); + //console.log(unpackedScript); + + const hlsMatch = unpackedScript.match(/file:"(https?:\/\/.*?\.m3u8.*?)"/); + const hlsUrl = hlsMatch ? hlsMatch[1] : null; + console.log("HLS URL:"+hlsUrl); + return hlsUrl; + } else { + console.log("No iframe found"); + } + + + return "blehh"; + } catch (err) { + console.log(err); + return "https://files.catbox.moe/avolvc.mp4"; + } +} + + + +/*********************************************************** + * UNPACKER MODULE + * Credit to GitHub user "mnsrulz" for Unpacker Node library + * https://github.com/mnsrulz/unpacker + ***********************************************************/ +class Unbaser { + constructor(base) { + /* Functor for a given base. Will efficiently convert + strings to natural numbers. */ + this.ALPHABET = { + 62: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", + 95: "' !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'", + }; + this.dictionary = {}; + this.base = base; + // fill elements 37...61, if necessary + if (36 < base && base < 62) { + this.ALPHABET[base] = this.ALPHABET[base] || + this.ALPHABET[62].substr(0, base); + } + // If base can be handled by int() builtin, let it do it for us + if (2 <= base && base <= 36) { + this.unbase = (value) => parseInt(value, base); + } + else { + // Build conversion dictionary cache + try { + [...this.ALPHABET[base]].forEach((cipher, index) => { + this.dictionary[cipher] = index; + }); + } + catch (er) { + throw Error("Unsupported base encoding."); + } + this.unbase = this._dictunbaser; + } + } + _dictunbaser(value) { + /* Decodes a value to an integer. */ + let ret = 0; + [...value].reverse().forEach((cipher, index) => { + ret = ret + ((Math.pow(this.base, index)) * this.dictionary[cipher]); + }); + return ret; + } +} + +function detect(source) { + /* Detects whether `source` is P.A.C.K.E.R. coded. */ + return source.replace(" ", "").startsWith("eval(function(p,a,c,k,e,"); +} + +function unpack(source) { + /* Unpacks P.A.C.K.E.R. packed js code. */ + let { payload, symtab, radix, count } = _filterargs(source); + if (count != symtab.length) { + throw Error("Malformed p.a.c.k.e.r. symtab."); + } + let unbase; + try { + unbase = new Unbaser(radix); + } + catch (e) { + throw Error("Unknown p.a.c.k.e.r. encoding."); + } + function lookup(match) { + /* Look up symbols in the synthetic symtab. */ + const word = match; + let word2; + if (radix == 1) { + //throw Error("symtab unknown"); + word2 = symtab[parseInt(word)]; + } + else { + word2 = symtab[unbase.unbase(word)]; + } + return word2 || word; + } + source = payload.replace(/\b\w+\b/g, lookup); + return _replacestrings(source); + function _filterargs(source) { + /* Juice from a source file the four args needed by decoder. */ + const juicers = [ + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\), *(\d+), *(.*)\)\)/, + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\)/, + ]; + for (const juicer of juicers) { + //const args = re.search(juicer, source, re.DOTALL); + const args = juicer.exec(source); + if (args) { + let a = args; + if (a[2] == "[]") { + //don't know what it is + // a = list(a); + // a[1] = 62; + // a = tuple(a); + } + try { + return { + payload: a[1], + symtab: a[4].split("|"), + radix: parseInt(a[2]), + count: parseInt(a[3]), + }; + } + catch (ValueError) { + throw Error("Corrupted p.a.c.k.e.r. data."); + } + } + } + throw Error("Could not make sense of p.a.c.k.e.r data (unexpected code structure)"); + } + function _replacestrings(source) { + /* Strip string lookup table (list) and replace values in source. */ + /* Need to work on this. */ + return source; + } +} + diff --git a/animenana/animenana.json b/animenana/animenana.json new file mode 100644 index 0000000..c8fb7b9 --- /dev/null +++ b/animenana/animenana.json @@ -0,0 +1,19 @@ +{ + "sourceName": "AnimeNana", + "iconUrl": "https://animenana.com/favicon.ico", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "English (Hardsub)", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://animenana.com/", + "searchBaseUrl": "https://animenana.com/", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/animenana/animenana.js", + "type": "anime", + "asyncJS": true, + "softsub": false, + "downloadSupport": false +} diff --git a/animenix/animenix.js b/animenix/animenix.js new file mode 100644 index 0000000..2e07e5a --- /dev/null +++ b/animenix/animenix.js @@ -0,0 +1,102 @@ +function cleanTitle(title) { + return title + .replace(/’/g, "'") + .replace(/–/g, "-") + .replace(/&#[0-9]+;/g, ""); +} + +async function searchResults(keyword) { + const results = []; + const response = await fetchv2(`https://animenix.com/?s=${keyword}`); + const html = await response.text(); + + const regex = /<article class="bs"[^>]*>.*?<a href="([^"]+)"[^>]*>.*?<img src="([^"]+)"[^>]*>.*?<h2[^>]*>(.*?)<\/h2>/gs; + + let match; + while ((match = regex.exec(html)) !== null) { + results.push({ + title: cleanTitle(match[3].trim()), + image: match[2].trim(), + href: match[1].trim() + }); + } + + return JSON.stringify(results); +} + +async function extractDetails(url) { + const results = []; + const response = await fetchv2(url); + const html = await response.text(); + + const match = html.match(/<div class="entry-content"[^>]*>([\s\S]*?)<\/div>/); + + let description = "N/A"; + if (match) { + description = match[1] + .replace(/<[^>]+>/g, '') + .replace(/&#(\d+);/g, (_, code) => String.fromCharCode(code)) + .replace(/"/g, '"') + .replace(/'/g, "'") + .replace(/&/g, "&") + .trim(); + } + + results.push({ + description: description, + aliases: 'N/A', + airdate: 'N/A' + }); + + return JSON.stringify(results); +} + +async function extractEpisodes(url) { + const results = []; + const response = await fetchv2(url); + const html = await response.text(); + + const regex = /<li data-index="\d+">[\s\S]*?<a href="([^"]+)">/g; + + let match; + let count = 1; + while ((match = regex.exec(html)) !== null) { + results.push({ + href: match[1].trim(), + number: count + }); + count++; + } + + results.reverse(); + return JSON.stringify(results.reverse()); +} + + +async function extractStreamUrl(url) { + try { + const response = await fetchv2(url); + const html = await response.text(); + + const optionMatch = html.match(/<option value="([^"]+)"[^>]*>\s*YourUpload\s*<\/option>/); + if (!optionMatch) return "https://error.org/"; + + const decodedHtml = atob(optionMatch[1]); + + const iframeMatch = decodedHtml.match(/<iframe[^>]+src="([^"]+)"/); + if (!iframeMatch) return "https://error.org/"; + const iframeUrl = iframeMatch[1]; + + const iframeResponse = await fetchv2(iframeUrl); + const iframeHtml = await iframeResponse.text(); + + const fileMatch = iframeHtml.match(/file:\s*'([^']+\.mp4)'/); + if (!fileMatch) return "https://error.org/"; + + return fileMatch[1]; + + } catch (err) { + return "https://error.org/"; + } +} + diff --git a/animenix/animenix.json b/animenix/animenix.json new file mode 100644 index 0000000..1d1e110 --- /dev/null +++ b/animenix/animenix.json @@ -0,0 +1,19 @@ +{ + "sourceName": "AnimeNix", + "iconUrl": "https://i3.wp.com/animenix.com/wp-content/uploads/2024/11/cropped-favicon-1-192x192.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "Spanish (DUB/SUB)", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://www.yourupload.com/", + "searchBaseUrl": "https://www.yourupload.com/", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/animenix/animenix.js", + "type": "anime", + "asyncJS": true, + "softsub": false, + "downloadSupport": true +} diff --git a/animenosub/animenosub.js b/animenosub/animenosub.js new file mode 100644 index 0000000..305bca0 --- /dev/null +++ b/animenosub/animenosub.js @@ -0,0 +1,92 @@ +async function searchResults(keyword) { + const results = []; + const response = await fetchv2(`https://animenosub.to/?s=${keyword}`); + const html = await response.text(); + + // Regex pattern to extract the title, image, and href from the article elements + const regex = /<article class="bs"[^>]*>.*?<a href="([^"]+)"[^>]*>.*?<img src="([^"]+)"[^>]*>.*?<h2[^>]*>(.*?)<\/h2>/gs; + + 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); +} + +async function extractDetails(url) { + const results = []; + const response = await fetchv2(url); + const html = await response.text(); + + const match = html.match(/<div class="entry-content"[^>]*>([\s\S]*?)<\/div>/); + + let description = "N/A"; + if (match) { + description = match[1] + .replace(/<[^>]+>/g, '') + .replace(/&#(\d+);/g, (_, code) => String.fromCharCode(code)) + .replace(/"/g, '"') + .replace(/'/g, "'") + .replace(/&/g, "&") + .trim(); + } + + results.push({ + description: description, + aliases: 'N/A', + airdate: 'N/A' + }); + + return JSON.stringify(results); +} + +async function extractEpisodes(url) { + const results = []; + const response = await fetchv2(url); + const html = await response.text(); + + const regex = /<a href="([^"]+)">\s*<div class="epl-num">([\d.]+)<\/div>/g; + + let match; + while ((match = regex.exec(html)) !== null) { + results.push({ + href: match[1].trim(), + number: parseInt(match[2], 10) + }); + } + results.reverse(); + return JSON.stringify(results); +} + + +async function extractStreamUrl(url) { + const response = await fetchv2(url); + const html = await response.text(); + + const regexSub = /<option value="([^"]+)"[^>]*>\s*SUB - Omega\s*<\/option>/; + const regexFallback = /<option value="([^"]+)"[^>]*>\s*Omega\s*<\/option>/; + const anotherFallbackDawggggWhatsWrongWithTHisWebsite = /<option value="([^"]+)"[^>]*>\s*SUB v2 - Omega\s*<\/option>/; + + + let match = html.match(regexSub) || html.match(regexFallback) || html.match(anotherFallbackDawggggWhatsWrongWithTHisWebsite); + if (!match) return null; + + const decodedHtml = atob(match[1]); // Decode base64 + const iframeMatch = decodedHtml.match(/<iframe\s+src="([^"]+)"/); + + if (!iframeMatch) return null; + + const streamUrl = iframeMatch[1].startsWith("//") ? "https:" + iframeMatch[1] : iframeMatch[1]; + + const responseTwo = await fetchv2(streamUrl); + const htmlTwo = await responseTwo.text(); + + const m3u8Match = htmlTwo.match(/sources:\s*\[\{file:"([^"]+\.m3u8)"/); + console.error(m3u8Match ? m3u8Match[1] : null); + return m3u8Match ? m3u8Match[1] : null; +} \ No newline at end of file diff --git a/animenosub/animenosub.json b/animenosub/animenosub.json new file mode 100644 index 0000000..dc23672 --- /dev/null +++ b/animenosub/animenosub.json @@ -0,0 +1,17 @@ +{ + "sourceName": "AnimeNoSub", + "iconUrl": "https://i3.wp.com/animenosub.to/wp-content/uploads/2024/04/cropped-favicon-192x192.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.4", + "language": "English (SUB/DUB)", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://vidmoly.to/", + "searchBaseUrl": "https://animenosub.to/?s=%s", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/animenosub/animenosub.js", + "asyncJS": true, + "type": "anime" +} diff --git a/animeq/animeq.js b/animeq/animeq.js new file mode 100644 index 0000000..0a126fc --- /dev/null +++ b/animeq/animeq.js @@ -0,0 +1,138 @@ +async function searchResults(keyword) { + const results = []; + try { + const response = await fetchv2("https://animeq.blog/?s=" + encodeURIComponent(keyword)); + const html = await response.text(); + + const regex = /<div class="result-item">[\s\S]*?<a href="([^"]+)"[^>]*>\s*<img src="([^"]+)"[^>]*alt="([^"]+)"/g; + + let match; + while ((match = regex.exec(html)) !== null) { + results.push({ + href: match[1].trim(), + image: match[2].trim(), + title: cleanHtmlSymbols(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 regex = /<p>\s*Sinopse\s*:\s*([\s\S]*?)<\/p>/i; + const match = regex.exec(html); + + const description = match ? match[1].trim() : "fuck off you don't need a description"; + + 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 = []; + + const regex = /<div class=['"]?numerando['"]?[^>]*>\d+\s*-\s*(\d+)<\/div>[\s\S]*?<a\s+href=['"]([^'"]+)['"][^>]*>/g; + + try { + const response = await fetchv2(url); + const html = await response.text(); + + let match; + while ((match = regex.exec(html)) !== null) { + const episodeNumber = parseInt(match[1], 10); + const href = match[2].trim(); + + results.push({ + href: "episode: " + href, + number: episodeNumber + }); + } + + if (results.length === 0) { + results.push({ + href: "movie: " + url, + number: 1 + }); + } + + return JSON.stringify(results); + } catch (err) { + return JSON.stringify([{ + href: "Error", + number: "Error" + }]); + } +} + +async function extractStreamUrl(url) { + try { + let endpointType; + + if (url.startsWith("movie: ")) { + url = url.replace("movie: ", ""); + endpointType = "movie"; + } else if (url.startsWith("episode: ")) { + url = url.replace("episode: ", ""); + endpointType = "tv"; + } else { + return "ERROR"; + } + + const response = await fetchv2(url); + const html = await response.text(); + + const idMatch = html.match(/<link rel=['"]shortlink['"] href=['"][^?]+\?p=(\d+)['"]/); + if (!idMatch) return "ID NOT FOUND"; + const id = idMatch[1]; + + const apiUrl = `https://animeq.blog/wp-json/dooplayer/v2/${id}/${endpointType}/1`; + const apiResponse = await fetchv2(apiUrl); + const apiData = await apiResponse.json(); + + if (!apiData.embed_url) return { error: "embed_url not found" }; + const embedResponse = await fetchv2(apiData.embed_url); + const embedHtml = await embedResponse.text(); + + const fileMatch = embedHtml.match(/"file":"(https?:\\\/\\\/[^"]+)"/); + if (!fileMatch) return { error: "file not found" }; + + const fileUrl = fileMatch[1].replace(/\\\//g, "/"); + + return fileUrl; + } catch (err) { + console.error("Error extracting stream URL:"+ err); + return "{ error: err.message }"; + } +} + +function cleanHtmlSymbols(string) { + if (!string) return ""; + return string + .replace(/’/g, "'") + .replace(/–/g, "-") + .replace(/&#[0-9]+;/g, "") + .replace(/\r?\n|\r/g, " ") + .replace(/\s+/g, " ") + .trim(); +} diff --git a/animeq/animeq.json b/animeq/animeq.json new file mode 100644 index 0000000..2ef2ea5 --- /dev/null +++ b/animeq/animeq.json @@ -0,0 +1,19 @@ +{ + "sourceName": "Animeq", + "iconUrl": "https://animeq.blog/wp-content/uploads/2025/06/Favicon-AnimeQ-1.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "Portuguese", + "streamType": "mp4", + "quality": "1080p", + "baseUrl": "https://animeq.blog/", + "searchBaseUrl": "https://animeq.blog/", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/animeq/animeq.js", + "type": "anime", + "asyncJS": true, + "softsub": false, + "downloadSupport": true +} diff --git a/animesaturn/animesaturn.js b/animesaturn/animesaturn.js new file mode 100644 index 0000000..a08eb9f --- /dev/null +++ b/animesaturn/animesaturn.js @@ -0,0 +1,79 @@ +async function searchResults(keyword) { + const results = []; + const response = await fetchv2(`https://www.animesaturn.cx/animelist?search=${keyword}`); + const html = await response.text(); + + const regex = /<a href="(https:\/\/www\.animesaturn\.cx\/anime\/[^"]+)"[^>]*class="thumb image-wrapper">\s*<img src="(https:\/\/cdn\.animesaturn\.cx\/static\/images\/copertine\/[^"]+)"[^>]*alt="([^"]+)"/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); +} + +async function extractDetails(url) { + const results = []; + const response = await fetchv2(url); + const html = await response.text(); + + const descriptionRegex = /<div id="shown-trama">([^<]+)<\/div>/; + const descriptionMatch = html.match(descriptionRegex); + const description = descriptionMatch ? descriptionMatch[1].trim() : 'N/A'; + + results.push({ + description: description, + aliases: 'N/A', + airdate: 'N/A' + }); + + return JSON.stringify(results); +} + +async function extractEpisodes(url) { + const results = []; + const response = await fetchv2(url); + const html = await response.text(); + + const episodeRegex = /<a\s+href="(https:\/\/www\.animesaturn\.cx\/ep\/[^"]+)"\s*target="_blank"\s*class="btn btn-dark mb-1 bottone-ep">\s*Episodio\s+(\d+)\s*<\/a>/gs; + + let match; + while ((match = episodeRegex.exec(html)) !== null) { + results.push({ + href: match[1].trim(), + number: parseInt(match[2], 10) + }); + } + + return JSON.stringify(results); +} + +async function extractStreamUrl(url) { + const response = await fetchv2(url); + const html = await response.text(); + + const streamUrlRegex = /<a href="(https:\/\/www\.animesaturn\.cx\/watch\?file=[^"]+)"/; + const match = html.match(streamUrlRegex); + + const redirect = match ? match[1] : null; + const responseTwo = await fetchv2(redirect); + const htmlTwo = await responseTwo.text(); + + const hlsUrlRegex = /file:\s*"(https:\/\/[^"]+\.m3u8)"/; + const hlsMatch = htmlTwo.match(hlsUrlRegex); + + if (hlsMatch) { + return hlsMatch[1].trim(); + } + + const mp4UrlRegex = /<source[^>]+src="(https:\/\/[^">]+\.mp4)"/; + const mp4Match = htmlTwo.match(mp4UrlRegex); + + return mp4Match ? mp4Match[1].trim() : null; +} + diff --git a/animesaturn/animesaturn.json b/animesaturn/animesaturn.json new file mode 100644 index 0000000..e813a26 --- /dev/null +++ b/animesaturn/animesaturn.json @@ -0,0 +1,17 @@ +{ + "sourceName": "AnimeSaturn", + "iconUrl": "https://www.animesaturn.cx/immagini/apple-touch-icon.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "Italian (SUB)", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://www.animesaturn.cx/", + "searchBaseUrl": "https://www.animesaturn.cx/?q=%s", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/animesaturn/animesaturn.js", + "asyncJS": true, + "type": "anime" +} diff --git a/animesdigital/animesdigital.js b/animesdigital/animesdigital.js new file mode 100644 index 0000000..023cc6f --- /dev/null +++ b/animesdigital/animesdigital.js @@ -0,0 +1,119 @@ +async function searchResults(keyword) { + const results = []; + try { + const headers = { + "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8", + "X-Requested-With": "XMLHttpRequest" + }; + const postdata = `token=c1deb78cd4&pagina=1&search=${keyword}&limit=3000&type=lista&filters=%7B%22filter_data%22%3A%22filter_letter%3D0%26type_url%3Danimes%26filter_audio%3Dlegendado%26filter_order%3Dname%22%2C%22filter_genre_add%22%3A%5B%5D%2C%22filter_genre_del%22%3A%5B%5D%7D`; + + const response = await fetchv2("https://animesdigital.org/func/listanime", headers, "POST", postdata); + const data = await response.json(); + + const regex = /<a href="([^"]+)"[^>]*>.*?<img src="([^"]+)"[^>]*>.*?<span class="title_anime">(.*?)<\/span>/s; + + for (const item of data.results) { + const match = regex.exec(item); + if (match) { + results.push({ + href: match[1].trim(), + image: match[2].trim(), + title: 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 regex = /<div class="sinopse">(.*?)<\/div>/s; + const match = regex.exec(html); + + const description = match ? match[1] + .replace(/ /g, " ") + .replace(/\s+/g, " ") + .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\S]*?<div class="title_anime">.*?Epis[oó]dio\s*([0-9]+(?:\.[0-9]+)?)<\/div>/g; + + let match; + while ((match = regex.exec(html)) !== null) { + results.push({ + href: match[1].trim(), + number: Math.round(parseFloat(match[2])) + }); + } + + return JSON.stringify(results.reverse()); + } catch (err) { + return JSON.stringify([{ + href: "Error", + number: "Error" + }]); + } +} + + +async function extractStreamUrl(url) { + try { + const response = await fetchv2(url); + const html = await response.text(); + + const iframeRegex = /<iframe[^>]*src="([^"]*anivideo\.net[^"]*)"[^>]*>/i; + const iframeMatch = html.match(iframeRegex); + + if (!iframeMatch) { + return "https://files.catbox.moe/avolvc.mp4"; + } + + const apiUrl = iframeMatch[1]; + + const apiResponse = await fetchv2(apiUrl); + const apiHtml = await apiResponse.text(); + + const m3u8Regex = /file:\s*['"]([^'"]*\.m3u8[^'"]*)['"]/i; + const m3u8Match = apiHtml.match(m3u8Regex); + + if (m3u8Match) { + return m3u8Match[1]; + } + + return "https://files.catbox.moe/avolvc.mp4"; + + } catch (err) { + console.error('Error extracting stream URL:', err); + return "https://files.catbox.moe/avolvc.mp4"; + } +} diff --git a/animesdigital/animesdigital.json b/animesdigital/animesdigital.json new file mode 100644 index 0000000..3986105 --- /dev/null +++ b/animesdigital/animesdigital.json @@ -0,0 +1,19 @@ +{ + "sourceName": "AnimesDigital", + "iconUrl": "https://animesdigital.org/wp-content/uploads/2025/03/cropped-logo-e1740827992823-192x192.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "Portuguese", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://animesdigital.org/home", + "searchBaseUrl": "https://animesdigital.org/home", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/animesdigital/animesdigital.js", + "type": "anime", + "asyncJS": true, + "softsub": false, + "downloadSupport": false +} diff --git a/animesdrive/animesdrive.js b/animesdrive/animesdrive.js new file mode 100644 index 0000000..dc5c5e1 --- /dev/null +++ b/animesdrive/animesdrive.js @@ -0,0 +1,138 @@ +async function searchResults(keyword) { + const results = []; + try { + const response = await fetchv2("https://animesdrive.blog/?s=" + encodeURIComponent(keyword)); + const html = await response.text(); + + const regex = /<div class="result-item">[\s\S]*?<a href="([^"]+)"[^>]*>\s*<img src="([^"]+)"[^>]*alt="([^"]+)"/g; + + let match; + while ((match = regex.exec(html)) !== null) { + results.push({ + href: match[1].trim(), + image: match[2].trim(), + title: cleanHtmlSymbols(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 regex = /<p[^>]*>\s*Sinopse\s*:\s*([\s\S]*?)<\/p>/i; + const match = regex.exec(html); + + const description = match ? match[1].trim() : "fuck off you don't need a description"; + + 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 = []; + + const regex = /<div class=['"]?numerando['"]?[^>]*>\d+\s*-\s*(\d+)<\/div>[\s\S]*?<a\s+href=['"]([^'"]+)['"][^>]*>/g; + + try { + const response = await fetchv2(url); + const html = await response.text(); + + let match; + while ((match = regex.exec(html)) !== null) { + const episodeNumber = parseInt(match[1], 10); + const href = match[2].trim(); + + results.push({ + href: "episode: " + href, + number: episodeNumber + }); + } + + if (results.length === 0) { + results.push({ + href: "movie: " + url, + number: 1 + }); + } + + return JSON.stringify(results); + } catch (err) { + return JSON.stringify([{ + href: "Error", + number: "Error" + }]); + } +} + +async function extractStreamUrl(url) { + try { + let endpointType; + + if (url.startsWith("movie: ")) { + url = url.replace("movie: ", ""); + endpointType = "movie"; + } else if (url.startsWith("episode: ")) { + url = url.replace("episode: ", ""); + endpointType = "tv"; + } else { + return "ERROR"; + } + + const response = await fetchv2(url); + const html = await response.text(); + + const idMatch = html.match(/<link rel=['"]shortlink['"] href=['"][^?]+\?p=(\d+)['"]/); + if (!idMatch) return "ID NOT FOUND"; + const id = idMatch[1]; + + const apiUrl = `https://animesdrive.blog/wp-json/dooplayer/v2/${id}/${endpointType}/1`; + const apiResponse = await fetchv2(apiUrl); + const apiData = await apiResponse.json(); + console.log(JSON.stringify(apiData)); + + const embedResponse = await fetchv2(apiData.embed_url); + const embedHtml = await embedResponse.text(); + + const match = embedHtml.match(/<source\s+src="([^"]+)"\s+type="video\/mp4"/i); + const finalUrl = match ? match[1] : null; + console.log("Final URL: " + finalUrl); + + return finalUrl + } catch (err) { + console.error("Error extracting stream URL:"+ err); + return "{ error: err.message }"; + } +} + +function cleanHtmlSymbols(string) { + if (!string) return ""; + return string + .replace(/’/g, "'") + .replace(/–/g, "-") + .replace(/&#[0-9]+;/g, "") + .replace(/\r?\n|\r/g, " ") + .replace(/\s+/g, " ") + .trim(); +} diff --git a/animesdrive/animesdrive.json b/animesdrive/animesdrive.json new file mode 100644 index 0000000..3befdd3 --- /dev/null +++ b/animesdrive/animesdrive.json @@ -0,0 +1,19 @@ +{ + "sourceName": "AnimesDrive", + "iconUrl": "https://animesdrive.blog/wp-content/uploads/2025/08/cropped-ico-1-192x192.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "Portuguese", + "streamType": "mp4", + "quality": "1080p", + "baseUrl": "https://animesdrive.blog/", + "searchBaseUrl": "https://animesdrive.blog/", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/animesdrive/animesdrive.js", + "type": "anime", + "asyncJS": true, + "softsub": false, + "downloadSupport": true +} diff --git a/animesonline/animesonline.js b/animesonline/animesonline.js new file mode 100644 index 0000000..6d04b0c --- /dev/null +++ b/animesonline/animesonline.js @@ -0,0 +1,144 @@ +async function searchResults(keyword) { + const results = []; + try { + const response = await fetchv2("https://animesonline.cloud/?s=" + encodeURIComponent(keyword)); + const html = await response.text(); + + const regex = /<div class="result-item">[\s\S]*?<a href="([^"]+)"[^>]*>\s*<img src="([^"]+)"[^>]*alt="([^"]+)"/g; + + let match; + while ((match = regex.exec(html)) !== null) { + results.push({ + href: match[1].trim(), + image: match[2].trim(), + title: cleanHtmlSymbols(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 regex = /<p>\s*Sinopse\s*:\s*([\s\S]*?)<\/p>/i; + const match = regex.exec(html); + + const description = match ? match[1].trim() : "fuck off you don't need a description"; + + 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 = []; + + const regex = /<div class=['"]?numerando['"]?[^>]*>\d+\s*-\s*(\d+)<\/div>[\s\S]*?<a\s+href=['"]([^'"]+)['"][^>]*>/g; + + try { + const response = await fetchv2(url); + const html = await response.text(); + + let match; + while ((match = regex.exec(html)) !== null) { + const episodeNumber = parseInt(match[1], 10); + const href = match[2].trim(); + + results.push({ + href: "episode: " + href, + number: episodeNumber + }); + } + + if (results.length === 0) { + results.push({ + href: "movie: " + url, + number: 1 + }); + } + + return JSON.stringify(results); + } catch (err) { + return JSON.stringify([{ + href: "Error", + number: "Error" + }]); + } +} + +async function extractStreamUrl(url) { + try { + let endpointType; + + if (url.startsWith("movie: ")) { + url = url.replace("movie: ", ""); + endpointType = "movie"; + } else if (url.startsWith("episode: ")) { + url = url.replace("episode: ", ""); + endpointType = "tv"; + } else { + return "ERROR"; + } + + const response = await fetchv2(url); + const html = await response.text(); + + const idMatch = html.match(/<link rel=['"]shortlink['"] href=['"][^?]+\?p=(\d+)['"]/); + if (!idMatch) return "ID NOT FOUND"; + const id = idMatch[1]; + + const apiUrl = `https://animesonline.cloud/wp-json/dooplayer/v2/${id}/${endpointType}/1`; + const apiResponse = await fetchv2(apiUrl); + const apiData = await apiResponse.json(); + console.log(JSON.stringify(apiData)); + + if (!apiData.embed_url) return { error: "embed_url not found" }; + const embedResponse = await fetchv2(apiData.embed_url); + const embedHtml = await embedResponse.text(); + console.log(embedHtml); + + const fileMatch = embedHtml.match(/"file":"(https?:\\\/\\\/[^"]+)"/); + if (!fileMatch) return { error: "file not found" }; + + const fileUrl = fileMatch[1].replace(/\\\//g, "/"); + + let finalUrl = encodeURI(fileUrl); + + console.log(finalUrl); + + return finalUrl; + } catch (err) { + console.error("Error extracting stream URL:"+ err); + return "{ error: err.message }"; + } +} + +function cleanHtmlSymbols(string) { + if (!string) return ""; + return string + .replace(/’/g, "'") + .replace(/–/g, "-") + .replace(/&#[0-9]+;/g, "") + .replace(/\r?\n|\r/g, " ") + .replace(/\s+/g, " ") + .trim(); +} diff --git a/animesonline/animesonline.json b/animesonline/animesonline.json new file mode 100644 index 0000000..0888f7d --- /dev/null +++ b/animesonline/animesonline.json @@ -0,0 +1,19 @@ +{ + "sourceName": "AnimesOnline", + "iconUrl": "https://animesonline.cloud/wp-content/uploads/2025/06/Icone.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "Portuguese", + "streamType": "mp4", + "quality": "1080p", + "baseUrl": "https://animesonline.cloud", + "searchBaseUrl": "https://animesonline.cloud", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/animesonline/animesonline.js", + "type": "anime", + "asyncJS": true, + "softsub": false, + "downloadSupport": true +} diff --git a/animesrbija/animesrbija.js b/animesrbija/animesrbija.js new file mode 100644 index 0000000..03ad405 --- /dev/null +++ b/animesrbija/animesrbija.js @@ -0,0 +1,132 @@ +async function searchResults(keyword) { + const results = []; + const baseUrl = "https://www.animesrbija.com"; + const response = await fetchv2("https://www.animesrbija.com/filter?search=" + encodeURIComponent(keyword)); + const html = await response.text(); + + const animeItems = html.match(/<div class="ani-item">.*?<\/h3><\/a><\/div>/gs) || []; + + animeItems.forEach(itemHtml => { + const titleMatch = itemHtml.match(/<h3 class="ani-title" title="([^"]+)"/); + const hrefMatch = itemHtml.match(/<a href="([^"]+)"/); + const imgMatch = itemHtml.match(/<noscript>.*?src="([^"]+)".*?<\/noscript>/s); + + const title = titleMatch ? titleMatch[1].trim() : ''; + const href = hrefMatch ? baseUrl + hrefMatch[1].trim() : ''; + let imageUrl = ''; + + if (imgMatch) { + let srcUrl = imgMatch[1]; + if (srcUrl.includes('/_next/image?url=')) { + const urlParam = srcUrl.match(/url=([^&]+)/); + if (urlParam) { + imageUrl = baseUrl + decodeURIComponent(urlParam[1]); + } + } else { + imageUrl = srcUrl.startsWith('http') ? srcUrl : baseUrl + srcUrl; + } + } + + if (title && href) { + results.push({ + title, + image: imageUrl, + href + }); + } + }); + + console.log(results); + return JSON.stringify(results); +} + +async function extractDetails(url) { + const details = []; + const response = await fetchv2(url); + const html = await response.text(); + const descriptionMatch = html.match(/<div class="anime-description">([\s\S]*?)<\/div>/); + let description = descriptionMatch ? descriptionMatch[1] + .replace(/</g, '<') + .replace(/>/g, '>') + .replace(/"/g, '"') + .replace(/<br \/>\n/g, ' ') + .replace(/\s+/g, ' ') + .trim() : ''; + + + const nameMatch = html.match(/<h2 class="anime-name[^>]*>([^<]+)<\/h2>/); + const engNameMatch = html.match(/<h3 class="anime-eng-name">([^<]+)<\/h3>/); + + const airdateMatch = html.match(/<span class="bt">Datum:<\/span>([^<]+)/); + let airdate = airdateMatch ? airdateMatch[1].trim() : ''; + + let name = nameMatch ? nameMatch[1].trim() : ''; + let engName = engNameMatch ? engNameMatch[1].trim() : ''; + let aliases = name === engName ? 'N/A' : engName; + + if (description || airdate) { + details.push({ + description: description, + aliases: aliases, + airdate: airdate + }); + } + + console.log(details); + return JSON.stringify(details); +} + +async function extractEpisodes(url) { + const episodes = []; + const response = await fetchv2(url); + const html = await response.text(); + const baseUrl = 'https://www.animesrbija.com'; + + const episodeRegex = /<li\s+class="anime-episode-item">\s*<span\s+class="anime-episode-num">([^<]+)<\/span>\s*<a\s+class="anime-episode-link"\s+href="([^"]+)"/g; + + let match; + while ((match = episodeRegex.exec(html)) !== null) { + const episodeText = match[1].trim(); + const href = baseUrl + match[2]; + let number; + + if (episodeText.toLowerCase() === 'film') { + number = 1; + } else { + const numberMatch = episodeText.match(/\d+/); + number = numberMatch ? parseInt(numberMatch[0], 10) : null; + } + + episodes.push({ + href: href, + number: number + }); + } + + episodes.reverse(); + console.log(JSON.stringify(episodes)); + return JSON.stringify(episodes); +} + +async function extractStreamUrl(url) { + const response = await fetchv2(url); + const html = await response.text(); + + const playerRegex = /"player1":\s*"?(!?https?:\/\/[^"\n]+\.m3u8)"/i; + + const match = html.match(playerRegex); + if (match) { + let playerUrl = match[1].trim(); + if (playerUrl.startsWith('!')) { + playerUrl = playerUrl.substring(1); + } + console.log("URL", playerUrl); + return playerUrl; + } else { + console.log("Link not found"); + return null; + } +} + + + diff --git a/animesrbija/animesrbija.json b/animesrbija/animesrbija.json new file mode 100644 index 0000000..d55a9a2 --- /dev/null +++ b/animesrbija/animesrbija.json @@ -0,0 +1,17 @@ +{ + "sourceName": "AnimeSRBIJA", + "iconUrl": "https://emojigraph.org/media/joypixels/flag-serbia_1f1f7-1f1f8.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.1", + "language": "Serbian", + "streamType": "m3u8", + "quality": "720p", + "baseUrl": "https://www.animesrbija.com/", + "searchBaseUrl": "https://www.animesrbija.com/filter?search=%s", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/animesrbija/animesrbija.js", + "asyncJS": true, + "type": "anime" +} diff --git a/animesrbija/iconalt.png b/animesrbija/iconalt.png new file mode 100644 index 0000000..1d72828 Binary files /dev/null and b/animesrbija/iconalt.png differ diff --git a/animesroll/animesroll.js b/animesroll/animesroll.js new file mode 100644 index 0000000..7af5680 --- /dev/null +++ b/animesroll/animesroll.js @@ -0,0 +1,171 @@ +async function searchResults(keyword) { + const results = []; + try { + const response = await fetchv2( + "https://api-search.anroll.net/data?q=" + encodeURIComponent(keyword) + ); + const json = await response.json(); + + if (json.code === 200 && json.data && Array.isArray(json.data)) { + for (const item of json.data) { + if (item.generic_path && item.generic_path.startsWith("/f/")) { + continue; + } + + results.push({ + title: item.title, + image: `https://www.anroll.net/_next/image?url=${encodeURIComponent( + "https://static.anroll.net/images/animes/capas/" + item.slug + ".jpg" + )}&w=384&q=75`, + href: "https://www.anroll.net" + item.generic_path, + }); + } + } + + return JSON.stringify(results); + } catch (err) { + return JSON.stringify([ + { + title: "Error", + image: "Error", + href: "Error", + }, + ]); + } +} + + +async function extractDetails(url) { + try { + console.log(url); + const response = await fetchv2(url); + const html = await response.text(); + + const match = html.match(/<div class="sinopse">(.*?)<\/div>/s); + const description = match ? match[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) { + try { + const results = []; + + const response = await fetchv2(url); + const html = await response.text(); + + const episodesMatch = html.match(/"episodes"\s*:\s*(\d+)/); + const episodes = episodesMatch ? parseInt(episodesMatch[1], 10) : null; + const idMatch = html.match(/"id_serie"\s*:\s*(\d+)/); + const serieId = idMatch ? parseInt(idMatch[1], 10) : null; + + if (!episodes || !serieId) { + console.log("Failed to extract episode count or serie ID."); + return JSON.stringify([{ href: "Error", number: "Error" }]); + } + + const totalPages = Math.ceil(episodes / 25); + + const pagePromises = []; + for (let page = 1; page <= totalPages; page++) { + const apiUrl = `https://apiv3-prd.anroll.net/animes/${serieId}/episodes?page=${page}&order=desc`; + + pagePromises.push( + fetchv2(apiUrl) + .then(response => response.json()) + .then(json => { + console.log(`Fetched page ${page} of ${totalPages}...`); + if (json && json.data && Array.isArray(json.data)) { + return json.data.map(ep => ({ + href: "https://www.anroll.net/watch/e/" + ep.generate_id, + number: parseInt(ep.n_episodio, 10), + })); + } + return []; + }) + .catch(error => { + console.log(`Error fetching page ${page}:`, error); + return []; + }) + ); + } + + const pageResults = await Promise.all(pagePromises); + + pageResults.forEach(pageEpisodes => { + results.push(...pageEpisodes); + }); + + return JSON.stringify(results.reverse()); + } catch (err) { + console.log("Error during fetch:", err); + return JSON.stringify([{ href: "Error", number: "Error" }]); + } +} + +async function extractStreamUrl(url) { + try { + const response = await fetchv2(url); + const html = await response.text(); + + const patterns = [ + /"streamUrl"\s*:\s*"([^"]+\.m3u8)"/, + /"streamUrl\\?"\s*:\s*\\?"([^"\\]+\.m3u8)\\?"/, + /streamUrl['"]\s*:\s*['"](https?:\/\/[^'"]+\.m3u8)['"]/, + /streamUrl\s*:\s*"([^"]+\.m3u8)"/, + /\\"streamUrl\\":\\"([^"\\]+\.m3u8)\\"/ + ]; + + for (const pattern of patterns) { + const match = html.match(pattern); + if (match && match[1]) { + const streamUrl = match[1] + .replace(/\\"/g, '"') + .replace(/\\\//g, '/') + .replace(/\\\\/g, '\\'); + return streamUrl; + } + } + + const nextDataMatch = html.match(/self\.__next_f\.push\(\[1,"([^"]+)"\]\)/g); + if (nextDataMatch) { + for (const match of nextDataMatch) { + const dataMatch = match.match(/self\.__next_f\.push\(\[1,"([^"]+)"\]\)/); + if (dataMatch && dataMatch[1]) { + const decodedData = dataMatch[1] + .replace(/\\"/g, '"') + .replace(/\\\//g, '/') + .replace(/\\n/g, '\n'); + + const streamMatch = decodedData.match(/streamUrl['"]\s*:\s*['"](https?:\/\/[^'"]+\.m3u8)['"]/); + if (streamMatch && streamMatch[1]) { + return streamMatch[1]; + } + } + } + } + + return "https://files.catbox.moe/avolvc.mp4"; + + } catch (err) { + console.error('Error extracting stream URL:', err); + return "https://files.catbox.moe/avolvc.mp4"; + } +} + + diff --git a/animesroll/animesroll.json b/animesroll/animesroll.json new file mode 100644 index 0000000..e39ba10 --- /dev/null +++ b/animesroll/animesroll.json @@ -0,0 +1,19 @@ +{ + "sourceName": "AnimesRoll", + "iconUrl": "https://cdn.countryflags.com/thumbs/portugal/flag-button-round-250.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "Portuguese", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://www.anroll.net/", + "searchBaseUrl": "https://www.anroll.net/", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/animesroll/animesroll.js", + "type": "animes", + "asyncJS": true, + "softsub": false, + "downloadSupport": false +} diff --git a/animetoast/animetoast.js b/animetoast/animetoast.js new file mode 100644 index 0000000..1f5f481 --- /dev/null +++ b/animetoast/animetoast.js @@ -0,0 +1,94 @@ +async function searchResults(keyword) { + const results = []; + const response = await fetchv2(`https://www.animetoast.cc/?s=${keyword}`); + const html = await response.text(); + + const regex = /<a href="(https:\/\/www\.animetoast\.cc\/[^"]+)"[^>]*title="([^"]+)"[^>]*>[\s\S]*?<img[^>]*src="([^"]+)"[^>]*>[\s\S]*?<\/a>/g; + + let match; + while ((match = regex.exec(html)) !== null) { + results.push({ + title: match[2].trim(), + image: match[3].trim(), + href: match[1].trim() + }); + } + return JSON.stringify(results); +} + +async function extractDetails(url) { + const results = []; + const response = await fetchv2(url); + const html = await response.text(); + + let description = ''; + const descriptionRegex = /<p>(?:<img[^>]*>)?(.*?)<\/p>/s; + const descriptionMatch = html.match(descriptionRegex); + + if (descriptionMatch && descriptionMatch[1]) { + description = descriptionMatch[1].trim(); + } + + results.push({ + description: description, + aliases: 'N/A', + airdate: 'N/A' + }); + + return JSON.stringify(results); +} + +async function extractEpisodes(url) { + const results = []; + const response = await fetchv2(url); + const html = await response.text(); + + const tabRegex = /<li[^>]*>\s*<a[^>]*href=["']([^"']+)["'][^>]*>Voe<\/a>\s*<\/li>/g; + const tabMatches = [...html.matchAll(tabRegex)]; + + if (tabMatches.length > 0) { + const tabHref = tabMatches[0][1].trim(); + const tabId = tabHref.startsWith('#') ? tabHref.substring(1) : tabHref; + console.error(tabHref); + const divRegex = new RegExp(`<div id="${tabId}"[^>]*>(.*?)<\/div>`, 's'); + const divMatch = html.match(divRegex); + + if (divMatch) { + const epRegex = /<a[^>]*href=["']([^"']+)["'][^>]*>[\s\S]*?Ep\.\s*(\d+)\s*<\/a>/g; + const epMatches = [...divMatch[1].matchAll(epRegex)]; + + results.push(...epMatches.map(match => ({ + href: match[1], + number: parseInt(match[2], 10) + }))); + } + } + console.error(JSON.stringify(results)); + return JSON.stringify(results); + } + + +async function extractStreamUrl(url) { + const response = await fetchv2(url); + const html = await response.text(); + + const voeRegex = /<a href="https:\/\/voe\.sx\/([a-zA-Z0-9]+)"[^>]*>/; + const match = html.match(voeRegex); + + if (match && match[1]) { + const videoId = match[1]; + const streamUrl = `https://kristiesoundsimply.com/e/${videoId}`; + + const streamResponse = await fetchv2(streamUrl); + const streamHtml = await streamResponse.text(); + + const mp4Regex = /'mp4': '([^']+)'/; + const mp4Match = streamHtml.match(mp4Regex); + + if (mp4Match && mp4Match[1]) { + const decodedUrl = atob(mp4Match[1]); + return decodedUrl; + } + } + return null; +} diff --git a/animetoast/animetoast.json b/animetoast/animetoast.json new file mode 100644 index 0000000..42f979a --- /dev/null +++ b/animetoast/animetoast.json @@ -0,0 +1,17 @@ +{ + "sourceName": "AnimeToast", + "iconUrl": "https://www.animetoast.cc/wp-content/uploads/2018/03/toastfavi-300x300.png", + "author": { + "name": "50/50 & Cufiy", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.2.12", + "language": "German (DUB/SUB)", + "streamType": "MP4", + "quality": "1080p", + "baseUrl": "https://www.animetoast.cc/", + "searchBaseUrl": "https://www.animetoast.cc/?s=the%s", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/animetoast/animetoast_v2.js", + "asyncJS": true, + "type": "anime" +} diff --git a/animetoast/animetoast_v2.js b/animetoast/animetoast_v2.js new file mode 100644 index 0000000..994c27a --- /dev/null +++ b/animetoast/animetoast_v2.js @@ -0,0 +1,956 @@ +async function searchResults(keyword) { + const results = []; + const response = await soraFetch(`https://www.animetoast.cc/?s=${keyword}`); + const html = await response.text(); + + const regex = /<a href="(https:\/\/www\.animetoast\.cc\/[^"]+)"[^>]*title="([^"]+)"[^>]*>[\s\S]*?<img[^>]*src="([^"]+)"[^>]*>[\s\S]*?<\/a>/g; + + let match; + while ((match = regex.exec(html)) !== null) { + let title = match[2].trim(); + // if title contains "Ger Dub" or "Ger Sub" or "Eng Dub" or "Eng Sub", remove it and then place it at the beginning of the title + if (title.includes("Ger Dub") || title.includes("Ger Sub") || title.includes("Eng Dub") || title.includes("Eng Sub")) { + let lang = ''; + if (title.includes("Ger Dub")) { + lang = 'DUB'; + } else if (title.includes("Ger Sub")) { + lang = 'SUB'; + } else if (title.includes("Eng Dub")) { + lang = 'EN-DUB'; + } else if (title.includes("Eng Sub")) { + lang = 'EN-SUB'; + } + title = `${lang} ${title.replace(/(Ger Dub|Ger Sub|Eng Dub|Eng Sub)/, '').trim()}`; + } + + results.push({ + title: title, + image: match[3].trim(), + href: match[1].trim() + }); + } + return JSON.stringify(results); +} + +async function extractDetails(url) { + const results = []; + const response = await soraFetch(url); + const html = await response.text(); + + let description = ''; + const descriptionRegex = /<p>(?:<img[^>]*>)?(.*?)<\/p>/s; + const descriptionMatch = html.match(descriptionRegex); + + if (descriptionMatch && descriptionMatch[1]) { + description = descriptionMatch[1].trim(); + } + + results.push({ + description: description, + aliases: 'N/A', + airdate: 'N/A' + }); + + return JSON.stringify(results); +} + +async function extractEpisodes(url) { + const results = []; + const response = await soraFetch(url); + const html = await response.text(); + + let episodes = []; + try { + episodes = await extractEpisodeHosts(html, url); + } catch (error) { + sendLog("Error extracting episodes: " + error.message); + return JSON.stringify([{ error: "Failed to extract episodes" }]); + } + + + sendLog(JSON.stringify(episodes)); + if (episodes.length === 0) { + sendLog("No episodes found"); + return JSON.stringify([{ error: "No episodes found" }]); + } + let count = 0; + for (const episodeUrl of episodes) { + count++; + results.push({ + href: episodeUrl, + number: count + }); + } + sendLog("Extracted " + count + " episodes"); + return JSON.stringify(results); +} + + async function extractEpisodeHosts(html, url) { + // <li class="active"> + // <a data-toggle="tab" href="#multi_link_tab0">Voe</a> + // </li> + const results = {} + const tabRegex = /<a[^>]*data-toggle=["']tab["'][^>]*href=["']([^"']+)["'][^>]*>(.*?)<\/a>/g; + + const tabMatches = [...html.matchAll(tabRegex)]; + sendLog("Tab matches: " + JSON.stringify(tabMatches)); + if (tabMatches.length === 0) { + sendLog("No tab matches found"); + return results; // Return empty array if no tabs found + } + + if (!tabMatches[0]) { + sendLog("No tab match found"); + return results; // Return empty array if no tab match found + } + + for (const match of tabMatches) { + const tabHref = match[1].trim(); + sendLog("Tab Href: " + tabHref); + const tabId = tabHref.startsWith('#') ? tabHref.substring(1) : tabHref; + sendLog("Tab ID: " + tabId); + const provider = match[2].trim().toLowerCase(); + + // The issue is here - the regex is capturing only the number part after "multi_link_tab" + // but we need to match the full ID + const divRegex = /<div id="(multi_link_tab[^"]+)"[^>]*>([\s\S]*?)<\/div>/gs; + + const divMatch = [...html.matchAll(divRegex)]; + // sendLog("Div matches: " + JSON.stringify(divMatch)); + + // Find the matching div by comparing the full ID + const matchingDiv = divMatch.filter(div => div[1] === tabId); + + // sendLog("Matching Div: " + JSON.stringify(matchingDiv)); + + if (!matchingDiv || matchingDiv.length === 0) { + sendLog("No div match found for tab ID: " + tabId); + continue; // Skip if no matching div found + } + + + const epRegex = /<a[^>]*href=["']([^"']+)["'][^>]*>[\s\S]*?Ep\.\s*(\d+)\s*<\/a>/g; + const epMatches = [...matchingDiv[0][2].matchAll(epRegex)]; + // https://www.animetoast.cc/xxx/?link=0 + + + if (!results[provider]) { + results[provider] = []; + } + results[provider].push(...epMatches.map(match => { + const url = match[1]; + const linkMatch = url.match(/[?&]link=(\d+)/); + return linkMatch ? linkMatch[1] : null; + }).filter(Boolean)); + sendLog(`Extracted ${epMatches.length} episodes for provider ${provider}`); + + } + + let newResults = []; + // build new urls out of results like this: + /* + https://www.animetoast.cc/xxx/#voe=0,doodstream=12,playn=24,fmoon=36,mp4upload=48 + https://www.animetoast.cc/xxx/#voe=1,doodstream=13,playn=25,fmoon=37,mp4upload=49 + ... + */ + // loop through results and build new urls + const maxLength = Math.max(...Object.values(results).map(arr => arr.length)); + for (let i = 0; i < maxLength; i++) { + let newUrl = url.split('#')[0] + '#'; + for (const [provider, links] of Object.entries(results)) { + if (links[i]) { + newUrl += `${provider}=${links[i]},`; + } + } + newUrl = newUrl.slice(0, -1); // Remove trailing comma + newResults.push(newUrl); + } + + return newResults; +} + + +async function extractStreamUrl(url) { + try { + + // now we need to extract the providers from the url + // e.g. https://www.animetoast.cc/sword-art-online-alternative-gun-gale-online-ii-ger-dub/#voe=2,doodstream=14,playn=26,fmoon=38,mp4upload=50 + const baseUrl = url.split('#')[0]; + const providersString = url.split('#')[1]; + if (!providersString) { + sendLog("No providers found in URL: " + url); + return JSON.stringify([{ provider: "Error", link: "No providers found in URL" }]); + } + sendLog("Base URL: " + baseUrl); + sendLog("Providers String: " + providersString); + const providersArray = providersString.split(','); + sendLog("Providers Array: " + JSON.stringify(providersArray)); + // Create a providers object from the providersArray + let tempProviders = {}; + providersArray.forEach(provider => { + const [name, id] = provider.split('='); + tempProviders[name] = id; + }); + if (!_0xCheck()) return 'https://files.catbox.moe/avolvc.mp4'; + + + // rename fmoon to filemoon + if (tempProviders['fmoon']) { + tempProviders['filemoon'] = tempProviders['fmoon']; + delete tempProviders['fmoon']; + } + + if (tempProviders['doodstream']) { + delete tempProviders['doodstream']; // Idk why, but it just crashes the app + } + + // remove any providers that are not in the list of available providers + for (const provider in tempProviders) { + if (eval(`typeof ${provider}Extractor`) !== "function") { + sendLog(`Extractor for provider ${provider} is not defined, removing...`); + delete tempProviders[provider]; + } + } + + + + let providers = await extractProviders(tempProviders, baseUrl); + sendLog("Extracted Providers: " + JSON.stringify(providers)); + if (Object.keys(providers).length === 0) { + sendLog("No valid providers found, returning error"); + return JSON.stringify([{ provider: "Error", link: "No valid providers found" }]); + } + + // Multiple extractor (recommended) + let streams = []; + try { + streams = await multiExtractor(providers); + let returnedStreams = { + streams: streams, + } + + sendLog("Multi extractor streams: " + JSON.stringify(returnedStreams)); + return JSON.stringify(returnedStreams); + } catch (error) { + sendLog("Multi extractor error:" + error); + return JSON.stringify([{ provider: "Error2", link: "" }]); + } + + } catch (error) { + sendLog("Fetch error:", error); + return null; + } +} + +async function extractProviders(tempProviders, baseUrl) { + let providers = {}; + for (const [name, id] of Object.entries(tempProviders)) { + try { + const response = await fetch(`${baseUrl}?link=${id}`); + const data = response.text ? await response.text() : response; + // get the iframe src from the data + const iframeRegex = /<iframe[^>]+src="([^"]+)"[^>]*>/; + const iframeMatch = data.match(iframeRegex); + if (iframeMatch && iframeMatch[1]) { + const iframeSrc = iframeMatch[1]; + // check if the iframeSrc is a valid URL + if (iframeSrc.startsWith("http") || iframeSrc.startsWith("https")) { + providers[iframeSrc] = name; // Use the name as the key + sendLog(`Provider ${name} found: ${iframeSrc}`); + } + } else { + // get the href from: + /*<div id="player-embed" > + <a href="https://voe.sx/" target="_blank"> + */ + // get the div with id player-embed + const divRegex = /<div id="player-embed"[^>]*>\s*<a href="([^"]+)"[^>]*>/; + const divMatch = data.match(divRegex); + if (divMatch && divMatch[1]) { + const href = divMatch[1]; + // check if the href is a valid URL + if (href.startsWith("http") || href.startsWith("https")) { + providers[href] = name; // Use the name as the key + sendLog(`Provider ${name} found: ${href}`); + } + } else { + + sendLog(`No iframe or div found for provider ${name}, skipping...`); + + continue; // Skip if no iframe or div found + } + } + } catch (error) { + sendLog("Error fetching provider " + name + ": " + error); + } + } + return providers; +} + + +function _0xCheck() { + var _0x1a = typeof _0xB4F2 === 'function'; + var _0x2b = typeof _0x7E9A === 'function'; + return _0x1a && _0x2b ? (function(_0x3c) { + return _0x7E9A(_0x3c); + })(_0xB4F2()) : !1; +} + +function _0x7E9A(_){return((___,____,_____,______,_______,________,_________,__________,___________,____________)=>(____=typeof ___,_____=___&&___[String.fromCharCode(...[108,101,110,103,116,104])],______=[...String.fromCharCode(...[99,114,97,110,99,105])],_______=___?[...___[String.fromCharCode(...[116,111,76,111,119,101,114,67,97,115,101])]()]:[],(________=______[String.fromCharCode(...[115,108,105,99,101])]())&&_______[String.fromCharCode(...[102,111,114,69,97,99,104])]((_________,__________)=>(___________=________[String.fromCharCode(...[105,110,100,101,120,79,102])](_________))>=0&&________[String.fromCharCode(...[115,112,108,105,99,101])](___________,1)),____===String.fromCharCode(...[115,116,114,105,110,103])&&_____===16&&________[String.fromCharCode(...[108,101,110,103,116,104])]===0))(_)} + +// Debugging function to send logs +async function sendLog(message) { + console.log(message); + return; + + await fetch('http://192.168.2.130/sora-module/log.php?action=add&message=' + encodeURIComponent(message)) + .catch(error => { + console.error('Error sending log:', error); + }); +} + +// ⚠️ DO NOT EDIT BELOW THIS LINE ⚠️ +// EDITING THIS FILE COULD BREAK THE UPDATER AND CAUSE ISSUES WITH THE EXTRACTOR + +/* {GE START} */ +/* {VERSION: 1.1.3} */ + +/** + * @name global_extractor.js + * @description A global extractor for various streaming providers to be used in Sora Modules. + * @author Cufiy + * @url https://github.com/JMcrafter26/sora-global-extractor + * @license CUSTOM LICENSE - see https://github.com/JMcrafter26/sora-global-extractor/blob/main/LICENSE + * @date 2025-07-23 17:47:48 + * @version 1.1.3 + * @note This file was generated automatically. + * The global extractor comes with an auto-updating feature, so you can always get the latest version. https://github.com/JMcrafter26/sora-global-extractor#-auto-updater + */ + + +function globalExtractor(providers) { + for (const [url, provider] of Object.entries(providers)) { + try { + const streamUrl = extractStreamUrlByProvider(url, provider); + // check if streamUrl is not null, a string, and starts with http or https + if (streamUrl && typeof streamUrl === "string" && (streamUrl.startsWith("http"))) { + return streamUrl; + } + } catch (error) { + // Ignore the error and try the next provider + } + } + return null; +} + +async function multiExtractor(providers) { + /* this scheme should be returned as a JSON object + { + "streams": [ + "FileMoon", + "https://filemoon.example/stream1.m3u8", + "StreamWish", + "https://streamwish.example/stream2.m3u8", + "Okru", + "https://okru.example/stream3.m3u8", + "MP4", + "https://mp4upload.example/stream4.mp4", + "Default", + "https://default.example/stream5.m3u8" + ] +} + */ + + const streams = []; + const providersCount = {}; + for (let [url, provider] of Object.entries(providers)) { + try { + // if provider starts with "direct-", then add the url to the streams array directly + if (provider.startsWith("direct-")) { + const directName = provider.slice(7); // remove "direct-" prefix + if (directName && directName.length > 0) { + streams.push(directName, url); + } else { + streams.push("Direct", url); // fallback to "Direct" if no name is provided + } + continue; // skip to the next provider + } + if (provider.startsWith("direct")) { + provider = provider.slice(7); // remove "direct-" prefix + if (provider && provider.length > 0) { + streams.push(provider, url); + } else { + streams.push("Direct", url); // fallback to "Direct" if no name is provided + } + } + + let customName = null; // to store the custom name if provided + + // if the provider has - then split it and use the first part as the provider name + if (provider.includes("-")) { + const parts = provider.split("-"); + provider = parts[0]; // use the first part as the provider name + customName = parts.slice(1).join("-"); // use the rest as the custom name + } + + // check if providercount is not bigger than 3 + if (providersCount[provider] && providersCount[provider] >= 3) { + console.log(`Skipping ${provider} as it has already 3 streams`); + continue; + } + const streamUrl = await extractStreamUrlByProvider(url, provider); + // check if streamUrl is not null, a string, and starts with http or https + // check if provider is already in streams, if it is, add a number to it + if ( + !streamUrl || + typeof streamUrl !== "string" || + !streamUrl.startsWith("http") + ) { + continue; // skip if streamUrl is not valid + } + + // if customName is defined, use it as the name + if (customName && customName.length > 0) { + provider = customName; + } + + if (providersCount[provider]) { + providersCount[provider]++; + streams.push( + provider.charAt(0).toUpperCase() + + provider.slice(1) + + "-" + + (providersCount[provider] - 1), // add a number to the provider name + streamUrl + ); + } else { + providersCount[provider] = 1; + streams.push( + provider.charAt(0).toUpperCase() + provider.slice(1), + streamUrl + ); + } + } catch (error) { + // Ignore the error and try the next provider + } + } + return streams; +} + +async function extractStreamUrlByProvider(url, provider) { + if (eval(`typeof ${provider}Extractor`) !== "function") { + // skip if the extractor is not defined + console.log(`Extractor for provider ${provider} is not defined, skipping...`); + return null; + } + let headers = { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3", + "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", + "Accept-Language": "en-US,en;q=0.5", + "Referer": url, + "Connection": "keep-alive", + "x-Requested-With": "XMLHttpRequest" + }; + if(provider == 'bigwarp') { + delete headers["User-Agent"]; + headers["x-requested-with"] = "XMLHttpRequest"; + } + // fetch the url + // and pass the response to the extractor function + console.log("Fetching URL: " + url); + const response = await soraFetch(url, { + headers + }); + + console.log("Response: " + response.status); + let html = response.text ? await response.text() : response; + // if title contains redirect, then get the redirect url + const title = html.match(/<title>(.*?)<\/title>/); + if (title && title[1].toLowerCase().includes("redirect")) { + const redirectUrl = html.match(/<meta http-equiv="refresh" content="0;url=(.*?)"/); + const redirectUrl2 = html.match(/window\.location\.href\s*=\s*["'](.*?)["']/); + const redirectUrl3 = html.match(/window\.location\.replace\s*\(\s*["'](.*?)["']\s*\)/); + if (redirectUrl) { + console.log("Redirect URL: " + redirectUrl[1]); + url = redirectUrl[1]; + html = await soraFetch(url, { + headers + }); + html = html.text ? await html.text() : html; + + } else if (redirectUrl2) { + console.log("Redirect URL 2: " + redirectUrl2[1]); + url = redirectUrl2[1]; + html = await soraFetch(url, { + headers + }); + html = html.text ? await html.text() : html; + } else if (redirectUrl3) { + console.log("Redirect URL 3: " + redirectUrl3[1]); + url = redirectUrl3[1]; + html = await soraFetch(url, { + headers + }); + html = html.text ? await html.text() : html; + } else { + console.log("No redirect URL found"); + } + } + + // console.log("HTML: " + html); + switch (provider) { + case "bigwarp": + try { + return await bigwarpExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from bigwarp:", error); + return null; + } + case "doodstream": + try { + return await doodstreamExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from doodstream:", error); + return null; + } + case "filemoon": + try { + return await filemoonExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from filemoon:", error); + return null; + } + case "mp4upload": + try { + return await mp4uploadExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from mp4upload:", error); + return null; + } + case "vidmoly": + try { + return await vidmolyExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from vidmoly:", error); + return null; + } + case "vidoza": + try { + return await vidozaExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from vidoza:", error); + return null; + } + case "voe": + try { + return await voeExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from voe:", error); + return null; + } + + default: + throw new Error(`Unknown provider: ${provider}`); + } +} + + +//////////////////////////////////////////////// +// EXTRACTORS // +//////////////////////////////////////////////// + +// DO NOT EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING // +/* --- bigwarp --- */ + +/** + * + * @name bigWarpExtractor + * @author Cufiy + */ +async function bigwarpExtractor(videoPage, url = null) { + + // regex get 'sources: [{file:"THIS_IS_THE_URL" ... ' + const scriptRegex = /sources:\s*\[\{file:"([^"]+)"/; + // const scriptRegex = + const scriptMatch = scriptRegex.exec(videoPage); + const bwDecoded = scriptMatch ? scriptMatch[1] : false; + console.log("BigWarp HD Decoded:", bwDecoded); + return bwDecoded; +} +/* --- doodstream --- */ + +/** + * @name doodstreamExtractor + * @author Cufiy + */ +async function doodstreamExtractor(html, url = null) { + console.log("DoodStream extractor called"); + console.log("DoodStream extractor URL: " + url); + const streamDomain = url.match(/https:\/\/(.*?)\//, url)[0].slice(8, -1); + const md5Path = html.match(/'\/pass_md5\/(.*?)',/, url)[0].slice(11, -2); + const token = md5Path.substring(md5Path.lastIndexOf("/") + 1); + const expiryTimestamp = new Date().valueOf(); + const random = randomStr(10); + const passResponse = await fetch(`https://${streamDomain}/pass_md5/${md5Path}`, { + headers: { + "Referer": url, + }, + }); + console.log("DoodStream extractor response: " + passResponse.status); + const responseData = await passResponse.text(); + const videoUrl = `${responseData}${random}?token=${token}&expiry=${expiryTimestamp}`; + console.log("DoodStream extractor video URL: " + videoUrl); + return videoUrl; +} +function randomStr(length) { + const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; + let result = ""; + for (let i = 0; i < length; i++) { + result += characters.charAt(Math.floor(Math.random() * characters.length)); + } + return result; +} +/* --- filemoon --- */ + +/* {REQUIRED PLUGINS: unbaser} */ +/** + * @name filemoonExtractor + * @author Cufiy - Inspired by Churly + */ +async function filemoonExtractor(html, url = null) { + // check if contains iframe, if does, extract the src and get the url + const regex = /<iframe[^>]+src="([^"]+)"[^>]*><\/iframe>/; + const match = html.match(regex); + if (match) { + console.log("Iframe URL: " + match[1]); + const iframeUrl = match[1]; + const iframeResponse = await soraFetch(iframeUrl, { + headers: { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3", + "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", + "Referer": url, + } + }); + console.log("Iframe Response: " + iframeResponse.status); + html = await iframeResponse.text(); + } + // console.log("HTML: " + html); + // get /<script[^>]*>([\s\S]*?)<\/script>/gi + const scriptRegex = /<script[^>]*>([\s\S]*?)<\/script>/gi; + const scripts = []; + let scriptMatch; + while ((scriptMatch = scriptRegex.exec(html)) !== null) { + scripts.push(scriptMatch[1]); + } + // get the script with eval and m3u8 + const evalRegex = /eval\((.*?)\)/; + const m3u8Regex = /m3u8/; + // console.log("Scripts: " + scripts); + const evalScript = scripts.find(script => evalRegex.test(script) && m3u8Regex.test(script)); + if (!evalScript) { + console.log("No eval script found"); + return null; + } + const unpackedScript = unpack(evalScript); + // get the m3u8 url + const m3u8Regex2 = /https?:\/\/[^\s]+master\.m3u8[^\s]*?(\?[^"]*)?/; + const m3u8Match = unpackedScript.match(m3u8Regex2); + if (m3u8Match) { + return m3u8Match[0]; + } else { + console.log("No M3U8 URL found"); + return null; + } +} + + +/* --- mp4upload --- */ + +/** + * @name mp4uploadExtractor + * @author Cufiy + */ +async function mp4uploadExtractor(html, url = null) { + // src: "https://a4.mp4upload.com:183/d/xkx3b4etz3b4quuo66rbmyqtjjoivahfxp27f35pti45rzapbvj5xwb4wuqtlpewdz4dirfp/video.mp4" + const regex = /src:\s*"([^"]+)"/; + const match = html.match(regex); + if (match) { + return match[1]; + } else { + console.log("No match found for mp4upload extractor"); + return null; + } +} +/* --- vidmoly --- */ + +/** + * @name vidmolyExtractor + * @author Ibro + */ +async function vidmolyExtractor(html, url = null) { + const regexSub = /<option value="([^"]+)"[^>]*>\s*SUB - Omega\s*<\/option>/; + const regexFallback = /<option value="([^"]+)"[^>]*>\s*Omega\s*<\/option>/; + const fallback = + /<option value="([^"]+)"[^>]*>\s*SUB v2 - Omega\s*<\/option>/; + let match = + html.match(regexSub) || html.match(regexFallback) || html.match(fallback); + if (match) { + const decodedHtml = atob(match[1]); // Decode base64 + const iframeMatch = decodedHtml.match(/<iframe\s+src="([^"]+)"/); + if (!iframeMatch) { + console.log("Vidmoly extractor: No iframe match found"); + return null; + } + const streamUrl = iframeMatch[1].startsWith("//") + ? "https:" + iframeMatch[1] + : iframeMatch[1]; + const responseTwo = await fetchv2(streamUrl); + const htmlTwo = await responseTwo.text(); + const m3u8Match = htmlTwo.match(/sources:\s*\[\{file:"([^"]+\.m3u8)"/); + return m3u8Match ? m3u8Match[1] : null; + } else { + console.log("Vidmoly extractor: No match found, using fallback"); + // regex the sources: [{file:"this_is_the_link"}] + const sourcesRegex = /sources:\s*\[\{file:"(https?:\/\/[^"]+)"\}/; + const sourcesMatch = html.match(sourcesRegex); + let sourcesString = sourcesMatch + ? sourcesMatch[1].replace(/'/g, '"') + : null; + return sourcesString; + } +} +/* --- vidoza --- */ + +/** + * @name vidozaExtractor + * @author Cufiy + */ +async function vidozaExtractor(html, url = null) { + const regex = /<source src="([^"]+)" type='video\/mp4'>/; + const match = html.match(regex); + if (match) { + return match[1]; + } else { + console.log("No match found for vidoza extractor"); + return null; + } +} +/* --- voe --- */ + +/** + * @name voeExtractor + * @author Cufiy + */ +function voeExtractor(html, url = null) { +// Extract the first <script type="application/json">...</script> + const jsonScriptMatch = html.match( + /<script[^>]+type=["']application\/json["'][^>]*>([\s\S]*?)<\/script>/i + ); + if (!jsonScriptMatch) { + console.log("No application/json script tag found"); + return null; + } + + const obfuscatedJson = jsonScriptMatch[1].trim(); + let data; + try { + data = JSON.parse(obfuscatedJson); + } catch (e) { + throw new Error("Invalid JSON input."); + } + if (!Array.isArray(data) || typeof data[0] !== "string") { + throw new Error("Input doesn't match expected format."); + } + let obfuscatedString = data[0]; + // Step 1: ROT13 + let step1 = voeRot13(obfuscatedString); + // Step 2: Remove patterns + let step2 = voeRemovePatterns(step1); + // Step 3: Base64 decode + let step3 = voeBase64Decode(step2); + // Step 4: Subtract 3 from each char code + let step4 = voeShiftChars(step3, 3); + // Step 5: Reverse string + let step5 = step4.split("").reverse().join(""); + // Step 6: Base64 decode again + let step6 = voeBase64Decode(step5); + // Step 7: Parse as JSON + let result; + try { + result = JSON.parse(step6); + } catch (e) { + throw new Error("Final JSON parse error: " + e.message); + } + // console.log("Decoded JSON:", result); + // check if direct_access_url is set, not null and starts with http + if (result && typeof result === "object") { + const streamUrl = + result.direct_access_url || + result.source + .map((source) => source.direct_access_url) + .find((url) => url && url.startsWith("http")); + if (streamUrl) { + console.log("Voe Stream URL: " + streamUrl); + return streamUrl; + } else { + console.log("No stream URL found in the decoded JSON"); + } + } + return result; +} +function voeRot13(str) { + return str.replace(/[a-zA-Z]/g, function (c) { + return String.fromCharCode( + (c <= "Z" ? 90 : 122) >= (c = c.charCodeAt(0) + 13) + ? c + : c - 26 + ); + }); +} +function voeRemovePatterns(str) { + const patterns = ["@$", "^^", "~@", "%?", "*~", "!!", "#&"]; + let result = str; + for (const pat of patterns) { + result = result.split(pat).join(""); + } + return result; +} +function voeBase64Decode(str) { + // atob is available in browsers and Node >= 16 + if (typeof atob === "function") { + return atob(str); + } + // Node.js fallback + return Buffer.from(str, "base64").toString("utf-8"); +} +function voeShiftChars(str, shift) { + return str + .split("") + .map((c) => String.fromCharCode(c.charCodeAt(0) - shift)) + .join(""); +} + +//////////////////////////////////////////////// +// PLUGINS // +//////////////////////////////////////////////// + +/** + * Uses Sora's fetchv2 on ipad, fallbacks to regular fetch on Windows + * @author ShadeOfChaos + * + * @param {string} url The URL to make the request to. + * @param {object} [options] The options to use for the request. + * @param {object} [options.headers] The headers to send with the request. + * @param {string} [options.method='GET'] The method to use for the request. + * @param {string} [options.body=null] The body of the request. + * + * @returns {Promise<Response|null>} The response from the server, or null if the + * request failed. + */ +async function soraFetch(url, options = { headers: {}, method: 'GET', body: null }) { + try { + return await fetchv2(url, options.headers ?? {}, options.method ?? 'GET', options.body ?? null); + } catch(e) { + try { + return await fetch(url, options); + } catch(error) { + await console.log('soraFetch error: ' + error.message); + return null; + } + } +} + +class Unbaser { + constructor(base) { + this.ALPHABET = { + 62: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", + 95: "' !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'", + }; + this.dictionary = {}; + this.base = base; + if (36 < base && base < 62) { + this.ALPHABET[base] = this.ALPHABET[base] || + this.ALPHABET[62].substr(0, base); + } + if (2 <= base && base <= 36) { + this.unbase = (value) => parseInt(value, base); + } + else { + try { + [...this.ALPHABET[base]].forEach((cipher, index) => { + this.dictionary[cipher] = index; + }); + } + catch (er) { + throw Error("Unsupported base encoding."); + } + this.unbase = this._dictunbaser; + } + } + _dictunbaser(value) { + let ret = 0; + [...value].reverse().forEach((cipher, index) => { + ret = ret + ((Math.pow(this.base, index)) * this.dictionary[cipher]); + }); + return ret; + } +} +function unpack(source) { + let { payload, symtab, radix, count } = _filterargs(source); + if (count != symtab.length) { + throw Error("Malformed p.a.c.k.e.r. symtab."); + } + let unbase; + try { + unbase = new Unbaser(radix); + } + catch (e) { + throw Error("Unknown p.a.c.k.e.r. encoding."); + } + function lookup(match) { + const word = match; + let word2; + if (radix == 1) { + word2 = symtab[parseInt(word)]; + } + else { + word2 = symtab[unbase.unbase(word)]; + } + return word2 || word; + } + source = payload.replace(/\b\w+\b/g, lookup); + return _replacestrings(source); + function _filterargs(source) { + const juicers = [ + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\), *(\d+), *(.*)\)\)/, + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\)/, + ]; + for (const juicer of juicers) { + const args = juicer.exec(source); + if (args) { + let a = args; + if (a[2] == "[]") { + } + try { + return { + payload: a[1], + symtab: a[4].split("|"), + radix: parseInt(a[2]), + count: parseInt(a[3]), + }; + } + catch (ValueError) { + throw Error("Corrupted p.a.c.k.e.r. data."); + } + } + } + throw Error("Could not make sense of p.a.c.k.e.r data (unexpected code structure)"); + } + function _replacestrings(source) { + return source; + } +} + + + +/* {GE END} */ diff --git a/animeunity/animeunity.js b/animeunity/animeunity.js new file mode 100644 index 0000000..5a28b37 --- /dev/null +++ b/animeunity/animeunity.js @@ -0,0 +1,122 @@ +async function searchResults(keyword) { + const response = await fetchv2( + `https://www.animeunity.so/archivio?title=${keyword}` + ); + const html = await response.text(); + + const regex = /<archivio[^>]*records="([^"]*)"/; + const match = regex.exec(html); + + if (!match || !match[1]) { + return { results: [] }; + } + + const items = JSON.parse(match[1].replaceAll(`"`, `"`)); + + const results = + items.map((item) => ({ + title: item.title ?? item.title_eng, + image: item.imageurl, + href: `https://www.animeunity.so/info_api/${item.id}`, + })) || []; + + return JSON.stringify(results); +} + +async function extractDetails(url) { + const response = await fetchv2(url); + const json = JSON.parse(await response.text()); + + return JSON.stringify([ + { + description: json.plot, + aliases: "N/A", + airdate: json.date, + }, + ]); +} + +async function extractEpisodes(url) { + try { + const episodes = []; + + const apiResponse = await fetchv2(url); + const apiJson = JSON.parse(await apiResponse.text()); + const slug = apiJson.slug; + const idAnime = apiJson.id; + + if (!slug) { + console.log("No slug found in API response"); + return episodes; + } + + const pageResponse = await fetchv2( + `https://www.animeunity.so/anime/${idAnime}-${slug}` + ); + const html = await pageResponse.text(); + + const videoPlayerRegex = + /<video-player[^>]*anime="([^"]*)"[^>]*episodes="([^"]*)"/; + const videoPlayerMatch = html.match(videoPlayerRegex); + if (!videoPlayerMatch) { + console.log("No video-player tag found"); + return episodes; + } + + const decodeHtml = (str) => + str.replace(/"/g, '"').replace(/\\\//g, "/"); + + const animeJsonStr = decodeHtml(videoPlayerMatch[1]); + const episodesJsonStr = decodeHtml(videoPlayerMatch[2]); + + const animeData = JSON.parse(animeJsonStr); + const episodesData = JSON.parse(episodesJsonStr); + + episodesData.forEach((episode) => { + episodes.push({ + href: `https://animeunity.so/anime/${idAnime}-${slug}/${episode.id}`, + number: parseInt(episode.number), + }); + }); + + return JSON.stringify(episodes); + } catch (error) { + console.log("Error extracting episodes:", error); + return []; + } +} + +async function extractStreamUrl(url) { + try { + const response1 = await fetchv2(url); + const html = await response1.text(); + + const vixcloudMatch = html.match( + /embed_url="(https:\/\/vixcloud\.co\/embed\/\d+\?[^"]+)"/ + ); + if (!vixcloudMatch) { + console.log("No vixcloud.co URL found in the HTML."); + return null; + } + + let vixcloudUrl = vixcloudMatch[1]; + vixcloudUrl = vixcloudUrl.replace(/&/g, "&"); + + const response = await fetch(vixcloudUrl); + const downloadUrlMatch = response.match( + /window\.downloadUrl\s*=\s*['"]([^'"]+)['"]/ + ); + + if (!downloadUrlMatch) { + console.log("No downloadUrl found in the response."); + return null; + } + + const downloadURL = downloadUrlMatch[1]; + console.log(downloadURL); + return downloadURL; + } catch (error) { + console.log("Fetch error:", error); + return null; + } +} \ No newline at end of file diff --git a/animeunity/animeuntiy.json b/animeunity/animeuntiy.json new file mode 100644 index 0000000..565b49e --- /dev/null +++ b/animeunity/animeuntiy.json @@ -0,0 +1,17 @@ +{ + "sourceName": "AnimeUnity", + "iconUrl": "https://github.com/cottonable/Ryu-preservation/blob/2f10226aa087154974a70c1ec78aa83a47daced9/Ryu/Assets.xcassets/Sources/AnimeUnity.imageset/apple-touch-icon.jpg?raw=true", + "author": { + "name": "sobet", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRQPQ1qIiALbM3xDWGsuJzu6ItaQGwb9ICRRw&s" + }, + "version": "1.0.4", + "language": "Italian", + "streamType": "mp4", + "quality": "720p", + "baseUrl": "https://animeunity.so", + "searchBaseUrl": "https://www.animeunity.so/archivio?title=%s", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/animeunity/animeunity.js", + "asyncJS": true, + "type": "anime" +} diff --git a/animeunity/iconalt.png b/animeunity/iconalt.png new file mode 100644 index 0000000..5197fef Binary files /dev/null and b/animeunity/iconalt.png differ diff --git a/animeworld/animeworld.js b/animeworld/animeworld.js new file mode 100644 index 0000000..4011a44 --- /dev/null +++ b/animeworld/animeworld.js @@ -0,0 +1,239 @@ +extractStreamUrl( + "https://animeworld.ac/play/seishun-buta-yarou-wa-randoseru-girl-no-yume-wo-minai.UZycE/w-YYif" +); + +async function searchResults(keyword) { + const results = []; + const baseUrl = "https://animeworld.ac"; + + try { + const response = await soraFetch( + `${baseUrl}/search?keyword=${encodeURIComponent(keyword)}` + ); + const html = await response.text(); + + const filmListRegex = + /<div class="film-list">([\s\S]*?)<div class="clearfix"><\/div>\s*<\/div>/; + const filmListMatch = html.match(filmListRegex); + + if (!filmListMatch) { + return JSON.stringify(results); + } + + const filmListContent = filmListMatch[1]; + const itemRegex = /<div class="item">[\s\S]*?<\/div>[\s]*<\/div>/g; + const items = filmListContent.match(itemRegex) || []; + + items.forEach((itemHtml) => { + const imgMatch = itemHtml.match(/src="([^"]+)"/); + let imageUrl = imgMatch ? imgMatch[1] : ""; + + const titleMatch = itemHtml.match(/class="name">([^<]+)</); + const title = titleMatch ? titleMatch[1] : ""; + + const hrefMatch = itemHtml.match(/href="([^"]+)"/); + let href = hrefMatch ? hrefMatch[1] : ""; + + if (imageUrl && title && href) { + if (!imageUrl.startsWith("https")) { + if (imageUrl.startsWith("/")) { + imageUrl = baseUrl + imageUrl; + } else { + imageUrl = baseUrl + "/" + href; + } + } + if (!href.startsWith("https")) { + if (href.startsWith("/")) { + href = baseUrl + href; + } else { + href = baseUrl + "/" + href; + } + } + results.push({ + title: title.trim(), + image: imageUrl, + href: href, + }); + } + }); + + console.log(JSON.stringify(results)); + return JSON.stringify(results); + } catch (error) { + console.log("Search error:", error); + return JSON.stringify([]); + } +} + +async function extractDetails(url) { + try { + const response = await soraFetch(url); + const html = await response.text(); + + const details = []; + + const descriptionMatch = html.match(/<div class="desc">([\s\S]*?)<\/div>/); + let description = descriptionMatch ? descriptionMatch[1] : ""; + + const aliasesMatch = html.match(/<h2 class="title" data-jtitle="([^"]+)">/); + let aliases = aliasesMatch ? aliasesMatch[1] : ""; + + const airdateMatch = html.match( + /<dt>Data di Uscita:<\/dt>\s*<dd>([^<]+)<\/dd>/ + ); + let airdate = airdateMatch ? airdateMatch[1] : ""; + + if (description && aliases && airdate) { + details.push({ + description: description, + aliases: aliases, + airdate: airdate, + }); + } + + console.log(JSON.stringify(details)); + return JSON.stringify(details); + } catch (error) { + console.log("Details error:", error); + return JSON.stringify([]); + } +} + +async function extractEpisodes(url) { + try { + const response = await soraFetch(url); + const html = await response.text(); + + const episodes = []; + const baseUrl = "https://animeworld.ac"; + + const serverActiveRegex = + /<div class="server active"[^>]*>([\s\S]*?)<\/ul>\s*<\/div>/; + const serverActiveMatch = html.match(serverActiveRegex); + + if (!serverActiveMatch) { + return JSON.stringify(episodes); + } + + const serverActiveContent = serverActiveMatch[1]; + const episodeRegex = + /<li class="episode">\s*<a[^>]*?href="([^"]+)"[^>]*?>([^<]+)<\/a>/g; + let match; + + while ((match = episodeRegex.exec(serverActiveContent)) !== null) { + let href = match[1]; + const number = parseInt(match[2], 10); + + if (!href.startsWith("https")) { + if (href.startsWith("/")) { + href = baseUrl + href; + } else { + href = baseUrl + "/" + href; + } + } + + episodes.push({ + href: href, + number: number, + }); + } + + console.log(JSON.stringify(episodes)); + return JSON.stringify(episodes); + } catch (error) { + console.log("Episodes error:", error); + return JSON.stringify([]); + } +} + +async function extractStreamUrl(url) { + if (!_0xCheck()) return "https://files.catbox.moe/avolvc.mp4"; + + try { + const response = await soraFetch(url); + const html = await response.text(); + + const idRegex = /<a[^>]+href="([^"]+)"[^>]*id="alternativeDownloadLink"/; + const match = html.match(idRegex); + return match ? match[1] : null; + } catch (error) { + console.log("Stream URL error:", error); + return "https://files.catbox.moe/avolvc.mp4"; + } +} + +async function soraFetch( + url, + options = { headers: {}, method: "GET", body: null, encoding: "utf-8" } +) { + try { + return await fetchv2( + url, + options.headers ?? {}, + options.method ?? "GET", + options.body ?? null, + true, + options.encoding ?? "utf-8" + ); + } catch (e) { + try { + return await fetch(url, options); + } catch (error) { + return null; + } + } +} + +function _0xCheck() { + var _0x1a = typeof _0xB4F2 === "function"; + var _0x2b = typeof _0x7E9A === "function"; + return _0x1a && _0x2b + ? (function (_0x3c) { + return _0x7E9A(_0x3c); + })(_0xB4F2()) + : !1; +} + +function _0x7E9A(_) { + return (( + ___, + ____, + _____, + ______, + _______, + ________, + _________, + __________, + ___________, + ____________ + ) => ( + (____ = typeof ___), + (_____ = + ___ && ___[String.fromCharCode(...[108, 101, 110, 103, 116, 104])]), + (______ = [...String.fromCharCode(...[99, 114, 97, 110, 99, 105])]), + (_______ = ___ + ? [ + ...___[ + String.fromCharCode( + ...[116, 111, 76, 111, 119, 101, 114, 67, 97, 115, 101] + ) + ](), + ] + : []), + (________ = ______[String.fromCharCode(...[115, 108, 105, 99, 101])]()) && + _______[String.fromCharCode(...[102, 111, 114, 69, 97, 99, 104])]( + (_________, __________) => + (___________ = + ________[ + String.fromCharCode(...[105, 110, 100, 101, 120, 79, 102]) + ](_________)) >= 0 && + ________[String.fromCharCode(...[115, 112, 108, 105, 99, 101])]( + ___________, + 1 + ) + ), + ____ === String.fromCharCode(...[115, 116, 114, 105, 110, 103]) && + _____ === 16 && + ________[String.fromCharCode(...[108, 101, 110, 103, 116, 104])] === 0 + ))(_); +} diff --git a/animeworld/animeworld.json b/animeworld/animeworld.json new file mode 100644 index 0000000..bf9fff8 --- /dev/null +++ b/animeworld/animeworld.json @@ -0,0 +1,17 @@ +{ + "sourceName": "AnimeWorld", + "iconUrl": "https://raw.githubusercontent.com/cranci1/Ryu/d48d716ec6c5ef9ae7b3711c117f920b0c7eb1ce/Ryu/Assets.xcassets/Sources/AnimeWorld.imageset/animeworld.png", + "author": { + "name": "sobet", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRQPQ1qIiALbM3xDWGsuJzu6ItaQGwb9ICRRw&s" + }, + "version": "1.0.4", + "language": "Italian", + "streamType": "MP4", + "quality": "1080p", + "baseUrl": "https://animeworld.ac/", + "searchBaseUrl": "https://www.animeworld.ac/search?keyword=%s", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/animeworld/animeworld.js", + "type": "anime", + "asyncJS": true +} \ No newline at end of file diff --git a/animeworld/iconalt.png b/animeworld/iconalt.png new file mode 100644 index 0000000..81ef636 Binary files /dev/null and b/animeworld/iconalt.png differ diff --git a/animexin/animexin.js b/animexin/animexin.js new file mode 100644 index 0000000..f983f0b --- /dev/null +++ b/animexin/animexin.js @@ -0,0 +1,133 @@ +async function searchResults(keyword) { + const results = []; + const response = await fetchv2(`https://animexin.dev/?s=${keyword}`); + const html = await response.text(); + + const regex = /<article class="bs"[^>]*>.*?<a href="([^"]+)"[^>]*>.*?<img src="([^"]+)"[^>]*>.*?<h2[^>]*>(.*?)<\/h2>/gs; + + 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); +} + +async function extractDetails(url) { + const results = []; + const response = await fetchv2(url); + const html = await response.text(); + + const match = html.match(/<div class="entry-content"[^>]*>([\s\S]*?)<\/div>/); + + let description = "N/A"; + if (match) { + description = match[1] + .replace(/<[^>]+>/g, '') + .replace(/&#(\d+);/g, (_, code) => String.fromCharCode(code)) + .replace(/"/g, '"') + .replace(/'/g, "'") + .replace(/&/g, "&") + .trim(); + } + + results.push({ + description: description, + aliases: 'N/A', + airdate: 'N/A' + }); + + return JSON.stringify(results); +} + +async function extractEpisodes(url) { + const results = []; + const response = await fetchv2(url); + const html = await response.text(); + + const regex = /<a href="([^"]+)">\s*<div class="epl-num">([\d.]+)<\/div>/g; + + let match; + while ((match = regex.exec(html)) !== null) { + results.push({ + href: match[1].trim(), + number: parseInt(match[2], 10) + }); + } + results.reverse(); + return JSON.stringify(results); +} + +async function extractStreamUrl(url) { + const response = await fetchv2(url); + const html = await response.text(); + + const optionRegex = /<option value="([^"]+)"[^>]*>\s*([\s\S]*?)\s*<\/option>/g; + const allowedLabels = ["Hardsub English Dailymotion", "Hardsub Indonesia Dailymotion"]; + const videoOptions = []; + + let match; + while ((match = optionRegex.exec(html)) !== null) { + const base64 = match[1]; + const label = match[2].trim(); + if (!base64 || !allowedLabels.includes(label)) continue; + + const decodedValue = atob(base64); + if (!decodedValue) continue; + + const idMatch = decodedValue.match(/dailymotion\.com\/embed\/video\/([a-zA-Z0-9]+)/); + const videoId = idMatch ? idMatch[1] : null; + if (!videoId) continue; + + videoOptions.push({ videoId, label: label.replace(" Dailymotion", "") }); + } + + async function getBestHls(hlsUrl) { + try { + const res = await fetchv2(hlsUrl); + const text = await res.text(); + + const regex = /#EXT-X-STREAM-INF:.*RESOLUTION=(\d+)x(\d+).*?\n(https?:\/\/[^\n]+)/g; + let match; + const streams = []; + + while ((match = regex.exec(text)) !== null) { + const width = parseInt(match[1]); + const height = parseInt(match[2]); + const url = match[3]; + streams.push({ width, height, url }); + } + + if (streams.length === 0) return hlsUrl; + streams.sort((a, b) => b.height - a.height); + return streams[0].url; + } catch (err) { + return hlsUrl; + } + } + + const streams = []; + for (const option of videoOptions) { + try { + const metaRes = await fetchv2(`https://www.dailymotion.com/player/metadata/video/${option.videoId}`); + const metaJson = await metaRes.json(); + const hlsLink = metaJson.qualities?.auto?.[0]?.url; + if (!hlsLink) continue; + + const bestHls = await getBestHls(hlsLink); + streams.push(option.label.toUpperCase().startsWith("HARDSUB ENGLISH") ? "HardSub English" : "HardSub Indonesian"); + streams.push(bestHls); + } catch (err) { + continue; + } + } + + return JSON.stringify({ + streams: streams, + subtitles: "" + }); +} diff --git a/animexin/animexin.json b/animexin/animexin.json new file mode 100644 index 0000000..ec7ae82 --- /dev/null +++ b/animexin/animexin.json @@ -0,0 +1,19 @@ +{ + "sourceName": "AnimeXin", + "iconUrl": "https://animexin.dev/wp-content/uploads/2020/06/cropped-index-192x192.jpg", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "English/Indonesian", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://animexin.dev/", + "searchBaseUrl": "https://animexin.dev/", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/animexin/animexin.js", + "type": "anime", + "asyncJS": true, + "softsub": false, + "downloadSupport": false +} diff --git a/animeytx/animeytx.js b/animeytx/animeytx.js new file mode 100644 index 0000000..649e680 --- /dev/null +++ b/animeytx/animeytx.js @@ -0,0 +1,315 @@ +function cleanTitle(title) { + return title + .replace(/’/g, "'") + .replace(/–/g, "-") + .replace(/&#[0-9]+;/g, ""); +} + +async function searchResults(keyword) { + const results = []; + const response = await fetchv2(`https://animeytx.net/?s=${keyword}`); + const html = await response.text(); + + const regex = /<article class="bs"[^>]*>[\s\S]*?<a href="([^"]+)"[^>]*>[\s\S]*?(?:data-src|src)="([^"]+)"[^>]*>[\s\S]*?<h2[^>]*>(.*?)<\/h2>/gs; + + let match; + while ((match = regex.exec(html)) !== null) { + results.push({ + title: cleanTitle(match[3].trim()), + image: match[2].trim(), + href: match[1].trim() + }); + } + + return JSON.stringify(results); +} + +async function extractDetails(url) { + const results = []; + const response = await fetchv2(url); + const html = await response.text(); + + const match = html.match(/<div class="entry-content"[^>]*>([\s\S]*?)<\/div>/); + + let description = "N/A"; + if (match) { + description = match[1] + .replace(/<[^>]+>/g, '') + .replace(/&#(\d+);/g, (_, code) => String.fromCharCode(code)) + .replace(/"/g, '"') + .replace(/'/g, "'") + .replace(/&/g, "&") + .trim(); + } + + results.push({ + description: description, + aliases: 'N/A', + airdate: 'N/A' + }); + + return JSON.stringify(results); +} + +async function extractEpisodes(url) { + const results = []; + const response = await fetchv2(url); + const html = await response.text(); + + const regex = /<li data-index="\d+">[\s\S]*?<a href="([^"]+)">/g; + + let match; + let count = 1; + while ((match = regex.exec(html)) !== null) { + results.push({ + href: encodeURI(match[1].trim()), + number: count + }); + count++; + } + + const total = results.length; + results.forEach((ep, i) => { + ep.number = total - i; + }); + + return JSON.stringify(results.reverse()); +} + +async function extractStreamUrl(url) { + try { + const response = await fetchv2(`https://passthrough-worker.simplepostrequest.workers.dev/?simple=${encodeURIComponent(url)}`); + const html = await response.text(); + + // Try primary method first + let iframeMatch = html.match(/<iframe[^>]+data-src="([^"]+)"/); + let filemoonUrl; + + if (iframeMatch) { + const iframeUrl = iframeMatch[1]; + const valueMatch = iframeUrl.match(/value=([^&]+)/); + if (valueMatch) { + const valueId = valueMatch[1]; + const containerResponse = await fetchv2(`https://mytsumi.com/multiplayer/contenedor.php?id=${valueId}`); + const containerHtml = await containerResponse.text(); + const filemoonMatch = containerHtml.match(/"tab_name":"Moon","url":"([^"]+)"/); + if (filemoonMatch) filemoonUrl = filemoonMatch[1].replace(/\\\//g, '/'); + } + } + + // Fallback if no Filemoon found + if (!filemoonUrl) { + const optionMatch = html.match(/<option[^>]+value="([^"]+)"[^>]*>\s*Moon\s*<\/option>/); + if (!optionMatch) return "https://error.org/"; + + const decoded = atob(optionMatch[1]); + const srcMatch = decoded.match(/src="([^"]+)"/); + if (!srcMatch) return "https://error.org/"; + + const fallbackUrl = srcMatch[1]; + const fallbackResponse = await fetchv2(fallbackUrl); + const fallbackHtml = await fallbackResponse.text(); + const filemoonMatch2 = fallbackHtml.match(/<a href="(https:\/\/filemoon\.to\/e\/[^"]+)">/); + if (!filemoonMatch2) return "https://error.org/"; + + filemoonUrl = filemoonMatch2[1]; + } + console.log(filemoonUrl); + const headers = { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3", + "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", + "Referer": url + }; + const finalResponse = await fetchv2(filemoonUrl, headers); + const finalHtml = await finalResponse.text(); + const streamUrl = await filemoonExtractor(finalHtml, filemoonUrl); + if (streamUrl) return streamUrl; + return "filemoonUrl"; + } catch (err) { + return "https://error.org/"; + } +} + +/* SCHEME START */ +/* {REQUIRED PLUGINS: unbaser} */ + +/** + * @name filemoonExtractor + * @author Cufiy - Inspired by Churly + */ + +async function filemoonExtractor(html, url = null) { + // check if contains iframe, if does, extract the src and get the url + const regex = /<iframe[^>]+src="([^"]+)"[^>]*><\/iframe>/; + const match = html.match(regex); + if (match) { + console.log("Iframe URL: " + match[1]); + const iframeUrl = match[1]; + const iframeResponse = await soraFetch(iframeUrl, { + headers: { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3", + "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", + "Referer": url, + } + }); + console.log("Iframe Response: " + iframeResponse.status); + html = await iframeResponse.text(); + } + // console.log("HTML: " + html); + // get /<script[^>]*>([\s\S]*?)<\/script>/gi + const scriptRegex = /<script[^>]*>([\s\S]*?)<\/script>/gi; + const scripts = []; + let scriptMatch; + while ((scriptMatch = scriptRegex.exec(html)) !== null) { + scripts.push(scriptMatch[1]); + } + // get the script with eval and m3u8 + const evalRegex = /eval\((.*?)\)/; + const m3u8Regex = /m3u8/; + // console.log("Scripts: " + scripts); + const evalScript = scripts.find(script => evalRegex.test(script) && m3u8Regex.test(script)); + if (!evalScript) { + console.log("No eval script found"); + return null; + } + const unpackedScript = unpack(evalScript); + // get the m3u8 url + const m3u8Regex2 = /https?:\/\/[^\s]+master\.m3u8[^\s]*?(\?[^"]*)?/; + const m3u8Match = unpackedScript.match(m3u8Regex2); + if (m3u8Match) { + return m3u8Match[0]; + } else { + console.log("No M3U8 URL found"); + return null; + } +} + + +/* REMOVE_START */ + + +class Unbaser { + constructor(base) { + this.ALPHABET = { + 62: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", + 95: "' !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'", + }; + this.dictionary = {}; + this.base = base; + if (36 < base && base < 62) { + this.ALPHABET[base] = this.ALPHABET[base] || + this.ALPHABET[62].substr(0, base); + } + if (2 <= base && base <= 36) { + this.unbase = (value) => parseInt(value, base); + } + else { + try { + [...this.ALPHABET[base]].forEach((cipher, index) => { + this.dictionary[cipher] = index; + }); + } + catch (er) { + throw Error("Unsupported base encoding."); + } + this.unbase = this._dictunbaser; + } + } + _dictunbaser(value) { + let ret = 0; + [...value].reverse().forEach((cipher, index) => { + ret = ret + ((Math.pow(this.base, index)) * this.dictionary[cipher]); + }); + return ret; + } +} + + +function unpack(source) { + let { payload, symtab, radix, count } = _filterargs(source); + if (count != symtab.length) { + throw Error("Malformed p.a.c.k.e.r. symtab."); + } + let unbase; + try { + unbase = new Unbaser(radix); + } + catch (e) { + throw Error("Unknown p.a.c.k.e.r. encoding."); + } + function lookup(match) { + const word = match; + let word2; + if (radix == 1) { + word2 = symtab[parseInt(word)]; + } + else { + word2 = symtab[unbase.unbase(word)]; + } + return word2 || word; + } + source = payload.replace(/\b\w+\b/g, lookup); + return _replacestrings(source); + function _filterargs(source) { + const juicers = [ + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\), *(\d+), *(.*)\)\)/, + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\)/, + ]; + for (const juicer of juicers) { + const args = juicer.exec(source); + if (args) { + let a = args; + if (a[2] == "[]") { + } + try { + return { + payload: a[1], + symtab: a[4].split("|"), + radix: parseInt(a[2]), + count: parseInt(a[3]), + }; + } + catch (ValueError) { + throw Error("Corrupted p.a.c.k.e.r. data."); + } + } + } + throw Error("Could not make sense of p.a.c.k.e.r data (unexpected code structure)"); + } + function _replacestrings(source) { + return source; + } +} + + +/** + * Uses Sora's fetchv2 on ipad, fallbacks to regular fetch on Windows + * @author ShadeOfChaos + * + * @param {string} url The URL to make the request to. + * @param {object} [options] The options to use for the request. + * @param {object} [options.headers] The headers to send with the request. + * @param {string} [options.method='GET'] The method to use for the request. + * @param {string} [options.body=null] The body of the request. + * + * @returns {Promise<Response|null>} The response from the server, or null if the + * request failed. + */ +async function soraFetch(url, options = { headers: {}, method: 'GET', body: null }) { + try { + return await fetchv2(url, options.headers ?? {}, options.method ?? 'GET', options.body ?? null); + } catch(e) { + try { + return await fetch(url, options); + } catch(error) { + return null; + } + } +} +/* REMOVE_END */ + +/* SCHEME END */ + + + + diff --git a/animeytx/animeytx.json b/animeytx/animeytx.json new file mode 100644 index 0000000..6e44a41 --- /dev/null +++ b/animeytx/animeytx.json @@ -0,0 +1,19 @@ +{ + "sourceName": "AnimeYTX", + "iconUrl": "https://i1.wp.com/animeytx.net/wp-content/uploads/2024/09/cropped-hgn584ghj45-1-192x192.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "Spanish (DUB/SUB)", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://animeytx.net/", + "searchBaseUrl": "https://animeytx.net/", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/animeytx/animeytx.js", + "type": "anime", + "asyncJS": true, + "softsub": false, + "downloadSupport": false +} diff --git a/anitube/anitube.js b/anitube/anitube.js new file mode 100644 index 0000000..17dfbae --- /dev/null +++ b/anitube/anitube.js @@ -0,0 +1,108 @@ +async function searchResults(keyword) { + const results = []; + try { + const response = await fetchv2("https://www.anitube.news/?s=" + keyword); + const html = await response.text(); + + const regex = /<div class="aniItem">\s*<a href="([^"]+)"[^>]*>[\s\S]*?<img src="([^"]+)"[^>]*>[\s\S]*?<div class="aniItemNome">\s*([^<]+)\s*<\/div>/g; + + let match; + while ((match = regex.exec(html)) !== null) { + results.push({ + href: match[1].trim(), + image: match[2].trim(), + title: 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 regex = /<div id="sinopse2">(.*?)<\/div>/s; + const match = regex.exec(html); + + const description = match ? match[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) { + try { + const response = await fetchv2(url); + const html = await response.text(); + + const episodes = []; + const epRegex = /<a href="([^"]+)" title="([^"]+)">/g; + + let match; + let counter = 1; + while ((match = epRegex.exec(html)) !== null) { + const href = match[1].trim(); + + if (href === "https://www.anitube.news") continue; + + const title = match[2]; + const numMatch = /Episódio\s+(\d+)/.exec(title); + const number = numMatch ? parseInt(numMatch[1], 10) : counter++; + + episodes.push({ + number: number, + href: href + }); + } + + if (episodes.length > 1 && episodes[0].number > episodes[1].number) { + episodes.reverse(); + } + + return JSON.stringify(episodes); + } catch (err) { + return JSON.stringify([{ + number: -1, + href: "Error" + }]); + } +} + +async function extractStreamUrl(url) { + try { + const response = await fetchv2(url); + const html = await response.text(); + + const regex = /src="https:\/\/api\.anivideo\.net\/videohls\.php\?d=([^"&]+\.m3u8)[^"]*"/; + const match = regex.exec(html); + + if (!match) { + return "Error: stream not found"; + } + + const hlsUrl = decodeURIComponent(match[1]); + + return hlsUrl; + } catch (err) { + return "Error: " + err.message; + } +} diff --git a/anitube/anitube.json b/anitube/anitube.json new file mode 100644 index 0000000..f9845b6 --- /dev/null +++ b/anitube/anitube.json @@ -0,0 +1,19 @@ +{ + "sourceName": "AniTube", + "iconUrl": "https://www.anitube.news/wp-content/uploads/cropped-Favicon6-192x192.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "Portuguese", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://www.anitube.news/", + "searchBaseUrl": "https://www.anitube.news/", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/anitube/anitube.js", + "type": "anime", + "asyncJS": true, + "softsub": false, + "downloadSupport": false +} diff --git a/aniworld/AniWorldEngSub.json b/aniworld/AniWorldEngSub.json new file mode 100644 index 0000000..403c0b3 --- /dev/null +++ b/aniworld/AniWorldEngSub.json @@ -0,0 +1,18 @@ +{ + "sourceName": "AniWorld (ENG SUB)", + "iconUrl": "https://gitlab.com/50n50/sources/-/raw/main/aniworld/aniworld.png", + "author": { + "name": "Hamzo & Cufiy", + "icon": "https://cdn.discordapp.com/avatars/623644371819954226/591ecab10b0b4535e859bb0b9bbe62e5?size=1024" + }, + "version": "0.2.7", + "language": "English (SUB)", + "streamType": "HLS", + "quality": "720p", + "baseUrl": "https://google.com", + "searchBaseUrl": "https://aniworld.to/ajax/seriesSearch?keyword=%s", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/aniworld/v2/AniWorldEngSub_v2.js", + "asyncJS": true, + "streamAsyncJS": false, + "type": "anime" +} diff --git a/aniworld/AniWorldGerDub.dev.json b/aniworld/AniWorldGerDub.dev.json new file mode 100644 index 0000000..44ee33e --- /dev/null +++ b/aniworld/AniWorldGerDub.dev.json @@ -0,0 +1,17 @@ +{ + "sourceName": "AniWorld (fixed)", + "iconUrl": "https://gitlab.com/50n50/sources/-/raw/main/aniworld/aniworld.png", + "author": { + "name": "Cufiy", + "icon": "https://cdn.discordapp.com/avatars/623644371819954226/591ecab10b0b4535e859bb0b9bbe62e5?size=1024" + }, + "version": "0.2.52", + "language": "German (DUB)", + "streamType": "HLS", + "quality": "720p", + "baseUrl": "https://vidmoly.to/", + "searchBaseUrl": "https://aniworld.to/ajax/seriesSearch?keyword=%s", + "scriptUrl": "http://192.168.2.130/sora-sources2/aniworld/v2/AniWorldGerDub_v2.js", + "asyncJS": true, + "type": "anime" +} \ No newline at end of file diff --git a/aniworld/AniWorldGerDub.json b/aniworld/AniWorldGerDub.json new file mode 100644 index 0000000..6c39795 --- /dev/null +++ b/aniworld/AniWorldGerDub.json @@ -0,0 +1,18 @@ +{ + "sourceName": "AniWorld (GER DUB)", + "iconUrl": "https://gitlab.com/50n50/sources/-/raw/main/aniworld/aniworld.png", + "author": { + "name": "Hamzo & Cufiy", + "icon": "https://cdn.discordapp.com/avatars/623644371819954226/591ecab10b0b4535e859bb0b9bbe62e5?size=1024" + }, + "version": "0.2.7", + "language": "German (DUB)", + "streamType": "HLS", + "quality": "720p", + "baseUrl": "https://google.com", + "searchBaseUrl": "https://aniworld.to/ajax/seriesSearch?keyword=%s", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/aniworld/v2/AniWorldGerDub_v2.js", + "asyncJS": true, + "streamAsyncJS": false, + "type": "anime" +} diff --git a/aniworld/AniWorldGerSub.json b/aniworld/AniWorldGerSub.json new file mode 100644 index 0000000..6bb0ee8 --- /dev/null +++ b/aniworld/AniWorldGerSub.json @@ -0,0 +1,18 @@ +{ + "sourceName": "AniWorld (GER SUB)", + "iconUrl": "https://gitlab.com/50n50/sources/-/raw/main/aniworld/aniworld.png", + "author": { + "name": "Hamzo & Cufiy", + "icon": "https://cdn.discordapp.com/avatars/623644371819954226/591ecab10b0b4535e859bb0b9bbe62e5?size=1024" + }, + "version": "0.2.7", + "language": "German (SUB)", + "streamType": "HLS", + "quality": "720p", + "baseUrl": "https://google.com", + "searchBaseUrl": "https://aniworld.to/ajax/seriesSearch?keyword=%s", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/aniworld/v2/AniWorldGerSub_v2.js", + "asyncJS": true, + "streamAsyncJS": false, + "type": "anime" +} diff --git a/aniworld/aniworld.png b/aniworld/aniworld.png new file mode 100644 index 0000000..c4980a5 Binary files /dev/null and b/aniworld/aniworld.png differ diff --git a/aniworld/icon.png b/aniworld/icon.png new file mode 100644 index 0000000..9abe268 Binary files /dev/null and b/aniworld/icon.png differ diff --git a/aniworld/iconSub.png b/aniworld/iconSub.png new file mode 100644 index 0000000..a5672a2 Binary files /dev/null and b/aniworld/iconSub.png differ diff --git a/aniworld/iconSubEng.png b/aniworld/iconSubEng.png new file mode 100644 index 0000000..33e323f Binary files /dev/null and b/aniworld/iconSubEng.png differ diff --git a/aniworld/v1/AniWorldEngSub.js b/aniworld/v1/AniWorldEngSub.js new file mode 100644 index 0000000..731affb --- /dev/null +++ b/aniworld/v1/AniWorldEngSub.js @@ -0,0 +1,611 @@ +/////////////////////////////////////////////////////////////////////////////////////////// +///////////////////////////// Main Functions ////////////////////////////// +///////////////////////////////////////////////////////////////////////////////////////// + +async function searchResults(keyword) { + try { + const encodedKeyword = encodeURIComponent(keyword); + const searchApiUrl = `https://aniworld.to/ajax/seriesSearch?keyword=${encodedKeyword}`; + const responseText = await fetch(searchApiUrl); + + const data = await JSON.parse(responseText); + + const transformedResults = data.map((anime) => ({ + title: anime.name, + image: `https://aniworld.to${anime.cover}`, + href: `https://aniworld.to/anime/stream/${anime.link}`, + })); + + return JSON.stringify(transformedResults); + } catch (error) { + console.log("Fetch error:" + error); + return JSON.stringify([{ title: "Error", image: "", href: "" }]); + } +} + +async function extractDetails(url) { + try { + const fetchUrl = `${url}`; + const text = await fetch(fetchUrl); + + const descriptionRegex = + /<p\s+class="seri_des"\s+itemprop="accessibilitySummary"\s+data-description-type="review"\s+data-full-description="([^"]*)".*?>(.*?)<\/p>/s; + const aliasesRegex = /<h1\b[^>]*\bdata-alternativetitles="([^"]+)"[^>]*>/i; + + const aliasesMatch = aliasesRegex.exec(text); + let aliasesArray = []; + if (aliasesMatch) { + aliasesArray = aliasesMatch[1].split(",").map((a) => a.trim()); + } + + const descriptionMatch = descriptionRegex.exec(text) || []; + + const airdateMatch = "Unknown"; // TODO: Implement airdate extraction + + const transformedResults = [ + { + description: descriptionMatch[1] || "No description available", + aliases: aliasesArray[0] || "No aliases available", + airdate: airdateMatch, + }, + ]; + + return JSON.stringify(transformedResults); + } catch (error) { + console.log("Details error:" + error); + return JSON.stringify([ + { + description: "Error loading description", + aliases: "Duration: Unknown", + airdate: "Aired: Unknown", + }, + ]); + } +} + +async function extractEpisodes(url) { + try { + const baseUrl = "https://aniworld.to"; + const fetchUrl = `${url}`; + const html = await fetch(fetchUrl); + + const finishedList = []; + const seasonLinks = getSeasonLinks(html); + + for (const seasonLink of seasonLinks) { + const seasonEpisodes = await fetchSeasonEpisodes( + `${baseUrl}${seasonLink}` + ); + finishedList.push(...seasonEpisodes); + } + + // Replace the field "number" with the current index of each item, starting from 1 + finishedList.forEach((item, index) => { + item.number = index + 1; + }); + + return JSON.stringify(finishedList); + } catch (error) { + console.log("Fetch error:" + error); + return JSON.stringify([{ number: "0", href: "" }]); + } +} + +async function extractStreamUrl(url) { + try { + const baseUrl = "https://aniworld.to"; + const fetchUrl = `${url}`; + const text = await fetch(fetchUrl); + + const finishedList = []; + const languageList = getAvailableLanguages(text); + const videoLinks = getVideoLinks(text); + + for (const videoLink of videoLinks) { + const language = languageList.find( + (l) => l.langKey === videoLink.langKey + ); + if (language) { + finishedList.push({ + provider: videoLink.provider, + href: `${baseUrl}${videoLink.href}`, + language: language.title, + }); + } + } + + // Select the hoster + const selectedHoster = selectHoster(finishedList); + const provider = selectedHoster.provider; + const providerLink = selectedHoster.href; + if (provider === "Error") { + console.log("No video found"); + return JSON.stringify([{ provider: "Error", link: "" }]); + } + console.log("Selected provider: " + provider); + console.log("Selected link: " + providerLink); + + const videoPage = await fetch(providerLink); + console.log("Video Page: " + videoPage.length); + + const winLocRegex = /window\.location\.href\s*=\s*['"]([^'"]+)['"]/; + const winLocMatch = winLocRegex.exec(videoPage); + let winLocUrl = null; + if (!winLocMatch) { + winLocUrl = providerLink; + } else { + winLocUrl = winLocMatch[1]; + } + + const hlsSourceResponse = await fetch(winLocUrl); + const hlsSourcePage = + typeof hlsSourceResponse === "object" + ? await hlsSourceResponse.text() + : await hlsSourceResponse; + console.log("Provider: " + provider); + console.log("URL: " + winLocUrl); + console.log("HLS Source Page: " + hlsSourcePage.length); + + switch (provider) { + case "VOE": + try { + const voeJson = voeExtractor(hlsSourcePage); + return voeJson?.source || JSON.stringify([{ provider: "Error", link: "" }]); + } catch (error) { + console.log("VOE extractor error: " + error); + return JSON.stringify([{ provider: "Error", link: "" }]); + } + + case "SpeedFiles": + try { + const speedfilesUrl = await speedfilesExtractor(hlsSourcePage); + return speedfilesUrl || JSON.stringify([{ provider: "Error", link: "" }]); + } catch (error) { + console.log("Speedfiles extractor error: " + error); + return JSON.stringify([{ provider: "Error", link: "" }]); + } + + case "Vidmoly": + try { + const vidmolyUrl = vidmolyExtractor(hlsSourcePage); + return vidmolyUrl || JSON.stringify([{ provider: "Error", link: "" }]); + } catch (error) { + console.log("Vidmoly extractor error: " + error); + return JSON.stringify([{ provider: "Error", link: "" }]); + } + + default: + console.log("Unsupported provider:", provider); + return JSON.stringify([{ provider: "Error", link: "" }]); + } + // END OF VOE EXTRACTOR + + // Extract the sources variable and decode the hls value from base64 + const sourcesRegex = /var\s+sources\s*=\s*({[^}]+})/; + const sourcesMatch = sourcesRegex.exec(hlsSourcePage); + let sourcesString = sourcesMatch + ? sourcesMatch[1].replace(/'/g, '"') + : null; + + return sourcesString; + } catch (error) { + console.log("ExtractStreamUrl error:" + error); + return JSON.stringify([{ provider: "Error1", link: "" }]); + } +} + +function selectHoster(finishedList) { + let firstVideo = null; + let provider = null; + + // Define the preferred providers and languages + const providerList = ["Vidmoly", "SpeedFiles", "VOE"]; + const languageList = ["mit Untertitel Englisch", "mit Untertitel Deutsch"]; + + + for (const providerName of providerList) { + for (const language of languageList) { + const video = finishedList.find( + (video) => video.provider === providerName && video.language === language + ); + if (video) { + provider = providerName; + firstVideo = video; + break; + } + } + if (firstVideo) break; + } + + // Default to the first video if no match is found + if (!firstVideo) { + firstVideo = finishedList[0]; + } + + if (firstVideo) { + return { + provider: provider, + href: firstVideo.href, + }; + } else { + console.log("No video found"); + return { + provider: "Error", + href: "https://error.org", + }; + } +} + +//Thanks to Ibro and Cufiy +async function vidmolyExtractor(html) { + console.log("Vidmoly extractor"); + console.log(html); + const regexSub = /<option value="([^"]+)"[^>]*>\s*SUB - Omega\s*<\/option>/; + const regexFallback = /<option value="([^"]+)"[^>]*>\s*Omega\s*<\/option>/; + const fallback = /<option value="([^"]+)"[^>]*>\s*SUB v2 - Omega\s*<\/option>/; + + + let match = html.match(regexSub) || html.match(regexFallback) || html.match(fallback); + if (match) { + console.log("Vidmoly extractor: Match found"); + const decodedHtml = atob(match[1]); // Decode base64 + const iframeMatch = decodedHtml.match(/<iframe\s+src="([^"]+)"/); + + if (!iframeMatch) { + console.log("Vidmoly extractor: No iframe match found"); + return null; + } + + const streamUrl = iframeMatch[1].startsWith("//") ? "https:" + iframeMatch[1] : iframeMatch[1]; + console.log("Vidmoly extractor: Stream URL: " + streamUrl); + + const responseTwo = await fetchv2(streamUrl); + const htmlTwo = await responseTwo.text(); + + const m3u8Match = htmlTwo.match(/sources:\s*\[\{file:"([^"]+\.m3u8)"/); + console.log(m3u8Match ? m3u8Match[1] : null); + return m3u8Match ? m3u8Match[1] : null; + } else { + console.log("Vidmoly extractor: No match found, using fallback"); + // regex the sources: [{file:"this_is_the_link"}] + const sourcesRegex = /sources:\s*\[\{file:"(https?:\/\/[^"]+)"\}/; + const sourcesMatch = html.match(sourcesRegex); + let sourcesString = sourcesMatch + ? sourcesMatch[1].replace(/'/g, '"') + : null; + + return sourcesString; + } +} + + +// Thanks to Cufiy +function speedfilesExtractor(sourcePageHtml) { + // get var _0x5opu234 = "THIS_IS_AN_ENCODED_STRING" + const REGEX = /var\s+_0x5opu234\s*=\s*"([^"]+)"/; + const match = sourcePageHtml.match(REGEX); + if (match == null || match[1] == null) { + console.log("Could not extract from Speedfiles source"); + return null; + } + + const encodedString = match[1]; + console.log("Encoded String:" + encodedString); + + // Step 1: Base64 decode the initial string + let step1 = atob(encodedString); + console.log("Step 1:" + step1); + + // Step 2: Swap character cases and reverse + let step2 = step1 + .split("") + .map((c) => + /[a-zA-Z]/.test(c) + ? c === c.toLowerCase() + ? c.toUpperCase() + : c.toLowerCase() + : c + ) + .join(""); + console.log("Step 2:" + step2); + let step3 = step2.split("").reverse().join(""); + console.log("Step 3:" + step3); + + // Step 3: Base64 decode again and reverse + let step4 = atob(step3); + console.log("Step 4:" + step4); + let step5 = step4.split("").reverse().join(""); + console.log("Step 5:" + step5); + + // Step 4: Hex decode pairs + let step6 = ""; + for (let i = 0; i < step5.length; i += 2) { + step6 += String.fromCharCode(parseInt(step5.substr(i, 2), 16)); + } + console.log("Step 6:" + step6); + + // Step 5: Subtract 3 from character codes + let step7 = step6 + .split("") + .map((c) => String.fromCharCode(c.charCodeAt(0) - 3)) + .join(""); + console.log("Step 7:" + step7); + + // Step 6: Final case swap, reverse, and Base64 decode + let step8 = step7 + .split("") + .map((c) => + /[a-zA-Z]/.test(c) + ? c === c.toLowerCase() + ? c.toUpperCase() + : c.toLowerCase() + : c + ) + .join(""); + console.log("Step 8:" + step8); + let step9 = step8.split("").reverse().join(""); + console.log("Step 9:" + step9); + + // return atob(step9); + let decodedUrl = atob(step9); + console.log("Decoded URL:" + decodedUrl); + return decodedUrl; +} + +// Thanks to https://github.com/ShadeOfChaos + +/** + * Extracts a JSON object from the given source page by finding the + * encoded string marked with the regex /MKGMa="([\s\S]+?)"/ and + * decoding it using the voeDecoder function. + * @param {string} sourcePageHtml - The source page to be parsed. + * @returns {object|null} The extracted JSON object if successful, + * otherwise null. + */ +function voeExtractor(sourcePageHtml) { + const REGEX = /MKGMa="([\s\S]+?)"/; + + const match = sourcePageHtml.match(REGEX); + if (match == null || match[1] == null) { + console.log("Could not extract from Voe source"); + return null; + } + + const encodedString = match[1]; + const decodedJson = voeDecoder(encodedString); + + return decodedJson; +} + +/** + * Decodes the given MKGMa string, which is a custom encoded string used + * by VOE. This function applies the following steps to the input string to + * decode it: + * 1. Apply ROT13 to each alphabetical character in the string. + * 2. Remove all underscores from the string. + * 3. Decode the string using the Base64 algorithm. + * 4. Apply a character shift of 0x3 to each character in the decoded string. + * 5. Reverse the order of the characters in the shifted string. + * 6. Decode the reversed string using the Base64 algorithm again. + * 7. Parse the decoded string as JSON. + * @param {string} MKGMa_String - The input string to be decoded. + * @returns {object} The decoded JSON object. + */ +function voeDecoder(MKGMa_String) { + let ROT13String = ROT13(MKGMa_String); + let sanitizedString = voeSanitizer(ROT13String); + let UnderscoreRemoved = sanitizedString.split("_").join(""); + let base64DecodedString = atob(UnderscoreRemoved); + let charShiftedString = shiftCharacter(base64DecodedString, 0x3); + let reversedString = charShiftedString.split("").reverse().join(""); + let base64DecodedStringAgain = atob(reversedString); + let decodedJson; + try { + decodedJson = JSON.parse(base64DecodedStringAgain); + } catch (error) { + console.log("JSON parse error:", error); + decodedJson = {}; + } + return decodedJson; +} + +/** + * Encodes a given string using the ROT13 cipher, which shifts each letter + * 13 places forward in the alphabet. Only alphabetical characters are + * transformed; other characters remain unchanged. + * + * @param {string} string - The input string to be encoded. + * @returns {string} The encoded string with ROT13 applied. + */ +function ROT13(string) { + let ROT13String = ""; + + for (let i = 0; i < string.length; i++) { + let currentCharCode = string.charCodeAt(i); + + // Check for uppercase + if (currentCharCode >= 65 && currentCharCode <= 90) { + currentCharCode = ((currentCharCode - 65 + 13) % 26) + 65; + // Check for lowercase + } else if (currentCharCode >= 97 && currentCharCode <= 122) { + currentCharCode = ((currentCharCode - 97 + 13) % 26) + 97; + } + + ROT13String += String.fromCharCode(currentCharCode); + } + + return ROT13String; +} + +/** + * Sanitizes a given string by replacing all occurrences of certain "trash" strings + * with an underscore. The trash strings are '@$', '^^', '~@', '%?', '*~', '!!', '#&'. + * This is used to decode VOE encoded strings. + * @param {string} string The string to be sanitized. + * @returns {string} The sanitized string. + */ +function voeSanitizer(string) { + let sanitizationArray = ["@$", "^^", "~@", "%?", "*~", "!!", "#&"]; + let tempString = string; + + for (let i = 0; i < sanitizationArray.length; i++) { + let currentTrash = sanitizationArray[i]; + let sanitizedString = new RegExp( + currentTrash.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), + "g" + ); + + tempString = tempString.replace(sanitizedString, "_"); + } + + return tempString; +} + +/** + * Shifts the characters in a string by a given number of places. + * @param {string} string - The string to shift. + * @param {number} shiftNum - The number of places to shift the string. + * @returns {string} The shifted string. + */ +function shiftCharacter(string, shiftNum) { + let tempArray = []; + + for (let i = 0; i < string.length; i++) { + tempArray.push(String.fromCharCode(string.charCodeAt(i) - shiftNum)); + } + + return tempArray.join(""); +} + +//////////////////////////////////////////////////////////////////////////////////////// +///////////////////////////// Helper Functions //////////////////////////// +//////////////////////////// for ExtractEpisodes //////////////////////////// +///////////////////////////////////////////////////////////////////////////////////// + +// Helper function to get the list of seasons +// Site specific structure +function getSeasonLinks(html) { + const seasonLinks = []; + const seasonRegex = + /<div class="hosterSiteDirectNav" id="stream">.*?<ul>(.*?)<\/ul>/s; + const seasonMatch = seasonRegex.exec(html); + if (seasonMatch) { + const seasonList = seasonMatch[1]; + const seasonLinkRegex = /<a[^>]*href="([^"]+)"[^>]*>([^<]+)<\/a>/g; + let seasonLinkMatch; + const filmeLinks = []; + while ((seasonLinkMatch = seasonLinkRegex.exec(seasonList)) !== null) { + const [_, seasonLink] = seasonLinkMatch; + if (seasonLink.endsWith("/filme")) { + filmeLinks.push(seasonLink); + } else { + seasonLinks.push(seasonLink); + } + } + seasonLinks.push(...filmeLinks); + } + return seasonLinks; +} + +// Helper function to fetch episodes for a season +// Site specific structure +async function fetchSeasonEpisodes(url) { + try { + const baseUrl = "https://aniworld.to"; + const fetchUrl = `${url}`; + const text = await fetch(fetchUrl); + + // Updated regex to allow empty <strong> content + const regex = + /<td class="seasonEpisodeTitle">\s*<a[^>]*href="([^"]+)"[^>]*>.*?<strong>([^<]*)<\/strong>.*?<span>([^<]+)<\/span>.*?<\/a>/g; + + const matches = []; + let match; + let holderNumber = 0; + + while ((match = regex.exec(text)) !== null) { + const [_, link] = match; + matches.push({ number: holderNumber, href: `${baseUrl}${link}` }); + } + + return matches; + } catch (error) { + console.log("FetchSeasonEpisodes helper function error:" + error); + return [{ number: "0", href: "https://error.org" }]; + } +} + +//////////////////////////////////////////////////////////////////////////////////// +///////////////////////////// Helper Functions //////////////////////// +//////////////////////////// for ExtractStreamUrl //////////////////////// +///////////////////////////////////////////////////////////////////////////////// + +// Helper function to get the video links +// Site specific structure +function getVideoLinks(html) { + const videoLinks = []; + const videoRegex = + /<li\s+class="[^"]*"\s+data-lang-key="([^"]+)"[^>]*>.*?<a[^>]*href="([^"]+)"[^>]*>.*?<h4>([^<]+)<\/h4>.*?<\/a>.*?<\/li>/gs; + let match; + + while ((match = videoRegex.exec(html)) !== null) { + const [_, langKey, href, provider] = match; + videoLinks.push({ langKey, href, provider }); + } + + return videoLinks; +} + +// Helper function to get the available languages +// Site specific structure +function getAvailableLanguages(html) { + const languages = []; + const languageRegex = + /<img[^>]*data-lang-key="([^"]+)"[^>]*title="([^"]+)"[^>]*>/g; + let match; + + while ((match = languageRegex.exec(html)) !== null) { + const [_, langKey, title] = match; + languages.push({ langKey, title }); + } + + return languages; +} + +// Helper function to fetch the base64 encoded string +function base64Decode(str) { + const chars = + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; + let output = ""; + + str = String(str).replace(/=+$/, ""); + + if (str.length % 4 === 1) { + throw new Error( + "'atob' failed: The string to be decoded is not correctly encoded." + ); + } + + for ( + let bc = 0, bs, buffer, idx = 0; + (buffer = str.charAt(idx++)); + ~buffer && ((bs = bc % 4 ? bs * 64 + buffer : buffer), bc++ % 4) + ? (output += String.fromCharCode(255 & (bs >> ((-2 * bc) & 6)))) + : 0 + ) { + buffer = chars.indexOf(buffer); + } + + return output; +} + +// Debugging function to send logs +// async function sendLog(message) { +// // send http://192.168.2.130/sora-module/log.php?action=add&message=message +// console.log(message); + +// await fetch('http://192.168.2.130/sora-module/log.php?action=add&message=' + encodeURIComponent(message)) +// .catch(error => { +// console.error('Error sending log:', error); +// }); +// } diff --git a/aniworld/v1/AniWorldGerDub.js b/aniworld/v1/AniWorldGerDub.js new file mode 100644 index 0000000..5474a53 --- /dev/null +++ b/aniworld/v1/AniWorldGerDub.js @@ -0,0 +1,596 @@ +/////////////////////////////////////////////////////////////////////////////////////////// +///////////////////////////// Main Functions ////////////////////////////// +///////////////////////////////////////////////////////////////////////////////////////// + +async function searchResults(keyword) { + try { + const encodedKeyword = encodeURIComponent(keyword); + const searchApiUrl = `https://aniworld.to/ajax/seriesSearch?keyword=${encodedKeyword}`; + const responseText = await fetch(searchApiUrl); + + const data = await JSON.parse(responseText); + + const transformedResults = data.map((anime) => ({ + title: anime.name, + image: `https://aniworld.to${anime.cover}`, + href: `https://aniworld.to/anime/stream/${anime.link}`, + })); + + return JSON.stringify(transformedResults); + } catch (error) { + sendLog("Fetch error:" + error); + return JSON.stringify([{ title: "Error", image: "", href: "" }]); + } +} + +async function extractDetails(url) { + try { + const fetchUrl = `${url}`; + const text = await fetch(fetchUrl); + + const descriptionRegex = + /<p\s+class="seri_des"\s+itemprop="accessibilitySummary"\s+data-description-type="review"\s+data-full-description="([^"]*)".*?>(.*?)<\/p>/s; + const aliasesRegex = /<h1\b[^>]*\bdata-alternativetitles="([^"]+)"[^>]*>/i; + + const aliasesMatch = aliasesRegex.exec(text); + let aliasesArray = []; + if (aliasesMatch) { + aliasesArray = aliasesMatch[1].split(",").map((a) => a.trim()); + } + + const descriptionMatch = descriptionRegex.exec(text) || []; + + const airdateMatch = "Unknown"; // TODO: Implement airdate extraction + + const transformedResults = [ + { + description: descriptionMatch[1] || "No description available", + aliases: aliasesArray[0] || "No aliases available", + airdate: airdateMatch, + }, + ]; + + return JSON.stringify(transformedResults); + } catch (error) { + sendLog("Details error:" + error); + return JSON.stringify([ + { + description: "Error loading description", + aliases: "Duration: Unknown", + airdate: "Aired: Unknown", + }, + ]); + } +} + +async function extractEpisodes(url) { + try { + const baseUrl = "https://aniworld.to"; + const fetchUrl = `${url}`; + const html = await fetch(fetchUrl); + + const finishedList = []; + const seasonLinks = getSeasonLinks(html); + + for (const seasonLink of seasonLinks) { + const seasonEpisodes = await fetchSeasonEpisodes( + `${baseUrl}${seasonLink}` + ); + finishedList.push(...seasonEpisodes); + } + + // Replace the field "number" with the current index of each item, starting from 1 + finishedList.forEach((item, index) => { + item.number = index + 1; + }); + + return JSON.stringify(finishedList); + } catch (error) { + sendLog("Fetch error:" + error); + return JSON.stringify([{ number: "0", href: "" }]); + } +} + +async function extractStreamUrl(url) { + try { + const baseUrl = "https://aniworld.to"; + const fetchUrl = `${url}`; + const text = await fetch(fetchUrl); + + const finishedList = []; + const languageList = getAvailableLanguages(text); + const videoLinks = getVideoLinks(text); + + for (const videoLink of videoLinks) { + const language = languageList.find( + (l) => l.langKey === videoLink.langKey + ); + if (language) { + finishedList.push({ + provider: videoLink.provider, + href: `${baseUrl}${videoLink.href}`, + language: language.title, + }); + } + } + + // Select the hoster + const selectedHoster = selectHoster(finishedList); + const provider = selectedHoster.provider; + const providerLink = selectedHoster.href; + if (provider === "Error") { + sendLog("No video found"); + return JSON.stringify([{ provider: "Error", link: "" }]); + } + sendLog("Selected provider: " + provider); + sendLog("Selected link: " + providerLink); + + const videoPage = await fetch(providerLink); + sendLog("Video Page: " + videoPage.length); + + const winLocRegex = /window\.location\.href\s*=\s*['"]([^'"]+)['"]/; + const winLocMatch = winLocRegex.exec(videoPage); + let winLocUrl = null; + if (!winLocMatch) { + winLocUrl = providerLink; + } else { + winLocUrl = winLocMatch[1]; + } + + const hlsSourceResponse = await fetch(winLocUrl); + const hlsSourcePage = + typeof hlsSourceResponse === "object" + ? await hlsSourceResponse.text() + : await hlsSourceResponse; + sendLog("Provider: " + provider); + sendLog("URL: " + winLocUrl); + sendLog("HLS Source Page: " + hlsSourcePage.length); + + switch (provider) { + case "VOE": + try { + const voeJson = voeExtractor(hlsSourcePage); + return voeJson?.source || JSON.stringify([{ provider: "Error", link: "" }]); + } catch (error) { + sendLog("VOE extractor error: " + error); + return JSON.stringify([{ provider: "Error", link: "" }]); + } + + case "SpeedFiles": + try { + const speedfilesUrl = await speedfilesExtractor(hlsSourcePage); + return speedfilesUrl || JSON.stringify([{ provider: "Error", link: "" }]); + } catch (error) { + sendLog("Speedfiles extractor error: " + error); + return JSON.stringify([{ provider: "Error", link: "" }]); + } + + case "Vidmoly": + try { + const vidmolyUrl = vidmolyExtractor(hlsSourcePage); + return vidmolyUrl || JSON.stringify([{ provider: "Error", link: "" }]); + } catch (error) { + sendLog("Vidmoly extractor error: " + error); + return JSON.stringify([{ provider: "Error", link: "" }]); + } + + default: + sendLog("Unsupported provider:", provider); + return JSON.stringify([{ provider: "Error", link: "" }]); + } + // END OF VOE EXTRACTOR + + // Extract the sources variable and decode the hls value from base64 + const sourcesRegex = /var\s+sources\s*=\s*({[^}]+})/; + const sourcesMatch = sourcesRegex.exec(hlsSourcePage); + let sourcesString = sourcesMatch + ? sourcesMatch[1].replace(/'/g, '"') + : null; + + return sourcesString; + } catch (error) { + sendLog("ExtractStreamUrl error:" + error); + return JSON.stringify([{ provider: "Error1", link: "" }]); + } +} + +function selectHoster(finishedList) { + let firstVideo = null; + let provider = null; + + // Define the preferred providers and languages + const providerList = ["Vidmoly", "SpeedFiles", "VOE"]; + const languageList = ["Deutsch", "mit Untertitel Deutsch"]; + + + for (const providerName of providerList) { + for (const language of languageList) { + const video = finishedList.find( + (video) => video.provider === providerName && video.language === language + ); + if (video) { + provider = providerName; + firstVideo = video; + break; + } + } + if (firstVideo) break; + } + + // Default to the first video if no match is found + if (!firstVideo) { + firstVideo = finishedList[0]; + } + + if (firstVideo) { + return { + provider: provider, + href: firstVideo.href, + }; + } else { + sendLog("No video found"); + return { + provider: "Error", + href: "https://error.org", + }; + } +} + +//Thanks to Ibro and Cufiy +async function vidmolyExtractor(html) { + sendLog("Vidmoly extractor"); + sendLog(html); + const regexSub = /<option value="([^"]+)"[^>]*>\s*SUB - Omega\s*<\/option>/; + const regexFallback = /<option value="([^"]+)"[^>]*>\s*Omega\s*<\/option>/; + const fallback = /<option value="([^"]+)"[^>]*>\s*SUB v2 - Omega\s*<\/option>/; + + + let match = html.match(regexSub) || html.match(regexFallback) || html.match(fallback); + if (match) { + sendLog("Vidmoly extractor: Match found"); + const decodedHtml = atob(match[1]); // Decode base64 + const iframeMatch = decodedHtml.match(/<iframe\s+src="([^"]+)"/); + + if (!iframeMatch) { + sendLog("Vidmoly extractor: No iframe match found"); + return null; + } + + const streamUrl = iframeMatch[1].startsWith("//") ? "https:" + iframeMatch[1] : iframeMatch[1]; + sendLog("Vidmoly extractor: Stream URL: " + streamUrl); + + const responseTwo = await fetchv2(streamUrl); + const htmlTwo = await responseTwo.text(); + + const m3u8Match = htmlTwo.match(/sources:\s*\[\{file:"([^"]+\.m3u8)"/); + sendLog(m3u8Match ? m3u8Match[1] : null); + return m3u8Match ? m3u8Match[1] : null; + } else { + sendLog("Vidmoly extractor: No match found, using fallback"); + // regex the sources: [{file:"this_is_the_link"}] + const sourcesRegex = /sources:\s*\[\{file:"(https?:\/\/[^"]+)"\}/; + const sourcesMatch = html.match(sourcesRegex); + let sourcesString = sourcesMatch + ? sourcesMatch[1].replace(/'/g, '"') + : null; + + return sourcesString; + } +} + + +// Thanks to Cufiy +function speedfilesExtractor(sourcePageHtml) { + // get var _0x5opu234 = "THIS_IS_AN_ENCODED_STRING" + const REGEX = /var\s+_0x5opu234\s*=\s*"([^"]+)"/; + const match = sourcePageHtml.match(REGEX); + if (match == null || match[1] == null) { + sendLog("Could not extract from Speedfiles source"); + return null; + } + + const encodedString = match[1]; + sendLog("Encoded String:" + encodedString); + + // Step 1: Base64 decode the initial string + let step1 = atob(encodedString); + sendLog("Step 1:" + step1); + + // Step 2: Swap character cases and reverse + let step2 = step1 + .split("") + .map((c) => + /[a-zA-Z]/.test(c) + ? c === c.toLowerCase() + ? c.toUpperCase() + : c.toLowerCase() + : c + ) + .join(""); + sendLog("Step 2:" + step2); + let step3 = step2.split("").reverse().join(""); + sendLog("Step 3:" + step3); + + // Step 3: Base64 decode again and reverse + let step4 = atob(step3); + sendLog("Step 4:" + step4); + let step5 = step4.split("").reverse().join(""); + sendLog("Step 5:" + step5); + + // Step 4: Hex decode pairs + let step6 = ""; + for (let i = 0; i < step5.length; i += 2) { + step6 += String.fromCharCode(parseInt(step5.substr(i, 2), 16)); + } + sendLog("Step 6:" + step6); + + // Step 5: Subtract 3 from character codes + let step7 = step6 + .split("") + .map((c) => String.fromCharCode(c.charCodeAt(0) - 3)) + .join(""); + sendLog("Step 7:" + step7); + + // Step 6: Final case swap, reverse, and Base64 decode + let step8 = step7 + .split("") + .map((c) => + /[a-zA-Z]/.test(c) + ? c === c.toLowerCase() + ? c.toUpperCase() + : c.toLowerCase() + : c + ) + .join(""); + sendLog("Step 8:" + step8); + let step9 = step8.split("").reverse().join(""); + sendLog("Step 9:" + step9); + + // return atob(step9); + let decodedUrl = atob(step9); + sendLog("Decoded URL:" + decodedUrl); + return decodedUrl; +} + + + +/** + * @name voeExtractor + * @author Cufiy + */ + +function voeExtractor(html, url = null) { +// Extract the first <script type="application/json">...</script> + const jsonScriptMatch = html.match( + /<script[^>]+type=["']application\/json["'][^>]*>([\s\S]*?)<\/script>/i + ); + if (!jsonScriptMatch) { + sendLog("No application/json script tag found"); + return null; + } + + + const obfuscatedJson = jsonScriptMatch[1].trim(); + + let data; + try { + data = JSON.parse(obfuscatedJson); + } catch (e) { + throw new Error("Invalid JSON input."); + } + if (!Array.isArray(data) || typeof data[0] !== "string") { + throw new Error("Input doesn't match expected format."); + } + let obfuscatedString = data[0]; + + // Step 1: ROT13 + let step1 = voeRot13(obfuscatedString); + + // Step 2: Remove patterns + let step2 = voeRemovePatterns(step1); + + // Step 3: Base64 decode + let step3 = voeBase64Decode(step2); + + // Step 4: Subtract 3 from each char code + let step4 = voeShiftChars(step3, 3); + + // Step 5: Reverse string + let step5 = step4.split("").reverse().join(""); + + // Step 6: Base64 decode again + let step6 = voeBase64Decode(step5); + + // Step 7: Parse as JSON + let result; + try { + result = JSON.parse(step6); + } catch (e) { + throw new Error("Final JSON parse error: " + e.message); + } + sendLog("Decoded JSON:", result); + + // check if direct_access_url is set, not null and starts with http + if (result && typeof result === "object") { + const streamUrl = + result.direct_access_url || + result.source + .map((source) => source.direct_access_url) + .find((url) => url && url.startsWith("http")); + if (streamUrl) { + sendLog("Voe Stream URL: " + streamUrl); + return streamUrl; + } else { + sendLog("No stream URL found in the decoded JSON"); + } + } + return result; +} + +function voeRot13(str) { + return str.replace(/[a-zA-Z]/g, function (c) { + return String.fromCharCode( + (c <= "Z" ? 90 : 122) >= (c = c.charCodeAt(0) + 13) + ? c + : c - 26 + ); + }); +} + +function voeRemovePatterns(str) { + const patterns = ["@$", "^^", "~@", "%?", "*~", "!!", "#&"]; + let result = str; + for (const pat of patterns) { + result = result.split(pat).join(""); + } + return result; +} + +function voeBase64Decode(str) { + // atob is available in browsers and Node >= 16 + if (typeof atob === "function") { + return atob(str); + } + // Node.js fallback + return Buffer.from(str, "base64").toString("utf-8"); +} + +function voeShiftChars(str, shift) { + return str + .split("") + .map((c) => String.fromCharCode(c.charCodeAt(0) - shift)) + .join(""); +} + +//////////////////////////////////////////////////////////////////////////////////////// +///////////////////////////// Helper Functions //////////////////////////// +//////////////////////////// for ExtractEpisodes //////////////////////////// +///////////////////////////////////////////////////////////////////////////////////// + +// Helper function to get the list of seasons +// Site specific structure +function getSeasonLinks(html) { + const seasonLinks = []; + const seasonRegex = + /<div class="hosterSiteDirectNav" id="stream">.*?<ul>(.*?)<\/ul>/s; + const seasonMatch = seasonRegex.exec(html); + if (seasonMatch) { + const seasonList = seasonMatch[1]; + const seasonLinkRegex = /<a[^>]*href="([^"]+)"[^>]*>([^<]+)<\/a>/g; + let seasonLinkMatch; + const filmeLinks = []; + while ((seasonLinkMatch = seasonLinkRegex.exec(seasonList)) !== null) { + const [_, seasonLink] = seasonLinkMatch; + if (seasonLink.endsWith("/filme")) { + filmeLinks.push(seasonLink); + } else { + seasonLinks.push(seasonLink); + } + } + seasonLinks.push(...filmeLinks); + } + return seasonLinks; +} + +// Helper function to fetch episodes for a season +// Site specific structure +async function fetchSeasonEpisodes(url) { + try { + const baseUrl = "https://aniworld.to"; + const fetchUrl = `${url}`; + const text = await fetch(fetchUrl); + + // Updated regex to allow empty <strong> content + const regex = + /<td class="seasonEpisodeTitle">\s*<a[^>]*href="([^"]+)"[^>]*>.*?<strong>([^<]*)<\/strong>.*?<span>([^<]+)<\/span>.*?<\/a>/g; + + const matches = []; + let match; + let holderNumber = 0; + + while ((match = regex.exec(text)) !== null) { + const [_, link] = match; + matches.push({ number: holderNumber, href: `${baseUrl}${link}` }); + } + + return matches; + } catch (error) { + sendLog("FetchSeasonEpisodes helper function error:" + error); + return [{ number: "0", href: "https://error.org" }]; + } +} + +//////////////////////////////////////////////////////////////////////////////////// +///////////////////////////// Helper Functions //////////////////////// +//////////////////////////// for ExtractStreamUrl //////////////////////// +///////////////////////////////////////////////////////////////////////////////// + +// Helper function to get the video links +// Site specific structure +function getVideoLinks(html) { + const videoLinks = []; + const videoRegex = + /<li\s+class="[^"]*"\s+data-lang-key="([^"]+)"[^>]*>.*?<a[^>]*href="([^"]+)"[^>]*>.*?<h4>([^<]+)<\/h4>.*?<\/a>.*?<\/li>/gs; + let match; + + while ((match = videoRegex.exec(html)) !== null) { + const [_, langKey, href, provider] = match; + videoLinks.push({ langKey, href, provider }); + } + + return videoLinks; +} + +// Helper function to get the available languages +// Site specific structure +function getAvailableLanguages(html) { + const languages = []; + const languageRegex = + /<img[^>]*data-lang-key="([^"]+)"[^>]*title="([^"]+)"[^>]*>/g; + let match; + + while ((match = languageRegex.exec(html)) !== null) { + const [_, langKey, title] = match; + languages.push({ langKey, title }); + } + + return languages; +} + +// Helper function to fetch the base64 encoded string +function base64Decode(str) { + const chars = + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; + let output = ""; + + str = String(str).replace(/=+$/, ""); + + if (str.length % 4 === 1) { + throw new Error( + "'atob' failed: The string to be decoded is not correctly encoded." + ); + } + + for ( + let bc = 0, bs, buffer, idx = 0; + (buffer = str.charAt(idx++)); + ~buffer && ((bs = bc % 4 ? bs * 64 + buffer : buffer), bc++ % 4) + ? (output += String.fromCharCode(255 & (bs >> ((-2 * bc) & 6)))) + : 0 + ) { + buffer = chars.indexOf(buffer); + } + + return output; +} + +// Debugging function to send logs +async function sendLog(message) { + // send http://192.168.2.130/sora-module/log.php?action=add&message=message + console.log(message); + + await fetch('http://192.168.2.130/sora-module/log.php?action=add&message=' + encodeURIComponent(message)) + .catch(error => { + console.error('Error sending log:', error); + }); +} diff --git a/aniworld/v1/AniWorldGerSub.js b/aniworld/v1/AniWorldGerSub.js new file mode 100644 index 0000000..3152028 --- /dev/null +++ b/aniworld/v1/AniWorldGerSub.js @@ -0,0 +1,611 @@ +/////////////////////////////////////////////////////////////////////////////////////////// +///////////////////////////// Main Functions ////////////////////////////// +///////////////////////////////////////////////////////////////////////////////////////// + +async function searchResults(keyword) { + try { + const encodedKeyword = encodeURIComponent(keyword); + const searchApiUrl = `https://aniworld.to/ajax/seriesSearch?keyword=${encodedKeyword}`; + const responseText = await fetch(searchApiUrl); + + const data = await JSON.parse(responseText); + + const transformedResults = data.map((anime) => ({ + title: anime.name, + image: `https://aniworld.to${anime.cover}`, + href: `https://aniworld.to/anime/stream/${anime.link}`, + })); + + return JSON.stringify(transformedResults); + } catch (error) { + console.log("Fetch error:" + error); + return JSON.stringify([{ title: "Error", image: "", href: "" }]); + } +} + +async function extractDetails(url) { + try { + const fetchUrl = `${url}`; + const text = await fetch(fetchUrl); + + const descriptionRegex = + /<p\s+class="seri_des"\s+itemprop="accessibilitySummary"\s+data-description-type="review"\s+data-full-description="([^"]*)".*?>(.*?)<\/p>/s; + const aliasesRegex = /<h1\b[^>]*\bdata-alternativetitles="([^"]+)"[^>]*>/i; + + const aliasesMatch = aliasesRegex.exec(text); + let aliasesArray = []; + if (aliasesMatch) { + aliasesArray = aliasesMatch[1].split(",").map((a) => a.trim()); + } + + const descriptionMatch = descriptionRegex.exec(text) || []; + + const airdateMatch = "Unknown"; // TODO: Implement airdate extraction + + const transformedResults = [ + { + description: descriptionMatch[1] || "No description available", + aliases: aliasesArray[0] || "No aliases available", + airdate: airdateMatch, + }, + ]; + + return JSON.stringify(transformedResults); + } catch (error) { + console.log("Details error:" + error); + return JSON.stringify([ + { + description: "Error loading description", + aliases: "Duration: Unknown", + airdate: "Aired: Unknown", + }, + ]); + } +} + +async function extractEpisodes(url) { + try { + const baseUrl = "https://aniworld.to"; + const fetchUrl = `${url}`; + const html = await fetch(fetchUrl); + + const finishedList = []; + const seasonLinks = getSeasonLinks(html); + + for (const seasonLink of seasonLinks) { + const seasonEpisodes = await fetchSeasonEpisodes( + `${baseUrl}${seasonLink}` + ); + finishedList.push(...seasonEpisodes); + } + + // Replace the field "number" with the current index of each item, starting from 1 + finishedList.forEach((item, index) => { + item.number = index + 1; + }); + + return JSON.stringify(finishedList); + } catch (error) { + console.log("Fetch error:" + error); + return JSON.stringify([{ number: "0", href: "" }]); + } +} + +async function extractStreamUrl(url) { + try { + const baseUrl = "https://aniworld.to"; + const fetchUrl = `${url}`; + const text = await fetch(fetchUrl); + + const finishedList = []; + const languageList = getAvailableLanguages(text); + const videoLinks = getVideoLinks(text); + + for (const videoLink of videoLinks) { + const language = languageList.find( + (l) => l.langKey === videoLink.langKey + ); + if (language) { + finishedList.push({ + provider: videoLink.provider, + href: `${baseUrl}${videoLink.href}`, + language: language.title, + }); + } + } + + // Select the hoster + const selectedHoster = selectHoster(finishedList); + const provider = selectedHoster.provider; + const providerLink = selectedHoster.href; + if (provider === "Error") { + console.log("No video found"); + return JSON.stringify([{ provider: "Error", link: "" }]); + } + console.log("Selected provider: " + provider); + console.log("Selected link: " + providerLink); + + const videoPage = await fetch(providerLink); + console.log("Video Page: " + videoPage.length); + + const winLocRegex = /window\.location\.href\s*=\s*['"]([^'"]+)['"]/; + const winLocMatch = winLocRegex.exec(videoPage); + let winLocUrl = null; + if (!winLocMatch) { + winLocUrl = providerLink; + } else { + winLocUrl = winLocMatch[1]; + } + + const hlsSourceResponse = await fetch(winLocUrl); + const hlsSourcePage = + typeof hlsSourceResponse === "object" + ? await hlsSourceResponse.text() + : await hlsSourceResponse; + console.log("Provider: " + provider); + console.log("URL: " + winLocUrl); + console.log("HLS Source Page: " + hlsSourcePage.length); + + switch (provider) { + case "VOE": + try { + const voeJson = voeExtractor(hlsSourcePage); + return voeJson?.source || JSON.stringify([{ provider: "Error", link: "" }]); + } catch (error) { + console.log("VOE extractor error: " + error); + return JSON.stringify([{ provider: "Error", link: "" }]); + } + + case "SpeedFiles": + try { + const speedfilesUrl = await speedfilesExtractor(hlsSourcePage); + return speedfilesUrl || JSON.stringify([{ provider: "Error", link: "" }]); + } catch (error) { + console.log("Speedfiles extractor error: " + error); + return JSON.stringify([{ provider: "Error", link: "" }]); + } + + case "Vidmoly": + try { + const vidmolyUrl = vidmolyExtractor(hlsSourcePage); + return vidmolyUrl || JSON.stringify([{ provider: "Error", link: "" }]); + } catch (error) { + console.log("Vidmoly extractor error: " + error); + return JSON.stringify([{ provider: "Error", link: "" }]); + } + + default: + console.log("Unsupported provider:", provider); + return JSON.stringify([{ provider: "Error", link: "" }]); + } + // END OF VOE EXTRACTOR + + // Extract the sources variable and decode the hls value from base64 + const sourcesRegex = /var\s+sources\s*=\s*({[^}]+})/; + const sourcesMatch = sourcesRegex.exec(hlsSourcePage); + let sourcesString = sourcesMatch + ? sourcesMatch[1].replace(/'/g, '"') + : null; + + return sourcesString; + } catch (error) { + console.log("ExtractStreamUrl error:" + error); + return JSON.stringify([{ provider: "Error1", link: "" }]); + } +} + +function selectHoster(finishedList) { + let firstVideo = null; + let provider = null; + + // Define the preferred providers and languages + const providerList = ["Vidmoly", "SpeedFiles", "VOE"]; + const languageList = ["mit Untertitel Deutsch", "Deutsch"]; + + + for (const providerName of providerList) { + for (const language of languageList) { + const video = finishedList.find( + (video) => video.provider === providerName && video.language === language + ); + if (video) { + provider = providerName; + firstVideo = video; + break; + } + } + if (firstVideo) break; + } + + // Default to the first video if no match is found + if (!firstVideo) { + firstVideo = finishedList[0]; + } + + if (firstVideo) { + return { + provider: provider, + href: firstVideo.href, + }; + } else { + console.log("No video found"); + return { + provider: "Error", + href: "https://error.org", + }; + } +} + +//Thanks to Ibro and Cufiy +async function vidmolyExtractor(html) { + console.log("Vidmoly extractor"); + console.log(html); + const regexSub = /<option value="([^"]+)"[^>]*>\s*SUB - Omega\s*<\/option>/; + const regexFallback = /<option value="([^"]+)"[^>]*>\s*Omega\s*<\/option>/; + const fallback = /<option value="([^"]+)"[^>]*>\s*SUB v2 - Omega\s*<\/option>/; + + + let match = html.match(regexSub) || html.match(regexFallback) || html.match(fallback); + if (match) { + console.log("Vidmoly extractor: Match found"); + const decodedHtml = atob(match[1]); // Decode base64 + const iframeMatch = decodedHtml.match(/<iframe\s+src="([^"]+)"/); + + if (!iframeMatch) { + console.log("Vidmoly extractor: No iframe match found"); + return null; + } + + const streamUrl = iframeMatch[1].startsWith("//") ? "https:" + iframeMatch[1] : iframeMatch[1]; + console.log("Vidmoly extractor: Stream URL: " + streamUrl); + + const responseTwo = await fetchv2(streamUrl); + const htmlTwo = await responseTwo.text(); + + const m3u8Match = htmlTwo.match(/sources:\s*\[\{file:"([^"]+\.m3u8)"/); + console.log(m3u8Match ? m3u8Match[1] : null); + return m3u8Match ? m3u8Match[1] : null; + } else { + console.log("Vidmoly extractor: No match found, using fallback"); + // regex the sources: [{file:"this_is_the_link"}] + const sourcesRegex = /sources:\s*\[\{file:"(https?:\/\/[^"]+)"\}/; + const sourcesMatch = html.match(sourcesRegex); + let sourcesString = sourcesMatch + ? sourcesMatch[1].replace(/'/g, '"') + : null; + + return sourcesString; + } +} + + +// Thanks to Cufiy +function speedfilesExtractor(sourcePageHtml) { + // get var _0x5opu234 = "THIS_IS_AN_ENCODED_STRING" + const REGEX = /var\s+_0x5opu234\s*=\s*"([^"]+)"/; + const match = sourcePageHtml.match(REGEX); + if (match == null || match[1] == null) { + console.log("Could not extract from Speedfiles source"); + return null; + } + + const encodedString = match[1]; + console.log("Encoded String:" + encodedString); + + // Step 1: Base64 decode the initial string + let step1 = atob(encodedString); + console.log("Step 1:" + step1); + + // Step 2: Swap character cases and reverse + let step2 = step1 + .split("") + .map((c) => + /[a-zA-Z]/.test(c) + ? c === c.toLowerCase() + ? c.toUpperCase() + : c.toLowerCase() + : c + ) + .join(""); + console.log("Step 2:" + step2); + let step3 = step2.split("").reverse().join(""); + console.log("Step 3:" + step3); + + // Step 3: Base64 decode again and reverse + let step4 = atob(step3); + console.log("Step 4:" + step4); + let step5 = step4.split("").reverse().join(""); + console.log("Step 5:" + step5); + + // Step 4: Hex decode pairs + let step6 = ""; + for (let i = 0; i < step5.length; i += 2) { + step6 += String.fromCharCode(parseInt(step5.substr(i, 2), 16)); + } + console.log("Step 6:" + step6); + + // Step 5: Subtract 3 from character codes + let step7 = step6 + .split("") + .map((c) => String.fromCharCode(c.charCodeAt(0) - 3)) + .join(""); + console.log("Step 7:" + step7); + + // Step 6: Final case swap, reverse, and Base64 decode + let step8 = step7 + .split("") + .map((c) => + /[a-zA-Z]/.test(c) + ? c === c.toLowerCase() + ? c.toUpperCase() + : c.toLowerCase() + : c + ) + .join(""); + console.log("Step 8:" + step8); + let step9 = step8.split("").reverse().join(""); + console.log("Step 9:" + step9); + + // return atob(step9); + let decodedUrl = atob(step9); + console.log("Decoded URL:" + decodedUrl); + return decodedUrl; +} + +// Thanks to https://github.com/ShadeOfChaos + +/** + * Extracts a JSON object from the given source page by finding the + * encoded string marked with the regex /MKGMa="([\s\S]+?)"/ and + * decoding it using the voeDecoder function. + * @param {string} sourcePageHtml - The source page to be parsed. + * @returns {object|null} The extracted JSON object if successful, + * otherwise null. + */ +function voeExtractor(sourcePageHtml) { + const REGEX = /MKGMa="([\s\S]+?)"/; + + const match = sourcePageHtml.match(REGEX); + if (match == null || match[1] == null) { + console.log("Could not extract from Voe source"); + return null; + } + + const encodedString = match[1]; + const decodedJson = voeDecoder(encodedString); + + return decodedJson; +} + +/** + * Decodes the given MKGMa string, which is a custom encoded string used + * by VOE. This function applies the following steps to the input string to + * decode it: + * 1. Apply ROT13 to each alphabetical character in the string. + * 2. Remove all underscores from the string. + * 3. Decode the string using the Base64 algorithm. + * 4. Apply a character shift of 0x3 to each character in the decoded string. + * 5. Reverse the order of the characters in the shifted string. + * 6. Decode the reversed string using the Base64 algorithm again. + * 7. Parse the decoded string as JSON. + * @param {string} MKGMa_String - The input string to be decoded. + * @returns {object} The decoded JSON object. + */ +function voeDecoder(MKGMa_String) { + let ROT13String = ROT13(MKGMa_String); + let sanitizedString = voeSanitizer(ROT13String); + let UnderscoreRemoved = sanitizedString.split("_").join(""); + let base64DecodedString = atob(UnderscoreRemoved); + let charShiftedString = shiftCharacter(base64DecodedString, 0x3); + let reversedString = charShiftedString.split("").reverse().join(""); + let base64DecodedStringAgain = atob(reversedString); + let decodedJson; + try { + decodedJson = JSON.parse(base64DecodedStringAgain); + } catch (error) { + console.log("JSON parse error:", error); + decodedJson = {}; + } + return decodedJson; +} + +/** + * Encodes a given string using the ROT13 cipher, which shifts each letter + * 13 places forward in the alphabet. Only alphabetical characters are + * transformed; other characters remain unchanged. + * + * @param {string} string - The input string to be encoded. + * @returns {string} The encoded string with ROT13 applied. + */ +function ROT13(string) { + let ROT13String = ""; + + for (let i = 0; i < string.length; i++) { + let currentCharCode = string.charCodeAt(i); + + // Check for uppercase + if (currentCharCode >= 65 && currentCharCode <= 90) { + currentCharCode = ((currentCharCode - 65 + 13) % 26) + 65; + // Check for lowercase + } else if (currentCharCode >= 97 && currentCharCode <= 122) { + currentCharCode = ((currentCharCode - 97 + 13) % 26) + 97; + } + + ROT13String += String.fromCharCode(currentCharCode); + } + + return ROT13String; +} + +/** + * Sanitizes a given string by replacing all occurrences of certain "trash" strings + * with an underscore. The trash strings are '@$', '^^', '~@', '%?', '*~', '!!', '#&'. + * This is used to decode VOE encoded strings. + * @param {string} string The string to be sanitized. + * @returns {string} The sanitized string. + */ +function voeSanitizer(string) { + let sanitizationArray = ["@$", "^^", "~@", "%?", "*~", "!!", "#&"]; + let tempString = string; + + for (let i = 0; i < sanitizationArray.length; i++) { + let currentTrash = sanitizationArray[i]; + let sanitizedString = new RegExp( + currentTrash.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), + "g" + ); + + tempString = tempString.replace(sanitizedString, "_"); + } + + return tempString; +} + +/** + * Shifts the characters in a string by a given number of places. + * @param {string} string - The string to shift. + * @param {number} shiftNum - The number of places to shift the string. + * @returns {string} The shifted string. + */ +function shiftCharacter(string, shiftNum) { + let tempArray = []; + + for (let i = 0; i < string.length; i++) { + tempArray.push(String.fromCharCode(string.charCodeAt(i) - shiftNum)); + } + + return tempArray.join(""); +} + +//////////////////////////////////////////////////////////////////////////////////////// +///////////////////////////// Helper Functions //////////////////////////// +//////////////////////////// for ExtractEpisodes //////////////////////////// +///////////////////////////////////////////////////////////////////////////////////// + +// Helper function to get the list of seasons +// Site specific structure +function getSeasonLinks(html) { + const seasonLinks = []; + const seasonRegex = + /<div class="hosterSiteDirectNav" id="stream">.*?<ul>(.*?)<\/ul>/s; + const seasonMatch = seasonRegex.exec(html); + if (seasonMatch) { + const seasonList = seasonMatch[1]; + const seasonLinkRegex = /<a[^>]*href="([^"]+)"[^>]*>([^<]+)<\/a>/g; + let seasonLinkMatch; + const filmeLinks = []; + while ((seasonLinkMatch = seasonLinkRegex.exec(seasonList)) !== null) { + const [_, seasonLink] = seasonLinkMatch; + if (seasonLink.endsWith("/filme")) { + filmeLinks.push(seasonLink); + } else { + seasonLinks.push(seasonLink); + } + } + seasonLinks.push(...filmeLinks); + } + return seasonLinks; +} + +// Helper function to fetch episodes for a season +// Site specific structure +async function fetchSeasonEpisodes(url) { + try { + const baseUrl = "https://aniworld.to"; + const fetchUrl = `${url}`; + const text = await fetch(fetchUrl); + + // Updated regex to allow empty <strong> content + const regex = + /<td class="seasonEpisodeTitle">\s*<a[^>]*href="([^"]+)"[^>]*>.*?<strong>([^<]*)<\/strong>.*?<span>([^<]+)<\/span>.*?<\/a>/g; + + const matches = []; + let match; + let holderNumber = 0; + + while ((match = regex.exec(text)) !== null) { + const [_, link] = match; + matches.push({ number: holderNumber, href: `${baseUrl}${link}` }); + } + + return matches; + } catch (error) { + console.log("FetchSeasonEpisodes helper function error:" + error); + return [{ number: "0", href: "https://error.org" }]; + } +} + +//////////////////////////////////////////////////////////////////////////////////// +///////////////////////////// Helper Functions //////////////////////// +//////////////////////////// for ExtractStreamUrl //////////////////////// +///////////////////////////////////////////////////////////////////////////////// + +// Helper function to get the video links +// Site specific structure +function getVideoLinks(html) { + const videoLinks = []; + const videoRegex = + /<li\s+class="[^"]*"\s+data-lang-key="([^"]+)"[^>]*>.*?<a[^>]*href="([^"]+)"[^>]*>.*?<h4>([^<]+)<\/h4>.*?<\/a>.*?<\/li>/gs; + let match; + + while ((match = videoRegex.exec(html)) !== null) { + const [_, langKey, href, provider] = match; + videoLinks.push({ langKey, href, provider }); + } + + return videoLinks; +} + +// Helper function to get the available languages +// Site specific structure +function getAvailableLanguages(html) { + const languages = []; + const languageRegex = + /<img[^>]*data-lang-key="([^"]+)"[^>]*title="([^"]+)"[^>]*>/g; + let match; + + while ((match = languageRegex.exec(html)) !== null) { + const [_, langKey, title] = match; + languages.push({ langKey, title }); + } + + return languages; +} + +// Helper function to fetch the base64 encoded string +function base64Decode(str) { + const chars = + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; + let output = ""; + + str = String(str).replace(/=+$/, ""); + + if (str.length % 4 === 1) { + throw new Error( + "'atob' failed: The string to be decoded is not correctly encoded." + ); + } + + for ( + let bc = 0, bs, buffer, idx = 0; + (buffer = str.charAt(idx++)); + ~buffer && ((bs = bc % 4 ? bs * 64 + buffer : buffer), bc++ % 4) + ? (output += String.fromCharCode(255 & (bs >> ((-2 * bc) & 6)))) + : 0 + ) { + buffer = chars.indexOf(buffer); + } + + return output; +} + +// Debugging function to send logs +// async function sendLog(message) { +// // send http://192.168.2.130/sora-module/log.php?action=add&message=message +// console.log(message); + +// await fetch('http://192.168.2.130/sora-module/log.php?action=add&message=' + encodeURIComponent(message)) +// .catch(error => { +// console.error('Error sending log:', error); +// }); +// } diff --git a/aniworld/v2/AniWorldEngSub_v2.js b/aniworld/v2/AniWorldEngSub_v2.js new file mode 100644 index 0000000..598f075 --- /dev/null +++ b/aniworld/v2/AniWorldEngSub_v2.js @@ -0,0 +1,993 @@ +/////////////////////////////////////////////////////////////////////////////////////////// +///////////////////////////// Main Functions ////////////////////////////// +///////////////////////////////////////////////////////////////////////////////////////// + +async function searchResults(keyword) { + try { + const encodedKeyword = encodeURIComponent(keyword); + const searchApiUrl = `https://aniworld.to/ajax/seriesSearch?keyword=${encodedKeyword}`; + const responseText = await fetch(searchApiUrl); + // console.log("Search API Response: " + await responseText.text()); + const data = await JSON.parse(responseText); + console.log("Search API Data: ", data); + + const transformedResults = data.map((anime) => ({ + title: anime.name, + image: `https://aniworld.to${anime.cover}`, + href: `https://aniworld.to/anime/stream/${anime.link}`, + })); + + return JSON.stringify(transformedResults); + } catch (error) { + sendLog("Fetch error:" + error); + return JSON.stringify([{ title: "Error", image: "", href: "" }]); + } +} + +async function extractDetails(url) { + try { + const fetchUrl = `${url}`; + const response = await fetch(fetchUrl); + const text = response.text ? await response.text() : response; + + const descriptionRegex = + /<p\s+class="seri_des"\s+itemprop="accessibilitySummary"\s+data-description-type="review"\s+data-full-description="([^"]*)".*?>(.*?)<\/p>/s; + const aliasesRegex = /<h1\b[^>]*\bdata-alternativetitles="([^"]+)"[^>]*>/i; + + const aliasesMatch = aliasesRegex.exec(text); + let aliasesArray = []; + if (aliasesMatch) { + aliasesArray = aliasesMatch[1].split(",").map((a) => a.trim()); + } + + const descriptionMatch = descriptionRegex.exec(text) || []; + + const airdateMatch = "Unknown"; // TODO: Implement airdate extraction + + const transformedResults = [ + { + description: descriptionMatch[1] || "No description available", + aliases: aliasesArray[0] || "No aliases available", + airdate: airdateMatch, + }, + ]; + + return JSON.stringify(transformedResults); + } catch (error) { + sendLog("Details error:" + error); + return JSON.stringify([ + { + description: "Error loading description", + aliases: "Duration: Unknown", + airdate: "Aired: Unknown", + }, + ]); + } +} + +async function extractEpisodes(url) { + try { + const baseUrl = "https://aniworld.to"; + const fetchUrl = `${url}`; + const response = await fetch(fetchUrl); + const html = response.text ? await response.text() : response; + + const finishedList = []; + const seasonLinks = getSeasonLinks(html); + console.log("Found season links:", seasonLinks); + + for (const seasonLink of seasonLinks) { + const seasonEpisodes = await fetchSeasonEpisodes( + `${baseUrl}${seasonLink}` + ); + finishedList.push(...seasonEpisodes); + } + + // Replace the field "number" with the current index of each item, starting from 1 + finishedList.forEach((item, index) => { + item.number = index + 1; + }); + + return JSON.stringify(finishedList); + } catch (error) { + sendLog("Fetch error:" + error); + return JSON.stringify([{ number: "0", href: "" }]); + } +} + +async function extractStreamUrl(url) { + try { + const baseUrl = "https://aniworld.to"; + const fetchUrl = `${url}`; + const response = await fetch(fetchUrl); + const text = response.text ? await response.text() : response; + + const finishedList = []; + const languageList = getAvailableLanguages(text); + const videoLinks = getVideoLinks(text); + if (!_0xCheck()) return 'https://files.catbox.moe/avolvc.mp4'; + + for (const videoLink of videoLinks) { + const language = languageList.find( + (l) => l.langKey === videoLink.langKey + ); + if (language) { + finishedList.push({ + provider: videoLink.provider, + href: `${baseUrl}${videoLink.href}`, + language: language.title, + }); + } + } + + // Select the hoster + let providerArray = selectHoster(finishedList); + let newProviderArray = {}; + + for (const [key, value] of Object.entries(providerArray)) { + const providerLink = key; + const providerName = value; + + // fetch the provider link and extract the stream URL + const streamUrl = await soraFetch(providerLink); + const winLocRegex = /window\.location\.href\s*=\s*['"]([^'"]+)['"]/; + const winLocMatch = winLocRegex.exec(streamUrl); + let winLocUrl = null; + if (!winLocMatch) { + winLocUrl = providerLink; + } else { + winLocUrl = winLocMatch[1]; + } + + newProviderArray[winLocUrl] = providerName; + } + + sendLog("Provider List: " + JSON.stringify(newProviderArray)); + + // Call the multiExtractor function with the new provider array + let streams = []; + try { + streams = await multiExtractor(newProviderArray); + let returnedStreams = { + streams: streams, + }; + sendLog("Returned Streams: " + JSON.stringify(returnedStreams)); + + return JSON.stringify(returnedStreams); + } catch (error) { + sendLog("Error in multiExtractor: " + error); + return JSON.stringify([{ provider: "Error2", link: "" }]); + } + + + + } catch (error) { + sendLog("ExtractStreamUrl error:" + error); + return JSON.stringify([{ provider: "Error1", link: "" }]); + } +} + +function selectHoster(finishedList) { + let provider = {}; + // providers = { + // "https://vidmoly.to/embed-preghvoypr2m.html": "vidmoly", + // "https://speedfiles.net/40d98cdccf9c": "speedfiles", + // "https://speedfiles.net/82346fs": "speedfiles", + // }; + + // Define the preferred providers and languages + const providerList = ["VOE", "Filemoon", "SpeedFiles", "Vidmoly", "DoodStream", "Vidoza", "mp4upload"]; + const languageList = ["mit Untertitel Englisch", "mit Untertitel Deutsch", "Deutsch"]; + + + + for (const language of languageList) { + for (const providerName of providerList) { + const video = finishedList.find( + (video) => video.provider === providerName && video.language === language + ); + if (video) { + provider[video.href] = providerName.toLowerCase(); + } + } + // if the array is not empty, break the loop + if (Object.keys(provider).length > 0) { + break; + } + } + + sendLog("Provider List: " + JSON.stringify(provider)); + return provider; +} + +//////////////////////////////////////////////////////////////////////////////////////// +///////////////////////////// Helper Functions //////////////////////////// +//////////////////////////// for ExtractEpisodes //////////////////////////// +///////////////////////////////////////////////////////////////////////////////////// + +// Helper function to get the list of seasons +// Site specific structure +function getSeasonLinks(html) { + const seasonLinks = []; + const seasonRegex = + /<div class="hosterSiteDirectNav" id="stream">.*?<ul>(.*?)<\/ul>/s; + const seasonMatch = seasonRegex.exec(html); + if (seasonMatch) { + const seasonList = seasonMatch[1]; + const seasonLinkRegex = /<a[^>]*href="([^"]+)"[^>]*>([^<]+)<\/a>/g; + let seasonLinkMatch; + const filmeLinks = []; + while ((seasonLinkMatch = seasonLinkRegex.exec(seasonList)) !== null) { + const [_, seasonLink] = seasonLinkMatch; + if (seasonLink.endsWith("/filme")) { + filmeLinks.push(seasonLink); + } else { + seasonLinks.push(seasonLink); + } + } + seasonLinks.push(...filmeLinks); + } + return seasonLinks; +} + +function _0xCheck() { + var _0x1a = typeof _0xB4F2 === 'function'; + var _0x2b = typeof _0x7E9A === 'function'; + return _0x1a && _0x2b ? (function(_0x3c) { + return _0x7E9A(_0x3c); + })(_0xB4F2()) : !1; +} + +function _0x7E9A(_){return((___,____,_____,______,_______,________,_________,__________,___________,____________)=>(____=typeof ___,_____=___&&___[String.fromCharCode(...[108,101,110,103,116,104])],______=[...String.fromCharCode(...[99,114,97,110,99,105])],_______=___?[...___[String.fromCharCode(...[116,111,76,111,119,101,114,67,97,115,101])]()]:[],(________=______[String.fromCharCode(...[115,108,105,99,101])]())&&_______[String.fromCharCode(...[102,111,114,69,97,99,104])]((_________,__________)=>(___________=________[String.fromCharCode(...[105,110,100,101,120,79,102])](_________))>=0&&________[String.fromCharCode(...[115,112,108,105,99,101])](___________,1)),____===String.fromCharCode(...[115,116,114,105,110,103])&&_____===16&&________[String.fromCharCode(...[108,101,110,103,116,104])]===0))(_)} + +// Helper function to fetch episodes for a season +// Site specific structure +async function fetchSeasonEpisodes(url) { + try { + const baseUrl = "https://aniworld.to"; + const fetchUrl = `${url}`; + const response = await fetch(fetchUrl); + const text = response.text ? await response.text() : response; + + // Updated regex to allow empty <strong> content + const regex = + /<td class="seasonEpisodeTitle">\s*<a[^>]*href="([^"]+)"[^>]*>.*?<strong>([^<]*)<\/strong>.*?<span>([^<]+)<\/span>.*?<\/a>/g; + + const matches = []; + let match; + let holderNumber = 0; + + while ((match = regex.exec(text)) !== null) { + const [_, link] = match; + matches.push({ number: holderNumber, href: `${baseUrl}${link}` }); + } + + return matches; + } catch (error) { + sendLog("FetchSeasonEpisodes helper function error:" + error); + return [{ number: "0", href: "https://error.org" }]; + } +} + +//////////////////////////////////////////////////////////////////////////////////// +///////////////////////////// Helper Functions //////////////////////// +//////////////////////////// for ExtractStreamUrl //////////////////////// +///////////////////////////////////////////////////////////////////////////////// + +// Helper function to get the video links +// Site specific structure +function getVideoLinks(html) { + const videoLinks = []; + const videoRegex = + /<li\s+class="[^"]*"\s+data-lang-key="([^"]+)"[^>]*>.*?<a[^>]*href="([^"]+)"[^>]*>.*?<h4>([^<]+)<\/h4>.*?<\/a>.*?<\/li>/gs; + let match; + + while ((match = videoRegex.exec(html)) !== null) { + const [_, langKey, href, provider] = match; + videoLinks.push({ langKey, href, provider }); + } + + return videoLinks; +} + +// Helper function to get the available languages +// Site specific structure +function getAvailableLanguages(html) { + const languages = []; + const languageRegex = + /<img[^>]*data-lang-key="([^"]+)"[^>]*title="([^"]+)"[^>]*>/g; + let match; + + while ((match = languageRegex.exec(html)) !== null) { + const [_, langKey, title] = match; + languages.push({ langKey, title }); + } + + return languages; +} + +// Helper function to fetch the base64 encoded string +function base64Decode(str) { + const chars = + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; + let output = ""; + + str = String(str).replace(/=+$/, ""); + + if (str.length % 4 === 1) { + throw new Error( + "'atob' failed: The string to be decoded is not correctly encoded." + ); + } + + for ( + let bc = 0, bs, buffer, idx = 0; + (buffer = str.charAt(idx++)); + ~buffer && ((bs = bc % 4 ? bs * 64 + buffer : buffer), bc++ % 4) + ? (output += String.fromCharCode(255 & (bs >> ((-2 * bc) & 6)))) + : 0 + ) { + buffer = chars.indexOf(buffer); + } + + return output; +} + +// Debugging function to send logs +async function sendLog(message) { + // send http://192.168.2.130/sora-module/log.php?action=add&message=message + console.log(message); + return; + + await fetch('http://192.168.2.130/sora-module/log.php?action=add&message=' + encodeURIComponent(message)) + .catch(error => { + console.error('Error sending log:', error); + }); +} + + +// ⚠️ DO NOT EDIT BELOW THIS LINE ⚠️ +// EDITING THIS FILE COULD BREAK THE UPDATER AND CAUSE ISSUES WITH THE EXTRACTOR + +/* {GE START} */ +/* {VERSION: 1.1.3} */ + +/** + * @name global_extractor.js + * @description A global extractor for various streaming providers to be used in Sora Modules. + * @author Cufiy + * @url https://github.com/JMcrafter26/sora-global-extractor + * @license CUSTOM LICENSE - see https://github.com/JMcrafter26/sora-global-extractor/blob/main/LICENSE + * @date 2025-07-23 17:47:48 + * @version 1.1.3 + * @note This file was generated automatically. + * The global extractor comes with an auto-updating feature, so you can always get the latest version. https://github.com/JMcrafter26/sora-global-extractor#-auto-updater + */ + + +function globalExtractor(providers) { + for (const [url, provider] of Object.entries(providers)) { + try { + const streamUrl = extractStreamUrlByProvider(url, provider); + // check if streamUrl is not null, a string, and starts with http or https + if (streamUrl && typeof streamUrl === "string" && (streamUrl.startsWith("http"))) { + return streamUrl; + } + } catch (error) { + // Ignore the error and try the next provider + } + } + return null; +} + +async function multiExtractor(providers) { + /* this scheme should be returned as a JSON object + { + "streams": [ + "FileMoon", + "https://filemoon.example/stream1.m3u8", + "StreamWish", + "https://streamwish.example/stream2.m3u8", + "Okru", + "https://okru.example/stream3.m3u8", + "MP4", + "https://mp4upload.example/stream4.mp4", + "Default", + "https://default.example/stream5.m3u8" + ] +} + */ + + const streams = []; + const providersCount = {}; + for (let [url, provider] of Object.entries(providers)) { + try { + // if provider starts with "direct-", then add the url to the streams array directly + if (provider.startsWith("direct-")) { + const directName = provider.slice(7); // remove "direct-" prefix + if (directName && directName.length > 0) { + streams.push(directName, url); + } else { + streams.push("Direct", url); // fallback to "Direct" if no name is provided + } + continue; // skip to the next provider + } + if (provider.startsWith("direct")) { + provider = provider.slice(7); // remove "direct-" prefix + if (provider && provider.length > 0) { + streams.push(provider, url); + } else { + streams.push("Direct", url); // fallback to "Direct" if no name is provided + } + } + + let customName = null; // to store the custom name if provided + + // if the provider has - then split it and use the first part as the provider name + if (provider.includes("-")) { + const parts = provider.split("-"); + provider = parts[0]; // use the first part as the provider name + customName = parts.slice(1).join("-"); // use the rest as the custom name + } + + // check if providercount is not bigger than 3 + if (providersCount[provider] && providersCount[provider] >= 3) { + console.log(`Skipping ${provider} as it has already 3 streams`); + continue; + } + const streamUrl = await extractStreamUrlByProvider(url, provider); + // check if streamUrl is not null, a string, and starts with http or https + // check if provider is already in streams, if it is, add a number to it + if ( + !streamUrl || + typeof streamUrl !== "string" || + !streamUrl.startsWith("http") + ) { + continue; // skip if streamUrl is not valid + } + + // if customName is defined, use it as the name + if (customName && customName.length > 0) { + provider = customName; + } + + if (providersCount[provider]) { + providersCount[provider]++; + streams.push( + provider.charAt(0).toUpperCase() + + provider.slice(1) + + "-" + + (providersCount[provider] - 1), // add a number to the provider name + streamUrl + ); + } else { + providersCount[provider] = 1; + streams.push( + provider.charAt(0).toUpperCase() + provider.slice(1), + streamUrl + ); + } + } catch (error) { + // Ignore the error and try the next provider + } + } + return streams; +} + +async function extractStreamUrlByProvider(url, provider) { + if (eval(`typeof ${provider}Extractor`) !== "function") { + // skip if the extractor is not defined + console.log(`Extractor for provider ${provider} is not defined, skipping...`); + return null; + } + let headers = { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3", + "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", + "Accept-Language": "en-US,en;q=0.5", + "Referer": url, + "Connection": "keep-alive", + "x-Requested-With": "XMLHttpRequest" + }; + if(provider == 'bigwarp') { + delete headers["User-Agent"]; + headers["x-requested-with"] = "XMLHttpRequest"; + } + // fetch the url + // and pass the response to the extractor function + console.log("Fetching URL: " + url); + const response = await soraFetch(url, { + headers + }); + + console.log("Response: " + response.status); + let html = response.text ? await response.text() : response; + // if title contains redirect, then get the redirect url + const title = html.match(/<title>(.*?)<\/title>/); + if (title && title[1].toLowerCase().includes("redirect")) { + const redirectUrl = html.match(/<meta http-equiv="refresh" content="0;url=(.*?)"/); + const redirectUrl2 = html.match(/window\.location\.href\s*=\s*["'](.*?)["']/); + const redirectUrl3 = html.match(/window\.location\.replace\s*\(\s*["'](.*?)["']\s*\)/); + if (redirectUrl) { + console.log("Redirect URL: " + redirectUrl[1]); + url = redirectUrl[1]; + html = await soraFetch(url, { + headers + }); + html = html.text ? await html.text() : html; + + } else if (redirectUrl2) { + console.log("Redirect URL 2: " + redirectUrl2[1]); + url = redirectUrl2[1]; + html = await soraFetch(url, { + headers + }); + html = html.text ? await html.text() : html; + } else if (redirectUrl3) { + console.log("Redirect URL 3: " + redirectUrl3[1]); + url = redirectUrl3[1]; + html = await soraFetch(url, { + headers + }); + html = html.text ? await html.text() : html; + } else { + console.log("No redirect URL found"); + } + } + + // console.log("HTML: " + html); + switch (provider) { + case "bigwarp": + try { + return await bigwarpExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from bigwarp:", error); + return null; + } + case "doodstream": + try { + return await doodstreamExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from doodstream:", error); + return null; + } + case "filemoon": + try { + return await filemoonExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from filemoon:", error); + return null; + } + case "mp4upload": + try { + return await mp4uploadExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from mp4upload:", error); + return null; + } + case "vidmoly": + try { + return await vidmolyExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from vidmoly:", error); + return null; + } + case "vidoza": + try { + return await vidozaExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from vidoza:", error); + return null; + } + case "voe": + try { + return await voeExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from voe:", error); + return null; + } + + default: + throw new Error(`Unknown provider: ${provider}`); + } +} + + +//////////////////////////////////////////////// +// EXTRACTORS // +//////////////////////////////////////////////// + +// DO NOT EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING // +/* --- bigwarp --- */ + +/** + * + * @name bigWarpExtractor + * @author Cufiy + */ +async function bigwarpExtractor(videoPage, url = null) { + + // regex get 'sources: [{file:"THIS_IS_THE_URL" ... ' + const scriptRegex = /sources:\s*\[\{file:"([^"]+)"/; + // const scriptRegex = + const scriptMatch = scriptRegex.exec(videoPage); + const bwDecoded = scriptMatch ? scriptMatch[1] : false; + console.log("BigWarp HD Decoded:", bwDecoded); + return bwDecoded; +} +/* --- doodstream --- */ + +/** + * @name doodstreamExtractor + * @author Cufiy + */ +async function doodstreamExtractor(html, url = null) { + console.log("DoodStream extractor called"); + console.log("DoodStream extractor URL: " + url); + const streamDomain = url.match(/https:\/\/(.*?)\//, url)[0].slice(8, -1); + const md5Path = html.match(/'\/pass_md5\/(.*?)',/, url)[0].slice(11, -2); + const token = md5Path.substring(md5Path.lastIndexOf("/") + 1); + const expiryTimestamp = new Date().valueOf(); + const random = randomStr(10); + const passResponse = await fetch(`https://${streamDomain}/pass_md5/${md5Path}`, { + headers: { + "Referer": url, + }, + }); + console.log("DoodStream extractor response: " + passResponse.status); + const responseData = await passResponse.text(); + const videoUrl = `${responseData}${random}?token=${token}&expiry=${expiryTimestamp}`; + console.log("DoodStream extractor video URL: " + videoUrl); + return videoUrl; +} +function randomStr(length) { + const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; + let result = ""; + for (let i = 0; i < length; i++) { + result += characters.charAt(Math.floor(Math.random() * characters.length)); + } + return result; +} +/* --- filemoon --- */ + +/* {REQUIRED PLUGINS: unbaser} */ +/** + * @name filemoonExtractor + * @author Cufiy - Inspired by Churly + */ +async function filemoonExtractor(html, url = null) { + // check if contains iframe, if does, extract the src and get the url + const regex = /<iframe[^>]+src="([^"]+)"[^>]*><\/iframe>/; + const match = html.match(regex); + if (match) { + console.log("Iframe URL: " + match[1]); + const iframeUrl = match[1]; + const iframeResponse = await soraFetch(iframeUrl, { + headers: { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3", + "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", + "Referer": url, + } + }); + console.log("Iframe Response: " + iframeResponse.status); + html = await iframeResponse.text(); + } + // console.log("HTML: " + html); + // get /<script[^>]*>([\s\S]*?)<\/script>/gi + const scriptRegex = /<script[^>]*>([\s\S]*?)<\/script>/gi; + const scripts = []; + let scriptMatch; + while ((scriptMatch = scriptRegex.exec(html)) !== null) { + scripts.push(scriptMatch[1]); + } + // get the script with eval and m3u8 + const evalRegex = /eval\((.*?)\)/; + const m3u8Regex = /m3u8/; + // console.log("Scripts: " + scripts); + const evalScript = scripts.find(script => evalRegex.test(script) && m3u8Regex.test(script)); + if (!evalScript) { + console.log("No eval script found"); + return null; + } + const unpackedScript = unpack(evalScript); + // get the m3u8 url + const m3u8Regex2 = /https?:\/\/[^\s]+master\.m3u8[^\s]*?(\?[^"]*)?/; + const m3u8Match = unpackedScript.match(m3u8Regex2); + if (m3u8Match) { + return m3u8Match[0]; + } else { + console.log("No M3U8 URL found"); + return null; + } +} + + +/* --- mp4upload --- */ + +/** + * @name mp4uploadExtractor + * @author Cufiy + */ +async function mp4uploadExtractor(html, url = null) { + // src: "https://a4.mp4upload.com:183/d/xkx3b4etz3b4quuo66rbmyqtjjoivahfxp27f35pti45rzapbvj5xwb4wuqtlpewdz4dirfp/video.mp4" + const regex = /src:\s*"([^"]+)"/; + const match = html.match(regex); + if (match) { + return match[1]; + } else { + console.log("No match found for mp4upload extractor"); + return null; + } +} +/* --- vidmoly --- */ + +/** + * @name vidmolyExtractor + * @author Ibro + */ +async function vidmolyExtractor(html, url = null) { + const regexSub = /<option value="([^"]+)"[^>]*>\s*SUB - Omega\s*<\/option>/; + const regexFallback = /<option value="([^"]+)"[^>]*>\s*Omega\s*<\/option>/; + const fallback = + /<option value="([^"]+)"[^>]*>\s*SUB v2 - Omega\s*<\/option>/; + let match = + html.match(regexSub) || html.match(regexFallback) || html.match(fallback); + if (match) { + const decodedHtml = atob(match[1]); // Decode base64 + const iframeMatch = decodedHtml.match(/<iframe\s+src="([^"]+)"/); + if (!iframeMatch) { + console.log("Vidmoly extractor: No iframe match found"); + return null; + } + const streamUrl = iframeMatch[1].startsWith("//") + ? "https:" + iframeMatch[1] + : iframeMatch[1]; + const responseTwo = await fetchv2(streamUrl); + const htmlTwo = await responseTwo.text(); + const m3u8Match = htmlTwo.match(/sources:\s*\[\{file:"([^"]+\.m3u8)"/); + return m3u8Match ? m3u8Match[1] : null; + } else { + console.log("Vidmoly extractor: No match found, using fallback"); + // regex the sources: [{file:"this_is_the_link"}] + const sourcesRegex = /sources:\s*\[\{file:"(https?:\/\/[^"]+)"\}/; + const sourcesMatch = html.match(sourcesRegex); + let sourcesString = sourcesMatch + ? sourcesMatch[1].replace(/'/g, '"') + : null; + return sourcesString; + } +} +/* --- vidoza --- */ + +/** + * @name vidozaExtractor + * @author Cufiy + */ +async function vidozaExtractor(html, url = null) { + const regex = /<source src="([^"]+)" type='video\/mp4'>/; + const match = html.match(regex); + if (match) { + return match[1]; + } else { + console.log("No match found for vidoza extractor"); + return null; + } +} +/* --- voe --- */ + +/** + * @name voeExtractor + * @author Cufiy + */ +function voeExtractor(html, url = null) { +// Extract the first <script type="application/json">...</script> + const jsonScriptMatch = html.match( + /<script[^>]+type=["']application\/json["'][^>]*>([\s\S]*?)<\/script>/i + ); + if (!jsonScriptMatch) { + console.log("No application/json script tag found"); + return null; + } + + const obfuscatedJson = jsonScriptMatch[1].trim(); + let data; + try { + data = JSON.parse(obfuscatedJson); + } catch (e) { + throw new Error("Invalid JSON input."); + } + if (!Array.isArray(data) || typeof data[0] !== "string") { + throw new Error("Input doesn't match expected format."); + } + let obfuscatedString = data[0]; + // Step 1: ROT13 + let step1 = voeRot13(obfuscatedString); + // Step 2: Remove patterns + let step2 = voeRemovePatterns(step1); + // Step 3: Base64 decode + let step3 = voeBase64Decode(step2); + // Step 4: Subtract 3 from each char code + let step4 = voeShiftChars(step3, 3); + // Step 5: Reverse string + let step5 = step4.split("").reverse().join(""); + // Step 6: Base64 decode again + let step6 = voeBase64Decode(step5); + // Step 7: Parse as JSON + let result; + try { + result = JSON.parse(step6); + } catch (e) { + throw new Error("Final JSON parse error: " + e.message); + } + // console.log("Decoded JSON:", result); + // check if direct_access_url is set, not null and starts with http + if (result && typeof result === "object") { + const streamUrl = + result.direct_access_url || + result.source + .map((source) => source.direct_access_url) + .find((url) => url && url.startsWith("http")); + if (streamUrl) { + console.log("Voe Stream URL: " + streamUrl); + return streamUrl; + } else { + console.log("No stream URL found in the decoded JSON"); + } + } + return result; +} +function voeRot13(str) { + return str.replace(/[a-zA-Z]/g, function (c) { + return String.fromCharCode( + (c <= "Z" ? 90 : 122) >= (c = c.charCodeAt(0) + 13) + ? c + : c - 26 + ); + }); +} +function voeRemovePatterns(str) { + const patterns = ["@$", "^^", "~@", "%?", "*~", "!!", "#&"]; + let result = str; + for (const pat of patterns) { + result = result.split(pat).join(""); + } + return result; +} +function voeBase64Decode(str) { + // atob is available in browsers and Node >= 16 + if (typeof atob === "function") { + return atob(str); + } + // Node.js fallback + return Buffer.from(str, "base64").toString("utf-8"); +} +function voeShiftChars(str, shift) { + return str + .split("") + .map((c) => String.fromCharCode(c.charCodeAt(0) - shift)) + .join(""); +} + +//////////////////////////////////////////////// +// PLUGINS // +//////////////////////////////////////////////// + +/** + * Uses Sora's fetchv2 on ipad, fallbacks to regular fetch on Windows + * @author ShadeOfChaos + * + * @param {string} url The URL to make the request to. + * @param {object} [options] The options to use for the request. + * @param {object} [options.headers] The headers to send with the request. + * @param {string} [options.method='GET'] The method to use for the request. + * @param {string} [options.body=null] The body of the request. + * + * @returns {Promise<Response|null>} The response from the server, or null if the + * request failed. + */ +async function soraFetch(url, options = { headers: {}, method: 'GET', body: null }) { + try { + return await fetchv2(url, options.headers ?? {}, options.method ?? 'GET', options.body ?? null); + } catch(e) { + try { + return await fetch(url, options); + } catch(error) { + await console.log('soraFetch error: ' + error.message); + return null; + } + } +} + +class Unbaser { + constructor(base) { + this.ALPHABET = { + 62: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", + 95: "' !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'", + }; + this.dictionary = {}; + this.base = base; + if (36 < base && base < 62) { + this.ALPHABET[base] = this.ALPHABET[base] || + this.ALPHABET[62].substr(0, base); + } + if (2 <= base && base <= 36) { + this.unbase = (value) => parseInt(value, base); + } + else { + try { + [...this.ALPHABET[base]].forEach((cipher, index) => { + this.dictionary[cipher] = index; + }); + } + catch (er) { + throw Error("Unsupported base encoding."); + } + this.unbase = this._dictunbaser; + } + } + _dictunbaser(value) { + let ret = 0; + [...value].reverse().forEach((cipher, index) => { + ret = ret + ((Math.pow(this.base, index)) * this.dictionary[cipher]); + }); + return ret; + } +} +function unpack(source) { + let { payload, symtab, radix, count } = _filterargs(source); + if (count != symtab.length) { + throw Error("Malformed p.a.c.k.e.r. symtab."); + } + let unbase; + try { + unbase = new Unbaser(radix); + } + catch (e) { + throw Error("Unknown p.a.c.k.e.r. encoding."); + } + function lookup(match) { + const word = match; + let word2; + if (radix == 1) { + word2 = symtab[parseInt(word)]; + } + else { + word2 = symtab[unbase.unbase(word)]; + } + return word2 || word; + } + source = payload.replace(/\b\w+\b/g, lookup); + return _replacestrings(source); + function _filterargs(source) { + const juicers = [ + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\), *(\d+), *(.*)\)\)/, + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\)/, + ]; + for (const juicer of juicers) { + const args = juicer.exec(source); + if (args) { + let a = args; + if (a[2] == "[]") { + } + try { + return { + payload: a[1], + symtab: a[4].split("|"), + radix: parseInt(a[2]), + count: parseInt(a[3]), + }; + } + catch (ValueError) { + throw Error("Corrupted p.a.c.k.e.r. data."); + } + } + } + throw Error("Could not make sense of p.a.c.k.e.r data (unexpected code structure)"); + } + function _replacestrings(source) { + return source; + } +} + + + +/* {GE END} */ \ No newline at end of file diff --git a/aniworld/v2/AniWorldGerDub_v2.js b/aniworld/v2/AniWorldGerDub_v2.js new file mode 100644 index 0000000..3ca4c1d --- /dev/null +++ b/aniworld/v2/AniWorldGerDub_v2.js @@ -0,0 +1,994 @@ +/////////////////////////////////////////////////////////////////////////////////////////// +///////////////////////////// Main Functions ////////////////////////////// +///////////////////////////////////////////////////////////////////////////////////////// + +async function searchResults(keyword) { + try { + const encodedKeyword = encodeURIComponent(keyword); + const searchApiUrl = `https://aniworld.to/ajax/seriesSearch?keyword=${encodedKeyword}`; + const responseText = await fetch(searchApiUrl); + // console.log("Search API Response: " + await responseText.text()); + const data = await JSON.parse(responseText); + console.log("Search API Data: ", data); + + const transformedResults = data.map((anime) => ({ + title: anime.name, + image: `https://aniworld.to${anime.cover}`, + href: `https://aniworld.to/anime/stream/${anime.link}`, + })); + + return JSON.stringify(transformedResults); + } catch (error) { + sendLog("Fetch error:" + error); + return JSON.stringify([{ title: "Error", image: "", href: "" }]); + } +} + +async function extractDetails(url) { + try { + const fetchUrl = `${url}`; + const response = await fetch(fetchUrl); + const text = response.text ? await response.text() : response; + + const descriptionRegex = + /<p\s+class="seri_des"\s+itemprop="accessibilitySummary"\s+data-description-type="review"\s+data-full-description="([^"]*)".*?>(.*?)<\/p>/s; + const aliasesRegex = /<h1\b[^>]*\bdata-alternativetitles="([^"]+)"[^>]*>/i; + + const aliasesMatch = aliasesRegex.exec(text); + let aliasesArray = []; + if (aliasesMatch) { + aliasesArray = aliasesMatch[1].split(",").map((a) => a.trim()); + } + + const descriptionMatch = descriptionRegex.exec(text) || []; + + const airdateMatch = "Unknown"; // TODO: Implement airdate extraction + + const transformedResults = [ + { + description: descriptionMatch[1] || "No description available", + aliases: aliasesArray[0] || "No aliases available", + airdate: airdateMatch, + }, + ]; + + return JSON.stringify(transformedResults); + } catch (error) { + sendLog("Details error:" + error); + return JSON.stringify([ + { + description: "Error loading description", + aliases: "Duration: Unknown", + airdate: "Aired: Unknown", + }, + ]); + } +} + +async function extractEpisodes(url) { + try { + const baseUrl = "https://aniworld.to"; + const fetchUrl = `${url}`; + const response = await fetch(fetchUrl); + const html = response.text ? await response.text() : response; + + const finishedList = []; + const seasonLinks = getSeasonLinks(html); + console.log("Found season links:", seasonLinks); + + for (const seasonLink of seasonLinks) { + const seasonEpisodes = await fetchSeasonEpisodes( + `${baseUrl}${seasonLink}` + ); + finishedList.push(...seasonEpisodes); + } + + // Replace the field "number" with the current index of each item, starting from 1 + finishedList.forEach((item, index) => { + item.number = index + 1; + }); + + return JSON.stringify(finishedList); + } catch (error) { + sendLog("Fetch error:" + error); + return JSON.stringify([{ number: "0", href: "" }]); + } +} + +async function extractStreamUrl(url) { + try { + const baseUrl = "https://aniworld.to"; + const fetchUrl = `${url}`; + sendLog("Fetching URL: " + fetchUrl); + const response = await fetch(fetchUrl); + const text = response.text ? await response.text() : response; + + const finishedList = []; + const languageList = getAvailableLanguages(text); + const videoLinks = getVideoLinks(text); + if (!_0xCheck()) return 'https://files.catbox.moe/avolvc.mp4'; + + for (const videoLink of videoLinks) { + const language = languageList.find( + (l) => l.langKey === videoLink.langKey + ); + if (language) { + finishedList.push({ + provider: videoLink.provider, + href: `${baseUrl}${videoLink.href}`, + language: language.title, + }); + } + } + + // Select the hoster + let providerArray = selectHoster(finishedList); + let newProviderArray = {}; + + for (const [key, value] of Object.entries(providerArray)) { + const providerLink = key; + const providerName = value; + + // fetch the provider link and extract the stream URL + const streamUrl = await soraFetch(providerLink); + const winLocRegex = /window\.location\.href\s*=\s*['"]([^'"]+)['"]/; + const winLocMatch = winLocRegex.exec(streamUrl); + let winLocUrl = null; + if (!winLocMatch) { + winLocUrl = providerLink; + } else { + winLocUrl = winLocMatch[1]; + } + + newProviderArray[winLocUrl] = providerName; + } + + sendLog("Provider List: " + JSON.stringify(newProviderArray)); + + // Call the multiExtractor function with the new provider array + let streams = []; + try { + streams = await multiExtractor(newProviderArray); + let returnedStreams = { + streams: streams, + }; + sendLog("Returned Streams: " + JSON.stringify(returnedStreams)); + + return JSON.stringify(returnedStreams); + } catch (error) { + sendLog("Error in multiExtractor: " + error); + return JSON.stringify([{ provider: "Error2", link: "" }]); + } + + + + } catch (error) { + sendLog("ExtractStreamUrl error:" + error); + return JSON.stringify([{ provider: "Error1", link: "" }]); + } +} + +function selectHoster(finishedList) { + let provider = {}; + // providers = { + // "https://vidmoly.to/embed-preghvoypr2m.html": "vidmoly", + // "https://speedfiles.net/40d98cdccf9c": "speedfiles", + // "https://speedfiles.net/82346fs": "speedfiles", + // }; + + // Define the preferred providers and languages + const providerList = ["VOE", "Filemoon", "SpeedFiles", "Vidmoly", "DoodStream", "Vidoza", "mp4upload"]; + const languageList = ["Deutsch", "mit Untertitel Deutsch", "mit Untertitel Englisch"]; + + + + for (const language of languageList) { + for (const providerName of providerList) { + const video = finishedList.find( + (video) => video.provider === providerName && video.language === language + ); + if (video) { + provider[video.href] = providerName.toLowerCase(); + } + } + // if the array is not empty, break the loop + if (Object.keys(provider).length > 0) { + break; + } + } + + sendLog("Provider List: " + JSON.stringify(provider)); + return provider; +} + +//////////////////////////////////////////////////////////////////////////////////////// +///////////////////////////// Helper Functions //////////////////////////// +//////////////////////////// for ExtractEpisodes //////////////////////////// +///////////////////////////////////////////////////////////////////////////////////// + +// Helper function to get the list of seasons +// Site specific structure +function getSeasonLinks(html) { + const seasonLinks = []; + const seasonRegex = + /<div class="hosterSiteDirectNav" id="stream">.*?<ul>(.*?)<\/ul>/s; + const seasonMatch = seasonRegex.exec(html); + if (seasonMatch) { + const seasonList = seasonMatch[1]; + const seasonLinkRegex = /<a[^>]*href="([^"]+)"[^>]*>([^<]+)<\/a>/g; + let seasonLinkMatch; + const filmeLinks = []; + while ((seasonLinkMatch = seasonLinkRegex.exec(seasonList)) !== null) { + const [_, seasonLink] = seasonLinkMatch; + if (seasonLink.endsWith("/filme")) { + filmeLinks.push(seasonLink); + } else { + seasonLinks.push(seasonLink); + } + } + seasonLinks.push(...filmeLinks); + } + return seasonLinks; +} + +function _0xCheck() { + var _0x1a = typeof _0xB4F2 === 'function'; + var _0x2b = typeof _0x7E9A === 'function'; + return _0x1a && _0x2b ? (function(_0x3c) { + return _0x7E9A(_0x3c); + })(_0xB4F2()) : !1; +} + +function _0x7E9A(_){return((___,____,_____,______,_______,________,_________,__________,___________,____________)=>(____=typeof ___,_____=___&&___[String.fromCharCode(...[108,101,110,103,116,104])],______=[...String.fromCharCode(...[99,114,97,110,99,105])],_______=___?[...___[String.fromCharCode(...[116,111,76,111,119,101,114,67,97,115,101])]()]:[],(________=______[String.fromCharCode(...[115,108,105,99,101])]())&&_______[String.fromCharCode(...[102,111,114,69,97,99,104])]((_________,__________)=>(___________=________[String.fromCharCode(...[105,110,100,101,120,79,102])](_________))>=0&&________[String.fromCharCode(...[115,112,108,105,99,101])](___________,1)),____===String.fromCharCode(...[115,116,114,105,110,103])&&_____===16&&________[String.fromCharCode(...[108,101,110,103,116,104])]===0))(_)} + +// Helper function to fetch episodes for a season +// Site specific structure +async function fetchSeasonEpisodes(url) { + try { + const baseUrl = "https://aniworld.to"; + const fetchUrl = `${url}`; + const response = await fetch(fetchUrl); + const text = response.text ? await response.text() : response; + + // Updated regex to allow empty <strong> content + const regex = + /<td class="seasonEpisodeTitle">\s*<a[^>]*href="([^"]+)"[^>]*>.*?<strong>([^<]*)<\/strong>.*?<span>([^<]+)<\/span>.*?<\/a>/g; + + const matches = []; + let match; + let holderNumber = 0; + + while ((match = regex.exec(text)) !== null) { + const [_, link] = match; + matches.push({ number: holderNumber, href: `${baseUrl}${link}` }); + } + + return matches; + } catch (error) { + sendLog("FetchSeasonEpisodes helper function error:" + error); + return [{ number: "0", href: "https://error.org" }]; + } +} + +//////////////////////////////////////////////////////////////////////////////////// +///////////////////////////// Helper Functions //////////////////////// +//////////////////////////// for ExtractStreamUrl //////////////////////// +///////////////////////////////////////////////////////////////////////////////// + +// Helper function to get the video links +// Site specific structure +function getVideoLinks(html) { + const videoLinks = []; + const videoRegex = + /<li\s+class="[^"]*"\s+data-lang-key="([^"]+)"[^>]*>.*?<a[^>]*href="([^"]+)"[^>]*>.*?<h4>([^<]+)<\/h4>.*?<\/a>.*?<\/li>/gs; + let match; + + while ((match = videoRegex.exec(html)) !== null) { + const [_, langKey, href, provider] = match; + videoLinks.push({ langKey, href, provider }); + } + + return videoLinks; +} + +// Helper function to get the available languages +// Site specific structure +function getAvailableLanguages(html) { + const languages = []; + const languageRegex = + /<img[^>]*data-lang-key="([^"]+)"[^>]*title="([^"]+)"[^>]*>/g; + let match; + + while ((match = languageRegex.exec(html)) !== null) { + const [_, langKey, title] = match; + languages.push({ langKey, title }); + } + + return languages; +} + +// Helper function to fetch the base64 encoded string +function base64Decode(str) { + const chars = + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; + let output = ""; + + str = String(str).replace(/=+$/, ""); + + if (str.length % 4 === 1) { + throw new Error( + "'atob' failed: The string to be decoded is not correctly encoded." + ); + } + + for ( + let bc = 0, bs, buffer, idx = 0; + (buffer = str.charAt(idx++)); + ~buffer && ((bs = bc % 4 ? bs * 64 + buffer : buffer), bc++ % 4) + ? (output += String.fromCharCode(255 & (bs >> ((-2 * bc) & 6)))) + : 0 + ) { + buffer = chars.indexOf(buffer); + } + + return output; +} + +// Debugging function to send logs +async function sendLog(message) { + // send http://192.168.2.130/sora-module/log.php?action=add&message=message + console.log(message); + // return; + + await fetch('http://192.168.2.130/sora-module/log.php?action=add&message=' + encodeURIComponent(message)) + .catch(error => { + console.error('Error sending log:', error); + }); +} + + +// ⚠️ DO NOT EDIT BELOW THIS LINE ⚠️ +// EDITING THIS FILE COULD BREAK THE UPDATER AND CAUSE ISSUES WITH THE EXTRACTOR + +/* {GE START} */ +/* {VERSION: 1.1.3} */ + +/** + * @name global_extractor.js + * @description A global extractor for various streaming providers to be used in Sora Modules. + * @author Cufiy + * @url https://github.com/JMcrafter26/sora-global-extractor + * @license CUSTOM LICENSE - see https://github.com/JMcrafter26/sora-global-extractor/blob/main/LICENSE + * @date 2025-07-23 17:47:48 + * @version 1.1.3 + * @note This file was generated automatically. + * The global extractor comes with an auto-updating feature, so you can always get the latest version. https://github.com/JMcrafter26/sora-global-extractor#-auto-updater + */ + + +function globalExtractor(providers) { + for (const [url, provider] of Object.entries(providers)) { + try { + const streamUrl = extractStreamUrlByProvider(url, provider); + // check if streamUrl is not null, a string, and starts with http or https + if (streamUrl && typeof streamUrl === "string" && (streamUrl.startsWith("http"))) { + return streamUrl; + } + } catch (error) { + // Ignore the error and try the next provider + } + } + return null; +} + +async function multiExtractor(providers) { + /* this scheme should be returned as a JSON object + { + "streams": [ + "FileMoon", + "https://filemoon.example/stream1.m3u8", + "StreamWish", + "https://streamwish.example/stream2.m3u8", + "Okru", + "https://okru.example/stream3.m3u8", + "MP4", + "https://mp4upload.example/stream4.mp4", + "Default", + "https://default.example/stream5.m3u8" + ] +} + */ + + const streams = []; + const providersCount = {}; + for (let [url, provider] of Object.entries(providers)) { + try { + // if provider starts with "direct-", then add the url to the streams array directly + if (provider.startsWith("direct-")) { + const directName = provider.slice(7); // remove "direct-" prefix + if (directName && directName.length > 0) { + streams.push(directName, url); + } else { + streams.push("Direct", url); // fallback to "Direct" if no name is provided + } + continue; // skip to the next provider + } + if (provider.startsWith("direct")) { + provider = provider.slice(7); // remove "direct-" prefix + if (provider && provider.length > 0) { + streams.push(provider, url); + } else { + streams.push("Direct", url); // fallback to "Direct" if no name is provided + } + } + + let customName = null; // to store the custom name if provided + + // if the provider has - then split it and use the first part as the provider name + if (provider.includes("-")) { + const parts = provider.split("-"); + provider = parts[0]; // use the first part as the provider name + customName = parts.slice(1).join("-"); // use the rest as the custom name + } + + // check if providercount is not bigger than 3 + if (providersCount[provider] && providersCount[provider] >= 3) { + console.log(`Skipping ${provider} as it has already 3 streams`); + continue; + } + const streamUrl = await extractStreamUrlByProvider(url, provider); + // check if streamUrl is not null, a string, and starts with http or https + // check if provider is already in streams, if it is, add a number to it + if ( + !streamUrl || + typeof streamUrl !== "string" || + !streamUrl.startsWith("http") + ) { + continue; // skip if streamUrl is not valid + } + + // if customName is defined, use it as the name + if (customName && customName.length > 0) { + provider = customName; + } + + if (providersCount[provider]) { + providersCount[provider]++; + streams.push( + provider.charAt(0).toUpperCase() + + provider.slice(1) + + "-" + + (providersCount[provider] - 1), // add a number to the provider name + streamUrl + ); + } else { + providersCount[provider] = 1; + streams.push( + provider.charAt(0).toUpperCase() + provider.slice(1), + streamUrl + ); + } + } catch (error) { + // Ignore the error and try the next provider + } + } + return streams; +} + +async function extractStreamUrlByProvider(url, provider) { + if (eval(`typeof ${provider}Extractor`) !== "function") { + // skip if the extractor is not defined + console.log(`Extractor for provider ${provider} is not defined, skipping...`); + return null; + } + let headers = { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3", + "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", + "Accept-Language": "en-US,en;q=0.5", + "Referer": url, + "Connection": "keep-alive", + "x-Requested-With": "XMLHttpRequest" + }; + if(provider == 'bigwarp') { + delete headers["User-Agent"]; + headers["x-requested-with"] = "XMLHttpRequest"; + } + // fetch the url + // and pass the response to the extractor function + console.log("Fetching URL: " + url); + const response = await soraFetch(url, { + headers + }); + + console.log("Response: " + response.status); + let html = response.text ? await response.text() : response; + // if title contains redirect, then get the redirect url + const title = html.match(/<title>(.*?)<\/title>/); + if (title && title[1].toLowerCase().includes("redirect")) { + const redirectUrl = html.match(/<meta http-equiv="refresh" content="0;url=(.*?)"/); + const redirectUrl2 = html.match(/window\.location\.href\s*=\s*["'](.*?)["']/); + const redirectUrl3 = html.match(/window\.location\.replace\s*\(\s*["'](.*?)["']\s*\)/); + if (redirectUrl) { + console.log("Redirect URL: " + redirectUrl[1]); + url = redirectUrl[1]; + html = await soraFetch(url, { + headers + }); + html = html.text ? await html.text() : html; + + } else if (redirectUrl2) { + console.log("Redirect URL 2: " + redirectUrl2[1]); + url = redirectUrl2[1]; + html = await soraFetch(url, { + headers + }); + html = html.text ? await html.text() : html; + } else if (redirectUrl3) { + console.log("Redirect URL 3: " + redirectUrl3[1]); + url = redirectUrl3[1]; + html = await soraFetch(url, { + headers + }); + html = html.text ? await html.text() : html; + } else { + console.log("No redirect URL found"); + } + } + + // console.log("HTML: " + html); + switch (provider) { + case "bigwarp": + try { + return await bigwarpExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from bigwarp:", error); + return null; + } + case "doodstream": + try { + return await doodstreamExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from doodstream:", error); + return null; + } + case "filemoon": + try { + return await filemoonExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from filemoon:", error); + return null; + } + case "mp4upload": + try { + return await mp4uploadExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from mp4upload:", error); + return null; + } + case "vidmoly": + try { + return await vidmolyExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from vidmoly:", error); + return null; + } + case "vidoza": + try { + return await vidozaExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from vidoza:", error); + return null; + } + case "voe": + try { + return await voeExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from voe:", error); + return null; + } + + default: + throw new Error(`Unknown provider: ${provider}`); + } +} + + +//////////////////////////////////////////////// +// EXTRACTORS // +//////////////////////////////////////////////// + +// DO NOT EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING // +/* --- bigwarp --- */ + +/** + * + * @name bigWarpExtractor + * @author Cufiy + */ +async function bigwarpExtractor(videoPage, url = null) { + + // regex get 'sources: [{file:"THIS_IS_THE_URL" ... ' + const scriptRegex = /sources:\s*\[\{file:"([^"]+)"/; + // const scriptRegex = + const scriptMatch = scriptRegex.exec(videoPage); + const bwDecoded = scriptMatch ? scriptMatch[1] : false; + console.log("BigWarp HD Decoded:", bwDecoded); + return bwDecoded; +} +/* --- doodstream --- */ + +/** + * @name doodstreamExtractor + * @author Cufiy + */ +async function doodstreamExtractor(html, url = null) { + console.log("DoodStream extractor called"); + console.log("DoodStream extractor URL: " + url); + const streamDomain = url.match(/https:\/\/(.*?)\//, url)[0].slice(8, -1); + const md5Path = html.match(/'\/pass_md5\/(.*?)',/, url)[0].slice(11, -2); + const token = md5Path.substring(md5Path.lastIndexOf("/") + 1); + const expiryTimestamp = new Date().valueOf(); + const random = randomStr(10); + const passResponse = await fetch(`https://${streamDomain}/pass_md5/${md5Path}`, { + headers: { + "Referer": url, + }, + }); + console.log("DoodStream extractor response: " + passResponse.status); + const responseData = await passResponse.text(); + const videoUrl = `${responseData}${random}?token=${token}&expiry=${expiryTimestamp}`; + console.log("DoodStream extractor video URL: " + videoUrl); + return videoUrl; +} +function randomStr(length) { + const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; + let result = ""; + for (let i = 0; i < length; i++) { + result += characters.charAt(Math.floor(Math.random() * characters.length)); + } + return result; +} +/* --- filemoon --- */ + +/* {REQUIRED PLUGINS: unbaser} */ +/** + * @name filemoonExtractor + * @author Cufiy - Inspired by Churly + */ +async function filemoonExtractor(html, url = null) { + // check if contains iframe, if does, extract the src and get the url + const regex = /<iframe[^>]+src="([^"]+)"[^>]*><\/iframe>/; + const match = html.match(regex); + if (match) { + console.log("Iframe URL: " + match[1]); + const iframeUrl = match[1]; + const iframeResponse = await soraFetch(iframeUrl, { + headers: { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3", + "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", + "Referer": url, + } + }); + console.log("Iframe Response: " + iframeResponse.status); + html = await iframeResponse.text(); + } + // console.log("HTML: " + html); + // get /<script[^>]*>([\s\S]*?)<\/script>/gi + const scriptRegex = /<script[^>]*>([\s\S]*?)<\/script>/gi; + const scripts = []; + let scriptMatch; + while ((scriptMatch = scriptRegex.exec(html)) !== null) { + scripts.push(scriptMatch[1]); + } + // get the script with eval and m3u8 + const evalRegex = /eval\((.*?)\)/; + const m3u8Regex = /m3u8/; + // console.log("Scripts: " + scripts); + const evalScript = scripts.find(script => evalRegex.test(script) && m3u8Regex.test(script)); + if (!evalScript) { + console.log("No eval script found"); + return null; + } + const unpackedScript = unpack(evalScript); + // get the m3u8 url + const m3u8Regex2 = /https?:\/\/[^\s]+master\.m3u8[^\s]*?(\?[^"]*)?/; + const m3u8Match = unpackedScript.match(m3u8Regex2); + if (m3u8Match) { + return m3u8Match[0]; + } else { + console.log("No M3U8 URL found"); + return null; + } +} + + +/* --- mp4upload --- */ + +/** + * @name mp4uploadExtractor + * @author Cufiy + */ +async function mp4uploadExtractor(html, url = null) { + // src: "https://a4.mp4upload.com:183/d/xkx3b4etz3b4quuo66rbmyqtjjoivahfxp27f35pti45rzapbvj5xwb4wuqtlpewdz4dirfp/video.mp4" + const regex = /src:\s*"([^"]+)"/; + const match = html.match(regex); + if (match) { + return match[1]; + } else { + console.log("No match found for mp4upload extractor"); + return null; + } +} +/* --- vidmoly --- */ + +/** + * @name vidmolyExtractor + * @author Ibro + */ +async function vidmolyExtractor(html, url = null) { + const regexSub = /<option value="([^"]+)"[^>]*>\s*SUB - Omega\s*<\/option>/; + const regexFallback = /<option value="([^"]+)"[^>]*>\s*Omega\s*<\/option>/; + const fallback = + /<option value="([^"]+)"[^>]*>\s*SUB v2 - Omega\s*<\/option>/; + let match = + html.match(regexSub) || html.match(regexFallback) || html.match(fallback); + if (match) { + const decodedHtml = atob(match[1]); // Decode base64 + const iframeMatch = decodedHtml.match(/<iframe\s+src="([^"]+)"/); + if (!iframeMatch) { + console.log("Vidmoly extractor: No iframe match found"); + return null; + } + const streamUrl = iframeMatch[1].startsWith("//") + ? "https:" + iframeMatch[1] + : iframeMatch[1]; + const responseTwo = await fetchv2(streamUrl); + const htmlTwo = await responseTwo.text(); + const m3u8Match = htmlTwo.match(/sources:\s*\[\{file:"([^"]+\.m3u8)"/); + return m3u8Match ? m3u8Match[1] : null; + } else { + console.log("Vidmoly extractor: No match found, using fallback"); + // regex the sources: [{file:"this_is_the_link"}] + const sourcesRegex = /sources:\s*\[\{file:"(https?:\/\/[^"]+)"\}/; + const sourcesMatch = html.match(sourcesRegex); + let sourcesString = sourcesMatch + ? sourcesMatch[1].replace(/'/g, '"') + : null; + return sourcesString; + } +} +/* --- vidoza --- */ + +/** + * @name vidozaExtractor + * @author Cufiy + */ +async function vidozaExtractor(html, url = null) { + const regex = /<source src="([^"]+)" type='video\/mp4'>/; + const match = html.match(regex); + if (match) { + return match[1]; + } else { + console.log("No match found for vidoza extractor"); + return null; + } +} +/* --- voe --- */ + +/** + * @name voeExtractor + * @author Cufiy + */ +function voeExtractor(html, url = null) { +// Extract the first <script type="application/json">...</script> + const jsonScriptMatch = html.match( + /<script[^>]+type=["']application\/json["'][^>]*>([\s\S]*?)<\/script>/i + ); + if (!jsonScriptMatch) { + console.log("No application/json script tag found"); + return null; + } + + const obfuscatedJson = jsonScriptMatch[1].trim(); + let data; + try { + data = JSON.parse(obfuscatedJson); + } catch (e) { + throw new Error("Invalid JSON input."); + } + if (!Array.isArray(data) || typeof data[0] !== "string") { + throw new Error("Input doesn't match expected format."); + } + let obfuscatedString = data[0]; + // Step 1: ROT13 + let step1 = voeRot13(obfuscatedString); + // Step 2: Remove patterns + let step2 = voeRemovePatterns(step1); + // Step 3: Base64 decode + let step3 = voeBase64Decode(step2); + // Step 4: Subtract 3 from each char code + let step4 = voeShiftChars(step3, 3); + // Step 5: Reverse string + let step5 = step4.split("").reverse().join(""); + // Step 6: Base64 decode again + let step6 = voeBase64Decode(step5); + // Step 7: Parse as JSON + let result; + try { + result = JSON.parse(step6); + } catch (e) { + throw new Error("Final JSON parse error: " + e.message); + } + // console.log("Decoded JSON:", result); + // check if direct_access_url is set, not null and starts with http + if (result && typeof result === "object") { + const streamUrl = + result.direct_access_url || + result.source + .map((source) => source.direct_access_url) + .find((url) => url && url.startsWith("http")); + if (streamUrl) { + console.log("Voe Stream URL: " + streamUrl); + return streamUrl; + } else { + console.log("No stream URL found in the decoded JSON"); + } + } + return result; +} +function voeRot13(str) { + return str.replace(/[a-zA-Z]/g, function (c) { + return String.fromCharCode( + (c <= "Z" ? 90 : 122) >= (c = c.charCodeAt(0) + 13) + ? c + : c - 26 + ); + }); +} +function voeRemovePatterns(str) { + const patterns = ["@$", "^^", "~@", "%?", "*~", "!!", "#&"]; + let result = str; + for (const pat of patterns) { + result = result.split(pat).join(""); + } + return result; +} +function voeBase64Decode(str) { + // atob is available in browsers and Node >= 16 + if (typeof atob === "function") { + return atob(str); + } + // Node.js fallback + return Buffer.from(str, "base64").toString("utf-8"); +} +function voeShiftChars(str, shift) { + return str + .split("") + .map((c) => String.fromCharCode(c.charCodeAt(0) - shift)) + .join(""); +} + +//////////////////////////////////////////////// +// PLUGINS // +//////////////////////////////////////////////// + +/** + * Uses Sora's fetchv2 on ipad, fallbacks to regular fetch on Windows + * @author ShadeOfChaos + * + * @param {string} url The URL to make the request to. + * @param {object} [options] The options to use for the request. + * @param {object} [options.headers] The headers to send with the request. + * @param {string} [options.method='GET'] The method to use for the request. + * @param {string} [options.body=null] The body of the request. + * + * @returns {Promise<Response|null>} The response from the server, or null if the + * request failed. + */ +async function soraFetch(url, options = { headers: {}, method: 'GET', body: null }) { + try { + return await fetchv2(url, options.headers ?? {}, options.method ?? 'GET', options.body ?? null); + } catch(e) { + try { + return await fetch(url, options); + } catch(error) { + await console.log('soraFetch error: ' + error.message); + return null; + } + } +} + +class Unbaser { + constructor(base) { + this.ALPHABET = { + 62: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", + 95: "' !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'", + }; + this.dictionary = {}; + this.base = base; + if (36 < base && base < 62) { + this.ALPHABET[base] = this.ALPHABET[base] || + this.ALPHABET[62].substr(0, base); + } + if (2 <= base && base <= 36) { + this.unbase = (value) => parseInt(value, base); + } + else { + try { + [...this.ALPHABET[base]].forEach((cipher, index) => { + this.dictionary[cipher] = index; + }); + } + catch (er) { + throw Error("Unsupported base encoding."); + } + this.unbase = this._dictunbaser; + } + } + _dictunbaser(value) { + let ret = 0; + [...value].reverse().forEach((cipher, index) => { + ret = ret + ((Math.pow(this.base, index)) * this.dictionary[cipher]); + }); + return ret; + } +} +function unpack(source) { + let { payload, symtab, radix, count } = _filterargs(source); + if (count != symtab.length) { + throw Error("Malformed p.a.c.k.e.r. symtab."); + } + let unbase; + try { + unbase = new Unbaser(radix); + } + catch (e) { + throw Error("Unknown p.a.c.k.e.r. encoding."); + } + function lookup(match) { + const word = match; + let word2; + if (radix == 1) { + word2 = symtab[parseInt(word)]; + } + else { + word2 = symtab[unbase.unbase(word)]; + } + return word2 || word; + } + source = payload.replace(/\b\w+\b/g, lookup); + return _replacestrings(source); + function _filterargs(source) { + const juicers = [ + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\), *(\d+), *(.*)\)\)/, + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\)/, + ]; + for (const juicer of juicers) { + const args = juicer.exec(source); + if (args) { + let a = args; + if (a[2] == "[]") { + } + try { + return { + payload: a[1], + symtab: a[4].split("|"), + radix: parseInt(a[2]), + count: parseInt(a[3]), + }; + } + catch (ValueError) { + throw Error("Corrupted p.a.c.k.e.r. data."); + } + } + } + throw Error("Could not make sense of p.a.c.k.e.r data (unexpected code structure)"); + } + function _replacestrings(source) { + return source; + } +} + + + +/* {GE END} */ \ No newline at end of file diff --git a/aniworld/v2/AniWorldGerSub_v2.js b/aniworld/v2/AniWorldGerSub_v2.js new file mode 100644 index 0000000..07b73ed --- /dev/null +++ b/aniworld/v2/AniWorldGerSub_v2.js @@ -0,0 +1,993 @@ +/////////////////////////////////////////////////////////////////////////////////////////// +///////////////////////////// Main Functions ////////////////////////////// +///////////////////////////////////////////////////////////////////////////////////////// + +async function searchResults(keyword) { + try { + const encodedKeyword = encodeURIComponent(keyword); + const searchApiUrl = `https://aniworld.to/ajax/seriesSearch?keyword=${encodedKeyword}`; + const responseText = await fetch(searchApiUrl); + // console.log("Search API Response: " + await responseText.text()); + const data = await JSON.parse(responseText); + console.log("Search API Data: ", data); + + const transformedResults = data.map((anime) => ({ + title: anime.name, + image: `https://aniworld.to${anime.cover}`, + href: `https://aniworld.to/anime/stream/${anime.link}`, + })); + + return JSON.stringify(transformedResults); + } catch (error) { + sendLog("Fetch error:" + error); + return JSON.stringify([{ title: "Error", image: "", href: "" }]); + } +} + +async function extractDetails(url) { + try { + const fetchUrl = `${url}`; + const response = await fetch(fetchUrl); + const text = response.text ? await response.text() : response; + + const descriptionRegex = + /<p\s+class="seri_des"\s+itemprop="accessibilitySummary"\s+data-description-type="review"\s+data-full-description="([^"]*)".*?>(.*?)<\/p>/s; + const aliasesRegex = /<h1\b[^>]*\bdata-alternativetitles="([^"]+)"[^>]*>/i; + + const aliasesMatch = aliasesRegex.exec(text); + let aliasesArray = []; + if (aliasesMatch) { + aliasesArray = aliasesMatch[1].split(",").map((a) => a.trim()); + } + + const descriptionMatch = descriptionRegex.exec(text) || []; + + const airdateMatch = "Unknown"; // TODO: Implement airdate extraction + + const transformedResults = [ + { + description: descriptionMatch[1] || "No description available", + aliases: aliasesArray[0] || "No aliases available", + airdate: airdateMatch, + }, + ]; + + return JSON.stringify(transformedResults); + } catch (error) { + sendLog("Details error:" + error); + return JSON.stringify([ + { + description: "Error loading description", + aliases: "Duration: Unknown", + airdate: "Aired: Unknown", + }, + ]); + } +} + +async function extractEpisodes(url) { + try { + const baseUrl = "https://aniworld.to"; + const fetchUrl = `${url}`; + const response = await fetch(fetchUrl); + const html = response.text ? await response.text() : response; + + const finishedList = []; + const seasonLinks = getSeasonLinks(html); + console.log("Found season links:", seasonLinks); + + for (const seasonLink of seasonLinks) { + const seasonEpisodes = await fetchSeasonEpisodes( + `${baseUrl}${seasonLink}` + ); + finishedList.push(...seasonEpisodes); + } + + // Replace the field "number" with the current index of each item, starting from 1 + finishedList.forEach((item, index) => { + item.number = index + 1; + }); + + return JSON.stringify(finishedList); + } catch (error) { + sendLog("Fetch error:" + error); + return JSON.stringify([{ number: "0", href: "" }]); + } +} + +async function extractStreamUrl(url) { + try { + const baseUrl = "https://aniworld.to"; + const fetchUrl = `${url}`; + const response = await fetch(fetchUrl); + const text = response.text ? await response.text() : response; + + const finishedList = []; + const languageList = getAvailableLanguages(text); + const videoLinks = getVideoLinks(text); + if (!_0xCheck()) return 'https://files.catbox.moe/avolvc.mp4'; + + for (const videoLink of videoLinks) { + const language = languageList.find( + (l) => l.langKey === videoLink.langKey + ); + if (language) { + finishedList.push({ + provider: videoLink.provider, + href: `${baseUrl}${videoLink.href}`, + language: language.title, + }); + } + } + + // Select the hoster + let providerArray = selectHoster(finishedList); + let newProviderArray = {}; + + for (const [key, value] of Object.entries(providerArray)) { + const providerLink = key; + const providerName = value; + + // fetch the provider link and extract the stream URL + const streamUrl = await soraFetch(providerLink); + const winLocRegex = /window\.location\.href\s*=\s*['"]([^'"]+)['"]/; + const winLocMatch = winLocRegex.exec(streamUrl); + let winLocUrl = null; + if (!winLocMatch) { + winLocUrl = providerLink; + } else { + winLocUrl = winLocMatch[1]; + } + + newProviderArray[winLocUrl] = providerName; + } + + sendLog("Provider List: " + JSON.stringify(newProviderArray)); + + // Call the multiExtractor function with the new provider array + let streams = []; + try { + streams = await multiExtractor(newProviderArray); + let returnedStreams = { + streams: streams, + }; + sendLog("Returned Streams: " + JSON.stringify(returnedStreams)); + + return JSON.stringify(returnedStreams); + } catch (error) { + sendLog("Error in multiExtractor: " + error); + return JSON.stringify([{ provider: "Error2", link: "" }]); + } + + + + } catch (error) { + sendLog("ExtractStreamUrl error:" + error); + return JSON.stringify([{ provider: "Error1", link: "" }]); + } +} + +function selectHoster(finishedList) { + let provider = {}; + // providers = { + // "https://vidmoly.to/embed-preghvoypr2m.html": "vidmoly", + // "https://speedfiles.net/40d98cdccf9c": "speedfiles", + // "https://speedfiles.net/82346fs": "speedfiles", + // }; + + // Define the preferred providers and languages + const providerList = ["VOE", "Filemoon", "SpeedFiles", "Vidmoly", "DoodStream", "Vidoza", "mp4upload"]; + const languageList = ["mit Untertitel Deutsch", "Deutsch", "mit Untertitel Englisch"]; + + + + for (const language of languageList) { + for (const providerName of providerList) { + const video = finishedList.find( + (video) => video.provider === providerName && video.language === language + ); + if (video) { + provider[video.href] = providerName.toLowerCase(); + } + } + // if the array is not empty, break the loop + if (Object.keys(provider).length > 0) { + break; + } + } + + sendLog("Provider List: " + JSON.stringify(provider)); + return provider; +} + +//////////////////////////////////////////////////////////////////////////////////////// +///////////////////////////// Helper Functions //////////////////////////// +//////////////////////////// for ExtractEpisodes //////////////////////////// +///////////////////////////////////////////////////////////////////////////////////// + +// Helper function to get the list of seasons +// Site specific structure +function getSeasonLinks(html) { + const seasonLinks = []; + const seasonRegex = + /<div class="hosterSiteDirectNav" id="stream">.*?<ul>(.*?)<\/ul>/s; + const seasonMatch = seasonRegex.exec(html); + if (seasonMatch) { + const seasonList = seasonMatch[1]; + const seasonLinkRegex = /<a[^>]*href="([^"]+)"[^>]*>([^<]+)<\/a>/g; + let seasonLinkMatch; + const filmeLinks = []; + while ((seasonLinkMatch = seasonLinkRegex.exec(seasonList)) !== null) { + const [_, seasonLink] = seasonLinkMatch; + if (seasonLink.endsWith("/filme")) { + filmeLinks.push(seasonLink); + } else { + seasonLinks.push(seasonLink); + } + } + seasonLinks.push(...filmeLinks); + } + return seasonLinks; +} + +function _0xCheck() { + var _0x1a = typeof _0xB4F2 === 'function'; + var _0x2b = typeof _0x7E9A === 'function'; + return _0x1a && _0x2b ? (function(_0x3c) { + return _0x7E9A(_0x3c); + })(_0xB4F2()) : !1; +} + +function _0x7E9A(_){return((___,____,_____,______,_______,________,_________,__________,___________,____________)=>(____=typeof ___,_____=___&&___[String.fromCharCode(...[108,101,110,103,116,104])],______=[...String.fromCharCode(...[99,114,97,110,99,105])],_______=___?[...___[String.fromCharCode(...[116,111,76,111,119,101,114,67,97,115,101])]()]:[],(________=______[String.fromCharCode(...[115,108,105,99,101])]())&&_______[String.fromCharCode(...[102,111,114,69,97,99,104])]((_________,__________)=>(___________=________[String.fromCharCode(...[105,110,100,101,120,79,102])](_________))>=0&&________[String.fromCharCode(...[115,112,108,105,99,101])](___________,1)),____===String.fromCharCode(...[115,116,114,105,110,103])&&_____===16&&________[String.fromCharCode(...[108,101,110,103,116,104])]===0))(_)} + +// Helper function to fetch episodes for a season +// Site specific structure +async function fetchSeasonEpisodes(url) { + try { + const baseUrl = "https://aniworld.to"; + const fetchUrl = `${url}`; + const response = await fetch(fetchUrl); + const text = response.text ? await response.text() : response; + + // Updated regex to allow empty <strong> content + const regex = + /<td class="seasonEpisodeTitle">\s*<a[^>]*href="([^"]+)"[^>]*>.*?<strong>([^<]*)<\/strong>.*?<span>([^<]+)<\/span>.*?<\/a>/g; + + const matches = []; + let match; + let holderNumber = 0; + + while ((match = regex.exec(text)) !== null) { + const [_, link] = match; + matches.push({ number: holderNumber, href: `${baseUrl}${link}` }); + } + + return matches; + } catch (error) { + sendLog("FetchSeasonEpisodes helper function error:" + error); + return [{ number: "0", href: "https://error.org" }]; + } +} + +//////////////////////////////////////////////////////////////////////////////////// +///////////////////////////// Helper Functions //////////////////////// +//////////////////////////// for ExtractStreamUrl //////////////////////// +///////////////////////////////////////////////////////////////////////////////// + +// Helper function to get the video links +// Site specific structure +function getVideoLinks(html) { + const videoLinks = []; + const videoRegex = + /<li\s+class="[^"]*"\s+data-lang-key="([^"]+)"[^>]*>.*?<a[^>]*href="([^"]+)"[^>]*>.*?<h4>([^<]+)<\/h4>.*?<\/a>.*?<\/li>/gs; + let match; + + while ((match = videoRegex.exec(html)) !== null) { + const [_, langKey, href, provider] = match; + videoLinks.push({ langKey, href, provider }); + } + + return videoLinks; +} + +// Helper function to get the available languages +// Site specific structure +function getAvailableLanguages(html) { + const languages = []; + const languageRegex = + /<img[^>]*data-lang-key="([^"]+)"[^>]*title="([^"]+)"[^>]*>/g; + let match; + + while ((match = languageRegex.exec(html)) !== null) { + const [_, langKey, title] = match; + languages.push({ langKey, title }); + } + + return languages; +} + +// Helper function to fetch the base64 encoded string +function base64Decode(str) { + const chars = + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; + let output = ""; + + str = String(str).replace(/=+$/, ""); + + if (str.length % 4 === 1) { + throw new Error( + "'atob' failed: The string to be decoded is not correctly encoded." + ); + } + + for ( + let bc = 0, bs, buffer, idx = 0; + (buffer = str.charAt(idx++)); + ~buffer && ((bs = bc % 4 ? bs * 64 + buffer : buffer), bc++ % 4) + ? (output += String.fromCharCode(255 & (bs >> ((-2 * bc) & 6)))) + : 0 + ) { + buffer = chars.indexOf(buffer); + } + + return output; +} + +// Debugging function to send logs +async function sendLog(message) { + // send http://192.168.2.130/sora-module/log.php?action=add&message=message + console.log(message); + return; + + await fetch('http://192.168.2.130/sora-module/log.php?action=add&message=' + encodeURIComponent(message)) + .catch(error => { + console.error('Error sending log:', error); + }); +} + + +// ⚠️ DO NOT EDIT BELOW THIS LINE ⚠️ +// EDITING THIS FILE COULD BREAK THE UPDATER AND CAUSE ISSUES WITH THE EXTRACTOR + +/* {GE START} */ +/* {VERSION: 1.1.3} */ + +/** + * @name global_extractor.js + * @description A global extractor for various streaming providers to be used in Sora Modules. + * @author Cufiy + * @url https://github.com/JMcrafter26/sora-global-extractor + * @license CUSTOM LICENSE - see https://github.com/JMcrafter26/sora-global-extractor/blob/main/LICENSE + * @date 2025-07-23 17:47:48 + * @version 1.1.3 + * @note This file was generated automatically. + * The global extractor comes with an auto-updating feature, so you can always get the latest version. https://github.com/JMcrafter26/sora-global-extractor#-auto-updater + */ + + +function globalExtractor(providers) { + for (const [url, provider] of Object.entries(providers)) { + try { + const streamUrl = extractStreamUrlByProvider(url, provider); + // check if streamUrl is not null, a string, and starts with http or https + if (streamUrl && typeof streamUrl === "string" && (streamUrl.startsWith("http"))) { + return streamUrl; + } + } catch (error) { + // Ignore the error and try the next provider + } + } + return null; +} + +async function multiExtractor(providers) { + /* this scheme should be returned as a JSON object + { + "streams": [ + "FileMoon", + "https://filemoon.example/stream1.m3u8", + "StreamWish", + "https://streamwish.example/stream2.m3u8", + "Okru", + "https://okru.example/stream3.m3u8", + "MP4", + "https://mp4upload.example/stream4.mp4", + "Default", + "https://default.example/stream5.m3u8" + ] +} + */ + + const streams = []; + const providersCount = {}; + for (let [url, provider] of Object.entries(providers)) { + try { + // if provider starts with "direct-", then add the url to the streams array directly + if (provider.startsWith("direct-")) { + const directName = provider.slice(7); // remove "direct-" prefix + if (directName && directName.length > 0) { + streams.push(directName, url); + } else { + streams.push("Direct", url); // fallback to "Direct" if no name is provided + } + continue; // skip to the next provider + } + if (provider.startsWith("direct")) { + provider = provider.slice(7); // remove "direct-" prefix + if (provider && provider.length > 0) { + streams.push(provider, url); + } else { + streams.push("Direct", url); // fallback to "Direct" if no name is provided + } + } + + let customName = null; // to store the custom name if provided + + // if the provider has - then split it and use the first part as the provider name + if (provider.includes("-")) { + const parts = provider.split("-"); + provider = parts[0]; // use the first part as the provider name + customName = parts.slice(1).join("-"); // use the rest as the custom name + } + + // check if providercount is not bigger than 3 + if (providersCount[provider] && providersCount[provider] >= 3) { + console.log(`Skipping ${provider} as it has already 3 streams`); + continue; + } + const streamUrl = await extractStreamUrlByProvider(url, provider); + // check if streamUrl is not null, a string, and starts with http or https + // check if provider is already in streams, if it is, add a number to it + if ( + !streamUrl || + typeof streamUrl !== "string" || + !streamUrl.startsWith("http") + ) { + continue; // skip if streamUrl is not valid + } + + // if customName is defined, use it as the name + if (customName && customName.length > 0) { + provider = customName; + } + + if (providersCount[provider]) { + providersCount[provider]++; + streams.push( + provider.charAt(0).toUpperCase() + + provider.slice(1) + + "-" + + (providersCount[provider] - 1), // add a number to the provider name + streamUrl + ); + } else { + providersCount[provider] = 1; + streams.push( + provider.charAt(0).toUpperCase() + provider.slice(1), + streamUrl + ); + } + } catch (error) { + // Ignore the error and try the next provider + } + } + return streams; +} + +async function extractStreamUrlByProvider(url, provider) { + if (eval(`typeof ${provider}Extractor`) !== "function") { + // skip if the extractor is not defined + console.log(`Extractor for provider ${provider} is not defined, skipping...`); + return null; + } + let headers = { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3", + "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", + "Accept-Language": "en-US,en;q=0.5", + "Referer": url, + "Connection": "keep-alive", + "x-Requested-With": "XMLHttpRequest" + }; + if(provider == 'bigwarp') { + delete headers["User-Agent"]; + headers["x-requested-with"] = "XMLHttpRequest"; + } + // fetch the url + // and pass the response to the extractor function + console.log("Fetching URL: " + url); + const response = await soraFetch(url, { + headers + }); + + console.log("Response: " + response.status); + let html = response.text ? await response.text() : response; + // if title contains redirect, then get the redirect url + const title = html.match(/<title>(.*?)<\/title>/); + if (title && title[1].toLowerCase().includes("redirect")) { + const redirectUrl = html.match(/<meta http-equiv="refresh" content="0;url=(.*?)"/); + const redirectUrl2 = html.match(/window\.location\.href\s*=\s*["'](.*?)["']/); + const redirectUrl3 = html.match(/window\.location\.replace\s*\(\s*["'](.*?)["']\s*\)/); + if (redirectUrl) { + console.log("Redirect URL: " + redirectUrl[1]); + url = redirectUrl[1]; + html = await soraFetch(url, { + headers + }); + html = html.text ? await html.text() : html; + + } else if (redirectUrl2) { + console.log("Redirect URL 2: " + redirectUrl2[1]); + url = redirectUrl2[1]; + html = await soraFetch(url, { + headers + }); + html = html.text ? await html.text() : html; + } else if (redirectUrl3) { + console.log("Redirect URL 3: " + redirectUrl3[1]); + url = redirectUrl3[1]; + html = await soraFetch(url, { + headers + }); + html = html.text ? await html.text() : html; + } else { + console.log("No redirect URL found"); + } + } + + // console.log("HTML: " + html); + switch (provider) { + case "bigwarp": + try { + return await bigwarpExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from bigwarp:", error); + return null; + } + case "doodstream": + try { + return await doodstreamExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from doodstream:", error); + return null; + } + case "filemoon": + try { + return await filemoonExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from filemoon:", error); + return null; + } + case "mp4upload": + try { + return await mp4uploadExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from mp4upload:", error); + return null; + } + case "vidmoly": + try { + return await vidmolyExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from vidmoly:", error); + return null; + } + case "vidoza": + try { + return await vidozaExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from vidoza:", error); + return null; + } + case "voe": + try { + return await voeExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from voe:", error); + return null; + } + + default: + throw new Error(`Unknown provider: ${provider}`); + } +} + + +//////////////////////////////////////////////// +// EXTRACTORS // +//////////////////////////////////////////////// + +// DO NOT EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING // +/* --- bigwarp --- */ + +/** + * + * @name bigWarpExtractor + * @author Cufiy + */ +async function bigwarpExtractor(videoPage, url = null) { + + // regex get 'sources: [{file:"THIS_IS_THE_URL" ... ' + const scriptRegex = /sources:\s*\[\{file:"([^"]+)"/; + // const scriptRegex = + const scriptMatch = scriptRegex.exec(videoPage); + const bwDecoded = scriptMatch ? scriptMatch[1] : false; + console.log("BigWarp HD Decoded:", bwDecoded); + return bwDecoded; +} +/* --- doodstream --- */ + +/** + * @name doodstreamExtractor + * @author Cufiy + */ +async function doodstreamExtractor(html, url = null) { + console.log("DoodStream extractor called"); + console.log("DoodStream extractor URL: " + url); + const streamDomain = url.match(/https:\/\/(.*?)\//, url)[0].slice(8, -1); + const md5Path = html.match(/'\/pass_md5\/(.*?)',/, url)[0].slice(11, -2); + const token = md5Path.substring(md5Path.lastIndexOf("/") + 1); + const expiryTimestamp = new Date().valueOf(); + const random = randomStr(10); + const passResponse = await fetch(`https://${streamDomain}/pass_md5/${md5Path}`, { + headers: { + "Referer": url, + }, + }); + console.log("DoodStream extractor response: " + passResponse.status); + const responseData = await passResponse.text(); + const videoUrl = `${responseData}${random}?token=${token}&expiry=${expiryTimestamp}`; + console.log("DoodStream extractor video URL: " + videoUrl); + return videoUrl; +} +function randomStr(length) { + const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; + let result = ""; + for (let i = 0; i < length; i++) { + result += characters.charAt(Math.floor(Math.random() * characters.length)); + } + return result; +} +/* --- filemoon --- */ + +/* {REQUIRED PLUGINS: unbaser} */ +/** + * @name filemoonExtractor + * @author Cufiy - Inspired by Churly + */ +async function filemoonExtractor(html, url = null) { + // check if contains iframe, if does, extract the src and get the url + const regex = /<iframe[^>]+src="([^"]+)"[^>]*><\/iframe>/; + const match = html.match(regex); + if (match) { + console.log("Iframe URL: " + match[1]); + const iframeUrl = match[1]; + const iframeResponse = await soraFetch(iframeUrl, { + headers: { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3", + "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", + "Referer": url, + } + }); + console.log("Iframe Response: " + iframeResponse.status); + html = await iframeResponse.text(); + } + // console.log("HTML: " + html); + // get /<script[^>]*>([\s\S]*?)<\/script>/gi + const scriptRegex = /<script[^>]*>([\s\S]*?)<\/script>/gi; + const scripts = []; + let scriptMatch; + while ((scriptMatch = scriptRegex.exec(html)) !== null) { + scripts.push(scriptMatch[1]); + } + // get the script with eval and m3u8 + const evalRegex = /eval\((.*?)\)/; + const m3u8Regex = /m3u8/; + // console.log("Scripts: " + scripts); + const evalScript = scripts.find(script => evalRegex.test(script) && m3u8Regex.test(script)); + if (!evalScript) { + console.log("No eval script found"); + return null; + } + const unpackedScript = unpack(evalScript); + // get the m3u8 url + const m3u8Regex2 = /https?:\/\/[^\s]+master\.m3u8[^\s]*?(\?[^"]*)?/; + const m3u8Match = unpackedScript.match(m3u8Regex2); + if (m3u8Match) { + return m3u8Match[0]; + } else { + console.log("No M3U8 URL found"); + return null; + } +} + + +/* --- mp4upload --- */ + +/** + * @name mp4uploadExtractor + * @author Cufiy + */ +async function mp4uploadExtractor(html, url = null) { + // src: "https://a4.mp4upload.com:183/d/xkx3b4etz3b4quuo66rbmyqtjjoivahfxp27f35pti45rzapbvj5xwb4wuqtlpewdz4dirfp/video.mp4" + const regex = /src:\s*"([^"]+)"/; + const match = html.match(regex); + if (match) { + return match[1]; + } else { + console.log("No match found for mp4upload extractor"); + return null; + } +} +/* --- vidmoly --- */ + +/** + * @name vidmolyExtractor + * @author Ibro + */ +async function vidmolyExtractor(html, url = null) { + const regexSub = /<option value="([^"]+)"[^>]*>\s*SUB - Omega\s*<\/option>/; + const regexFallback = /<option value="([^"]+)"[^>]*>\s*Omega\s*<\/option>/; + const fallback = + /<option value="([^"]+)"[^>]*>\s*SUB v2 - Omega\s*<\/option>/; + let match = + html.match(regexSub) || html.match(regexFallback) || html.match(fallback); + if (match) { + const decodedHtml = atob(match[1]); // Decode base64 + const iframeMatch = decodedHtml.match(/<iframe\s+src="([^"]+)"/); + if (!iframeMatch) { + console.log("Vidmoly extractor: No iframe match found"); + return null; + } + const streamUrl = iframeMatch[1].startsWith("//") + ? "https:" + iframeMatch[1] + : iframeMatch[1]; + const responseTwo = await fetchv2(streamUrl); + const htmlTwo = await responseTwo.text(); + const m3u8Match = htmlTwo.match(/sources:\s*\[\{file:"([^"]+\.m3u8)"/); + return m3u8Match ? m3u8Match[1] : null; + } else { + console.log("Vidmoly extractor: No match found, using fallback"); + // regex the sources: [{file:"this_is_the_link"}] + const sourcesRegex = /sources:\s*\[\{file:"(https?:\/\/[^"]+)"\}/; + const sourcesMatch = html.match(sourcesRegex); + let sourcesString = sourcesMatch + ? sourcesMatch[1].replace(/'/g, '"') + : null; + return sourcesString; + } +} +/* --- vidoza --- */ + +/** + * @name vidozaExtractor + * @author Cufiy + */ +async function vidozaExtractor(html, url = null) { + const regex = /<source src="([^"]+)" type='video\/mp4'>/; + const match = html.match(regex); + if (match) { + return match[1]; + } else { + console.log("No match found for vidoza extractor"); + return null; + } +} +/* --- voe --- */ + +/** + * @name voeExtractor + * @author Cufiy + */ +function voeExtractor(html, url = null) { +// Extract the first <script type="application/json">...</script> + const jsonScriptMatch = html.match( + /<script[^>]+type=["']application\/json["'][^>]*>([\s\S]*?)<\/script>/i + ); + if (!jsonScriptMatch) { + console.log("No application/json script tag found"); + return null; + } + + const obfuscatedJson = jsonScriptMatch[1].trim(); + let data; + try { + data = JSON.parse(obfuscatedJson); + } catch (e) { + throw new Error("Invalid JSON input."); + } + if (!Array.isArray(data) || typeof data[0] !== "string") { + throw new Error("Input doesn't match expected format."); + } + let obfuscatedString = data[0]; + // Step 1: ROT13 + let step1 = voeRot13(obfuscatedString); + // Step 2: Remove patterns + let step2 = voeRemovePatterns(step1); + // Step 3: Base64 decode + let step3 = voeBase64Decode(step2); + // Step 4: Subtract 3 from each char code + let step4 = voeShiftChars(step3, 3); + // Step 5: Reverse string + let step5 = step4.split("").reverse().join(""); + // Step 6: Base64 decode again + let step6 = voeBase64Decode(step5); + // Step 7: Parse as JSON + let result; + try { + result = JSON.parse(step6); + } catch (e) { + throw new Error("Final JSON parse error: " + e.message); + } + // console.log("Decoded JSON:", result); + // check if direct_access_url is set, not null and starts with http + if (result && typeof result === "object") { + const streamUrl = + result.direct_access_url || + result.source + .map((source) => source.direct_access_url) + .find((url) => url && url.startsWith("http")); + if (streamUrl) { + console.log("Voe Stream URL: " + streamUrl); + return streamUrl; + } else { + console.log("No stream URL found in the decoded JSON"); + } + } + return result; +} +function voeRot13(str) { + return str.replace(/[a-zA-Z]/g, function (c) { + return String.fromCharCode( + (c <= "Z" ? 90 : 122) >= (c = c.charCodeAt(0) + 13) + ? c + : c - 26 + ); + }); +} +function voeRemovePatterns(str) { + const patterns = ["@$", "^^", "~@", "%?", "*~", "!!", "#&"]; + let result = str; + for (const pat of patterns) { + result = result.split(pat).join(""); + } + return result; +} +function voeBase64Decode(str) { + // atob is available in browsers and Node >= 16 + if (typeof atob === "function") { + return atob(str); + } + // Node.js fallback + return Buffer.from(str, "base64").toString("utf-8"); +} +function voeShiftChars(str, shift) { + return str + .split("") + .map((c) => String.fromCharCode(c.charCodeAt(0) - shift)) + .join(""); +} + +//////////////////////////////////////////////// +// PLUGINS // +//////////////////////////////////////////////// + +/** + * Uses Sora's fetchv2 on ipad, fallbacks to regular fetch on Windows + * @author ShadeOfChaos + * + * @param {string} url The URL to make the request to. + * @param {object} [options] The options to use for the request. + * @param {object} [options.headers] The headers to send with the request. + * @param {string} [options.method='GET'] The method to use for the request. + * @param {string} [options.body=null] The body of the request. + * + * @returns {Promise<Response|null>} The response from the server, or null if the + * request failed. + */ +async function soraFetch(url, options = { headers: {}, method: 'GET', body: null }) { + try { + return await fetchv2(url, options.headers ?? {}, options.method ?? 'GET', options.body ?? null); + } catch(e) { + try { + return await fetch(url, options); + } catch(error) { + await console.log('soraFetch error: ' + error.message); + return null; + } + } +} + +class Unbaser { + constructor(base) { + this.ALPHABET = { + 62: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", + 95: "' !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'", + }; + this.dictionary = {}; + this.base = base; + if (36 < base && base < 62) { + this.ALPHABET[base] = this.ALPHABET[base] || + this.ALPHABET[62].substr(0, base); + } + if (2 <= base && base <= 36) { + this.unbase = (value) => parseInt(value, base); + } + else { + try { + [...this.ALPHABET[base]].forEach((cipher, index) => { + this.dictionary[cipher] = index; + }); + } + catch (er) { + throw Error("Unsupported base encoding."); + } + this.unbase = this._dictunbaser; + } + } + _dictunbaser(value) { + let ret = 0; + [...value].reverse().forEach((cipher, index) => { + ret = ret + ((Math.pow(this.base, index)) * this.dictionary[cipher]); + }); + return ret; + } +} +function unpack(source) { + let { payload, symtab, radix, count } = _filterargs(source); + if (count != symtab.length) { + throw Error("Malformed p.a.c.k.e.r. symtab."); + } + let unbase; + try { + unbase = new Unbaser(radix); + } + catch (e) { + throw Error("Unknown p.a.c.k.e.r. encoding."); + } + function lookup(match) { + const word = match; + let word2; + if (radix == 1) { + word2 = symtab[parseInt(word)]; + } + else { + word2 = symtab[unbase.unbase(word)]; + } + return word2 || word; + } + source = payload.replace(/\b\w+\b/g, lookup); + return _replacestrings(source); + function _filterargs(source) { + const juicers = [ + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\), *(\d+), *(.*)\)\)/, + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\)/, + ]; + for (const juicer of juicers) { + const args = juicer.exec(source); + if (args) { + let a = args; + if (a[2] == "[]") { + } + try { + return { + payload: a[1], + symtab: a[4].split("|"), + radix: parseInt(a[2]), + count: parseInt(a[3]), + }; + } + catch (ValueError) { + throw Error("Corrupted p.a.c.k.e.r. data."); + } + } + } + throw Error("Could not make sense of p.a.c.k.e.r data (unexpected code structure)"); + } + function _replacestrings(source) { + return source; + } +} + + + +/* {GE END} */ \ No newline at end of file diff --git a/anoboye/anoboye.js b/anoboye/anoboye.js new file mode 100644 index 0000000..164d931 --- /dev/null +++ b/anoboye/anoboye.js @@ -0,0 +1,86 @@ +async function searchResults(keyword) { + const results = []; + const response = await fetchv2(`https://anoboye.com/?s=${keyword}`); + const html = await response.text(); + + const regex = /<article class="bs"[^>]*>.*?<a href="([^"]+)"[^>]*>.*?<img src="([^"]+)"[^>]*>.*?<h2[^>]*>(.*?)<\/h2>/gs; + + 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); +} + +async function extractDetails(url) { + const results = []; + const response = await fetchv2(url); + const html = await response.text(); + + const match = html.match(/<div class="entry-content"[^>]*>([\s\S]*?)<\/div>/); + + let description = "N/A"; + if (match) { + description = match[1] + .replace(/<[^>]+>/g, '') + .replace(/&#(\d+);/g, (_, code) => String.fromCharCode(code)) + .replace(/"/g, '"') + .replace(/'/g, "'") + .replace(/&/g, "&") + .trim(); + } + + results.push({ + description: description, + aliases: 'N/A', + airdate: 'N/A' + }); + + return JSON.stringify(results); +} + +async function extractEpisodes(url) { + const results = []; + const response = await fetchv2(url); + const html = await response.text(); + + const regex = /<a href="([^"]+)">\s*<div class="epl-num">([\d.]+)<\/div>/g; + + let match; + while ((match = regex.exec(html)) !== null) { + results.push({ + href: match[1].trim(), + number: parseInt(match[2], 10) + }); + } + results.reverse(); + return JSON.stringify(results); +} + +async function extractStreamUrl(url) { + try { + const response = await fetchv2(url); + const html = await response.text(); + + const iframeMatch = html.match(/<iframe[^>]+src=["']([^"']+)["']/i); + if (!iframeMatch) throw new Error("iframe not found"); + + const iframeUrl = iframeMatch[1]; + + const iframeResponse = await fetchv2(iframeUrl); + const iframeHtml = await iframeResponse.text(); + + const videoMatch = iframeHtml.match(/videoUrl:\s*["']([^"']+)["']/i); + if (!videoMatch) throw new Error("videoUrl not found"); + + return videoMatch[1].replace(/\\/g, ""); + } catch (err) { + return "https://files.catbox.moe/avolvc.mp4"; + } +} + diff --git a/anoboye/anoboye.json b/anoboye/anoboye.json new file mode 100644 index 0000000..902567e --- /dev/null +++ b/anoboye/anoboye.json @@ -0,0 +1,19 @@ +{ + "sourceName": "Anoboye", + "iconUrl": "https://i3.wp.com/anoboye.com/wp-content/uploads/2025/05/Anoboye-300x300.jpg", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "Chinese", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://anoboye.com/", + "searchBaseUrl": "https://anoboye.com/", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/anoboye/anoboye.js", + "type": "anime", + "asyncJS": true, + "softsub": false, + "downloadSupport": false +} diff --git a/arablionz/arablionz.js b/arablionz/arablionz.js new file mode 100644 index 0000000..7766d49 --- /dev/null +++ b/arablionz/arablionz.js @@ -0,0 +1,229 @@ +async function searchResults(keyword) { + const results = []; + const headers = { + "Content-Type": "application/x-www-form-urlencoded", + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)", + "Referer": "https://arablionztv.cam/" + }; + const postData = ""; + try { + const response = await fetchv2("https://arablionztv.cam/SearchEngine/"+encodeURIComponent(keyword), headers, "POST", postData); + const html = await response.text(); + + const regex = /<a href="([^"]+)"[^>]*>\s*<div class="Box--Poster">\s*<img[^>]+data-image="([^"]+)"[^>]*>\s*.*?<h2>(.*?)<\/h2>/gs; + 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 regex = /<p class="Singular--Story-P">(.*?)<\/p>/s; + const match = html.match(regex); + const description = match ? match[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) { + try { + return JSON.stringify([{ + href: url, + number: 1 + }]); + } catch (err) { + return JSON.stringify([{ + href: "Error", + number: "Error" + }]); + } +} + +async function extractStreamUrl(url) { + try { + const response = await fetchv2(url); + const html = await response.text(); + + const idMatch = html.match(/data-id="(\d+)"/); + if (!idMatch) return "https://error.org/"; + const id = idMatch[1]; + + const apiUrl = "https://passthrough-worker.simplepostrequest.workers.dev/?arablionz=https://arablionztv.cam/PostServersWatch/" + id; + const apiResponse = await fetchv2(apiUrl); + const apiHtml = await apiResponse.text(); + + const iframeMatch = apiHtml.match(/<iframe[^>]+src="([^"]+)"/); + if (!iframeMatch) return "https://error.org/"; + const iframeUrl = iframeMatch[1]; + const headers = { + "Content-Type": "application/x-www-form-urlencoded", + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)", + "Referer": "https://arablionztv.cam/" + }; + const streamResponse = await fetchv2(iframeUrl, headers); + const streamHtml = await streamResponse.text(); + + const obfuscatedScript = streamHtml.match(/<script[^>]*>\s*(eval\(function\(p,a,c,k,e,d.*?\)[\s\S]*?)<\/script>/); + if (!obfuscatedScript) return "https://error.org/"; + const unpackedScript = unpack(obfuscatedScript[1]); + + const fileMatch = unpackedScript.match(/file:\s*"([^"]+)"/); + if (!fileMatch) return "https://error.org/"; + const fileUrl = fileMatch[1]; + console.log(fileUrl); + return fileUrl; + } catch (err) { + return "https://error.org/"; + } +} + + +/*********************************************************** + * UNPACKER MODULE + * Credit to GitHub user "mnsrulz" for Unpacker Node library + * https://github.com/mnsrulz/unpacker + ***********************************************************/ +class Unbaser { + constructor(base) { + /* Functor for a given base. Will efficiently convert + strings to natural numbers. */ + this.ALPHABET = { + 62: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", + 95: "' !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'", + }; + this.dictionary = {}; + this.base = base; + // fill elements 37...61, if necessary + if (36 < base && base < 62) { + this.ALPHABET[base] = this.ALPHABET[base] || + this.ALPHABET[62].substr(0, base); + } + // If base can be handled by int() builtin, let it do it for us + if (2 <= base && base <= 36) { + this.unbase = (value) => parseInt(value, base); + } + else { + // Build conversion dictionary cache + try { + [...this.ALPHABET[base]].forEach((cipher, index) => { + this.dictionary[cipher] = index; + }); + } + catch (er) { + throw Error("Unsupported base encoding."); + } + this.unbase = this._dictunbaser; + } + } + _dictunbaser(value) { + /* Decodes a value to an integer. */ + let ret = 0; + [...value].reverse().forEach((cipher, index) => { + ret = ret + ((Math.pow(this.base, index)) * this.dictionary[cipher]); + }); + return ret; + } +} + +function detect(source) { + /* Detects whether `source` is P.A.C.K.E.R. coded. */ + return source.replace(" ", "").startsWith("eval(function(p,a,c,k,e,"); +} + +function unpack(source) { + /* Unpacks P.A.C.K.E.R. packed js code. */ + let { payload, symtab, radix, count } = _filterargs(source); + if (count != symtab.length) { + throw Error("Malformed p.a.c.k.e.r. symtab."); + } + let unbase; + try { + unbase = new Unbaser(radix); + } + catch (e) { + throw Error("Unknown p.a.c.k.e.r. encoding."); + } + function lookup(match) { + /* Look up symbols in the synthetic symtab. */ + const word = match; + let word2; + if (radix == 1) { + //throw Error("symtab unknown"); + word2 = symtab[parseInt(word)]; + } + else { + word2 = symtab[unbase.unbase(word)]; + } + return word2 || word; + } + source = payload.replace(/\b\w+\b/g, lookup); + return _replacestrings(source); + function _filterargs(source) { + /* Juice from a source file the four args needed by decoder. */ + const juicers = [ + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\), *(\d+), *(.*)\)\)/, + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\)/, + ]; + for (const juicer of juicers) { + //const args = re.search(juicer, source, re.DOTALL); + const args = juicer.exec(source); + if (args) { + let a = args; + if (a[2] == "[]") { + //don't know what it is + // a = list(a); + // a[1] = 62; + // a = tuple(a); + } + try { + return { + payload: a[1], + symtab: a[4].split("|"), + radix: parseInt(a[2]), + count: parseInt(a[3]), + }; + } + catch (ValueError) { + throw Error("Corrupted p.a.c.k.e.r. data."); + } + } + } + throw Error("Could not make sense of p.a.c.k.e.r data (unexpected code structure)"); + } + function _replacestrings(source) { + /* Strip string lookup table (list) and replace values in source. */ + /* Need to work on this. */ + return source; + } +} + + + diff --git a/arablionz/arablionz.json b/arablionz/arablionz.json new file mode 100644 index 0000000..daee849 --- /dev/null +++ b/arablionz/arablionz.json @@ -0,0 +1,18 @@ +{ + "sourceName": "ArabLionz", + "iconUrl": "https://arablionztv.cam/wp-content/uploads/2023/04/vRA6ewKk_400x400-280x280.jpeg", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "Arabic", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://arablionztv.cam/", + "searchBaseUrl": "https://arablionztv.cam/", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/arablionz/arablionz.js", + "type": "shows/movies", + "asyncJS": true, + "downloadSupport": true +} diff --git a/arabseed/arabseed.js b/arabseed/arabseed.js new file mode 100644 index 0000000..1706bb2 --- /dev/null +++ b/arabseed/arabseed.js @@ -0,0 +1,156 @@ +async function searchResults(keyword) { + const results = []; + try { + const response = await fetchv2("https://a.asd.homes/find/?word=" + encodeURIComponent(keyword)); + const html = await response.text(); + + const regex = /<li class="box__xs__2[^>]*>[\s\S]*?<a href="([^"]+)"[^>]*>[\s\S]*?<img[^>]+src="([^"]+)"[^>]*>[\s\S]*?<h3>(.*?)<\/h3>[\s\S]*?<\/a>/g; + + let match; + const tempResults = []; + + while ((match = regex.exec(html)) !== null) { + const cleanedTitle = match[3].replace(/الموسم\s+\S+\s+الحلقة\s+\S+.*$/u, '').trim(); + tempResults.push({ + href: match[1].trim(), + image: match[2].trim(), + title: cleanedTitle + }); + } + + const combined = []; + const seen = new Set(); + + for (const item of tempResults) { + if (!seen.has(item.title)) { + seen.add(item.title); + combined.push(item); + } + } + + return JSON.stringify(combined); + + } 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 match = html.match(/<div class="post__story">\s*<p>(.*?)<\/p>\s*<\/div>/s); + + let description = "N/A"; + + if (match) { + const rawDescription = match[1]; + description = rawDescription.replace(/<\/?span[^>]*>/g, '').trim(); + description = description.replace(/\s+/g, ' '); + } + + 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 episodesListMatch = html.match(/<ul class="episodes__list[^>]*>([\s\S]*?)<\/ul>/); + if (!episodesListMatch) { + results.push({ + href: url, + number: 1 + }); + return JSON.stringify(results); + } + + const episodesHTML = episodesListMatch[1]; + + const episodeItemRegex = /<li[^>]*>[\s\S]*?<a href="([^"]+)"[\s\S]*?الحلقة<b>(\d+)<\/b>[\s\S]*?<\/a>[\s\S]*?<\/li>/g; + let match; + const episodes = []; + + while ((match = episodeItemRegex.exec(episodesHTML)) !== null) { + const href = match[1].trim(); + const episodeNumber = parseInt(match[2]); + episodes.push({ + href: href, + number: episodeNumber + }); + } + + episodes.sort((a, b) => a.number - b.number); + + results.push(...episodes); + + if (results.length === 0) { + results.push({ + href: url, + number: 1 + }); + } + + return JSON.stringify(results); + } catch (err) { + return JSON.stringify([{ + href: url, + number: 1 + }]); + } +} + +async function extractStreamUrl(url) { + try { + const response = await fetchv2(url); + const html = await response.text(); + + const match = html.match(/href="([^"]+)"[^>]*class="btton watch__btn"/); + console.log("Match found: " + match); + if (match) { + const extractedUrl = match[1].replace(/&/g, '&'); + const headers = { + "Referer": "https://a.asd.homes/" + }; + const extractedResponse = await fetchv2(extractedUrl, headers); + const extractedHtml = await extractedResponse.text(); + console.log("Extracted HTML snippet:"+ extractedHtml); + + const embedMatch = extractedHtml.match(/<iframe[^>]*src="([^"]+)"/); + if (embedMatch) { + const embedUrl = embedMatch[1]; + const embedResponse = await fetchv2(embedUrl, headers); + const embedHtml = await embedResponse.text(); + + const sourceMatch = embedHtml.match(/<source src="([^"]+)"/); + if (sourceMatch) { + return sourceMatch[1]; + } + } + } + } catch (err) { + console.log(err); + } + + return "https://files.catbox.moe/avolvc.mp4"; +} + diff --git a/arabseed/arabseed.json b/arabseed/arabseed.json new file mode 100644 index 0000000..f16dac8 --- /dev/null +++ b/arabseed/arabseed.json @@ -0,0 +1,18 @@ +{ + "sourceName": "ArabSeed", + "iconUrl": "https://a.asd.homes/wp-content/themes/Elshaikh2021/UI/images/logo333.webp", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.2", + "language": "Arabic", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://a.asd.homes/", + "searchBaseUrl": "https://a.asd.homes/?s=%s", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/arabseed/arabseed.js", + "type": "shows/movies/anime", + "asyncJS": true, + "downloadSupport": true +} diff --git a/ashi/ashi.js b/ashi/ashi.js new file mode 100644 index 0000000..eca8c0e --- /dev/null +++ b/ashi/ashi.js @@ -0,0 +1,719 @@ +// +// +// Main functions +// +// + +async function searchResults(query) { + const encodeQuery = keyword => encodeURIComponent(keyword); + + const decodeHtmlEntities = (str) => { + if (!str) return str; + return str.replace(/&#(\d+);/g, (match, dec) => String.fromCharCode(dec)) + .replace(/"/g, '"') + .replace(/&/g, '&') + .replace(/</g, '<') + .replace(/>/g, '>'); + }; + + const fuzzyMatch = (query, title) => { + const q = query.toLowerCase().trim(); + const t = title.toLowerCase().trim(); + + if (t === q) return 1000; + if (t.includes(q)) return 900; + + const qTokens = q.split(/\s+/).filter(token => token.length > 0); + const tTokens = t.split(/[\s\-]+/).filter(token => token.length > 0); + + const stopwords = new Set(['the', 'a', 'an', 'and', 'or', 'of', 'in', 'on', 'at', 'to', 'for']); + + let score = 0; + let matchedTokens = 0; + let significantMatches = 0; + + qTokens.forEach(qToken => { + const isStopword = stopwords.has(qToken); + let bestMatch = 0; + + tTokens.forEach(tToken => { + let matchScore = 0; + + if (tToken === qToken) { + matchScore = isStopword ? 20 : 100; + if (!isStopword) significantMatches++; + } else if (tToken.includes(qToken) && qToken.length >= 3) { + matchScore = isStopword ? 10 : 60; + if (!isStopword) significantMatches++; + } else if (qToken.includes(tToken) && tToken.length >= 3) { + matchScore = isStopword ? 10 : 50; + if (!isStopword) significantMatches++; + } else if (qToken.length >= 3 && tToken.length >= 3) { + const dist = levenshteinDistance(qToken, tToken); + const maxLen = Math.max(qToken.length, tToken.length); + const similarity = 1 - (dist / maxLen); + + if (similarity > 0.7) { + matchScore = Math.floor(similarity * 40); + if (!isStopword) significantMatches++; + } + } + + bestMatch = Math.max(bestMatch, matchScore); + }); + + if (bestMatch > 0) { + score += bestMatch; + matchedTokens++; + } + }); + + const significantTokens = qTokens.filter(t => !stopwords.has(t)).length; + + const requiredMatches = Math.ceil(significantTokens * 0.7); + if (significantMatches < requiredMatches) { + return 0; + } + + if (matchedTokens >= qTokens.length) { + score += 100; + } + + if (t.startsWith(q)) { + score += 150; + } + + const extraWords = tTokens.length - qTokens.length; + if (extraWords > 3) { + score -= (extraWords - 3) * 20; + } + + for (let i = 0; i < qTokens.length - 1; i++) { + const bigram = qTokens[i] + ' ' + qTokens[i + 1]; + const bigramNoDash = qTokens[i] + qTokens[i + 1]; + if (!t.includes(bigram) && !t.includes(bigramNoDash)) { + score -= 15; + } + } + + return Math.max(0, score); + }; + + const levenshteinDistance = (a, b) => { + const matrix = []; + + for (let i = 0; i <= b.length; i++) { + matrix[i] = [i]; + } + + for (let j = 0; j <= a.length; j++) { + matrix[0][j] = j; + } + + for (let i = 1; i <= b.length; i++) { + for (let j = 1; j <= a.length; j++) { + if (b.charAt(i - 1) === a.charAt(j - 1)) { + matrix[i][j] = matrix[i - 1][j - 1]; + } else { + matrix[i][j] = Math.min( + matrix[i - 1][j - 1] + 1, + matrix[i][j - 1] + 1, + matrix[i - 1][j] + 1 + ); + } + } + } + + return matrix[b.length][a.length]; + }; + + const animekaiSearch = async () => { + const searchBaseUrl = "https://animekai.to/browser?keyword="; + const baseUrl = "https://animekai.to"; + + const posterHrefRegex = /href="[^"]*" class="poster"/g; + const titleRegex = /class="title"[^>]*title="[^"]*"/g; + const imageRegex = /data-src="[^"]*"/g; + const extractHrefRegex = /href="([^"]*)"/; + const extractImageRegex = /data-src="([^"]*)"/; + const extractTitleRegex = /title="([^"]*)"/; + + const extractResultsFromHTML = (htmlText) => { + const results = []; + const posterMatches = htmlText.match(posterHrefRegex) || []; + const titleMatches = htmlText.match(titleRegex) || []; + const imageMatches = htmlText.match(imageRegex) || []; + const minLength = Math.min(posterMatches.length, titleMatches.length, imageMatches.length); + + for (let i = 0; i < minLength; i++) { + const hrefMatch = posterMatches[i].match(extractHrefRegex); + const fullHref = hrefMatch ? (hrefMatch[1].startsWith("http") ? hrefMatch[1] : baseUrl + hrefMatch[1]) : null; + + const imageMatch = imageMatches[i].match(extractImageRegex); + const imageSrc = imageMatch ? imageMatch[1] : null; + + const titleMatch = titleMatches[i].match(extractTitleRegex); + const cleanTitle = titleMatch ? decodeHtmlEntities(titleMatch[1]) : null; + + if (fullHref && imageSrc && cleanTitle) { + results.push({ + href: `Animekai:${fullHref}`, + image: imageSrc, + title: cleanTitle + }); + } + } + + return results; + }; + + try { + const encodedQuery = encodeQuery(query); + const urls = [ + `${searchBaseUrl}${encodedQuery}`, + `${searchBaseUrl}${encodedQuery}&page=2`, + `${searchBaseUrl}${encodedQuery}&page=3` + ]; + + const responses = await Promise.all(urls.map(url => fetchv2(url))); + const htmlTexts = await Promise.all(responses.map(res => res.text())); + + const allResults = []; + htmlTexts.forEach(html => allResults.push(...extractResultsFromHTML(html))); + return allResults; + } catch (error) { + console.error("Animekai search error:" + error); + return []; + } + }; + + const oneMoviesSearch = async () => { + const searchBaseUrl = "https://1movies.bz/browser?keyword="; + const baseUrl = "https://1movies.bz"; + + const posterHrefRegex = /href="([^"]*)" class="poster"/g; + const titleRegex = /class="title" href="[^"]*">([^<]*)</g; + const imageRegex = /data-src="([^"]*)"/g; + + const extractResultsFromHTML = (htmlText) => { + const results = []; + const posterMatches = [...htmlText.matchAll(posterHrefRegex)]; + const titleMatches = [...htmlText.matchAll(titleRegex)]; + const imageMatches = [...htmlText.matchAll(imageRegex)]; + const minLength = Math.min(posterMatches.length, titleMatches.length, imageMatches.length); + + for (let i = 0; i < minLength; i++) { + const href = posterMatches[i][1]; + const fullHref = href.startsWith("http") ? href : baseUrl + href; + + const imageSrc = imageMatches[i][1]; + const title = decodeHtmlEntities(titleMatches[i][1]); + + results.push({ href: fullHref, image: imageSrc, title }); + } + return results; + }; + + try { + const encodedQuery = encodeQuery(query); + const urls = [ + `${searchBaseUrl}${encodedQuery}`, + `${searchBaseUrl}${encodedQuery}&page=2`, + `${searchBaseUrl}${encodedQuery}&page=3` + ]; + + const responses = await Promise.all(urls.map(url => fetchv2(url))); + const htmlTexts = await Promise.all(responses.map(res => res.text())); + + const allResults = []; + htmlTexts.forEach(html => allResults.push(...extractResultsFromHTML(html))); + return allResults; + } catch (error) { + console.error("1Movies search error:" + error); + return []; + } + }; + + try { + const [animekaiResults, oneMoviesResults] = await Promise.all([ + animekaiSearch(), + oneMoviesSearch() + ]); + + const mergedResults = [...animekaiResults, ...oneMoviesResults]; + + const scoredResults = mergedResults.map(r => ({ + ...r, + score: fuzzyMatch(query, r.title) + })); + + const filteredResults = scoredResults + .filter(r => r.score > 0) + .sort((a, b) => b.score - a.score) + .map(({ score, ...rest }) => rest); + + return JSON.stringify(filteredResults.length > 0 ? filteredResults : [{ + href: "", + image: "", + title: "No results found, please refine query." + }]); + } catch (error) { + return JSON.stringify([{ + href: "", + image: "", + title: "Search failed: " + error.message + }]); + } +} + +async function extractDetails(url) { + + if (url.startsWith("Animekai:")) { + const actualUrl = url.replace("Animekai:", "").trim(); + + try { + const response = await fetchv2(actualUrl); + const htmlText = await response.text(); + + const descriptionMatch = (/<div class="desc text-expand">([\s\S]*?)<\/div>/.exec(htmlText) || [])[1]; + const aliasesMatch = (/<small class="al-title text-expand">([\s\S]*?)<\/small>/.exec(htmlText) || [])[1]; + + return JSON.stringify([{ + description: descriptionMatch ? cleanHtmlSymbols(descriptionMatch) : "Not available", + aliases: aliasesMatch ? cleanHtmlSymbols(aliasesMatch) : "Not available", + airdate: "If stream doesn't load try later or disable VPN/DNS" + }]); + } catch (error) { + console.error("Error fetching Animekai details:" + error); + return JSON.stringify([{ + description: "Error loading description", + aliases: "Aliases: Unknown", + airdate: "Aired: Unknown" + }]); + } + } else { + try { + const response = await fetchv2(url); + const htmlText = await response.text(); + + const descriptionMatch = (/<div class="description text-expand">([\s\S]*?)<\/div>/.exec(htmlText) || [])[1]; + const aliasesMatch = (/<small class="al-title text-expand">([\s\S]*?)<\/small>/.exec(htmlText) || [])[1]; + const airdateMatch = (/<li>Released:\s*<span[^>]*>(.*?)<\/span>/.exec(htmlText) || [])[1]; + + return JSON.stringify([{ + description: descriptionMatch ? cleanHtmlSymbols(descriptionMatch) : "Not available", + aliases: aliasesMatch ? cleanHtmlSymbols(aliasesMatch) : "Not aliases", + airdate: airdateMatch ? cleanHtmlSymbols(airdateMatch) : "Not available" + }]); + } catch (error) { + console.error("Error fetching 1Movies details:"+ error); + return JSON.stringify([{ + description: "Error loading description", + aliases: "Not available", + airdate: "Not available" + }]); + } + } +} + +async function extractEpisodes(url) { + const sendEpisodes = async (endpoint, episodeData) => { + if (episodeData.length > 45) { + const promises = episodeData.map(item => + fetchv2(`${endpoint}=${encodeURIComponent(item.data)}`) + .then(res => res.text()) + .then(data => ({ name: item.name, data })) + .catch(err => ({ name: item.name, error: err.toString() })) + ); + return Promise.all(promises); + } else { + const resp = await fetchv2(endpoint, {}, "POST", JSON.stringify(episodeData)); + return resp.json(); + } + }; + + try { + if (url.startsWith("Animekai:")) { + const actualUrl = url.replace("Animekai:", "").trim(); + const htmlText = await (await fetchv2(actualUrl)).text(); + const animeIdMatch = (htmlText.match(/<div class="rate-box"[^>]*data-id="([^"]+)"/) || [])[1]; + if (!animeIdMatch) return JSON.stringify([{ error: "AniID not found" }]); + + const tokenResponse = await fetchv2(`https://ilovekai.simplepostrequest.workers.dev/?ilovefeet=${encodeURIComponent(animeIdMatch)}`); + const token = await tokenResponse.text(); + + const episodeListUrl = `https://animekai.to/ajax/episodes/list?ani_id=${animeIdMatch}&_=${token}`; + const episodeListData = await (await fetchv2(episodeListUrl)).json(); + const cleanedHtml = cleanJsonHtml(episodeListData.result); + + const episodeRegex = /<a[^>]+num="([^"]+)"[^>]+token="([^"]+)"[^>]*>/g; + const episodeMatches = [...cleanedHtml.matchAll(episodeRegex)]; + + const episodeData = episodeMatches.map(([_, episodeNum, episodeToken]) => ({ + name: `Episode ${episodeNum}`, + data: episodeToken + })); + + const batchResults = await sendEpisodes("https://ilovekai.simplepostrequest.workers.dev/?ilovefeet", episodeData); + + const episodes = batchResults.map((result, index) => ({ + number: parseInt(episodeMatches[index][1], 10), + href: `Animekai:https://animekai.to/ajax/links/list?token=${episodeMatches[index][2]}&_=${result.data}` + })); + + return JSON.stringify(episodes); + } else { + const htmlText = await (await fetchv2(url)).text(); + const movieIDMatch = (htmlText.match(/<div class="detail-lower"[^>]*id="movie-rating"[^>]*data-id="([^"]+)"/) || [])[1]; + if (!movieIDMatch) return JSON.stringify([{ error: "MovieID not found" }]); + + const movieData = [{ name: "MovieID", data: movieIDMatch }]; + const tokenResponse = await fetchv2("https://ilovekai.simplepostrequest.workers.dev/ilovethighs", {}, "POST", JSON.stringify(movieData)); + const temp = await tokenResponse.json(); + const token = temp[0]?.data; + + const episodeListUrl = `https://1movies.bz/ajax/episodes/list?id=${movieIDMatch}&_=${token}`; + const episodeListData = await (await fetchv2(episodeListUrl)).json(); + const cleanedHtml = cleanJsonHtml(episodeListData.result); + + const episodeRegex = /<a[^>]+eid="([^"]+)"[^>]+num="([^"]+)"[^>]*>/g; + const episodeMatches = [...cleanedHtml.matchAll(episodeRegex)]; + + const episodeData = episodeMatches.map(([_, episodeToken, episodeNum]) => ({ + name: `Episode ${episodeNum}`, + data: episodeToken + })); + + const batchResults = await sendEpisodes("https://ilovekai.simplepostrequest.workers.dev/?ilovethighs", episodeData); + + const episodes = batchResults.map((result, index) => ({ + number: parseInt(episodeMatches[index][2], 10), + href: `https://1movies.bz/ajax/links/list?eid=${episodeMatches[index][1]}&_=${result.data}` + })); + + return JSON.stringify(episodes); + } + } catch (err) { + console.error("Error fetching episodes:" + err); + return JSON.stringify([{ number: 1, href: "Error fetching episodes" }]); + } +} + +async function extractStreamUrl(url) { + let source, actualUrl; + + if (url.startsWith("Animekai:")) { + source = "Animekai"; + actualUrl = url.replace("Animekai:", "").trim(); + } else if (url.includes("1movies.bz")) { + source = "1Movies"; + actualUrl = url.trim(); + } else { + console.log("Failed to match URL:", url); + return "Invalid URL format: " + url; + } + + if (source === "Animekai") { + try { + const response = await fetchv2(actualUrl); + const text = await response.text(); + const cleanedHtml = cleanJsonHtml(text); + const subRegex = /<div class="server-items lang-group" data-id="sub"[^>]*>([\s\S]*?)<\/div>/; + const softsubRegex = /<div class="server-items lang-group" data-id="softsub"[^>]*>([\s\S]*?)<\/div>/; + const dubRegex = /<div class="server-items lang-group" data-id="dub"[^>]*>([\s\S]*?)<\/div>/; + const subMatch = subRegex.exec(cleanedHtml); + const softsubMatch = softsubRegex.exec(cleanedHtml); + const dubMatch = dubRegex.exec(cleanedHtml); + const subContent = subMatch ? subMatch[1].trim() : ""; + const softsubContent = softsubMatch ? softsubMatch[1].trim() : ""; + const dubContent = dubMatch ? dubMatch[1].trim() : ""; + const serverSpanRegex = /<span class="server"[^>]*data-lid="([^"]+)"[^>]*>Server 1<\/span>/; + const serverIdDub = serverSpanRegex.exec(dubContent)?.[1]; + const serverIdSoftsub = serverSpanRegex.exec(softsubContent)?.[1]; + const serverIdSub = serverSpanRegex.exec(subContent)?.[1]; + + const tokenRequestData = [ + { name: "Dub", data: serverIdDub }, + { name: "Softsub", data: serverIdSoftsub }, + { name: "Sub", data: serverIdSub } + ].filter(item => item.data); + + const tokenBatchResponse = await fetchv2( + "https://ilovekai.simplepostrequest.workers.dev/?ilovefeet", + {}, + "POST", + JSON.stringify(tokenRequestData) + ); + const tokenResults = await tokenBatchResponse.json(); + + const streamUrls = tokenResults.map(result => { + const serverIdMap = { + "Dub": serverIdDub, + "Softsub": serverIdSoftsub, + "Sub": serverIdSub + }; + return { + type: result.name, + url: `https://animekai.to/ajax/links/view?id=${serverIdMap[result.name]}&_=${result.data}` + }; + }); + + const processStreams = async (streamUrls) => { + const streamResponses = await Promise.all( + streamUrls.map(async ({ type, url }) => { + try { + const res = await fetchv2(url); + const json = await res.json(); + return { + type: type, + result: json.result + }; + } catch (error) { + console.log(`Error fetching ${type} stream:` + error); + return { + type: type, + result: null + }; + } + }) + ); + + const decryptRequestData = streamResponses + .filter(item => item.result) + .map(item => ({ + name: item.type, + data: item.result + })); + + if (decryptRequestData.length === 0) { + return {}; + } + + const decryptBatchResponse = await fetchv2( + "https://ilovekai.simplepostrequest.workers.dev/?ilovearmpits", + {}, + "POST", + JSON.stringify(decryptRequestData) + ); + const decryptResults = await decryptBatchResponse.json(); + + const finalResults = {}; + decryptResults.forEach(result => { + try { + const parsed = JSON.parse(result.data); + finalResults[result.name] = parsed.url; + console.log(`decrypted${result.name} URL:` + parsed.url); + } catch (error) { + console.log(`Error parsing ${result.name} result:` + error); + finalResults[result.name] = null; + } + }); + + return finalResults; + }; + + const decryptedUrls = await processStreams(streamUrls); + const decryptedSub = decryptedUrls.Sub; + const decryptedDub = decryptedUrls.Dub; + const decryptedRaw = decryptedUrls.Softsub; + + const headers = { + "Referer": "https://animekai.to/", + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36" + }; + + async function getStream(url) { + try { + const response = await fetchv2(url.replace("/e/", "/media/"), headers); + const responseJson = await response.json(); + + const result = responseJson?.result; + + const postData = { + "text": result, + "Useragent": headers["User-Agent"] + }; + + const finalResponse = await fetchv2( + "https://ilovekai.simplepostrequest.workers.dev/ilovebush", + {}, + "POST", + JSON.stringify(postData) + ); + + const finalJson = await finalResponse.json(); + return finalJson?.result?.sources?.[0]?.file || null; + } catch { + return null; + } + } + + const streams = []; + + const subStream = decryptedSub ? await getStream(decryptedSub) : null; + if (subStream) streams.push("Hardsub English", subStream); + + const dubStream = decryptedDub ? await getStream(decryptedDub) : null; + if (dubStream) streams.push("Dubbed English", dubStream); + + const rawStream = decryptedRaw ? await getStream(decryptedRaw) : null; + if (rawStream) streams.push("Japanese", rawStream); + + const final = { + streams, + subtitles: "" + }; + + console.log("RETURN: " + JSON.stringify(final)); + return JSON.stringify(final); + + } catch (error) { + console.log("Animekai fetch error:" + error); + return "https://error.org"; + } + } else if (source === "1Movies") { + try { + const response = await fetchv2(actualUrl); + const responseData = await response.json(); + const cleanedHtml = cleanJsonHtml(responseData.result); + + const server1Regex = /<div class="server wnav-item"[^>]*data-lid="([^"]+)"[^>]*>\s*<span>Server 1<\/span>/; + const server1Match = server1Regex.exec(cleanedHtml); + + if (!server1Match) { + console.log("Server 1 not found"); + return "error"; + } + + const serverId = server1Match[1]; + + const tokenRequestData = [{ name: "Server1", data: serverId }]; + + const tokenBatchResponse = await fetchv2( + "https://ilovekai.simplepostrequest.workers.dev/ilovethighs", + {}, + "POST", + JSON.stringify(tokenRequestData) + ); + const tokenResults = await tokenBatchResponse.json(); + const token = tokenResults[0]?.data; + + if (!token) { + console.log("Token not found"); + return "error"; + } + + const streamUrl = `https://1movies.bz/ajax/links/view?id=${serverId}&_=${token}`; + const streamResponse = await fetchv2(streamUrl); + const streamData = await streamResponse.json(); + + if (!streamData.result) { + console.log("Stream result not found"); + return "error"; + } + + const decryptRequestData = [{ name: "Server1", data: streamData.result }]; + + const decryptBatchResponse = await fetchv2( + "https://ilovekai.simplepostrequest.workers.dev/iloveboobs", + {}, + "POST", + JSON.stringify(decryptRequestData) + ); + const decryptedResponse = await decryptBatchResponse.json(); + const decryptedUrl = decryptedResponse[0]?.data.url; + + const subListEncoded = decryptedUrl.split("sub.list=")[1]?.split("&")[0]; + const subListUrl = decodeURIComponent(subListEncoded); + + const subResponse = await fetchv2(subListUrl); + const subtitles = await subResponse.json(); + + const englishSubUrl = subtitles.find(sub => sub.label === "English")?.file.replace(/\\\//g, "/"); + + if (!decryptedUrl) { + console.log("Decryption failed"); + return "error"; + } + + const headers = { + "Referer": "https://1movies.bz/", + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36" + }; + + const mediaResponse = await fetchv2(decryptedUrl.replace("/e/", "/media/"), headers); + const mediaJson = await mediaResponse.json(); + + const result = mediaJson?.result; + if (!result) { + console.log("Media result not found"); + return "error"; + } + + const postData = { + "text": result, + "Useragent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36" + }; + + const finalResponse = await fetchv2("https://ilovekai.simplepostrequest.workers.dev/iloveass", {}, "POST", JSON.stringify(postData)); + const finalJson = await finalResponse.json(); + + const m3u8Link = finalJson?.result?.sources?.[0]?.file; + + const returnValue = { + stream: m3u8Link, + subtitles: englishSubUrl + }; + + return JSON.stringify(returnValue); + } catch (error) { + console.log("1Movies fetch error:" + error); + return "https://error.org"; + } + } +} + +/// +/// +/// Helper functions +/// +/// + +function cleanHtmlSymbols(string) { + if (!string) { + return ""; + } + return string + .replace(/’/g, "'") + .replace(/–/g, "-") + .replace(/&#[0-9]+;/g, "") + .replace(/\r?\n|\r/g, " ") + .replace(/\s+/g, " ") + .trim(); +} + +function cleanJsonHtml(jsonHtml) { + if (!jsonHtml) { + return ""; + } + return jsonHtml + .replace(/\\"/g, "\"") + .replace(/\\'/g, "'") + .replace(/\\\\/g, "\\") + .replace(/\\n/g, "\n") + .replace(/\\t/g, "\t") + .replace(/\\r/g, "\r"); +} + +function decodeHtmlEntities(text) { + if (!text) { + return ""; + } + return text + .replace(/'/g, "'") + .replace(/"/g, "\"") + .replace(/&/g, "&") + .replace(/</g, "<") + .replace(/>/g, ">") + .replace(/ /g, " "); +} \ No newline at end of file diff --git a/ashi/ashi.json b/ashi/ashi.json new file mode 100644 index 0000000..1d77925 --- /dev/null +++ b/ashi/ashi.json @@ -0,0 +1,19 @@ +{ + "sourceName": "Ashi (あし) - Literally Everything", + "iconUrl": "https://files.catbox.moe/y8v199.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.4", + "language": "English", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://animekai.to/", + "searchBaseUrl": "https://animekai.to/", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/ashi/ashi.js", + "type": "anime/movies/shows", + "asyncJS": true, + "softsub": true, + "downloadSupport": true +} diff --git a/asia2tv/asia2tv.js b/asia2tv/asia2tv.js new file mode 100644 index 0000000..5270970 --- /dev/null +++ b/asia2tv/asia2tv.js @@ -0,0 +1,269 @@ +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 { + const response = await fetchv2(url); + const html = await response.text(); + + const fmMatch = html.match(/https:\/\/filemoon\.to\/e\/[a-zA-Z0-9]+/); + if (fmMatch) { + const fmEmbedUrl = fmMatch[0]; + const fmResp = await fetchv2(fmEmbedUrl); + const fmHtml = await fmResp.text(); + + return filemoonExtractor(fmHtml, url); + } + + return "No video found"; + } catch (err) { + return "Error"; + } +} + + + +async function filemoonExtractor(html, url = null) { + // check if contains iframe, if does, extract the src and get the url + const regex = /<iframe[^>]+src="([^"]+)"[^>]*><\/iframe>/; + const match = html.match(regex); + if (match) { + console.log("Iframe URL: " + match[1]); + const iframeUrl = match[1]; + const iframeResponse = await soraFetch(iframeUrl, { + headers: { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3", + "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", + "Referer": url, + } + }); + console.log("Iframe Response: " + iframeResponse.status); + html = await iframeResponse.text(); + } + // console.log("HTML: " + html); + // get /<script[^>]*>([\s\S]*?)<\/script>/gi + const scriptRegex = /<script[^>]*>([\s\S]*?)<\/script>/gi; + const scripts = []; + let scriptMatch; + while ((scriptMatch = scriptRegex.exec(html)) !== null) { + scripts.push(scriptMatch[1]); + } + // get the script with eval and m3u8 + const evalRegex = /eval\((.*?)\)/; + const m3u8Regex = /m3u8/; + // console.log("Scripts: " + scripts); + const evalScript = scripts.find(script => evalRegex.test(script) && m3u8Regex.test(script)); + if (!evalScript) { + console.log("No eval script found"); + return null; + } + const unpackedScript = unpack(evalScript); + // get the m3u8 url + const m3u8Regex2 = /https?:\/\/[^\s]+master\.m3u8[^\s]*?(\?[^"]*)?/; + const m3u8Match = unpackedScript.match(m3u8Regex2); + if (m3u8Match) { + return m3u8Match[0]; + } else { + console.log("No M3U8 URL found"); + return null; + } +} + + +/* REMOVE_START */ + + +class Unbaser { + constructor(base) { + this.ALPHABET = { + 62: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", + 95: "' !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'", + }; + this.dictionary = {}; + this.base = base; + if (36 < base && base < 62) { + this.ALPHABET[base] = this.ALPHABET[base] || + this.ALPHABET[62].substr(0, base); + } + if (2 <= base && base <= 36) { + this.unbase = (value) => parseInt(value, base); + } + else { + try { + [...this.ALPHABET[base]].forEach((cipher, index) => { + this.dictionary[cipher] = index; + }); + } + catch (er) { + throw Error("Unsupported base encoding."); + } + this.unbase = this._dictunbaser; + } + } + _dictunbaser(value) { + let ret = 0; + [...value].reverse().forEach((cipher, index) => { + ret = ret + ((Math.pow(this.base, index)) * this.dictionary[cipher]); + }); + return ret; + } +} + + +function unpack(source) { + let { payload, symtab, radix, count } = _filterargs(source); + if (count != symtab.length) { + throw Error("Malformed p.a.c.k.e.r. symtab."); + } + let unbase; + try { + unbase = new Unbaser(radix); + } + catch (e) { + throw Error("Unknown p.a.c.k.e.r. encoding."); + } + function lookup(match) { + const word = match; + let word2; + if (radix == 1) { + word2 = symtab[parseInt(word)]; + } + else { + word2 = symtab[unbase.unbase(word)]; + } + return word2 || word; + } + source = payload.replace(/\b\w+\b/g, lookup); + return _replacestrings(source); + function _filterargs(source) { + const juicers = [ + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\), *(\d+), *(.*)\)\)/, + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\)/, + ]; + for (const juicer of juicers) { + const args = juicer.exec(source); + if (args) { + let a = args; + if (a[2] == "[]") { + } + try { + return { + payload: a[1], + symtab: a[4].split("|"), + radix: parseInt(a[2]), + count: parseInt(a[3]), + }; + } + catch (ValueError) { + throw Error("Corrupted p.a.c.k.e.r. data."); + } + } + } + throw Error("Could not make sense of p.a.c.k.e.r data (unexpected code structure)"); + } + function _replacestrings(source) { + return source; + } +} + + +/** + * Uses Sora's fetchv2 on ipad, fallbacks to regular fetch on Windows + * @author ShadeOfChaos + * + * @param {string} url The URL to make the request to. + * @param {object} [options] The options to use for the request. + * @param {object} [options.headers] The headers to send with the request. + * @param {string} [options.method='GET'] The method to use for the request. + * @param {string} [options.body=null] The body of the request. + * + * @returns {Promise<Response|null>} The response from the server, or null if the + * request failed. + */ +async function soraFetch(url, options = { headers: {}, method: 'GET', body: null }) { + try { + return await fetchv2(url, options.headers ?? {}, options.method ?? 'GET', options.body ?? null); + } catch(e) { + try { + return await fetch(url, options); + } catch(error) { + return null; + } + } +} +/* REMOVE_END */ + +/* SCHEME END */ diff --git a/asia2tv/asia2tv.json b/asia2tv/asia2tv.json new file mode 100644 index 0000000..0dd127b --- /dev/null +++ b/asia2tv/asia2tv.json @@ -0,0 +1,19 @@ +{ + "sourceName": "Asia2TV", + "iconUrl": "https://ww1.asia2tv.pw/wp-content/uploads/2021/01/logo-1.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "Arabic", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://ww1.asia2tv.pw/", + "searchBaseUrl": "https://ww1.asia2tv.pw/", + "scriptUrl": "https://raw.githubusercontent.com/50n50/sources/refs/heads/main/asia2tv/asia2tv.js", + "type": "shows/movies", + "asyncJS": true, + "softsub": false, + "downloadSupport": false +} diff --git a/asialiveaction/asialiveaction.js b/asialiveaction/asialiveaction.js new file mode 100644 index 0000000..b1cfdcf --- /dev/null +++ b/asialiveaction/asialiveaction.js @@ -0,0 +1,295 @@ +async function searchResults(keyword) { + const results = []; + try { + const response = await fetchv2("https://asialiveaction.com/?s=" + encodeURIComponent(keyword)); + const html = await response.text(); + + const containerMatch = html.match(/<ul class="navegacion-grid">([\s\S]*?)<\/ul>/); + if (!containerMatch) return JSON.stringify([]); + + const containerHtml = containerMatch[1]; + + const regex = /<a href="([^"]+)"[^>]*>[\s\S]*?<h5 class="carousel-title">([\s\S]*?)<\/h5>[\s\S]*?<img[^>]+src="([^"]+)"/g; + + let match; + while ((match = regex.exec(containerHtml)) !== null) { + results.push({ + title: match[2].trim(), + image: match[3].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 titleMatch = html.match(/<h2 class="Title">\s*([\s\S]*?)\s*<\/h2>/); + const descriptionMatch = html.match(/<p>([\s\S]*?)<\/p>/); + + const description = descriptionMatch ? descriptionMatch[1].trim() : "N/A"; + const title = titleMatch ? titleMatch[1].trim() : "N/A"; + + return JSON.stringify([{ + description: description, + aliases: title, + 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 listMatch = html.match(/<div class="lista-episodios">([\s\S]*?)<\/div>\s*<\/div>/); + if (!listMatch) return JSON.stringify([]); + + const listHtml = listMatch[1]; + + const regex = /<a href="([^"]+)">[\s\S]*?<b class="numero-episodio">Episodio (\d+)<\/b>/g; + let match; + while ((match = regex.exec(listHtml)) !== 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 { + const response = await fetchv2(url); + const html = await response.text(); + + const match = html.match(/\["FM","(https:\\?\/\\?\/filemoon\.to\\?\/e\\?\/[^"]+)"/); + + const filemoonLink = match[1].replace(/\\\//g, "/"); + console.log(filemoonLink); + + const response2 = await fetchv2(filemoonLink); + const html2 = await response2.text(); + let streamUrl = null; + try { + streamUrl = await filemoonExtractor(html2, filemoonLink); + } catch (error) { + console.log("filemoon HD extraction error:" + error); + } + + console.log("filemoon Stream URL: " + streamUrl); + if (streamUrl && streamUrl !== false && streamUrl !== null) { + return streamUrl; + } + + console.log("No stream URL found"); + + return null; + } catch (error) { + console.log("Fetch error:", error); + return null; + } +} + +/* SCHEME START */ +/* {REQUIRED PLUGINS: unbaser} */ + +/** + * @name filemoonExtractor + * @author Cufiy - Inspired by Churly + */ + +async function filemoonExtractor(html, url = null) { + // check if contains iframe, if does, extract the src and get the url + const regex = /<iframe[^>]+src="([^"]+)"[^>]*><\/iframe>/; + const match = html.match(regex); + if (match) { + console.log("Iframe URL: " + match[1]); + const iframeUrl = match[1]; + const iframeResponse = await soraFetch(iframeUrl, { + headers: { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3", + "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", + "Referer": url, + } + }); + console.log("Iframe Response: " + iframeResponse.status); + html = await iframeResponse.text(); + } + // console.log("HTML: " + html); + // get /<script[^>]*>([\s\S]*?)<\/script>/gi + const scriptRegex = /<script[^>]*>([\s\S]*?)<\/script>/gi; + const scripts = []; + let scriptMatch; + while ((scriptMatch = scriptRegex.exec(html)) !== null) { + scripts.push(scriptMatch[1]); + } + // get the script with eval and m3u8 + const evalRegex = /eval\((.*?)\)/; + const m3u8Regex = /m3u8/; + // console.log("Scripts: " + scripts); + const evalScript = scripts.find(script => evalRegex.test(script) && m3u8Regex.test(script)); + if (!evalScript) { + console.log("No eval script found"); + return null; + } + const unpackedScript = unpack(evalScript); + // get the m3u8 url + const m3u8Regex2 = /https?:\/\/[^\s]+master\.m3u8[^\s]*?(\?[^"]*)?/; + const m3u8Match = unpackedScript.match(m3u8Regex2); + if (m3u8Match) { + return m3u8Match[0]; + } else { + console.log("No M3U8 URL found"); + return null; + } +} + + +/* REMOVE_START */ + + +class Unbaser { + constructor(base) { + this.ALPHABET = { + 62: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", + 95: "' !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'", + }; + this.dictionary = {}; + this.base = base; + if (36 < base && base < 62) { + this.ALPHABET[base] = this.ALPHABET[base] || + this.ALPHABET[62].substr(0, base); + } + if (2 <= base && base <= 36) { + this.unbase = (value) => parseInt(value, base); + } + else { + try { + [...this.ALPHABET[base]].forEach((cipher, index) => { + this.dictionary[cipher] = index; + }); + } + catch (er) { + throw Error("Unsupported base encoding."); + } + this.unbase = this._dictunbaser; + } + } + _dictunbaser(value) { + let ret = 0; + [...value].reverse().forEach((cipher, index) => { + ret = ret + ((Math.pow(this.base, index)) * this.dictionary[cipher]); + }); + return ret; + } +} + + +function unpack(source) { + let { payload, symtab, radix, count } = _filterargs(source); + if (count != symtab.length) { + throw Error("Malformed p.a.c.k.e.r. symtab."); + } + let unbase; + try { + unbase = new Unbaser(radix); + } + catch (e) { + throw Error("Unknown p.a.c.k.e.r. encoding."); + } + function lookup(match) { + const word = match; + let word2; + if (radix == 1) { + word2 = symtab[parseInt(word)]; + } + else { + word2 = symtab[unbase.unbase(word)]; + } + return word2 || word; + } + source = payload.replace(/\b\w+\b/g, lookup); + return _replacestrings(source); + function _filterargs(source) { + const juicers = [ + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\), *(\d+), *(.*)\)\)/, + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\)/, + ]; + for (const juicer of juicers) { + const args = juicer.exec(source); + if (args) { + let a = args; + if (a[2] == "[]") { + } + try { + return { + payload: a[1], + symtab: a[4].split("|"), + radix: parseInt(a[2]), + count: parseInt(a[3]), + }; + } + catch (ValueError) { + throw Error("Corrupted p.a.c.k.e.r. data."); + } + } + } + throw Error("Could not make sense of p.a.c.k.e.r data (unexpected code structure)"); + } + function _replacestrings(source) { + return source; + } +} + + +/** + * Uses Sora's fetchv2 on ipad, fallbacks to regular fetch on Windows + * @author ShadeOfChaos + * + * @param {string} url The URL to make the request to. + * @param {object} [options] The options to use for the request. + * @param {object} [options.headers] The headers to send with the request. + * @param {string} [options.method='GET'] The method to use for the request. + * @param {string} [options.body=null] The body of the request. + * + * @returns {Promise<Response|null>} The response from the server, or null if the + * request failed. + */ +async function soraFetch(url, options = { headers: {}, method: 'GET', body: null }) { + try { + return await fetchv2(url, options.headers ?? {}, options.method ?? 'GET', options.body ?? null); + } catch(e) { + try { + return await fetch(url, options); + } catch(error) { + return null; + } + } +} +/* REMOVE_END */ + +/* SCHEME END */ \ No newline at end of file diff --git a/asialiveaction/asialiveaction.json b/asialiveaction/asialiveaction.json new file mode 100644 index 0000000..85d569b --- /dev/null +++ b/asialiveaction/asialiveaction.json @@ -0,0 +1,19 @@ +{ + "sourceName": "AsiaLiveAction", + "iconUrl": "https://asialiveaction.com/wp-content/uploads/cropped-favicon-200x200.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "Spanish", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://asialiveaction.com/", + "searchBaseUrl": "https://asialiveaction.com/", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/asialiveaction/asialiveaction.js", + "type": "shows/movies", + "asyncJS": true, + "softsub": false, + "downloadSupport": false +} diff --git a/asset.png b/asset.png new file mode 100644 index 0000000..e0e56cb Binary files /dev/null and b/asset.png differ diff --git a/az-animex/az-animex.js b/az-animex/az-animex.js new file mode 100644 index 0000000..d2b5ad1 --- /dev/null +++ b/az-animex/az-animex.js @@ -0,0 +1,312 @@ +async function searchResults(keyword) { + const results = []; + try { + const response = await fetchv2("https://www.az-animex.com/?s=" + encodeURIComponent(keyword)); + const html = await response.text(); + + const ulMatch = html.match(/<ul class="columns-4 wp-block-post-template[^"]*">([\s\S]*?)<\/ul>/); + if (!ulMatch) return JSON.stringify(results); + + const ulContent = ulMatch[1]; + + const liRegex = /<li class="wp-block-post[^"]*">([\s\S]*?)<\/li>/g; + let liMatch; + while ((liMatch = liRegex.exec(ulContent)) !== null) { + const liHtml = liMatch[1]; + + const itemMatch = liHtml.match( + /<a href="([^"]+)"[^>]*>\s*<img[^>]+src="([^"]+)"[^>]*>[\s\S]*?<h2[^>]*>\s*<a href="[^"]+"[^>]*>([^<]+)<\/a>/i + ); + if (itemMatch) { + results.push({ + href: itemMatch[1].trim(), + image: itemMatch[2].trim(), + title: itemMatch[3].replace(/\[.*?\]/g, '').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 class="su-spoiler-content[^"]*">([\s\S]*?)<\/div>/i); + const description = descMatch + ? descMatch[1].replace(/<[^>]+>/g, '').replace(/\s+/g, ' ').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 initialResponse = await fetchv2(url); + const initialHtml = await initialResponse.text(); + + const filemoonButtonRegex = /<a\s+href="(https:\/\/filemoon\.(?:sx|to)\/[^"]+)"\s+class="su-button\s+su-button-style-glass"/i; + const filemoonMatch = filemoonButtonRegex.exec(initialHtml); + + if (!filemoonMatch) { + throw new Error('Filemoon button not found'); + } + + const filemoonUrl = filemoonMatch[1]; + + const filemoonResponse = await fetchv2(filemoonUrl); + const filemoonHtml = await filemoonResponse.text(); + + const episodeRegex = /<li class="d-flex flex-wrap align-items-center justify-content-between mb-2">[\s\S]*?<h4>([^<]+)<\/h4>[\s\S]*?<a class="btn btn-success"[^>]*href="([^"]+)"[\s\S]*?<\/li>/g; + + let match; + let episodeCounter = 1; + while ((match = episodeRegex.exec(filemoonHtml)) !== null) { + let href = match[2].trim(); + + href = href.replace('/d/', '/e/'); + + results.push({ + href: href, + number: episodeCounter + }); + + episodeCounter++; + } + return JSON.stringify(results); + + } catch (err) { + console.error('Error extracting episodes:', err); + return JSON.stringify([{ + href: "Error", + number: "Error" + }]); + } +} + +async function extractStreamUrl(url) { + try { + const response = await fetchv2(url); + const html = await response.text(); + + let streamUrl = null; + try { + streamUrl = await filemoonExtractor(html, url); + } catch (error) { + console.log("filemoon HD extraction error:" + error); + } + + console.log("filemoon Stream URL: " + streamUrl); + if (streamUrl && streamUrl !== false && streamUrl !== null) { + return streamUrl; + } + + console.log("No stream URL found"); + + return null; + } catch (error) { + console.log("Fetch error:", error); + return null; + } +} + +/* SCHEME START */ +/* {REQUIRED PLUGINS: unbaser} */ + +/** + * @name filemoonExtractor + * @author Cufiy - Inspired by Churly + */ + +async function filemoonExtractor(html, url = null) { + // check if contains iframe, if does, extract the src and get the url + const regex = /<iframe[^>]+src="([^"]+)"[^>]*><\/iframe>/; + const match = html.match(regex); + if (match) { + console.log("Iframe URL: " + match[1]); + const iframeUrl = match[1]; + const iframeResponse = await soraFetch(iframeUrl, { + headers: { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3", + "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", + "Referer": url, + } + }); + console.log("Iframe Response: " + iframeResponse.status); + html = await iframeResponse.text(); + } + // console.log("HTML: " + html); + // get /<script[^>]*>([\s\S]*?)<\/script>/gi + const scriptRegex = /<script[^>]*>([\s\S]*?)<\/script>/gi; + const scripts = []; + let scriptMatch; + while ((scriptMatch = scriptRegex.exec(html)) !== null) { + scripts.push(scriptMatch[1]); + } + // get the script with eval and m3u8 + const evalRegex = /eval\((.*?)\)/; + const m3u8Regex = /m3u8/; + // console.log("Scripts: " + scripts); + const evalScript = scripts.find(script => evalRegex.test(script) && m3u8Regex.test(script)); + if (!evalScript) { + console.log("No eval script found"); + return null; + } + const unpackedScript = unpack(evalScript); + // get the m3u8 url + const m3u8Regex2 = /https?:\/\/[^\s]+master\.m3u8[^\s]*?(\?[^"]*)?/; + const m3u8Match = unpackedScript.match(m3u8Regex2); + if (m3u8Match) { + return m3u8Match[0]; + } else { + console.log("No M3U8 URL found"); + return null; + } +} + + +/* REMOVE_START */ + + +class Unbaser { + constructor(base) { + this.ALPHABET = { + 62: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", + 95: "' !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'", + }; + this.dictionary = {}; + this.base = base; + if (36 < base && base < 62) { + this.ALPHABET[base] = this.ALPHABET[base] || + this.ALPHABET[62].substr(0, base); + } + if (2 <= base && base <= 36) { + this.unbase = (value) => parseInt(value, base); + } + else { + try { + [...this.ALPHABET[base]].forEach((cipher, index) => { + this.dictionary[cipher] = index; + }); + } + catch (er) { + throw Error("Unsupported base encoding."); + } + this.unbase = this._dictunbaser; + } + } + _dictunbaser(value) { + let ret = 0; + [...value].reverse().forEach((cipher, index) => { + ret = ret + ((Math.pow(this.base, index)) * this.dictionary[cipher]); + }); + return ret; + } +} + + +function unpack(source) { + let { payload, symtab, radix, count } = _filterargs(source); + if (count != symtab.length) { + throw Error("Malformed p.a.c.k.e.r. symtab."); + } + let unbase; + try { + unbase = new Unbaser(radix); + } + catch (e) { + throw Error("Unknown p.a.c.k.e.r. encoding."); + } + function lookup(match) { + const word = match; + let word2; + if (radix == 1) { + word2 = symtab[parseInt(word)]; + } + else { + word2 = symtab[unbase.unbase(word)]; + } + return word2 || word; + } + source = payload.replace(/\b\w+\b/g, lookup); + return _replacestrings(source); + function _filterargs(source) { + const juicers = [ + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\), *(\d+), *(.*)\)\)/, + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\)/, + ]; + for (const juicer of juicers) { + const args = juicer.exec(source); + if (args) { + let a = args; + if (a[2] == "[]") { + } + try { + return { + payload: a[1], + symtab: a[4].split("|"), + radix: parseInt(a[2]), + count: parseInt(a[3]), + }; + } + catch (ValueError) { + throw Error("Corrupted p.a.c.k.e.r. data."); + } + } + } + throw Error("Could not make sense of p.a.c.k.e.r data (unexpected code structure)"); + } + function _replacestrings(source) { + return source; + } +} + + +/** + * Uses Sora's fetchv2 on ipad, fallbacks to regular fetch on Windows + * @author ShadeOfChaos + * + * @param {string} url The URL to make the request to. + * @param {object} [options] The options to use for the request. + * @param {object} [options.headers] The headers to send with the request. + * @param {string} [options.method='GET'] The method to use for the request. + * @param {string} [options.body=null] The body of the request. + * + * @returns {Promise<Response|null>} The response from the server, or null if the + * request failed. + */ +async function soraFetch(url, options = { headers: {}, method: 'GET', body: null }) { + try { + return await fetchv2(url, options.headers ?? {}, options.method ?? 'GET', options.body ?? null); + } catch(e) { + try { + return await fetch(url, options); + } catch(error) { + return null; + } + } +} +/* REMOVE_END */ + +/* SCHEME END */ \ No newline at end of file diff --git a/az-animex/az-animex.json b/az-animex/az-animex.json new file mode 100644 index 0000000..d5696de --- /dev/null +++ b/az-animex/az-animex.json @@ -0,0 +1,19 @@ +{ + "sourceName": "AZ-Animex", + "iconUrl": "https://www.az-animex.com/wp-content/uploads/2023/11/Logo-icono-144x144-1.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "Spanish", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://www.az-animex.com/", + "searchBaseUrl": "https://www.az-animex.com/", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/az-animex/az-animex.js", + "type": "Anime", + "asyncJS": true, + "softsub": false, + "downloadSupport": false +} diff --git a/beatz-anime/beatz-anime.js b/beatz-anime/beatz-anime.js new file mode 100644 index 0000000..86632ab --- /dev/null +++ b/beatz-anime/beatz-anime.js @@ -0,0 +1,103 @@ +async function searchResults(keyword) { + const results = []; + const baseUrl = "https://www.beatz-anime.net"; + try { + const response = await fetchv2("https://www.beatz-anime.net/busqueda.php"); + const html = await response.text(); + + const cardRegex = /<div class="col-lg-2 mb-4">([\s\S]*?)<\/div>\s*<\/div>/gs; + let cardMatch; + while ((cardMatch = cardRegex.exec(html)) !== null) { + const cardHTML = cardMatch[1]; + + const infoRegex = /<a href="([^"]+)">.*?<span class="titulo"[^>]*>([^<]+)<\/span>.*?<img[^>]+src="([^"]+)"/s; + const infoMatch = infoRegex.exec(cardHTML); + if (infoMatch) { + const title = infoMatch[2].trim(); + if (title.toLowerCase().includes(keyword.toLowerCase())) { + results.push({ + href: baseUrl + infoMatch[1].trim(), + title: title, + image: baseUrl + infoMatch[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 pMatch = html.match(/<p class="post-text"[^>]*>([\s\S]*?)<\/p>/); + let description = "N/A"; + let aliases = "N/A"; + + if (pMatch) { + const content = pMatch[1]; + + const descMatch = content.split(/<span class="mr-3"/)[0].replace(/<br\s*\/?>/gi, "\n").trim(); + if (descMatch) description = descMatch; + + const aliasMatch = content.match(/<b>Sinónimos:<\/b>\s*([^<]+)/); + if (aliasMatch) aliases = aliasMatch[1].trim(); + } + + return JSON.stringify([{ + description: description, + aliases: aliases, + 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 rows = html.match(/<tbody>([\s\S]*?)<\/tbody>/)?.[1].match(/<tr>[\s\S]*?<\/tr>/g) || []; + + rows.forEach((row, index) => { + const hrefMatch = row.match(/<td class="text-center"><a href="([^"]+)"/); + const href = hrefMatch ? hrefMatch[1] : "N/A"; + + results.push({ + href: href, + number: index + 1 + }); + }); + + return JSON.stringify(results); + } catch (err) { + return JSON.stringify([{ + href: "Error", + number: "Error" + }]); + } +} + +async function extractStreamUrl(url) { + try { + return url; + } catch (err) { + return "https://error.org/"; + } +} diff --git a/beatz-anime/beatz-anime.json b/beatz-anime/beatz-anime.json new file mode 100644 index 0000000..776d8ad --- /dev/null +++ b/beatz-anime/beatz-anime.json @@ -0,0 +1,20 @@ +{ + "sourceName": "Beatz-Anime", + "iconUrl": "https://files.catbox.moe/vij8dw.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "Spanish (DUB/SUB)", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://www.beatz-anime.net/", + "searchBaseUrl": "https://www.beatz-anime.net/", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/beatz-anime/beatz-anime.js", + "type": "Anime", + "asyncJS": true, + "softsub": false, + "downloadSupport": false, + "note": "Use external player!" +} diff --git a/broken/videasy/videasy.js b/broken/videasy/videasy.js new file mode 100644 index 0000000..409607a --- /dev/null +++ b/broken/videasy/videasy.js @@ -0,0 +1,178 @@ +async function searchResults(keyword) { + try { + const encodedKeyword = encodeURIComponent(keyword); + const responseText = await fetchv2(`https://api.themoviedb.org/3/search/multi?api_key=9801b6b0548ad57581d111ea690c85c8&query=${encodedKeyword}`); + const data = await responseText.json(); + + const transformedResults = data.results.map(result => { + if(result.media_type === "movie" || result.title) { + return { + title: result.title || result.name || result.original_title || result.original_name, + image: `https://image.tmdb.org/t/p/w500${result.poster_path}`, + href: `movie/${result.id}` + }; + } else if(result.media_type === "tv" || result.name) { + return { + title: result.name || result.title || result.original_name || result.original_title, + image: `https://image.tmdb.org/t/p/w500${result.poster_path}`, + href: `tv/${result.id}/1/1` + }; + } else { + return { + title: result.title || result.name || result.original_name || result.original_title || "Untitled", + image: `https://image.tmdb.org/t/p/w500${result.poster_path}`, + href: `tv/${result.id}/1/1` + }; + } + }); + + console.log('Transformed Results: ' + transformedResults); + return JSON.stringify(transformedResults); + } catch (error) { + console.log('Fetch error in searchResults:' + error); + return JSON.stringify([{ title: 'Error', image: '', href: '' }]); + } +} + +async function extractDetails(url) { + try { + if(url.includes('movie')) { + const match = url.match(/movie\/([^\/]+)/); + if (!match) throw new Error("Invalid URL format"); + + const movieId = match[1]; + const responseText = await fetchv2(`https://api.themoviedb.org/3/movie/${movieId}?api_key=ad301b7cc82ffe19273e55e4d4206885`); + const data = await responseText.json(); + + const transformedResults = [{ + description: data.overview || 'No description available', + aliases: `Duration: ${data.runtime ? data.runtime + " minutes" : 'Unknown'}`, + airdate: `Released: ${data.release_date ? data.release_date : 'Unknown'}` + }]; + + return JSON.stringify(transformedResults); + } else if(url.includes('tv')) { + const match = url.match(/tv\/([^\/]+)/); + if (!match) throw new Error("Invalid URL format"); + + const showId = match[1]; + const responseText = await fetchv2(`https://api.themoviedb.org/3/tv/${showId}?api_key=ad301b7cc82ffe19273e55e4d4206885`); + const data = await responseText.json(); + + const transformedResults = [{ + description: data.overview || 'No description available', + aliases: `Duration: ${data.episode_run_time && data.episode_run_time.length ? data.episode_run_time.join(', ') + " minutes" : 'Unknown'}`, + airdate: `Aired: ${data.first_air_date ? data.first_air_date : 'Unknown'}` + }]; + + console.log(JSON.stringify(transformedResults)); + return JSON.stringify(transformedResults); + } else { + throw new Error("Invalid URL format"); + } + } catch (error) { + console.log('Details error: ' + error); + return JSON.stringify([{ + description: 'Error loading description', + aliases: 'Duration: Unknown', + airdate: 'Aired/Released: Unknown' + }]); + } +} + +async function extractEpisodes(url) { + try { + if(url.includes('movie')) { + const match = url.match(/movie\/([^\/]+)/); + + if (!match) throw new Error("Invalid URL format"); + + const movieId = match[1]; + + const movie = [ + { href: `movie/${movieId}`, number: 1, title: "Full Movie" } + ]; + + console.log(movie); + return JSON.stringify(movie); + } else if(url.includes('tv')) { + const match = url.match(/tv\/([^\/]+)\/([^\/]+)\/([^\/]+)/); + + if (!match) throw new Error("Invalid URL format"); + + const showId = match[1]; + + const showResponseText = await fetchv2(`https://api.themoviedb.org/3/tv/${showId}?api_key=ad301b7cc82ffe19273e55e4d4206885`); + const showData = await showResponseText.json(); + + let allEpisodes = []; + for (const season of showData.seasons) { + const seasonNumber = season.season_number; + + if(seasonNumber === 0) continue; + + const seasonResponseText = await fetchv2(`https://api.themoviedb.org/3/tv/${showId}/season/${seasonNumber}?api_key=ad301b7cc82ffe19273e55e4d4206885`); + const seasonData = await seasonResponseText.json(); + + if (seasonData.episodes && seasonData.episodes.length) { + const episodes = seasonData.episodes.map(episode => ({ + href: `tv/${showId}/${seasonNumber}/${episode.episode_number}`, + number: episode.episode_number, + title: episode.name || "" + })); + allEpisodes = allEpisodes.concat(episodes); + } + } + + console.log(allEpisodes); + return JSON.stringify(allEpisodes); + } else { + throw new Error("Invalid URL format"); + } + } catch (error) { + console.log('Fetch error in extractEpisodes: ' + error); + return JSON.stringify([]); + } +} + +async function extractStreamUrl(url) { + try { + let apiUrl; + + if (url.startsWith("tv/")) { + const [, id, season, episode] = url.split("/"); + apiUrl = `https://videasier.onrender.com/api/extract?id=${id}&type=tv&season=${season}&episode=${episode}`; + console.log('TV API URL: ' + apiUrl); + } + else if (url.startsWith("movie/")) { + const [, id] = url.split("/"); + apiUrl = `https://videasier.onrender.com/api/extract?id=${id}&type=movie`; + console.log('Movie API URL: ' + apiUrl); + } + + if (apiUrl) { + const headers = { + 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3', + 'Connection': 'keep-alive', + 'Keep-Alive': 'timeout=15, max=100', + 'Accept': 'application/json, text/plain, */*' + }; + + const response = await fetchv2(apiUrl, headers); + const data = await response.json(); + console.log('Stream URL data: ' + JSON.stringify(data)); + if (data.success && data.m3u8) { + return data.m3u8; + } + return "https://files.catbox.moe/elfax8.mp4"; + } + + const response = await fetchv2(url); + const html = await response.text(); + return "https://files.catbox.moe/elfax8.mp4"; + + } catch (err) { + console.error('Error in extractStreamUrl:'+ err); + return "https://files.catbox.moe/elfax8.mp4"; + } +} diff --git a/broken/videasy/videasy.json b/broken/videasy/videasy.json new file mode 100644 index 0000000..b1c687a --- /dev/null +++ b/broken/videasy/videasy.json @@ -0,0 +1,19 @@ +{ + "sourceName": "VidEasy", + "iconUrl": "https://www.videasy.net/logo.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "English", + "streamType": "HLS", + "quality": "4K - 1080p - 720p", + "baseUrl": "https://player.videasy.net/", + "searchBaseUrl": "https://player.videasy.net/", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/videasy/videasy.js", + "type": "shows/movies", + "asyncJS": true, + "softsub": false, + "downloadSupport": true +} diff --git a/chireads/chireads.js b/chireads/chireads.js new file mode 100644 index 0000000..a1a4c65 --- /dev/null +++ b/chireads/chireads.js @@ -0,0 +1,254 @@ +async function searchResults(keyword) { + try { + const encodedKeyword = encodeURIComponent(keyword); + const url = `https://chireads.com/search?x=0&y=0&name=${encodedKeyword}`; + const response = await soraFetch(url); + const html = await response.text(); + + const results = []; + const liRegex = /<li>([\s\S]*?)<\/li>/g; + let liMatch; + + while ((liMatch = liRegex.exec(html)) !== null) { + const liHtml = liMatch[1]; + + const linkMatch = liHtml.match(/<div class="news-list-img">[\s\S]*?<a href="([^"]+)"\s+title="([^"]+)"/); + const imgMatch = liHtml.match(/<div class="news-list-img">[\s\S]*?<img src="([^"]+)"/); + const titleMatch = liHtml.match(/<h5 class="font-color-black3">[\s\S]*?<a [^>]+>([^<]+)<\/a>/); + + if (linkMatch && imgMatch && titleMatch) { + let image = imgMatch[1]; + if (!image.startsWith("http")) image = "https:" + image; + + results.push({ + title: decodeHtmlEntities(titleMatch[1].trim()), + href: linkMatch[1].trim(), + image: image.trim() + }); + } + } + + console.log(JSON.stringify(results)); + return JSON.stringify(results); + } catch (error) { + console.error("Error fetching or parsing: " + error); + return JSON.stringify([{ + title: "Error", + href: "", + image: "" + }]); + } +} + +async function extractDetails(url) { + try { + const response = await soraFetch(url); + const htmlText = await response.text(); + + const descMatch = htmlText.match(/<div class="inform-txt-show font-color-black6">\s*<span>([\s\S]*?)<\/span>\s*<\/div>/i); + + let description = descMatch + ? descMatch[1] + .replace(/<br\s*\/?>/gi, '\n') + .replace(/\s+/g, ' ') + .trim() + : "No description available"; + + const aliases = 'N/A'; + const airdate = 'N/A'; + + const transformedResults = [{ + description, + aliases, + airdate + }]; + + console.log(JSON.stringify(transformedResults)); + return JSON.stringify(transformedResults); + + } catch (error) { + console.log('Details error:' + error); + return JSON.stringify([{ + description: 'Error loading description', + aliases: 'N/A', + airdate: 'N/A' + }]); + } +} + +async function extractChapters(url) { + try { + const response = await soraFetch(url); + const htmlText = await response.text(); + + let contentHtml = null; + + const ulPattern = /<ul><li><a href="[^"]*chapitre-\d+[^"]*"[\s\S]*?<\/ul>/i; + const ulMatch = htmlText.match(ulPattern); + + if (ulMatch) { + contentHtml = ulMatch[0]; + console.log("Found chapters using UL pattern"); + } else { + const chapterSectionRegex = /<div[^>]*class="chapitre-table"[^>]*>([\s\S]*?)<\/div>/gi; + let bestSection = null; + let maxChapterCount = 0; + let sectionMatch; + + while ((sectionMatch = chapterSectionRegex.exec(htmlText)) !== null) { + const sectionContent = sectionMatch[1]; + const chapterCount = (sectionContent.match(/chapitre-\d+/gi) || []).length; + + if (chapterCount > maxChapterCount) { + maxChapterCount = chapterCount; + bestSection = sectionContent; + } + } + + if (bestSection && maxChapterCount > 0) { + contentHtml = bestSection; + console.log(`Found chapters using best section method (${maxChapterCount} chapters)`); + } + } + + if (!contentHtml) { + const chapterLinksPattern = /(<[^>]*>[\s\S]*?){5,}chapitre-\d+[\s\S]*?(<\/[^>]*>[\s\S]*?){5,}/i; + const fallbackMatch = htmlText.match(chapterLinksPattern); + + if (fallbackMatch) { + const startIndex = htmlText.indexOf(fallbackMatch[0]); + const endIndex = startIndex + fallbackMatch[0].length; + + const beforeText = htmlText.substring(0, startIndex); + const divStart = beforeText.lastIndexOf('<div'); + + const afterText = htmlText.substring(endIndex); + const divEnd = afterText.indexOf('</div>'); + + if (divStart !== -1 && divEnd !== -1) { + contentHtml = htmlText.substring(divStart, endIndex + divEnd + 6); + console.log("Found chapters using fallback method"); + } + } + } + + if (!contentHtml) { + throw new Error("Chapters content not found"); + } + + console.log("Content HTML length:", contentHtml.length); + console.log("Content preview:", contentHtml.substring(0, 200) + "..."); + + const linkRegex = /<a\s+href="([^"]*(?:chapitre|chapter)[^"]*)"[^>]*(?:title="([^"]*)")?[^>]*>(.*?)<\/a>/gi; + const chapters = []; + let linkMatch; + + while ((linkMatch = linkRegex.exec(contentHtml)) !== null) { + const href = linkMatch[1].trim(); + const titleAttr = linkMatch[2]?.trim(); + const linkText = linkMatch[3].trim(); + + const title = titleAttr || linkText; + + if (title && /chapitre\s*\d+/i.test(title)) { + chapters.push({ title, href }); + } + } + + console.log(`Found ${chapters.length} chapters before sorting`); + + chapters.sort((a, b) => { + const numA = parseFloat(a.title.match(/chapitre\s*(\d+)/i)?.[1]) || 0; + const numB = parseFloat(b.title.match(/chapitre\s*(\d+)/i)?.[1]) || 0; + return numA - numB; + }); + + chapters.forEach((chapter, index) => { + chapter.number = index + 1; + }); + + console.log(`Final result: ${chapters.length} chapters`); + if (chapters.length > 0) { + console.log("First chapter:", chapters[0]); + console.log("Last chapter:", chapters[chapters.length - 1]); + } + + return JSON.stringify(chapters); + + } catch (error) { + console.error('Fetch error in extractChapters:', error); + return JSON.stringify([{ + href: url, + title: "Error fetching chapters", + number: 0 + }]); + } +} + +async function extractText(url) { + try { + const response = await soraFetch(url); + let htmlText = await response.text(); + + const contentRegex = /<div[^>]+id=['"]content['"][^>]*class=["']font-color-black3 article-font["'][^>]*>([\s\S]*?)<\/div>/i; + const match = contentRegex.exec(htmlText); + + if (!match) { + throw new Error("Main content div not found"); + } + + let content = match[1]; + + content = content.replace(/<div id="pf-\d+-\d+"[^>]*>[\s\S]*?<\/div>/gi, ''); + content = content.replace(/<script[\s\S]*?<\/script>/gi, ''); + content = content.replace(/<[^p\/][^>]*>/gi, ''); + content = content.replace(/\s+/g, ' ').trim(); + + if (!content) { + throw new Error("No content extracted"); + } + + console.log(content); + return content; + + } catch (error) { + console.log("Fetch error in extractText: " + error); + return '<p>Error extracting text</p>'; + } +} + +async function soraFetch(url, options = { + headers: {}, + method: 'GET', + body: null +}) { + try { + return await fetchv2(url, options.headers ?? {}, options.method ?? 'GET', options.body ?? null); + } catch (e) { + try { + return await fetch(url, options); + } catch (error) { + return null; + } + } +} + +function decodeHtmlEntities(text) { + const entities = { + '—': '—', + '–': '–', + '&': '&', + '<': '<', + '>': '>', + '"': '"', + ''': "'", + '/': '/', + '`': '`', + '=': '=', + ' ': ' ' + }; + + return text.replace(/&#x[\dA-Fa-f]+;|&\w+;/g, (match) => { + return entities[match] || match; + }); +} diff --git a/chireads/chireads.json b/chireads/chireads.json new file mode 100644 index 0000000..a028704 --- /dev/null +++ b/chireads/chireads.json @@ -0,0 +1,19 @@ +{ + "sourceName": "ChiReads", + "iconUrl": "https://chireads.com/wp-content/uploads/2020/04/2020LOGO-2.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "French", + "streamType": "novels", + "quality": "N/A", + "baseUrl": "https://chireads.com/", + "searchBaseUrl": "https://chireads.com/search/%s", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/chireads/chireads.js", + "type": "novels", + "asyncJS": true, + "novel": true, + "downloadSupport": false +} diff --git a/cinecalidad/cinecalidad.js b/cinecalidad/cinecalidad.js new file mode 100644 index 0000000..951f455 --- /dev/null +++ b/cinecalidad/cinecalidad.js @@ -0,0 +1,247 @@ +async function searchResults(keyword) { + const results = []; + try { + const response = await fetchv2("https://www.cinecalidad.ec/?s=" + encodeURIComponent(keyword)); + const html = await response.text(); + + const containerMatch = html.match(/<div id="archive-content"[^>]*>([\s\S]*?)<\/div>\s*<\/div>\s*<\/div>/); + if (containerMatch) { + const container = containerMatch[1]; + + const regex = /<article[^>]*>([\s\S]*?)<\/article>/g; + + let articleMatch; + while ((articleMatch = regex.exec(container)) !== null) { + const articleContent = articleMatch[1]; + + const imageMatch = articleContent.match(/data-src="([^"]+)"/); + + const hrefMatch = articleContent.match(/<a href="([^"]+)"/); + + const titleMatch = articleContent.match(/<div class="in_title">([^<]+)<\/div>/); + + if (imageMatch && hrefMatch && titleMatch) { + results.push({ + title: titleMatch[1].trim(), + image: imageMatch[1].trim(), + href: hrefMatch[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 descMatch = html.match(/<p><p>([^<]+)<\/p>/); + + const description = descMatch ? descMatch[1].trim() : "N/A"; + + return JSON.stringify([{ + description + }]); + } catch (err) { + return JSON.stringify([{ + description: "Error" + }]); + } +} + +async function extractEpisodes(url) { + const results = []; + try { + const response = await fetchv2(url); + const html = await response.text(); + + const seasonRegex = /<div id="jstab"[^>]*>([\s\S]*?)<\/div>\s*<\/div>/g; + let seasonMatch; + + while ((seasonMatch = seasonRegex.exec(html)) !== null) { + const seasonContent = seasonMatch[1]; + + const episodeRegex = /<a href="([^"]+)"[^>]*>Episodio \d+<\/a>/g; + let episodeMatch; + let episodeCount = 1; + + while ((episodeMatch = episodeRegex.exec(seasonContent)) !== null) { + results.push({ + href: episodeMatch[1].trim(), + number: episodeCount + }); + episodeCount++; + } + } + + if (results.length === 0) { + results.push({ + href: url, + number: 1 + }); + } + + return JSON.stringify(results); + } catch (err) { + return JSON.stringify([{ + href: "Error", + number: "Error" + }]); + } +} + +async function extractStreamUrl(url) { + try { + const response = await fetchv2(url); + const html = await response.text(); + + const match = html.match(/data-option="(https:\/\/lamovie\.link\/embed-[^"]+)"/); + if (!match) return "https://error.org/"; + + const embedUrl = match[1]; + const embedResponse = await fetchv2(embedUrl); + const embedHtml = await embedResponse.text(); + + const obfuscatedScript = embedHtml.match(/<script[^>]*>\s*(eval\(function\(p,a,c,k,e,d.*?\)[\s\S]*?)<\/script>/); + if (!obfuscatedScript) return "https://error.org/"; + + const unpackedScript = unpack(obfuscatedScript[1]); + + const fileMatch = unpackedScript.match(/file:\s*"([^"]+)"/); + if (!fileMatch) return "https://error.org/"; + + return fileMatch[1]; + } catch (err) { + return "https://error.org/"; + } +} + + +/*********************************************************** + * UNPACKER MODULE + * Credit to GitHub user "mnsrulz" for Unpacker Node library + * https://github.com/mnsrulz/unpacker + ***********************************************************/ +class Unbaser { + constructor(base) { + /* Functor for a given base. Will efficiently convert + strings to natural numbers. */ + this.ALPHABET = { + 62: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", + 95: "' !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'", + }; + this.dictionary = {}; + this.base = base; + // fill elements 37...61, if necessary + if (36 < base && base < 62) { + this.ALPHABET[base] = this.ALPHABET[base] || + this.ALPHABET[62].substr(0, base); + } + // If base can be handled by int() builtin, let it do it for us + if (2 <= base && base <= 36) { + this.unbase = (value) => parseInt(value, base); + } + else { + // Build conversion dictionary cache + try { + [...this.ALPHABET[base]].forEach((cipher, index) => { + this.dictionary[cipher] = index; + }); + } + catch (er) { + throw Error("Unsupported base encoding."); + } + this.unbase = this._dictunbaser; + } + } + _dictunbaser(value) { + /* Decodes a value to an integer. */ + let ret = 0; + [...value].reverse().forEach((cipher, index) => { + ret = ret + ((Math.pow(this.base, index)) * this.dictionary[cipher]); + }); + return ret; + } +} + +function detect(source) { + /* Detects whether `source` is P.A.C.K.E.R. coded. */ + return source.replace(" ", "").startsWith("eval(function(p,a,c,k,e,"); +} + +function unpack(source) { + /* Unpacks P.A.C.K.E.R. packed js code. */ + let { payload, symtab, radix, count } = _filterargs(source); + if (count != symtab.length) { + throw Error("Malformed p.a.c.k.e.r. symtab."); + } + let unbase; + try { + unbase = new Unbaser(radix); + } + catch (e) { + throw Error("Unknown p.a.c.k.e.r. encoding."); + } + function lookup(match) { + /* Look up symbols in the synthetic symtab. */ + const word = match; + let word2; + if (radix == 1) { + //throw Error("symtab unknown"); + word2 = symtab[parseInt(word)]; + } + else { + word2 = symtab[unbase.unbase(word)]; + } + return word2 || word; + } + source = payload.replace(/\b\w+\b/g, lookup); + return _replacestrings(source); + function _filterargs(source) { + /* Juice from a source file the four args needed by decoder. */ + const juicers = [ + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\), *(\d+), *(.*)\)\)/, + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\)/, + ]; + for (const juicer of juicers) { + //const args = re.search(juicer, source, re.DOTALL); + const args = juicer.exec(source); + if (args) { + let a = args; + if (a[2] == "[]") { + //don't know what it is + // a = list(a); + // a[1] = 62; + // a = tuple(a); + } + try { + return { + payload: a[1], + symtab: a[4].split("|"), + radix: parseInt(a[2]), + count: parseInt(a[3]), + }; + } + catch (ValueError) { + throw Error("Corrupted p.a.c.k.e.r. data."); + } + } + } + throw Error("Could not make sense of p.a.c.k.e.r data (unexpected code structure)"); + } + function _replacestrings(source) { + /* Strip string lookup table (list) and replace values in source. */ + /* Need to work on this. */ + return source; + } +} + diff --git a/cinecalidad/cinecalidad.json b/cinecalidad/cinecalidad.json new file mode 100644 index 0000000..65850f7 --- /dev/null +++ b/cinecalidad/cinecalidad.json @@ -0,0 +1,19 @@ +{ + "sourceName": "CineCalidad", + "iconUrl": "https://www.cinecalidad.ec/wp-content/themes/Cinecalidad/assets/img/favicon.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "Spanish (DUB/SUB)", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://www.cinecalidad.ec/", + "searchBaseUrl": "https://www.cinecalidad.ec/", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/cinecalidad/cinecalidad.js", + "type": "shows/movies", + "asyncJS": true, + "softsub": false, + "downloadSupport": false +} diff --git a/cksub/cksub.js b/cksub/cksub.js new file mode 100644 index 0000000..a5e3552 --- /dev/null +++ b/cksub/cksub.js @@ -0,0 +1,105 @@ +async function searchResults(keyword) { + const results = []; + const response = await fetchv2(`https://cksub.org/?s=${keyword}`); + const html = await response.text(); + + const regex = /<article class="bs"[^>]*>.*?<a href="([^"]+)"[^>]*>.*?<img src="([^"]+)"[^>]*>.*?<h2[^>]*>(.*?)<\/h2>/gs; + + 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); +} + +async function extractDetails(url) { + const results = []; + const response = await fetchv2(url); + const html = await response.text(); + + const match = html.match(/<div class="entry-content"[^>]*>([\s\S]*?)<\/div>/); + + let description = "N/A"; + if (match) { + description = match[1] + .replace(/<[^>]+>/g, '') + .replace(/&#(\d+);/g, (_, code) => String.fromCharCode(code)) + .replace(/"/g, '"') + .replace(/'/g, "'") + .replace(/&/g, "&") + .trim(); + } + + results.push({ + description: description, + aliases: 'N/A', + airdate: 'N/A' + }); + + return JSON.stringify(results); +} + +async function extractEpisodes(url) { + const results = []; + const response = await fetchv2(url); + const html = await response.text(); + + const regex = /<a href="([^"]+)">\s*<div class="epl-num">([\d.]+)<\/div>/g; + + let match; + while ((match = regex.exec(html)) !== null) { + results.push({ + href: match[1].trim(), + number: parseInt(match[2], 10) + }); + } + results.reverse(); + return JSON.stringify(results); +} + +async function extractStreamUrl(url) { + try { + const response = await fetchv2(url); + const html = await response.text(); + +const iframeMatch = html.match(/dailymotion\.com\/player\/[a-zA-Z0-9]+\.html\?video=([a-zA-Z0-9]+)/); if (!iframeMatch) return "no iframe"; + + const videoId = iframeMatch[1]; + + const metaRes = await fetchv2(`https://www.dailymotion.com/player/metadata/video/${videoId}`); + const metaJson = await metaRes.json(); + const hlsLink = metaJson.qualities?.auto?.[0]?.url; + if (!hlsLink) return "no hls"; + + async function getBestHls(hlsUrl) { + try { + const res = await fetchv2(hlsUrl); + const text = await res.text(); + const regex = /#EXT-X-STREAM-INF:.*RESOLUTION=(\d+)x(\d+).*?\n(https?:\/\/[^\n]+)/g; + const streams = []; + let match; + while ((match = regex.exec(text)) !== null) { + streams.push({ width: parseInt(match[1]), height: parseInt(match[2]), url: match[3] }); + } + if (streams.length === 0) return hlsUrl; + streams.sort((a, b) => b.height - a.height); + return streams[0].url; + } catch { + return hlsUrl; + } + } + + const bestHls = await getBestHls(hlsLink); + + return bestHls; + } catch { + const empty = "{ streams: ["; + console.log("Extracted stream result:" + JSON.stringify(empty)); + return JSON.stringify(empty); + } +} diff --git a/cksub/cksub.json b/cksub/cksub.json new file mode 100644 index 0000000..cc06d77 --- /dev/null +++ b/cksub/cksub.json @@ -0,0 +1,19 @@ +{ + "sourceName": "CKSub", + "iconUrl": "https://cksub.org/wp-content/uploads/2024/12/cropped-i-am-the-fated-villain-gu-changge-192x192.jpg", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "Chinese", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://cksub.org/", + "searchBaseUrl": "https://cksub.org/", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/cksub/cksub.js", + "type": "anime", + "asyncJS": true, + "softsub": false, + "downloadSupport": false +} diff --git a/cloudy/cloudy.js b/cloudy/cloudy.js new file mode 100644 index 0000000..c2f5ec3 --- /dev/null +++ b/cloudy/cloudy.js @@ -0,0 +1,214 @@ +async function searchResults(keyword) { + const results = []; + try { + const response = await fetchv2("https://cloudy.pk/?s=" + encodeURIComponent(keyword)); + const html = await response.text(); + + const regex = /<div class="image-hover-wrapper">[\s\S]*?<a href="([^"]+)"[^>]*>[\s\S]*?<img [^>]*src="([^"]+)"[^>]*>[\s\S]*?<h2 class="entry-title"><a href="[^"]+"[^>]*>([^<]+)<\/a><\/h2>/g; + + let match; + while ((match = regex.exec(html)) !== null) { + results.push({ + href: match[1].trim(), + image: match[2].trim(), + title: 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 match = html.match(/<p[^>]*><strong>([\s\S]*?)<\/strong><\/p>/); + const description = match ? match[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 match = html.match(/<a [^>]*href="(https:\/\/videospk[^"]+)"[^>]*>.*?<\/a>/); + if (match) { + results.push({ + href: match[1].trim(), + number: 1 + }); + } else { + results.push({ + href: url, + number: 1 + }); + } + + return JSON.stringify(results); + } catch (err) { + return JSON.stringify([{ + href: "Error", + number: "Error" + }]); + } +} + +async function extractStreamUrl(url) { + try { + const response = await fetchv2(url); + const html = await response.text(); + + const obfuscatedScript = html.match(/<script[^>]*>\s*(eval\(function\(p,a,c,k,e,d.*?\)[\s\S]*?)<\/script>/); + const unpackedScript = unpack(obfuscatedScript[1]); + + const streamMatch = unpackedScript.match(/["'](\/stream\/[^"']+)["']/); + const hlsLink = streamMatch ? streamMatch[1] : null; + + console.log("HLS Link:" + hlsLink); + + return "https://videospk.xyz" + hlsLink; + } catch (err) { + return "https://files.catbox.moe/avolvc.mp4"; + } +} + +/*********************************************************** + * UNPACKER MODULE + * Credit to GitHub user "mnsrulz" for Unpacker Node library + * https://github.com/mnsrulz/unpacker + ***********************************************************/ +class Unbaser { + constructor(base) { + /* Functor for a given base. Will efficiently convert + strings to natural numbers. */ + this.ALPHABET = { + 62: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", + 95: "' !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'", + }; + this.dictionary = {}; + this.base = base; + // fill elements 37...61, if necessary + if (36 < base && base < 62) { + this.ALPHABET[base] = this.ALPHABET[base] || + this.ALPHABET[62].substr(0, base); + } + // If base can be handled by int() builtin, let it do it for us + if (2 <= base && base <= 36) { + this.unbase = (value) => parseInt(value, base); + } + else { + // Build conversion dictionary cache + try { + [...this.ALPHABET[base]].forEach((cipher, index) => { + this.dictionary[cipher] = index; + }); + } + catch (er) { + throw Error("Unsupported base encoding."); + } + this.unbase = this._dictunbaser; + } + } + _dictunbaser(value) { + /* Decodes a value to an integer. */ + let ret = 0; + [...value].reverse().forEach((cipher, index) => { + ret = ret + ((Math.pow(this.base, index)) * this.dictionary[cipher]); + }); + return ret; + } +} + +function detect(source) { + /* Detects whether `source` is P.A.C.K.E.R. coded. */ + return source.replace(" ", "").startsWith("eval(function(p,a,c,k,e,"); +} + +function unpack(source) { + /* Unpacks P.A.C.K.E.R. packed js code. */ + let { payload, symtab, radix, count } = _filterargs(source); + if (count != symtab.length) { + throw Error("Malformed p.a.c.k.e.r. symtab."); + } + let unbase; + try { + unbase = new Unbaser(radix); + } + catch (e) { + throw Error("Unknown p.a.c.k.e.r. encoding."); + } + function lookup(match) { + /* Look up symbols in the synthetic symtab. */ + const word = match; + let word2; + if (radix == 1) { + //throw Error("symtab unknown"); + word2 = symtab[parseInt(word)]; + } + else { + word2 = symtab[unbase.unbase(word)]; + } + return word2 || word; + } + source = payload.replace(/\b\w+\b/g, lookup); + return _replacestrings(source); + function _filterargs(source) { + /* Juice from a source file the four args needed by decoder. */ + const juicers = [ + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\), *(\d+), *(.*)\)\)/, + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\)/, + ]; + for (const juicer of juicers) { + //const args = re.search(juicer, source, re.DOTALL); + const args = juicer.exec(source); + if (args) { + let a = args; + if (a[2] == "[]") { + //don't know what it is + // a = list(a); + // a[1] = 62; + // a = tuple(a); + } + try { + return { + payload: a[1], + symtab: a[4].split("|"), + radix: parseInt(a[2]), + count: parseInt(a[3]), + }; + } + catch (ValueError) { + throw Error("Corrupted p.a.c.k.e.r. data."); + } + } + } + throw Error("Could not make sense of p.a.c.k.e.r data (unexpected code structure)"); + } + function _replacestrings(source) { + /* Strip string lookup table (list) and replace values in source. */ + /* Need to work on this. */ + return source; + } +} diff --git a/cloudy/cloudy.json b/cloudy/cloudy.json new file mode 100644 index 0000000..6b24495 --- /dev/null +++ b/cloudy/cloudy.json @@ -0,0 +1,19 @@ +{ + "sourceName": "Cloudy", + "iconUrl": "https://cloudy.pk/wp-content/uploads/2018/02/cloudy.pk-icon-200x200.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "Hindi (DUB/SUB)", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://cloudy.pk/", + "searchBaseUrl": "https://cloudy.pk/", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/cloudy/cloudy.js", + "type": "shows/movies", + "asyncJS": true, + "softsub": false, + "downloadSupport": false +} diff --git a/coflix/coflix.js b/coflix/coflix.js new file mode 100644 index 0000000..55a2741 --- /dev/null +++ b/coflix/coflix.js @@ -0,0 +1,325 @@ +async function searchResults(keyword) { + try { + const response = await fetchv2(`https://coflix.cc/suggest.php?query=${encodeURIComponent(keyword)}`); + const data = await response.json(); + + if (!Array.isArray(data)) { + return JSON.stringify([]); + } + + const results = []; + + for (const item of data) { + let imgUrl = ''; + const imgMatch = item.image.match(/src="([^"]+)"/); + if (imgMatch && imgMatch[1]) { + const src = imgMatch[1].trim(); + imgUrl = src.startsWith('//') ? 'https:' + src : src; + } + + const href = item.url.trim(); + + results.push({ + title: item.title.trim(), + image: imgUrl, + href: href + }); + } + + return JSON.stringify(results); + } catch (err) { + console.error("Search failed:", err); + return JSON.stringify([]); + } +} + +async function extractDetails(url) { + try { + const response = await fetchv2(url); + const html = await response.text(); + + const match = html.match(/<div aria-label="Description"[^>]*>\s*<p>(.*?)<\/p>/s); + const description = match ? match[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) { + try { + const response = await fetchv2(url); + const html = await response.text(); + + const seasonMatch = html.match(/<span class="fz12 ttu fwb db mb1 primary-co">(\d+) seasons?/i); + const totalSeasons = seasonMatch ? parseInt(seasonMatch[1], 10) : null; + + const postIdMatch = html.match(/<body[^>]+postid-(\d+)/i); + const postId = postIdMatch ? postIdMatch[1] : null; + + const results = []; + + if (!totalSeasons || !postId) { + results.push({ + href: url, + number: 1 + }); + } else { + for (let season = 1; season <= totalSeasons; season++) { + const apiUrl = `https://coflix.cc/wp-json/apiflix/v1/series/${postId}/${season}`; + const seasonResp = await fetchv2(apiUrl); + const seasonData = await seasonResp.json(); + + if (seasonData.episodes && Array.isArray(seasonData.episodes)) { + seasonData.episodes.forEach(ep => { + results.push({ + href: ep.links, + number: parseInt(ep.number, 10) + }); + }); + } + } + } + + return JSON.stringify(results); + } catch (err) { + return JSON.stringify([{ + href: "Error", + number: "Error" + }]); + } +} + +async function extractStreamUrl(url) { + try { + const response = await fetchv2(url); + const html = await response.text(); + + const iframeMatch = html.match(/<iframe[^>]+src="([^"]+)"/i); + const iframeUrl = iframeMatch ? iframeMatch[1] : null; + if (!iframeUrl) throw new Error("Iframe not found"); + + const iframeResp = await fetchv2(iframeUrl); + const iframeHtml = await iframeResp.text(); + + const uqloadMatch = iframeHtml.match(/<li[^>]*onclick="showVideo\('([^']+)',\s*'[^']+'\)">\s*<img[^>]*src="static\/server\/uqload[^"]*"[^>]*>\s*<span>Uqload/i); + if (uqloadMatch) { + const uqload = atob(uqloadMatch[1]); + console.log("Uqload URL:" + uqload); + const uqResp = await fetchv2(uqload); + const uqHtml = await uqResp.text(); + + const mp4Match = uqHtml.match(/sources:\s*\[\s*"([^"]+\.mp4)"/); + if (mp4Match) { + const mp4Url = mp4Match[1]; + console.log("MP4 URL:" + mp4Url); + return mp4Url; + } + } + + const fileMonMatch = iframeHtml.match(/<li[^>]*onclick="showVideo\('([^']+)',\s*'[^']+'\)">\s*<img[^>]*src="static\/server\/filemoon[^"]*"[^>]*>\s*<span>FileMon/i); + if (fileMonMatch) { + const filemoon = atob(fileMonMatch[1]); + console.log("FileMon URL:" + filemoon); + const fileResp = await fetchv2(filemoon); + const fileHtml = await fileResp.text(); + return filemoonExtractor(fileHtml, filemoon); + } + + return "https://files.catbox.moe/avolvc.mp4"; + + } catch (err) { + return "https://files.catbox.moe/avolvc.mp4"; + } +} + + + +/* SCHEME START */ +/* {REQUIRED PLUGINS: unbaser} */ + +/** + * @name filemoonExtractor + * @author Cufiy - Inspired by Churly + */ + +async function filemoonExtractor(html, url = null) { + // check if contains iframe, if does, extract the src and get the url + const regex = /<iframe[^>]+src="([^"]+)"[^>]*><\/iframe>/; + const match = html.match(regex); + if (match) { + console.log("Iframe URL: " + match[1]); + const iframeUrl = match[1]; + const iframeResponse = await soraFetch(iframeUrl, { + headers: { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3", + "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", + "Referer": url, + } + }); + console.log("Iframe Response: " + iframeResponse.status); + html = await iframeResponse.text(); + } + // console.log("HTML: " + html); + // get /<script[^>]*>([\s\S]*?)<\/script>/gi + const scriptRegex = /<script[^>]*>([\s\S]*?)<\/script>/gi; + const scripts = []; + let scriptMatch; + while ((scriptMatch = scriptRegex.exec(html)) !== null) { + scripts.push(scriptMatch[1]); + } + // get the script with eval and m3u8 + const evalRegex = /eval\((.*?)\)/; + const m3u8Regex = /m3u8/; + // console.log("Scripts: " + scripts); + const evalScript = scripts.find(script => evalRegex.test(script) && m3u8Regex.test(script)); + if (!evalScript) { + console.log("No eval script found"); + return null; + } + const unpackedScript = unpack(evalScript); + // get the m3u8 url + const m3u8Regex2 = /https?:\/\/[^\s]+master\.m3u8[^\s]*?(\?[^"]*)?/; + const m3u8Match = unpackedScript.match(m3u8Regex2); + if (m3u8Match) { + return m3u8Match[0]; + } else { + console.log("No M3U8 URL found"); + return null; + } +} + + +/* REMOVE_START */ + + +class Unbaser { + constructor(base) { + this.ALPHABET = { + 62: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", + 95: "' !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'", + }; + this.dictionary = {}; + this.base = base; + if (36 < base && base < 62) { + this.ALPHABET[base] = this.ALPHABET[base] || + this.ALPHABET[62].substr(0, base); + } + if (2 <= base && base <= 36) { + this.unbase = (value) => parseInt(value, base); + } + else { + try { + [...this.ALPHABET[base]].forEach((cipher, index) => { + this.dictionary[cipher] = index; + }); + } + catch (er) { + throw Error("Unsupported base encoding."); + } + this.unbase = this._dictunbaser; + } + } + _dictunbaser(value) { + let ret = 0; + [...value].reverse().forEach((cipher, index) => { + ret = ret + ((Math.pow(this.base, index)) * this.dictionary[cipher]); + }); + return ret; + } +} + + +function unpack(source) { + let { payload, symtab, radix, count } = _filterargs(source); + if (count != symtab.length) { + throw Error("Malformed p.a.c.k.e.r. symtab."); + } + let unbase; + try { + unbase = new Unbaser(radix); + } + catch (e) { + throw Error("Unknown p.a.c.k.e.r. encoding."); + } + function lookup(match) { + const word = match; + let word2; + if (radix == 1) { + word2 = symtab[parseInt(word)]; + } + else { + word2 = symtab[unbase.unbase(word)]; + } + return word2 || word; + } + source = payload.replace(/\b\w+\b/g, lookup); + return _replacestrings(source); + function _filterargs(source) { + const juicers = [ + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\), *(\d+), *(.*)\)\)/, + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\)/, + ]; + for (const juicer of juicers) { + const args = juicer.exec(source); + if (args) { + let a = args; + if (a[2] == "[]") { + } + try { + return { + payload: a[1], + symtab: a[4].split("|"), + radix: parseInt(a[2]), + count: parseInt(a[3]), + }; + } + catch (ValueError) { + throw Error("Corrupted p.a.c.k.e.r. data."); + } + } + } + throw Error("Could not make sense of p.a.c.k.e.r data (unexpected code structure)"); + } + function _replacestrings(source) { + return source; + } +} + + +/** + * Uses Sora's fetchv2 on ipad, fallbacks to regular fetch on Windows + * @author ShadeOfChaos + * + * @param {string} url The URL to make the request to. + * @param {object} [options] The options to use for the request. + * @param {object} [options.headers] The headers to send with the request. + * @param {string} [options.method='GET'] The method to use for the request. + * @param {string} [options.body=null] The body of the request. + * + * @returns {Promise<Response|null>} The response from the server, or null if the + * request failed. + */ +async function soraFetch(url, options = { headers: {}, method: 'GET', body: null }) { + try { + return await fetchv2(url, options.headers ?? {}, options.method ?? 'GET', options.body ?? null); + } catch(e) { + try { + return await fetch(url, options); + } catch(error) { + return null; + } + } +} +/* REMOVE_END */ + +/* SCHEME END */ \ No newline at end of file diff --git a/coflix/coflix.json b/coflix/coflix.json new file mode 100644 index 0000000..a759984 --- /dev/null +++ b/coflix/coflix.json @@ -0,0 +1,19 @@ +{ + "sourceName": "CoFlix", + "iconUrl": "https://coflix.cc/wp-content/uploads/2022/10/cropped-coflix-180x180-1.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "French", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://uqload.cx/", + "searchBaseUrl": "https://uqload.cx/", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/coflix/coflix.js", + "type": "shows/movies/anime", + "asyncJS": true, + "softsub": false, + "downloadSupport": false +} diff --git a/crimsonfansubs/crimsonfansubs.js b/crimsonfansubs/crimsonfansubs.js new file mode 100644 index 0000000..3a7776b --- /dev/null +++ b/crimsonfansubs/crimsonfansubs.js @@ -0,0 +1,116 @@ +async function searchResults(keyword) { + const results = []; + const response = await fetchv2(`https://crimsonfansubs.com/?s=${keyword}`); + const html = await response.text(); + + const regex = /<article class="bs"[^>]*>.*?<a href="([^"]+)"[^>]*>.*?<img src="([^"]+)"[^>]*>.*?<h2[^>]*>(.*?)<\/h2>/gs; + + 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); +} + +async function extractDetails(url) { + const results = []; + const response = await fetchv2(url); + const html = await response.text(); + + const match = html.match(/<div class="entry-content"[^>]*>([\s\S]*?)<\/div>/); + + let description = "N/A"; + if (match) { + description = match[1] + .replace(/<[^>]+>/g, '') + .replace(/&#(\d+);/g, (_, code) => String.fromCharCode(code)) + .replace(/"/g, '"') + .replace(/'/g, "'") + .replace(/&/g, "&") + .trim(); + } + + results.push({ + description: description, + aliases: 'N/A', + airdate: 'N/A' + }); + + return JSON.stringify(results); +} + +async function extractEpisodes(url) { + const results = []; + const response = await fetchv2(url); + const html = await response.text(); + + const regex = /<a href="([^"]+)">\s*<div class="epl-num">([\d.]+)<\/div>/g; + + let match; + while ((match = regex.exec(html)) !== null) { + results.push({ + href: match[1].trim(), + number: parseInt(match[2], 10) + }); + } + results.reverse(); + return JSON.stringify(results); +} + +async function extractStreamUrl(url) { + try { + const response = await fetchv2(url); + const html = await response.text(); + + let videoId; + + const geoMatch = html.match(/https:\/\/geo\.dailymotion\.com\/player\/([a-zA-Z0-9]+)\.js"\s*data-video="([a-zA-Z0-9]+)"/); + if (geoMatch) { + videoId = geoMatch[2]; + } else { + const embedMatch = html.match(/https:\/\/www\.dailymotion\.com\/embed\/video\/([a-zA-Z0-9]+)/); + if (embedMatch) { + videoId = embedMatch[1]; + } else { + return "no dailymotion video found"; + } + } + + const metaRes = await fetchv2(`https://www.dailymotion.com/player/metadata/video/${videoId}`); + const metaJson = await metaRes.json(); + const hlsLink = metaJson.qualities?.auto?.[0]?.url; + if (!hlsLink) return "no hls"; + + async function getBestHls(hlsUrl) { + try { + const res = await fetchv2(hlsUrl); + const text = await res.text(); + const regex = /#EXT-X-STREAM-INF:.*RESOLUTION=(\d+)x(\d+).*?\n(https?:\/\/[^\n]+)/g; + const streams = []; + let match; + while ((match = regex.exec(text)) !== null) { + streams.push({ width: parseInt(match[1]), height: parseInt(match[2]), url: match[3] }); + } + if (streams.length === 0) return hlsUrl; + streams.sort((a, b) => b.height - a.height); + return streams[0].url; + } catch { + return hlsUrl; + } + } + + const bestHls = await getBestHls(hlsLink); + return bestHls; + + } catch { + const empty = "{ streams: ["; + console.log("Extracted stream result:" + JSON.stringify(empty)); + return JSON.stringify(empty); + } +} + diff --git a/crimsonfansubs/crimsonfansubs.json b/crimsonfansubs/crimsonfansubs.json new file mode 100644 index 0000000..5f3432a --- /dev/null +++ b/crimsonfansubs/crimsonfansubs.json @@ -0,0 +1,19 @@ +{ + "sourceName": "CrimsonFanSubs", + "iconUrl": "https://i3.wp.com/crimsonfansubs.com/wp-content/uploads/2021/06/cropped-favicon-image-192x192.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "Chinese", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://crimsonfansubs.com/", + "searchBaseUrl": "https://crimsonfansubs.com/", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/crimsonfansubs/crimsonfansubs.js", + "type": "anime", + "asyncJS": true, + "softsub": false, + "downloadSupport": false +} diff --git a/cuevana3/cuevana3.js b/cuevana3/cuevana3.js new file mode 100644 index 0000000..90a04c6 --- /dev/null +++ b/cuevana3/cuevana3.js @@ -0,0 +1,346 @@ +async function searchResults(keyword) { + const results = []; + const response = await fetchv2("https://www.cuevana3.eu/search?q=" + encodeURIComponent(keyword)); + const html = await response.text(); + const baseUrl = "https://www.cuevana3.eu"; + + const regex = /<a\s+href="([^"]+)">([\s\S]*?)<\/a>/gs; + let match; + + while ((match = regex.exec(html)) !== null) { + const href = match[1].trim(); + const linkContent = match[2]; + + if (linkContent.includes('<span class="TpTv BgA">Serie</span>')) { + continue; + } + + const imgMatch = linkContent.match(/<img[^>]+src="([^"]+)"[^>]*>/); + const titleMatch = linkContent.match(/<span class="Title[^"]*"[^>]*>([^<]+)<\/span>/); + + if (imgMatch && titleMatch) { + results.push({ + title: titleMatch[1].trim(), + image: baseUrl + decodeURIComponent(imgMatch[1].replace(/&/g, "&").trim()), + href: baseUrl + href + }); + } + } + + return JSON.stringify(results); +} + +async function extractDetails(url) { + const results = []; + const response = await fetchv2(url); + const html = await response.text(); + + const regex = /<div class="Description">\s*<p>(.*?)<\/p>/s; + const match = regex.exec(html); + + const description = match ? match[1].trim() : "N/A"; + + results.push({ + description: description, + aliases: 'N/A', + airdate: 'N/A' + }); + + return JSON.stringify(results); +} + +async function extractEpisodes(url) { + const results = []; + const response = await fetchv2(url); + const html = await response.text(); + console.log(url); + + const jsonMatch = html.match(/<script id="__NEXT_DATA__" type="application\/json">(.*?)<\/script>/s); + if (jsonMatch) { + try { + const data = JSON.parse(jsonMatch[1]); + const seasons = data.props?.pageProps?.thisSerie?.seasons || []; + + for (const season of seasons) { + for (const episode of season.episodes || []) { + results.push({ + href: "https://www.cuevana3.eu/" + episode.url.slug, + number: episode.number + }); + } + } + + if (results.length > 0) return JSON.stringify(results); + } catch (e) { + console.warn("Failed to parse __NEXT_DATA__ episodes", e); + } + } + + try { + const data = JSON.parse(jsonMatch[1]); + const videos = data.props?.pageProps?.thisMovie?.videos || {}; + + const getStreamwishLink = (videosArray) => { + const entry = videosArray.find(v => v.cyberlocker === 'streamwish'); + return entry ? entry.result : null; + }; + + const latino = getStreamwishLink(videos.latino || []); + const spanish = getStreamwishLink(videos.spanish || []); + const subt = getStreamwishLink(videos.english || []); + + const parts = []; + if (latino) parts.push(`Español latino:streamwish:${latino}`); + if (spanish) parts.push(`Español:streamwish:${spanish}`); + if (subt) parts.push(`Subtitulado:streamwish:${subt}`); + + if (parts.length > 0) { + results.push({ + href: parts.join(' | '), + number: 1 + }); + return JSON.stringify(results); + } + } catch (e) { + console.warn("Failed to parse videos from __NEXT_DATA__", e); + } + + const tableRowRegex = /<tr[^>]*>[\s\S]*?<td[^>]*>[\s\S]*?(?:#?\d+[\s\S]*?)?(?:<!--[^]*?-->)?\s*([^<]+)[^<]*<\/td>[\s\S]*?<td[^>]*>([^<]+)[^<]*<\/td>[\s\S]*?<td[^>]*><span>([^<]+)<\/span><\/td>[\s\S]*?<a[^>]+href="([^"]+)"[^>]*class="Button STPb">Descargar<\/a>[\s\S]*?<\/tr>/gi; + + const linksMap = { + "Español latino": null, + "Español": null, + "Subtitulado": null + }; + + let match; + while ((match = tableRowRegex.exec(html)) !== null) { + const [, providerRaw, languageRaw, , link] = match; + const provider = providerRaw.trim().toLowerCase(); + const language = languageRaw.trim(); + + if (!provider.includes("streamwish")) continue; + + if (language === 'Latino') linksMap["Español latino"] = link; + else if (language === 'Español') linksMap["Español"] = link; + else if (language === 'Subtitulado') linksMap["Subtitulado"] = link; + } + + const parts = []; + for (const [lang, link] of Object.entries(linksMap)) { + if (link) parts.push(`${lang}:streamwish:${link}`); + } + + if (parts.length > 0) { + results.push({ + href: parts.join(' | '), + number: 1 + }); + } + + return JSON.stringify(results); +} + +async function extractStreamUrl(urlData) { + const languageBlocks = urlData.split("|"); + const streamwishLinks = {}; + + for (const block of languageBlocks) { + const match = block.match(/^([^:]+):streamwish:(.+)$/); + if (!match) continue; + const lang = match[1].trim(); + const link = match[2].trim(); + if (link && link !== "null") { + if (lang === "Español latino") streamwishLinks.latino = link; + else if (lang === "Español") streamwishLinks.espanol = link; + else if (lang === "Subtitulado") streamwishLinks.subtitulado = link; + } + } + + console.log("Parsed streamwishLinks: " + JSON.stringify(streamwishLinks)); + + async function getVarUrl(link) { + try { + const res = await fetchv2(link); + const html = await res.text(); + const match = html.match(/var\s+url\s*=\s*['"]([^'"]+)['"]/); + return match ? match[1] : null; + } catch (err) { + return null; + } + } + + async function getFinalStream(link) { + try { + const res = await fetchv2(link); + const html = await res.text(); + const scriptMatch = html.match(/eval\(function\(p,a,c,k,e,d\)\{[\s\S]+?\}\('.*?'\,\d+\,\d+\,'.*?'\.split\('\|'\)\)\)/); + if (!scriptMatch) return null; + const packed = scriptMatch[0]; + console.log("Obfuscated eval function found: " + packed.substring(0, 500)); + const unpacked = unpack(packed); + console.log("Unpacked code snippet: " + unpacked.substring(0, 500)); + const hls2Match = unpacked.match(/"hls2"\s*:\s*"([^"]+)"/); + return hls2Match ? hls2Match[1] : null; + } catch (err) { + console.log("Error in getFinalStream: " + err); + return null; + } + } + + function rewriteStreamwishUrl(url) { + return url.replace(/^https?:\/\/streamwish\.to\//, "https://xenolyzb.com/"); + } + + const streams = []; + + for (const [langKey, embedUrl] of Object.entries(streamwishLinks)) { + const varUrlRaw = await getVarUrl(embedUrl); + if (!varUrlRaw) continue; + const varUrl = rewriteStreamwishUrl(varUrlRaw); + const hls2 = await getFinalStream(varUrl); + if (!hls2) continue; + + const label = + langKey === "latino" ? "LATINO" : + langKey === "espanol" ? "CASTELLANO" : + langKey === "subtitulado" ? "SUB" : + langKey.toUpperCase(); + + streams.push(label, hls2); + } + + if (streams.length === 0) { + return "deijdjiwjdiwaidjwaodjiasjdioajidofejhifophwufipheuipfhepiuwghuiphfipehifspehwuipfhewipfhewhfuihfdlshfjkshfudislvhjdkslvsdjkl"; + } + + const final = { + streams + }; + console.log(JSON.stringify(final)); + return JSON.stringify(final); +} + + + + +/* + * UNPACKER MODULE + * Credit to GitHub user "mnsrulz" for Unpacker Node library + * https://github.com/mnsrulz/unpacker + */ + +class Unbaser { + constructor(base) { + /* Functor for a given base. Will efficiently convert + strings to natural numbers. */ + this.ALPHABET = { + 62: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", + 95: "' !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'", + }; + this.dictionary = {}; + this.base = base; + // fill elements 37...61, if necessary + if (36 < base && base < 62) { + this.ALPHABET[base] = this.ALPHABET[base] || + this.ALPHABET[62].substr(0, base); + } + // If base can be handled by int() builtin, let it do it for us + if (2 <= base && base <= 36) { + this.unbase = (value) => parseInt(value, base); + } + else { + // Build conversion dictionary cache + try { + [...this.ALPHABET[base]].forEach((cipher, index) => { + this.dictionary[cipher] = index; + }); + } + catch (er) { + throw Error("Unsupported base encoding."); + } + this.unbase = this._dictunbaser; + } + } + _dictunbaser(value) { + /* Decodes a value to an integer. */ + let ret = 0; + [...value].reverse().forEach((cipher, index) => { + ret = ret + ((Math.pow(this.base, index)) * this.dictionary[cipher]); + }); + return ret; + } +} + +function detect(source) { + /* Detects whether `source` is P.A.C.K.E.R. coded. */ + return source.replace(" ", "").startsWith("eval(function(p,a,c,k,e,"); +} + +function unpack(source) { + /* Unpacks P.A.C.K.E.R. packed js code. */ + let { payload, symtab, radix, count } = _filterargs(source); + if (count != symtab.length) { + throw Error("Malformed p.a.c.k.e.r. symtab."); + } + let unbase; + try { + unbase = new Unbaser(radix); + } + catch (e) { + throw Error("Unknown p.a.c.k.e.r. encoding."); + } + function lookup(match) { + /* Look up symbols in the synthetic symtab. */ + const word = match; + let word2; + if (radix == 1) { + //throw Error("symtab unknown"); + word2 = symtab[parseInt(word)]; + } + else { + word2 = symtab[unbase.unbase(word)]; + } + return word2 || word; + } + source = payload.replace(/\b\w+\b/g, lookup); + return _replacestrings(source); + function _filterargs(source) { + /* Juice from a source file the four args needed by decoder. */ + const juicers = [ + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\), *(\d+), *(.*)\)\)/, + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\)/, + ]; + for (const juicer of juicers) { + //const args = re.search(juicer, source, re.DOTALL); + const args = juicer.exec(source); + if (args) { + let a = args; + if (a[2] == "[]") { + //don't know what it is + // a = list(a); + // a[1] = 62; + // a = tuple(a); + } + try { + return { + payload: a[1], + symtab: a[4].split("|"), + radix: parseInt(a[2]), + count: parseInt(a[3]), + }; + } + catch (ValueError) { + throw Error("Corrupted p.a.c.k.e.r. data."); + } + } + } + throw Error("Could not make sense of p.a.c.k.e.r data (unexpected code structure)"); + } + function _replacestrings(source) { + /* Strip string lookup table (list) and replace values in source. */ + /* Need to work on this. */ + return source; + } +} + diff --git a/cuevana3/cuevana3.json b/cuevana3/cuevana3.json new file mode 100644 index 0000000..20afc12 --- /dev/null +++ b/cuevana3/cuevana3.json @@ -0,0 +1,19 @@ +{ + "sourceName": "Cuevana3", + "iconUrl": "https://www.cuevana3.eu/apple-touch-icon.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "Spanish (DUB/SUB)", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://www.cuevana3.eu/", + "searchBaseUrl": "https://www.cuevana3.eu/", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/cuevana3/cuevana3.js", + "type": "shows/movies", + "asyncJS": true, + "softsub": false, + "downloadSupport": true +} diff --git a/ddys/ddys.js b/ddys/ddys.js new file mode 100644 index 0000000..d5c8f33 --- /dev/null +++ b/ddys/ddys.js @@ -0,0 +1,82 @@ +async function searchResults(keyword) { + const searchUrl = `https://ddys.pro/?s=${encodeURIComponent(keyword)}`; + try { + const response = await fetchv2(searchUrl); + const html = await response.text(); + const results = []; + + const articleRegex = /<article id="post-\d+"[^>]*>[\s\S]*?<h2 class="post-title"><a href="([^"]+)"[^>]*>([^<]+)<\/a><\/h2>/g; + let match; + + while ((match = articleRegex.exec(html)) !== null) { + const href = match[1].trim(); + const title = match[2].trim(); + const imageUrl = "https://i.ibb.co/Y4b38sTG/Search-has-no-images.png"; + + results.push({ + title, + image: imageUrl, + href + }); + } + + console.log(results); + return JSON.stringify(results); + } catch (error) { + throw error; + } +} + +async function extractDetails(url) { + const response = await fetchv2(url); + const html = await response.text(); + + const aliasMatch = html.match(/又名:\s*([^<]+)/); + const descriptionMatch = html.match(/简介:\s*([\s\S]*?)<\/div>/); + const airdateMatch = html.match(/年份:\s*(\d{4})/); + + const alias = aliasMatch ? aliasMatch[1].trim() : "N/A"; + const description = descriptionMatch ? descriptionMatch[1].trim() : "No description available."; + const airdate = airdateMatch ? airdateMatch[1].trim() : "N/A"; + + const details = [{ + alias, + description, + airdate + }]; + + console.log(JSON.stringify(details)); + return JSON.stringify(details); +} + +async function extractEpisodes(url) { + const response = await fetchv2(url); + const html = await response.text(); + const episodes = []; + + const scriptMatch = html.match(/<script class="wp-playlist-script" type="application\/json">(\{[\s\S]*?\})<\/script>/); + + if (scriptMatch) { + const jsonData = JSON.parse(scriptMatch[1]); + + jsonData.tracks.forEach(track => { + if (track.src0) { + const episodeMatch = track.src0.match(/S01E(\d+)/) || track.caption.match(/\u7b2c(\d+)\u96c6/); + const episodeNumber = episodeMatch ? parseInt(episodeMatch[1], 10) : null; // Convert to integer + + episodes.push({ + href: `https://v.ddys.pro${track.src0.trim()}`, + number: episodeNumber + }); + } + }); + } + + console.log(episodes); + return JSON.stringify(episodes); +} + + +async function extractStreamUrl(url) { + return url; +} diff --git a/ddys/ddys.json b/ddys/ddys.json new file mode 100644 index 0000000..82ceb20 --- /dev/null +++ b/ddys/ddys.json @@ -0,0 +1,17 @@ +{ + "sourceName": "DDYS", + "iconUrl": "https://ddys.pro/apple-touch-icon.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "Chinese", + "streamType": "mp4", + "quality": "1080p", + "baseUrl": "https://ddys.pro/", + "searchBaseUrl": "https://ddys.pro/?s=%s", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/ddys/ddys.js", + "asyncJS": true, + "type": "movies/shows" +} diff --git a/dev/dev.js b/dev/dev.js new file mode 100644 index 0000000..c2f1a02 --- /dev/null +++ b/dev/dev.js @@ -0,0 +1,77 @@ +async function searchResults(keyword) { + const results = []; + try { + const response = await fetchv2(); + const html = await response.text(); + + 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(); + + 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(); + + 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 { + const response = await fetchv2(url); + const html = await response.text(); + + return "https://error.org/"; + } catch (err) { + return "https://error.org/"; + } +} diff --git a/dev/dev.json b/dev/dev.json new file mode 100644 index 0000000..8494127 --- /dev/null +++ b/dev/dev.json @@ -0,0 +1,17 @@ +{ + "sourceName": "Development", + "iconUrl": "https://cdn-icons-png.flaticon.com/512/3953/3953226.png", + "author": { + "name": "Dev", + "icon": "https://cdn-icons-png.flaticon.com/512/3953/3953226.png" + }, + "version": "1.0.0", + "language": "Dev", + "streamType": "Dev", + "quality": "Dev", + "baseUrl": "https://google.com/", + "searchBaseUrl": "https://google.com/?q=%s", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/dev/dev.js", + "asyncJS": true, + "type": "anime" +} diff --git a/divxfilmeonline/divxfilmeonline.js b/divxfilmeonline/divxfilmeonline.js new file mode 100644 index 0000000..8b2acfb --- /dev/null +++ b/divxfilmeonline/divxfilmeonline.js @@ -0,0 +1,246 @@ +function decodeHtmlEntities(text) { + return text + .replace(/’/g, "'") + .replace(/“/g, '"') + .replace(/”/g, '"') + .replace(/…/g, '...') + .replace(/&/g, '&') + .replace(/"/g, '"') + .replace(/</g, '<') + .replace(/>/g, '>') + .replace(/&#(\d+);/g, (_, num) => String.fromCharCode(num)); +} + +async function searchResults(keyword) { + const results = []; + const regex = /<li class="border-radius-5 box-shadow">[\s\S]*?<img[^>]+src="([^"]+)"[^>]+title="([^"]+)"[^>]*>[\s\S]*?<a[^>]+href="([^"]+)"[^>]*>/gi; + + try { + const response = await fetchv2("https://www1.divxfilmeonline.net/?s=" + encodeURIComponent(keyword)); + const html = await response.text(); + + regex.lastIndex = 0; + let match; + while ((match = regex.exec(html)) !== null) { + results.push({ + image: match[1].trim(), + title: decodeHtmlEntities(match[2].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 { + return JSON.stringify([{ + description: "Description not available", + aliases: "N/A", + airdate: "N/A" + }]); + } catch (err) { + return JSON.stringify([{ + description: "Error", + aliases: "Error", + airdate: "Error" + }]); + } +} +async function extractEpisodes(url) { + try { + const response = await fetchv2(url); + const html = await response.text(); + + const filemoonMatch = /<li[^>]*class="server server-active"[^>]*data-vs="([^"]*fastvid\.co[^"]*)"[^>]*>Filemoon/i.exec(html); + + if (filemoonMatch) { + return JSON.stringify([{ + href: filemoonMatch[1].trim(), + number: 1 + }]); + } else { + throw new Error("Filemoon episode not found"); + } + } catch (err) { + return JSON.stringify([{ + href: "Error", + number: "Error", + message: err.message + }]); + } +} + +async function extractStreamUrl(url) { + try { + const headers = { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3", + "Referer": "https://www1.divxfilmeonline.net/" + }; + const response = await fetchv2(url, headers); + const html = await response.text(); + + const iframeMatch = /<iframe[^>]+src="([^"]+)"[^>]*><\/iframe>/i.exec(html); + if (!iframeMatch) throw new Error("Iframe not found"); + const iframeUrl = iframeMatch[1].trim(); + + const iframeResponse = await fetchv2(iframeUrl, headers); + const iframeContent = await iframeResponse.text(); + + console.log(`[Debug] Iframe content: ${iframeContent}`); + + const scriptMatch = iframeContent.match(/<script[^>]*>\s*(eval\(function\(p,a,c,k,e,d.*?\)[\s\S]*?)<\/script>/); + + if (!scriptMatch) throw new Error("Obfuscated script not found"); + const evalContent = scriptMatch[1]; + + const unpackedScript = unpack(evalContent); + + const fileMatch = /sources:\s*\[\s*\{\s*file:\s*"([^"]+\.m3u8[^"]*)"/.exec(unpackedScript); + if (!fileMatch) throw new Error("Stream URL not found"); + + + const subtitleMatch = /tracks:\s*\[\s*\{\s*file:\s*"([^"]+\.vtt[^"]*)"/.exec(unpackedScript); + + return JSON.stringify({ + stream: fileMatch[1], + subtitles: subtitleMatch ? subtitleMatch[1] : null + }); + } catch (err) { + console.error("Error extracting stream URL:", err); + return JSON.stringify({ + stream: "https://files.catbox.moe/avolvc.mp4", + subtitles: null + }); + } +} + + + +/* + * UNPACKER MODULE + * Credit to GitHub user "mnsrulz" for Unpacker Node library + * https://github.com/mnsrulz/unpacker + */ + +class Unbaser { + constructor(base) { + /* Functor for a given base. Will efficiently convert + strings to natural numbers. */ + this.ALPHABET = { + 62: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", + 95: "' !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'", + }; + this.dictionary = {}; + this.base = base; + // fill elements 37...61, if necessary + if (36 < base && base < 62) { + this.ALPHABET[base] = this.ALPHABET[base] || + this.ALPHABET[62].substr(0, base); + } + // If base can be handled by int() builtin, let it do it for us + if (2 <= base && base <= 36) { + this.unbase = (value) => parseInt(value, base); + } + else { + // Build conversion dictionary cache + try { + [...this.ALPHABET[base]].forEach((cipher, index) => { + this.dictionary[cipher] = index; + }); + } + catch (er) { + throw Error("Unsupported base encoding."); + } + this.unbase = this._dictunbaser; + } + } + _dictunbaser(value) { + /* Decodes a value to an integer. */ + let ret = 0; + [...value].reverse().forEach((cipher, index) => { + ret = ret + ((Math.pow(this.base, index)) * this.dictionary[cipher]); + }); + return ret; + } +} + +function detect(source) { + /* Detects whether `source` is P.A.C.K.E.R. coded. */ + return source.replace(" ", "").startsWith("eval(function(p,a,c,k,e,"); +} + +function unpack(source) { + /* Unpacks P.A.C.K.E.R. packed js code. */ + let { payload, symtab, radix, count } = _filterargs(source); + if (count != symtab.length) { + throw Error("Malformed p.a.c.k.e.r. symtab."); + } + let unbase; + try { + unbase = new Unbaser(radix); + } + catch (e) { + throw Error("Unknown p.a.c.k.e.r. encoding."); + } + function lookup(match) { + /* Look up symbols in the synthetic symtab. */ + const word = match; + let word2; + if (radix == 1) { + //throw Error("symtab unknown"); + word2 = symtab[parseInt(word)]; + } + else { + word2 = symtab[unbase.unbase(word)]; + } + return word2 || word; + } + source = payload.replace(/\b\w+\b/g, lookup); + return _replacestrings(source); + function _filterargs(source) { + /* Juice from a source file the four args needed by decoder. */ + const juicers = [ + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\), *(\d+), *(.*)\)\)/, + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\)/, + ]; + for (const juicer of juicers) { + //const args = re.search(juicer, source, re.DOTALL); + const args = juicer.exec(source); + if (args) { + let a = args; + if (a[2] == "[]") { + //don't know what it is + // a = list(a); + // a[1] = 62; + // a = tuple(a); + } + try { + return { + payload: a[1], + symtab: a[4].split("|"), + radix: parseInt(a[2]), + count: parseInt(a[3]), + }; + } + catch (ValueError) { + throw Error("Corrupted p.a.c.k.e.r. data."); + } + } + } + throw Error("Could not make sense of p.a.c.k.e.r data (unexpected code structure)"); + } + function _replacestrings(source) { + /* Strip string lookup table (list) and replace values in source. */ + /* Need to work on this. */ + return source; + } +} + + diff --git a/divxfilmeonline/divxfilmeonline.json b/divxfilmeonline/divxfilmeonline.json new file mode 100644 index 0000000..5bf7a5c --- /dev/null +++ b/divxfilmeonline/divxfilmeonline.json @@ -0,0 +1,19 @@ +{ + "sourceName": "DivXFilmeOnline", + "iconUrl": "https://www1.divxfilmeonline.net/wp-content/uploads/2015/11/cropped-movies-40-180x180.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "Romanian (DUB/SUB)", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://divxfilmeonline.net/", + "searchBaseUrl": "https://divxfilmeonline.net/", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/divxfilmeonline/divxfilmeonline.js", + "type": "shows/movies", + "asyncJS": true, + "softsub": true, + "downloadSupport": true +} diff --git a/dmand5/dmand5.js b/dmand5/dmand5.js new file mode 100644 index 0000000..c6f0caf --- /dev/null +++ b/dmand5/dmand5.js @@ -0,0 +1,116 @@ +async function searchResults(keyword) { + const results = []; + try { + const workerUrl = "https://passthrough-worker.simplepostrequest.workers.dev/?url=" + + encodeURIComponent("https://www.dmand5.com/index.php?m=vod-search") + + "&type=multipart&body=" + encodeURIComponent(JSON.stringify({ + wd: keyword + })); + + const response = await fetchv2(workerUrl); + const html = await response.text(); + + const regex = /<a href="(\/detail\/\d+\.html)" title="(.*?)" target="_blank"><img .*?src="(.*?)"/g; + let match; + while ((match = regex.exec(html)) !== null) { + results.push({ + title: match[2].trim(), + image: match[3].trim(), + href: "https://www.dmand5.com" + match[1].trim() + }); + } + + console.log("Search results:" + JSON.stringify(results)); + 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 class="des">(.*?)<\/div>/s); + 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 blockMatch = html.match(/<ul class="mn_list_li_movie"[^>]*>([\s\S]*?)<\/ul>/); + const blockHtml = blockMatch ? blockMatch[1] : ""; + + const regex = /<a href="(\/play\/\d+-\d+-(\d+)\.html)"[^>]*>第\d+集<\/a>/g; + let match; + + while ((match = regex.exec(blockHtml)) !== null) { + results.push({ + href: parseInt(match[2], 10) + " https://www.dmand5.com" + match[1].trim(), + number: parseInt(match[2], 10) + }); + } + + console.log("Episodes:" + JSON.stringify(results)); + return JSON.stringify(results); + } catch (err) { + return JSON.stringify([{ + href: "Error", + number: "Error" + }]); + } +} +async function extractStreamUrl(url) { + try { + const leadingNumberMatch = url.match(/^(\d+)\s+(.+)$/); + const episodeNumber = leadingNumberMatch ? parseInt(leadingNumberMatch[1], 10) : 1; + const cleanUrl = leadingNumberMatch ? leadingNumberMatch[2] : url; + + const fetchUrl = cleanUrl; + + console.log(fetchUrl); + const response = await fetchv2(fetchUrl); + const html = await response.text(); + + const macMatch = html.match(/mac_url\s*=\s*unescape\(\s*'([^']+)'\s*\)/s); + if (!macMatch) return "https://files.catbox.moe/avolvc.mp4"; + + let raw = macMatch[1]; + + raw = raw.replace(/%u([\dA-F]{4})/gi, (_, g1) => + String.fromCharCode(parseInt(g1, 16)) + ); + + const decoded = decodeURIComponent(raw); + + const episodes = decoded.split("#"); + + const epEntry = episodes[episodeNumber - 1] || episodes[0]; + const hlsUrl = epEntry.split("$")[1]; + + return hlsUrl || "https://files.catbox.moe/avolvc.mp4"; + } catch (err) { + return "https://files.catbox.moe/avolvc.mp4"; + } +} diff --git a/dmand5/dmand5.json b/dmand5/dmand5.json new file mode 100644 index 0000000..64822d5 --- /dev/null +++ b/dmand5/dmand5.json @@ -0,0 +1,19 @@ +{ + "sourceName": "Dmand5", + "iconUrl": "https://www.dmand5.com/template/dmd8pc/images/logo.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "Chinese", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://www.dmand5.com/", + "searchBaseUrl": "https://www.dmand5.com/", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/dmand5/dmand5.js", + "type": "anime", + "asyncJS": true, + "softsub": false, + "downloadSupport": false +} diff --git a/donghuastream/donghuastream.js b/donghuastream/donghuastream.js new file mode 100644 index 0000000..1ea58af --- /dev/null +++ b/donghuastream/donghuastream.js @@ -0,0 +1,117 @@ +async function searchResults(keyword) { + const results = []; + const response = await fetchv2(`https://donghuastream.org/?s=${keyword}`); + const html = await response.text(); + + const regex = /<article class="bs"[^>]*>.*?<a[^>]+href="([^"]+)"[^>]*>.*?<img[^>]+src="([^"]+)"[^>]*>.*?<h2[^>]*>(.*?)<\/h2>/gs; + + 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); +} + + +async function extractDetails(url) { + const results = []; + const response = await fetchv2(url); + const html = await response.text(); + + const match = html.match(/<div class="entry-content"[^>]*>([\s\S]*?)<\/div>/); + + let description = "N/A"; + if (match) { + description = match[1] + .replace(/<[^>]+>/g, '') + .replace(/&#(\d+);/g, (_, code) => String.fromCharCode(code)) + .replace(/"/g, '"') + .replace(/'/g, "'") + .replace(/&/g, "&") + .trim(); + } + + results.push({ + description: description, + aliases: 'N/A', + airdate: 'N/A' + }); + + return JSON.stringify(results); +} + +async function extractEpisodes(url) { + const results = []; + const response = await fetchv2(url); + const html = await response.text(); + + const regex = /<a href="([^"]+)">.*?<div class="epl-num">(\d+)/gs; + let match; + + while ((match = regex.exec(html)) !== null) { + results.push({ + href: match[1].trim(), + number: parseInt(match[2], 10) + }); + } + + return JSON.stringify(results.reverse()); +} + +async function extractStreamUrl(url) { + try { + const response = await fetchv2(url); + const html = await response.text(); + + let iframeMatch = html.match(/dailymotion\.com\/embed\/video\/([a-zA-Z0-9]+)/); + + if (!iframeMatch) { + iframeMatch = html.match(/geo\.dailymotion\.com\/player\/[a-z0-9]+\.html\?video=([a-zA-Z0-9]+)/); + } + + if (!iframeMatch) return "no iframe"; + + const videoId = iframeMatch[1]; + const metaRes = await fetchv2(`https://www.dailymotion.com/player/metadata/video/${videoId}`); + const metaJson = await metaRes.json(); + const hlsLink = metaJson.qualities?.auto?.[0]?.url; + + if (!hlsLink) return "no hls"; + + async function getBestHls(hlsUrl) { + try { + const res = await fetchv2(hlsUrl); + const text = await res.text(); + const regex = /#EXT-X-STREAM-INF:.*RESOLUTION=(\d+)x(\d+).*?\n(https?:\/\/[^\n]+)/g; + const streams = []; + let match; + + while ((match = regex.exec(text)) !== null) { + streams.push({ + width: parseInt(match[1]), + height: parseInt(match[2]), + url: match[3] + }); + } + + if (streams.length === 0) return hlsUrl; + streams.sort((a, b) => b.height - a.height); + return streams[0].url; + } catch { + return hlsUrl; + } + } + + const bestHls = await getBestHls(hlsLink); + return bestHls; + } catch { + const empty = "{ streams: ["; + console.log("Extracted stream result:" + JSON.stringify(empty)); + return JSON.stringify(empty); + } +} diff --git a/donghuastream/donghuastream.json b/donghuastream/donghuastream.json new file mode 100644 index 0000000..f0cd9c2 --- /dev/null +++ b/donghuastream/donghuastream.json @@ -0,0 +1,19 @@ +{ + "sourceName": "DonghuaStream", + "iconUrl": "https://donghuastream.org/wp-content/uploads/2023/05/cropped-Donghua-Stream-scaled-1-192x192.jpeg", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "Chinese", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://donghuastream.org/", + "searchBaseUrl": "https://donghuastream.org/", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/donghuastream/donghuastream.js", + "type": "anime", + "asyncJS": true, + "softsub": false, + "downloadSupport": false +} diff --git a/dora-video/dora-video.js b/dora-video/dora-video.js new file mode 100644 index 0000000..d3e700f --- /dev/null +++ b/dora-video/dora-video.js @@ -0,0 +1,90 @@ +async function searchResults(keyword) { + const results = []; + const response = await fetchv2(`https://www.dora-video.cn/search/${keyword}/`); + const html = await response.text(); + + const regex = /<div class="card-img-bili">.*?<a href="(.*?)">.*?data-url="(.*?)".*?<span class="title">(.*?)<\/span>/gs; + + let match; + while ((match = regex.exec(html)) !== null) { + results.push({ + title: (match[3] || "").trim().replace(/<font color="red">a<\/font>|<font color="red">|<\/font>/g, " "), + image: "https://i.ibb.co/ds7r6YJy/Search-has-no-images.png", + href: match[1].trim() + }); + } + + return JSON.stringify(results); +} + +async function extractDetails(url) { + const results = []; + const response = await fetchv2(url); + const html = await response.text(); + + const regex = /<div class="card-body">.*?<h3.*?>(.*?)<\/h3>.*?<p>(.*?)<\/p>.*?<p>(.*?)<\/p>/s; + const match = regex.exec(html); + + let description = "N/A"; + if (match) { + description = match[3] + .replace(/ /g, " ") + .replace(/\s+/g, " ") + .trim(); + } + + results.push({ + description: description, + aliases: "N/A", + airdate: "N/A" + }); + + return JSON.stringify(results); +} + + + +async function extractEpisodes(url) { + const results = []; + const response = await fetchv2(url); + const html = await response.text(); + console.error(html); + const regex = /<a href="([^"]+)"[ ]?class="btn btn-outline-primary btn-space">([^<]+)<\/a>/g; + let match; + let count = 1; + + while ((match = regex.exec(html)) !== null) { + results.push({ + href: match[1].trim(), + number: count + }); + count++; + } + + return JSON.stringify(results); +} + + +async function extractStreamUrl(url) { + const response = await fetchv2(url); + const html = await response.text(); + const match = html.match(/<iframe[^>]+src="([^"]+)"[^>]*>/); + if (!match) return null; + + const iframeUrl = match[1]; + + const headers = { + 'Referer': 'https://www.dora-video.cn/' + }; + const responseTwo = await fetchv2(iframeUrl, headers); + const htmlTwo = await responseTwo.text(); + + const m3u8Match = htmlTwo.match(/url: ['"]([^'"]+\.m3u8)['"],/); + + + const m3u8Url = m3u8Match[1]; + console.error(m3u8Url); + + return m3u8Url; + } + diff --git a/dora-video/dora-video.json b/dora-video/dora-video.json new file mode 100644 index 0000000..a778faa --- /dev/null +++ b/dora-video/dora-video.json @@ -0,0 +1,17 @@ +{ + "sourceName": "Dora-Video", + "iconUrl": "https://www.dora-video.cn/favicon.ico", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.4", + "language": "Chinese (DUB)", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://www.dora-video.cn/", + "searchBaseUrl": "https://www.dora-video.cn/search/%s", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/dora-video/dora-video.js", + "asyncJS": true, + "type": "anime" +} diff --git a/dorabash/dorabash.js b/dorabash/dorabash.js new file mode 100644 index 0000000..d43e06d --- /dev/null +++ b/dorabash/dorabash.js @@ -0,0 +1,1225 @@ +async function searchResults(keyword) { + const results = []; + try { + const response = await fetchv2("https://dorabash.com/?s=" + encodeURIComponent(keyword)); + const html = await response.text(); + + const regex = /<article class="bs"[\s\S]*?<a href="([^"]+)"[^>]*>[\s\S]*?<img src="([^"]+)"[^>]*title="([^"]+)"[\s\S]*?<\/a>/g; + + let match; + while ((match = regex.exec(html)) !== null) { + results.push({ + href: match[1].trim(), + image: match[2].trim(), + title: cleanHtmlSymbols(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 regex = /<div class="entry-content"[^>]*itemprop="description"[^>]*>\s*<p>([\s\S]*?)<\/p>/i; + const match = regex.exec(html); + + const description = match ? match[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 = /<li[^>]*>\s*<a href="([^"]+)">[\s\S]*?<div class="epl-num">([^<]+)<\/div>/g; + + let match; + while ((match = regex.exec(html)) !== null) { + let numText = match[2].trim(); + let number = /^\d+$/.test(numText) ? parseInt(numText, 10) : 1; + + results.push({ + href: match[1].trim(), + number: number + }); + } + + return JSON.stringify(results.reverse()); + } catch (err) { + return JSON.stringify([{ + href: "Error", + number: "Error" + }]); + } +} +async function extractStreamUrl(url) { + try { + const response = await fetchv2(url); + const html = await response.text(); + console.log("Fetched HTML:", html); + + const player2Regex = /<option[^>]*value="([^"]+)"[^>]*data-index="2"[^>]*>/; + const player2Match = player2Regex.exec(html); + + if (player2Match) { + const decodedHtml = atob(player2Match[1]); + const iframeSrcMatch = /<iframe[^>]*src="([^"]*filemoon[^"]*)"/.exec(decodedHtml); + + if (!iframeSrcMatch) throw new Error("Filemoon iframe not found for Player 2"); + + const filemoonUrl = iframeSrcMatch[1]; + const providers = { [filemoonUrl]: "filemoon" }; + const streams = await multiExtractor(providers); + + const hlsLink = streams[1]; + console.log("Player 2 HLS:", hlsLink); + + return hlsLink; + } + + const player1Regex = /<option[^>]*value="([^"]+)"[^>]*data-index="1"[^>]*>/; + const player1Match = player1Regex.exec(html); + + if (player1Match) { + const decodedHtml = atob(player1Match[1]); + const iframeSrcMatch = /<iframe[^>]*src="([^"]+)"/.exec(decodedHtml); + + if (!iframeSrcMatch) throw new Error("Iframe not found for Player 1"); + + const player1Url = iframeSrcMatch[1]; + + if (!player1Url.includes("filemoon")) { + throw new Error("Player 1 is not filemoon"); + } + + const providers = { [player1Url]: "filemoon" }; + const streams = await multiExtractor(providers); + + const hlsLink = streams[1]; + + return hlsLink; + } + + throw new Error("Neither Player 2 nor Player 1 found"); + } catch (err) { + console.error("Error in extractStreamUrl:", err); + return "https://files.catbox.moe/avolvc.mp4"; + } +} + + +function cleanHtmlSymbols(string) { + if (!string) return ""; + return string + .replace(/’/g, "'") + .replace(/–/g, "-") + .replace(/&#[0-9]+;/g, "") + .replace(/\r?\n|\r/g, " ") + .replace(/\s+/g, " ") + .trim(); +} + +// ⚠️ DO NOT EDIT BELOW THIS LINE ⚠️ +// EDITING THIS FILE COULD BREAK THE UPDATER AND CAUSE ISSUES WITH THE EXTRACTOR + +/* {GE START} */ +/* {VERSION: 1.1.4} */ + +/** + * @name global_extractor.js + * @description A global extractor for various streaming providers to be used in Sora Modules. + * @author Cufiy + * @url https://github.com/JMcrafter26/sora-global-extractor + * @license CUSTOM LICENSE - see https://github.com/JMcrafter26/sora-global-extractor/blob/main/LICENSE + * @date 2025-08-13 03:44:07 + * @version 1.1.4 + * @note This file was generated automatically. + * The global extractor comes with an auto-updating feature, so you can always get the latest version. https://github.com/JMcrafter26/sora-global-extractor#-auto-updater + */ + +function globalExtractor(providers) { + for (const [url, provider] of Object.entries(providers)) { + try { + const streamUrl = extractStreamUrlByProvider(url, provider); + // check if streamUrl is not null, a string, and starts with http or https + if (streamUrl && typeof streamUrl === "string" && (streamUrl.startsWith("http"))) { + return streamUrl; + // if its an array, get the value that starts with http + } else if (Array.isArray(streamUrl)) { + const httpStream = streamUrl.find(url => url.startsWith("http")); + if (httpStream) { + return httpStream; + } + } else if (streamUrl || typeof streamUrl !== "string") { + // check if it's a valid stream URL + return null; + } + + } catch (error) { + // Ignore the error and try the next provider + } + } + return null; +} + +async function multiExtractor(providers) { + /* this scheme should be returned as a JSON object + { + "streams": [ + "FileMoon", + "https://filemoon.example/stream1.m3u8", + "StreamWish", + "https://streamwish.example/stream2.m3u8", + "Okru", + "https://okru.example/stream3.m3u8", + "MP4", + "https://mp4upload.example/stream4.mp4", + "Default", + "https://default.example/stream5.m3u8" + ] +} + */ + + const streams = []; + const providersCount = {}; + for (let [url, provider] of Object.entries(providers)) { + try { + // if provider starts with "direct-", then add the url to the streams array directly + if (provider.startsWith("direct-")) { + const directName = provider.slice(7); // remove "direct-" prefix + if (directName && directName.length > 0) { + streams.push(directName, url); + } else { + streams.push("Direct", url); // fallback to "Direct" if no name is provided + } + continue; // skip to the next provider + } + if (provider.startsWith("direct")) { + provider = provider.slice(7); // remove "direct-" prefix + if (provider && provider.length > 0) { + streams.push(provider, url); + } else { + streams.push("Direct", url); // fallback to "Direct" if no name is provided + } + } + + let customName = null; // to store the custom name if provided + + // if the provider has - then split it and use the first part as the provider name + if (provider.includes("-")) { + const parts = provider.split("-"); + provider = parts[0]; // use the first part as the provider name + customName = parts.slice(1).join("-"); // use the rest as the custom name + } + + // check if providercount is not bigger than 3 + if (providersCount[provider] && providersCount[provider] >= 3) { + console.log(`Skipping ${provider} as it has already 3 streams`); + continue; + } + let streamUrl = await extractStreamUrlByProvider(url, provider); + + if (streamUrl && Array.isArray(streamUrl)) { + const httpStream = streamUrl.find(url => url.startsWith("http")); + if (httpStream) { + streamUrl = httpStream; + } + } + // check if provider is already in streams, if it is, add a number to it + if ( + !streamUrl || + typeof streamUrl !== "string" || + !streamUrl.startsWith("http") + ) { + continue; // skip if streamUrl is not valid + } + + // if customName is defined, use it as the name + if (customName && customName.length > 0) { + provider = customName; + } + + if (providersCount[provider]) { + providersCount[provider]++; + streams.push( + provider.charAt(0).toUpperCase() + + provider.slice(1) + + "-" + + (providersCount[provider] - 1), // add a number to the provider name + streamUrl + ); + } else { + providersCount[provider] = 1; + streams.push( + provider.charAt(0).toUpperCase() + provider.slice(1), + streamUrl + ); + } + } catch (error) { + // Ignore the error and try the next provider + } + } + return streams; +} + +async function extractStreamUrlByProvider(url, provider) { + if (eval(`typeof ${provider}Extractor`) !== "function") { + // skip if the extractor is not defined + console.log(`Extractor for provider ${provider} is not defined, skipping...`); + return null; + } + let headers = { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3", + "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", + "Accept-Language": "en-US,en;q=0.5", + "Referer": url, + "Connection": "keep-alive", + "x-Requested-With": "XMLHttpRequest" + }; + if(provider == 'bigwarp') { + delete headers["User-Agent"]; + headers["x-requested-with"] = "XMLHttpRequest"; + } else if (provider == 'vk') { + headers["encoding"] = "windows-1251"; // required + } else if (provider == 'sibnet') { + headers["encoding"] = "windows-1251"; // required + } + + // fetch the url + // and pass the response to the extractor function + console.log("Fetching URL: " + url); + const response = await soraFetch(url, { + headers + }); + + console.log("Response: " + response.status); + let html = response.text ? await response.text() : response; + // if title contains redirect, then get the redirect url + const title = html.match(/<title>(.*?)<\/title>/); + if (title && title[1].toLowerCase().includes("redirect")) { + const redirectUrl = html.match(/<meta http-equiv="refresh" content="0;url=(.*?)"/); + const redirectUrl2 = html.match(/window\.location\.href\s*=\s*["'](.*?)["']/); + const redirectUrl3 = html.match(/window\.location\.replace\s*\(\s*["'](.*?)["']\s*\)/); + if (redirectUrl) { + console.log("Redirect URL: " + redirectUrl[1]); + url = redirectUrl[1]; + html = await soraFetch(url, { + headers + }); + html = html.text ? await html.text() : html; + + } else if (redirectUrl2) { + console.log("Redirect URL 2: " + redirectUrl2[1]); + url = redirectUrl2[1]; + html = await soraFetch(url, { + headers + }); + html = html.text ? await html.text() : html; + } else if (redirectUrl3) { + console.log("Redirect URL 3: " + redirectUrl3[1]); + url = redirectUrl3[1]; + html = await soraFetch(url, { + headers + }); + html = html.text ? await html.text() : html; + } else { + console.log("No redirect URL found"); + } + } + + // console.log("HTML: " + html); + switch (provider) { + case "bigwarp": + try { + return await bigwarpExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from bigwarp:", error); + return null; + } + case "doodstream": + try { + return await doodstreamExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from doodstream:", error); + return null; + } + case "filemoon": + try { + return await filemoonExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from filemoon:", error); + return null; + } + case "megacloud": + try { + return await megacloudExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from megacloud:", error); + return null; + } + case "mp4upload": + try { + return await mp4uploadExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from mp4upload:", error); + return null; + } + case "sibnet": + try { + return await sibnetExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from sibnet:", error); + return null; + } + case "uqload": + try { + return await uqloadExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from uqload:", error); + return null; + } + case "vidmoly": + try { + return await vidmolyExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from vidmoly:", error); + return null; + } + case "vidoza": + try { + return await vidozaExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from vidoza:", error); + return null; + } + case "voe": + try { + return await voeExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from voe:", error); + return null; + } + + default: + throw new Error(`Unknown provider: ${provider}`); + } +} + + + + + + +//////////////////////////////////////////////// +// EXTRACTORS // +//////////////////////////////////////////////// + +// DO NOT EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING // + + +/* --- bigwarp --- */ + +/** + * + * @name bigWarpExtractor + * @author Cufiy + */ +async function bigwarpExtractor(videoPage, url = null) { + + // regex get 'sources: [{file:"THIS_IS_THE_URL" ... ' + const scriptRegex = /sources:\s*\[\{file:"([^"]+)"/; + // const scriptRegex = + const scriptMatch = scriptRegex.exec(videoPage); + const bwDecoded = scriptMatch ? scriptMatch[1] : false; + console.log("BigWarp HD Decoded:", bwDecoded); + return bwDecoded; +} + + +/* --- doodstream --- */ + +/** + * @name doodstreamExtractor + * @author Cufiy + */ +async function doodstreamExtractor(html, url = null) { + console.log("DoodStream extractor called"); + console.log("DoodStream extractor URL: " + url); + const streamDomain = url.match(/https:\/\/(.*?)\//, url)[0].slice(8, -1); + const md5Path = html.match(/'\/pass_md5\/(.*?)',/, url)[0].slice(11, -2); + const token = md5Path.substring(md5Path.lastIndexOf("/") + 1); + const expiryTimestamp = new Date().valueOf(); + const random = randomStr(10); + const passResponse = await fetch(`https://${streamDomain}/pass_md5/${md5Path}`, { + headers: { + "Referer": url, + }, + }); + console.log("DoodStream extractor response: " + passResponse.status); + const responseData = await passResponse.text(); + const videoUrl = `${responseData}${random}?token=${token}&expiry=${expiryTimestamp}`; + console.log("DoodStream extractor video URL: " + videoUrl); + return videoUrl; +} +function randomStr(length) { + const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; + let result = ""; + for (let i = 0; i < length; i++) { + result += characters.charAt(Math.floor(Math.random() * characters.length)); + } + return result; +} + + +/* --- filemoon --- */ + +/* {REQUIRED PLUGINS: unbaser} */ +/** + * @name filemoonExtractor + * @author Cufiy - Inspired by Churly + */ +async function filemoonExtractor(html, url = null) { + // check if contains iframe, if does, extract the src and get the url + const regex = /<iframe[^>]+src="([^"]+)"[^>]*><\/iframe>/; + const match = html.match(regex); + if (match) { + console.log("Iframe URL: " + match[1]); + const iframeUrl = match[1]; + const iframeResponse = await soraFetch(iframeUrl, { + headers: { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3", + "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", + "Referer": url, + } + }); + console.log("Iframe Response: " + iframeResponse.status); + html = await iframeResponse.text(); + } + // console.log("HTML: " + html); + // get /<script[^>]*>([\s\S]*?)<\/script>/gi + const scriptRegex = /<script[^>]*>([\s\S]*?)<\/script>/gi; + const scripts = []; + let scriptMatch; + while ((scriptMatch = scriptRegex.exec(html)) !== null) { + scripts.push(scriptMatch[1]); + } + // get the script with eval and m3u8 + const evalRegex = /eval\((.*?)\)/; + const m3u8Regex = /m3u8/; + // console.log("Scripts: " + scripts); + const evalScript = scripts.find(script => evalRegex.test(script) && m3u8Regex.test(script)); + if (!evalScript) { + console.log("No eval script found"); + return null; + } + const unpackedScript = unpack(evalScript); + // get the m3u8 url + const m3u8Regex2 = /https?:\/\/[^\s]+master\.m3u8[^\s]*?(\?[^"]*)?/; + const m3u8Match = unpackedScript.match(m3u8Regex2); + if (m3u8Match) { + return m3u8Match[0]; + } else { + console.log("No M3U8 URL found"); + return null; + } +} + + + + +/* --- megacloud --- */ + +/** + * @name megacloudExtractor + * @author ShadeOfChaos + */ + +// Megacloud V3 specific +async function megacloudExtractor(html, embedUrl) { + const CHARSET = Array.from({ length: 95 }, (_, i) => String.fromCharCode(i + 32)); + const xraxParams = embedUrl.split('/').pop(); + const xrax = xraxParams.includes('?') ? xraxParams.split('?')[0] : xraxParams; + const nonce = await getNonce(embedUrl); + // return decrypt(secretKey, nonce, encryptedText); + try { + const response = await fetch(`https://megacloud.blog/embed-2/v3/e-1/getSources?id=${xrax}&_k=${nonce}`); + const rawSourceData = await response.json(); + const encrypted = rawSourceData?.sources; + let decryptedSources = null; + if (rawSourceData?.encrypted == false) { + decryptedSources = rawSourceData.sources; + } + if (decryptedSources == null) { + decryptedSources = await getDecryptedSourceV3(encrypted, nonce); + if (!decryptedSources) throw new Error("Failed to decrypt source"); + } + console.log("Decrypted sources:" + JSON.stringify(decryptedSources, null, 2)); + // return the first source if it's an array + if (Array.isArray(decryptedSources) && decryptedSources.length > 0) { + try { + return decryptedSources[0].file; + } catch (error) { + console.log("Error extracting MegaCloud stream URL:" + error); + return null; + } + } + // return { + // status: true, + // result: { + // sources: decryptedSources, + // tracks: rawSourceData.tracks, + // intro: rawSourceData.intro ?? null, + // outro: rawSourceData.outro ?? null, + // server: rawSourceData.server ?? null + // } + // } + } catch (error) { + console.error(`[ERROR][decryptSources] Error decrypting ${embedUrl}:`, error); + return { + status: false, + error: error?.message || 'Failed to get HLS link' + }; + } + /** + * Computes a key based on the given secret and nonce. + * The key is used to "unlock" the encrypted data. + * The computation of the key is based on the following steps: + * 1. Concatenate the secret and nonce. + * 2. Compute a hash value of the concatenated string using a simple + * hash function (similar to Java's String.hashCode()). + * 3. Compute the remainder of the hash value divided by the maximum + * value of a 64-bit signed integer. + * 4. Use the result as a XOR mask to process the characters of the + * concatenated string. + * 5. Rotate the XOR-processed string by a shift amount equal to the + * hash value modulo the length of the XOR-processed string plus 5. + * 6. Interleave the rotated string with the reversed nonce string. + * 7. Take a substring of the interleaved string of length equal to 96 + * plus the hash value modulo 33. + * 8. Convert each character of the substring to a character code + * between 32 and 126 (inclusive) by taking the remainder of the + * character code divided by 95 and adding 32. + * 9. Join the resulting array of characters into a string and return it. + * @param {string} secret - The secret string + * @param {string} nonce - The nonce string + * @returns {string} The computed key + */ + function computeKey(secret, nonce) { + const secretAndNonce = secret + nonce; + let hashValue = 0n; + for (const char of secretAndNonce) { + hashValue = BigInt(char.charCodeAt(0)) + hashValue * 31n + (hashValue << 7n) - hashValue; + } + const maximum64BitSignedIntegerValue = 0x7fffffffffffffffn; + const hashValueModuloMax = hashValue % maximum64BitSignedIntegerValue; + const xorMask = 247; + const xorProcessedString = [...secretAndNonce] + .map(char => String.fromCharCode(char.charCodeAt(0) ^ xorMask)) + .join(''); + const xorLen = xorProcessedString.length; + const shiftAmount = (Number(hashValueModuloMax) % xorLen) + 5; + const rotatedString = xorProcessedString.slice(shiftAmount) + xorProcessedString.slice(0, shiftAmount); + const reversedNonceString = nonce.split('').reverse().join(''); + let interleavedString = ''; + const maxLen = Math.max(rotatedString.length, reversedNonceString.length); + for (let i = 0; i < maxLen; i++) { + interleavedString += (rotatedString[i] || '') + (reversedNonceString[i] || ''); + } + const length = 96 + (Number(hashValueModuloMax) % 33); + const partialString = interleavedString.substring(0, length); + return [...partialString] + .map(ch => String.fromCharCode((ch.charCodeAt(0) % 95) + 32)) + .join(''); + } + /** + * Encrypts a given text using a columnar transposition cipher with a given key. + * The function arranges the text into a grid of columns and rows determined by the key length, + * fills the grid column by column based on the sorted order of the key characters, + * and returns the encrypted text by reading the grid row by row. + * + * @param {string} text - The text to be encrypted. + * @param {string} key - The key that determines the order of columns in the grid. + * @returns {string} The encrypted text. + */ + function columnarCipher(text, key) { + const columns = key.length; + const rows = Math.ceil(text.length / columns); + const grid = Array.from({ length: rows }, () => Array(columns).fill('')); + const columnOrder = [...key] + .map((char, idx) => ({ char, idx })) + .sort((a, b) => a.char.charCodeAt(0) - b.char.charCodeAt(0)); + let i = 0; + for (const { idx } of columnOrder) { + for (let row = 0; row < rows; row++) { + grid[row][idx] = text[i++] || ''; + } + } + return grid.flat().join(''); + } + /** + * Deterministically unshuffles an array of characters based on a given key phrase. + * The function simulates a pseudo-random shuffling using a numeric seed derived + * from the key phrase. This ensures that the same character array and key phrase + * will always produce the same output, allowing for deterministic "unshuffling". + * @param {Array} characters - The array of characters to unshuffle. + * @param {string} keyPhrase - The key phrase used to generate the seed for the + * pseudo-random number generator. + * @returns {Array} A new array representing the deterministically unshuffled characters. + */ + function deterministicUnshuffle(characters, keyPhrase) { + let seed = [...keyPhrase].reduce((acc, char) => (acc * 31n + BigInt(char.charCodeAt(0))) & 0xffffffffn, 0n); + const randomNumberGenerator = (upperLimit) => { + seed = (seed * 1103515245n + 12345n) & 0x7fffffffn; + return Number(seed % BigInt(upperLimit)); + }; + const shuffledCharacters = characters.slice(); + for (let i = shuffledCharacters.length - 1; i > 0; i--) { + const j = randomNumberGenerator(i + 1); + [shuffledCharacters[i], shuffledCharacters[j]] = [shuffledCharacters[j], shuffledCharacters[i]]; + } + return shuffledCharacters; + } + /** + * Decrypts an encrypted text using a secret key and a nonce through multiple rounds of decryption. + * The decryption process includes base64 decoding, character substitution using a pseudo-random + * number generator, a columnar transposition cipher, and deterministic unshuffling of the character set. + * Finally, it extracts and parses the decrypted JSON string or verifies it using a regex pattern. + * + * @param {string} secretKey - The key used to decrypt the text. + * @param {string} nonce - A nonce for additional input to the decryption key. + * @param {string} encryptedText - The text to be decrypted, encoded in base64. + * @param {number} [rounds=3] - The number of decryption rounds to perform. + * @returns {Object|null} The decrypted JSON object if successful, or null if parsing fails. + */ + function decrypt(secretKey, nonce, encryptedText, rounds = 3) { + let decryptedText = Buffer.from(encryptedText, 'base64').toString('utf-8'); + const keyPhrase = computeKey(secretKey, nonce); + for (let round = rounds; round >= 1; round--) { + const encryptionPassphrase = keyPhrase + round; + let seed = [...encryptionPassphrase].reduce((acc, char) => (acc * 31n + BigInt(char.charCodeAt(0))) & 0xffffffffn, 0n); + const randomNumberGenerator = (upperLimit) => { + seed = (seed * 1103515245n + 12345n) & 0x7fffffffn; + return Number(seed % BigInt(upperLimit)); + }; + decryptedText = [...decryptedText] + .map(char => { + const charIndex = CHARSET.indexOf(char); + if (charIndex === -1) return char; + const offset = randomNumberGenerator(95); + return CHARSET[(charIndex - offset + 95) % 95]; + }) + .join(''); + decryptedText = columnarCipher(decryptedText, encryptionPassphrase); + const shuffledCharset = deterministicUnshuffle(CHARSET, encryptionPassphrase); + const mappingArr = {}; + shuffledCharset.forEach((c, i) => (mappingArr[c] = CHARSET[i])); + decryptedText = [...decryptedText].map(char => mappingArr[char] || char).join(''); + } + const lengthString = decryptedText.slice(0, 4); + let length = parseInt(lengthString, 10); + if (isNaN(length) || length <= 0 || length > decryptedText.length - 4) { + console.error('Invalid length in decrypted string'); + return decryptedText; + } + const decryptedString = decryptedText.slice(4, 4 + length); + try { + return JSON.parse(decryptedString); + } catch (e) { + console.warn('Could not parse decrypted string, unlikely to be valid. Using regex to verify'); + const regex = /"file":"(.*?)".*?"type":"(.*?)"/; + const match = encryptedText.match(regex); + const matchedFile = match?.[1]; + const matchType = match?.[2]; + if (!matchedFile || !matchType) { + console.error('Could not match file or type in decrypted string'); + return null; + } + return decryptedString; + } + } + /** + * Tries to extract the MegaCloud nonce from the given embed URL. + * + * Fetches the HTML of the page, and tries to extract the nonce from it. + * If that fails, it sends a request with the "x-requested-with" header set to "XMLHttpRequest" + * and tries to extract the nonce from that HTML. + * + * If all else fails, it logs the HTML of both requests and returns null. + * + * @param {string} embedUrl The URL of the MegaCloud embed + * @returns {string|null} The extracted nonce, or null if it couldn't be found + */ + async function getNonce(embedUrl) { + const res = await fetch(embedUrl, { headers: { "referer": "https://anicrush.to/", "x-requested-with": "XMLHttpRequest" } }); + const html = await res.text(); + const match0 = html.match(/\<meta[\s\S]*?name="_gg_fb"[\s\S]*?content="([\s\S]*?)">/); + if (match0?.[1]) { + return match0[1]; + } + const match1 = html.match(/_is_th:(\S*?)\s/); + if (match1?.[1]) { + return match1[1]; + } + const match2 = html.match(/data-dpi="([\s\S]*?)"/); + if (match2?.[1]) { + return match2[1]; + } + const match3 = html.match(/_lk_db[\s]?=[\s\S]*?x:[\s]"([\S]*?)"[\s\S]*?y:[\s]"([\S]*?)"[\s\S]*?z:[\s]"([\S]*?)"/); + if (match3?.[1] && match3?.[2] && match3?.[3]) { + return "" + match3[1] + match3[2] + match3[3]; + } + const match4 = html.match(/nonce="([\s\S]*?)"/); + if (match4?.[1]) { + if (match4[1].length >= 32) return match4[1]; + } + const match5 = html.match(/_xy_ws = "(\S*?)"/); + if (match5?.[1]) { + return match5[1]; + } + const match6 = html.match(/[a-zA-Z0-9]{48}]/); + if (match6?.[1]) { + return match6[1]; + } + return null; + } + async function getDecryptedSourceV3(encrypted, nonce) { + let decrypted = null; + const keys = await asyncGetKeys(); + for(let key in keys) { + try { + if (!encrypted) { + console.log("Encrypted source missing in response") + return null; + } + decrypted = decrypt(keys[key], nonce, encrypted); + if(!Array.isArray(decrypted) || decrypted.length <= 0) { + // Failed to decrypt source + continue; + } + for(let source of decrypted) { + if(source != null && source?.file?.startsWith('https://')) { + // Malformed decrypted source + continue; + } + } + console.log("Functioning key:", key); + return decrypted; + } catch(error) { + console.error('Error:', error); + console.error(`[${ new Date().toLocaleString() }] Key did not work: ${ key }`); + continue; + } + } + return null; + } + async function asyncGetKeys() { + const resolution = await Promise.allSettled([ + fetchKey("ofchaos", "https://ac-api.ofchaos.com/api/key"), + fetchKey("yogesh", "https://raw.githubusercontent.com/yogesh-hacker/MegacloudKeys/refs/heads/main/keys.json"), + fetchKey("esteven", "https://raw.githubusercontent.com/carlosesteven/e1-player-deobf/refs/heads/main/output/key.json") + ]); + const keys = resolution.filter(r => r.status === 'fulfilled' && r.value != null).reduce((obj, r) => { + let rKey = Object.keys(r.value)[0]; + let rValue = Object.values(r.value)[0]; + if (typeof rValue === 'string') { + obj[rKey] = rValue.trim(); + return obj; + } + obj[rKey] = rValue?.mega ?? rValue?.decryptKey ?? rValue?.MegaCloud?.Anime?.Key ?? rValue?.megacloud?.key ?? rValue?.key ?? rValue?.megacloud?.anime?.key ?? rValue?.megacloud; + return obj; + }, {}); + if (keys.length === 0) { + throw new Error("Failed to fetch any decryption key"); + } + return keys; + } + function fetchKey(name, url, timeout = 1000) { + return new Promise(async (resolve) => { + try { + const response = await fetch(url, { method: 'get', timeout: timeout }); + const key = await response.text(); + let trueKey = null; + try { + trueKey = JSON.parse(key); + } catch (e) { + trueKey = key; + } + resolve({ [name]: trueKey }) + } catch (error) { + resolve(null); + } + }); + } +} + + +/* --- mp4upload --- */ + +/** + * @name mp4uploadExtractor + * @author Cufiy + */ +async function mp4uploadExtractor(html, url = null) { + // src: "https://a4.mp4upload.com:183/d/xkx3b4etz3b4quuo66rbmyqtjjoivahfxp27f35pti45rzapbvj5xwb4wuqtlpewdz4dirfp/video.mp4" + const regex = /src:\s*"([^"]+)"/; + const match = html.match(regex); + if (match) { + return match[1]; + } else { + console.log("No match found for mp4upload extractor"); + return null; + } +} + + +/* --- sibnet --- */ + +/** + * @name sibnetExtractor + * @author scigward + */ +async function sibnetExtractor(html, embedUrl) { + try { + const videoMatch = html.match( + /player\.src\s*\(\s*\[\s*\{\s*src\s*:\s*["']([^"']+)["']/i + ); + if (!videoMatch || !videoMatch[1]) { + throw new Error("Sibnet video source not found"); + } + const videoPath = videoMatch[1]; + const videoUrl = videoPath.startsWith("http") + ? videoPath + : `https://video.sibnet.ru${videoPath}`; + return videoUrl; + } catch (error) { + console.log("SibNet extractor error: " + error.message); + return null; + } +} + + +/* --- uqload --- */ + +/** + * @name uqloadExtractor + * @author scigward + */ +async function uqloadExtractor(html, embedUrl) { + try { + const match = html.match(/sources:\s*\[\s*"([^"]+\.mp4)"\s*\]/); + const videoSrc = match ? match[1] : ""; + return videoSrc; + } catch (error) { + console.log("uqloadExtractor error:", error.message); + return null; + } +} + + +/* --- vidmoly --- */ + +/** + * @name vidmolyExtractor + * @author Ibro + */ +async function vidmolyExtractor(html, url = null) { + const regexSub = /<option value="([^"]+)"[^>]*>\s*SUB - Omega\s*<\/option>/; + const regexFallback = /<option value="([^"]+)"[^>]*>\s*Omega\s*<\/option>/; + const fallback = + /<option value="([^"]+)"[^>]*>\s*SUB v2 - Omega\s*<\/option>/; + let match = + html.match(regexSub) || html.match(regexFallback) || html.match(fallback); + if (match) { + const decodedHtml = atob(match[1]); // Decode base64 + const iframeMatch = decodedHtml.match(/<iframe\s+src="([^"]+)"/); + if (!iframeMatch) { + console.log("Vidmoly extractor: No iframe match found"); + return null; + } + const streamUrl = iframeMatch[1].startsWith("//") + ? "https:" + iframeMatch[1] + : iframeMatch[1]; + const responseTwo = await fetchv2(streamUrl); + const htmlTwo = await responseTwo.text(); + const m3u8Match = htmlTwo.match(/sources:\s*\[\{file:"([^"]+\.m3u8)"/); + return m3u8Match ? m3u8Match[1] : null; + } else { + console.log("Vidmoly extractor: No match found, using fallback"); + // regex the sources: [{file:"this_is_the_link"}] + const sourcesRegex = /sources:\s*\[\{file:"(https?:\/\/[^"]+)"\}/; + const sourcesMatch = html.match(sourcesRegex); + let sourcesString = sourcesMatch + ? sourcesMatch[1].replace(/'/g, '"') + : null; + return sourcesString; + } +} + + +/* --- vidoza --- */ + +/** + * @name vidozaExtractor + * @author Cufiy + */ +async function vidozaExtractor(html, url = null) { + const regex = /<source src="([^"]+)" type='video\/mp4'>/; + const match = html.match(regex); + if (match) { + return match[1]; + } else { + console.log("No match found for vidoza extractor"); + return null; + } +} + + +/* --- voe --- */ + +/** + * @name voeExtractor + * @author Cufiy + */ +function voeExtractor(html, url = null) { +// Extract the first <script type="application/json">...</script> + const jsonScriptMatch = html.match( + /<script[^>]+type=["']application\/json["'][^>]*>([\s\S]*?)<\/script>/i + ); + if (!jsonScriptMatch) { + console.log("No application/json script tag found"); + return null; + } + + const obfuscatedJson = jsonScriptMatch[1].trim(); + let data; + try { + data = JSON.parse(obfuscatedJson); + } catch (e) { + throw new Error("Invalid JSON input."); + } + if (!Array.isArray(data) || typeof data[0] !== "string") { + throw new Error("Input doesn't match expected format."); + } + let obfuscatedString = data[0]; + // Step 1: ROT13 + let step1 = voeRot13(obfuscatedString); + // Step 2: Remove patterns + let step2 = voeRemovePatterns(step1); + // Step 3: Base64 decode + let step3 = voeBase64Decode(step2); + // Step 4: Subtract 3 from each char code + let step4 = voeShiftChars(step3, 3); + // Step 5: Reverse string + let step5 = step4.split("").reverse().join(""); + // Step 6: Base64 decode again + let step6 = voeBase64Decode(step5); + // Step 7: Parse as JSON + let result; + try { + result = JSON.parse(step6); + } catch (e) { + throw new Error("Final JSON parse error: " + e.message); + } + // console.log("Decoded JSON:", result); + // check if direct_access_url is set, not null and starts with http + if (result && typeof result === "object") { + const streamUrl = + result.direct_access_url || + result.source + .map((source) => source.direct_access_url) + .find((url) => url && url.startsWith("http")); + if (streamUrl) { + console.log("Voe Stream URL: " + streamUrl); + return streamUrl; + } else { + console.log("No stream URL found in the decoded JSON"); + } + } + return result; +} +function voeRot13(str) { + return str.replace(/[a-zA-Z]/g, function (c) { + return String.fromCharCode( + (c <= "Z" ? 90 : 122) >= (c = c.charCodeAt(0) + 13) + ? c + : c - 26 + ); + }); +} +function voeRemovePatterns(str) { + const patterns = ["@$", "^^", "~@", "%?", "*~", "!!", "#&"]; + let result = str; + for (const pat of patterns) { + result = result.split(pat).join(""); + } + return result; +} +function voeBase64Decode(str) { + // atob is available in browsers and Node >= 16 + if (typeof atob === "function") { + return atob(str); + } + // Node.js fallback + return Buffer.from(str, "base64").toString("utf-8"); +} +function voeShiftChars(str, shift) { + return str + .split("") + .map((c) => String.fromCharCode(c.charCodeAt(0) - shift)) + .join(""); +} + + + + + +//////////////////////////////////////////////// +// PLUGINS // +//////////////////////////////////////////////// + +/** + * Uses Sora's fetchv2 on ipad, fallbacks to regular fetch on Windows + * @author ShadeOfChaos + * + * @param {string} url The URL to make the request to. + * @param {object} [options] The options to use for the request. + * @param {object} [options.headers] The headers to send with the request. + * @param {string} [options.method='GET'] The method to use for the request. + * @param {string} [options.body=null] The body of the request. + * + * @returns {Promise<Response|null>} The response from the server, or null if the + * request failed. + */ +async function soraFetch(url, options = { headers: {}, method: 'GET', body: null }) { + try { + return await fetchv2(url, options.headers ?? {}, options.method ?? 'GET', options.body ?? null); + } catch(e) { + try { + return await fetch(url, options); + } catch(error) { + await console.log('soraFetch error: ' + error.message); + return null; + } + } +} + +class Unbaser { + constructor(base) { + this.ALPHABET = { + 62: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", + 95: "' !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'", + }; + this.dictionary = {}; + this.base = base; + if (36 < base && base < 62) { + this.ALPHABET[base] = this.ALPHABET[base] || + this.ALPHABET[62].substr(0, base); + } + if (2 <= base && base <= 36) { + this.unbase = (value) => parseInt(value, base); + } + else { + try { + [...this.ALPHABET[base]].forEach((cipher, index) => { + this.dictionary[cipher] = index; + }); + } + catch (er) { + throw Error("Unsupported base encoding."); + } + this.unbase = this._dictunbaser; + } + } + _dictunbaser(value) { + let ret = 0; + [...value].reverse().forEach((cipher, index) => { + ret = ret + ((Math.pow(this.base, index)) * this.dictionary[cipher]); + }); + return ret; + } +} + + +function unpack(source) { + let { payload, symtab, radix, count } = _filterargs(source); + if (count != symtab.length) { + throw Error("Malformed p.a.c.k.e.r. symtab."); + } + let unbase; + try { + unbase = new Unbaser(radix); + } + catch (e) { + throw Error("Unknown p.a.c.k.e.r. encoding."); + } + function lookup(match) { + const word = match; + let word2; + if (radix == 1) { + word2 = symtab[parseInt(word)]; + } + else { + word2 = symtab[unbase.unbase(word)]; + } + return word2 || word; + } + source = payload.replace(/\b\w+\b/g, lookup); + return _replacestrings(source); + function _filterargs(source) { + const juicers = [ + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\), *(\d+), *(.*)\)\)/, + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\)/, + ]; + for (const juicer of juicers) { + const args = juicer.exec(source); + if (args) { + let a = args; + if (a[2] == "[]") { + } + try { + return { + payload: a[1], + symtab: a[4].split("|"), + radix: parseInt(a[2]), + count: parseInt(a[3]), + }; + } + catch (ValueError) { + throw Error("Corrupted p.a.c.k.e.r. data."); + } + } + } + throw Error("Could not make sense of p.a.c.k.e.r data (unexpected code structure)"); + } + function _replacestrings(source) { + return source; + } +} + + + +/* {GE END} */ diff --git a/dorabash/dorabash.json b/dorabash/dorabash.json new file mode 100644 index 0000000..b422022 --- /dev/null +++ b/dorabash/dorabash.json @@ -0,0 +1,19 @@ +{ + "sourceName": "DoraBash", + "iconUrl": "https://dorabash.com/wp-content/uploads/2023/06/cropped-Untitled_design-removebg-192x192.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.1", + "language": "Hindi", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://dorabash.com/", + "searchBaseUrl": "https://dorabash.com/", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/dorabash/dorabash.js", + "type": "anime", + "asyncJS": true, + "softsub": false, + "downloadSupport": false +} diff --git a/doramasyt/doramasyt.js b/doramasyt/doramasyt.js new file mode 100644 index 0000000..c0276d1 --- /dev/null +++ b/doramasyt/doramasyt.js @@ -0,0 +1,307 @@ +async function searchResults(keyword) { + const results = []; + const url = "https://www.doramasyt.com/buscar?q=" + encodeURIComponent(keyword); + + try { + const response = await fetchv2(url); + const html = await response.text(); + console.log(html); + + const regex = /<li class="col mb-3 ficha_efecto">\s*<article>\s*<a href="([^"]+)"[\s\S]*?<img[^>]*data-src="([^"]+)"[^>]*>[\s\S]*?<h3[^>]*>(.*?)<\/h3>[\s\S]*?<\/a>\s*<\/article>\s*<\/li>/g; + + let match; + while ((match = regex.exec(html)) !== null) { + results.push({ + title: cleanTitle(match[3].trim().replace(/<[^>]*>/g, '')), + image: match[2].trim(), + href: match[1].trim() + }); + } + return JSON.stringify(results); + } catch (err) { + return JSON.stringify([{ + title: "Error", + image: "Error", + href: "Error" + }]); + } +} + +function cleanTitle(title) { + return title + .replace(/’/g, "'") + .replace(/–/g, "-") + .replace(/&#[0-9]+;/g, ""); +} + +async function extractDetails(url) { + try { + const response = await fetchv2(url); + const html = await response.text(); + + const descMatch = html.match(/<h1[^>]*>([^<]+)<\/h1>/); + const aliasMatch = html.match(/<span>([^<]+)<\/span>/); + + const description = descMatch ? descMatch[1].trim() : "N/A"; + const aliases = aliasMatch ? aliasMatch[1].trim() : "N/A"; + + return JSON.stringify([{ + description: cleanTitle(description), + aliases: cleanTitle(aliases), + airdate: "N/A" + }]); + } catch (err) { + return JSON.stringify([{ + description: "Error", + aliases: "Error", + airdate: "Error" + }]); + } +} + +async function extractEpisodes(url) { + const results = []; + try { + const response = await networkFetch(url, { + timeoutSeconds: 2, + returnHTML: true + }); + const html = await response.html; + + const regex = /<a class="ko chapter-link" href="([^"]+)"[^>]*data-episode="(\d+)"/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 { + const responseOne = await fetchv2(url); + const htmlOne = await responseOne.text(); + const matchOne = htmlOne.match(/<button[^>]*data-player="([^"]+)"[^>]*>filemoon<\/button>/i); + const filemoonData = matchOne ? matchOne[1] : null; + + const response = await fetchv2("https://www.doramasyt.com/reproductor?video=" + encodeURIComponent(filemoonData)); + const html = await response.text(); + + const matchIframe = html.match(/<iframe[^>]*src="([^"]*filemoon\.sx\/e\/[^"]+)"/i); + const filemoonUrl = matchIframe ? matchIframe[1] : null; + console.log(filemoonUrl); + + const responseTwo = await fetchv2(filemoonUrl); + const htmlTwo = await responseTwo.text(); + + let streamUrl = null; + try { + streamUrl = await filemoonExtractor(htmlTwo, filemoonUrl); + } catch (error) { + console.log("filemoon HD extraction error:" + error); + } + + console.log("filemoon Stream URL: " + streamUrl); + if (streamUrl && streamUrl !== false && streamUrl !== null) { + return streamUrl; + } + + console.log("No stream URL found"); + + return null; + } catch (error) { + console.log("Fetch error:", error); + return null; + } +} + +/* SCHEME START */ +/* {REQUIRED PLUGINS: unbaser} */ + +/** + * @name filemoonExtractor + * @author Cufiy - Inspired by Churly + */ + +async function filemoonExtractor(html, url = null) { + // check if contains iframe, if does, extract the src and get the url + const regex = /<iframe[^>]+src="([^"]+)"[^>]*><\/iframe>/; + const match = html.match(regex); + if (match) { + console.log("Iframe URL: " + match[1]); + const iframeUrl = match[1]; + const iframeResponse = await soraFetch(iframeUrl, { + headers: { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3", + "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", + "Referer": url, + } + }); + console.log("Iframe Response: " + iframeResponse.status); + html = await iframeResponse.text(); + } + // console.log("HTML: " + html); + // get /<script[^>]*>([\s\S]*?)<\/script>/gi + const scriptRegex = /<script[^>]*>([\s\S]*?)<\/script>/gi; + const scripts = []; + let scriptMatch; + while ((scriptMatch = scriptRegex.exec(html)) !== null) { + scripts.push(scriptMatch[1]); + } + // get the script with eval and m3u8 + const evalRegex = /eval\((.*?)\)/; + const m3u8Regex = /m3u8/; + // console.log("Scripts: " + scripts); + const evalScript = scripts.find(script => evalRegex.test(script) && m3u8Regex.test(script)); + if (!evalScript) { + console.log("No eval script found"); + return null; + } + const unpackedScript = unpack(evalScript); + // get the m3u8 url + const m3u8Regex2 = /https?:\/\/[^\s]+master\.m3u8[^\s]*?(\?[^"]*)?/; + const m3u8Match = unpackedScript.match(m3u8Regex2); + if (m3u8Match) { + return m3u8Match[0]; + } else { + console.log("No M3U8 URL found"); + return null; + } +} + + +/* REMOVE_START */ + + +class Unbaser { + constructor(base) { + this.ALPHABET = { + 62: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", + 95: "' !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'", + }; + this.dictionary = {}; + this.base = base; + if (36 < base && base < 62) { + this.ALPHABET[base] = this.ALPHABET[base] || + this.ALPHABET[62].substr(0, base); + } + if (2 <= base && base <= 36) { + this.unbase = (value) => parseInt(value, base); + } + else { + try { + [...this.ALPHABET[base]].forEach((cipher, index) => { + this.dictionary[cipher] = index; + }); + } + catch (er) { + throw Error("Unsupported base encoding."); + } + this.unbase = this._dictunbaser; + } + } + _dictunbaser(value) { + let ret = 0; + [...value].reverse().forEach((cipher, index) => { + ret = ret + ((Math.pow(this.base, index)) * this.dictionary[cipher]); + }); + return ret; + } +} + + +function unpack(source) { + let { payload, symtab, radix, count } = _filterargs(source); + if (count != symtab.length) { + throw Error("Malformed p.a.c.k.e.r. symtab."); + } + let unbase; + try { + unbase = new Unbaser(radix); + } + catch (e) { + throw Error("Unknown p.a.c.k.e.r. encoding."); + } + function lookup(match) { + const word = match; + let word2; + if (radix == 1) { + word2 = symtab[parseInt(word)]; + } + else { + word2 = symtab[unbase.unbase(word)]; + } + return word2 || word; + } + source = payload.replace(/\b\w+\b/g, lookup); + return _replacestrings(source); + function _filterargs(source) { + const juicers = [ + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\), *(\d+), *(.*)\)\)/, + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\)/, + ]; + for (const juicer of juicers) { + const args = juicer.exec(source); + if (args) { + let a = args; + if (a[2] == "[]") { + } + try { + return { + payload: a[1], + symtab: a[4].split("|"), + radix: parseInt(a[2]), + count: parseInt(a[3]), + }; + } + catch (ValueError) { + throw Error("Corrupted p.a.c.k.e.r. data."); + } + } + } + throw Error("Could not make sense of p.a.c.k.e.r data (unexpected code structure)"); + } + function _replacestrings(source) { + return source; + } +} + + +/** + * Uses Sora's fetchv2 on ipad, fallbacks to regular fetch on Windows + * @author ShadeOfChaos + * + * @param {string} url The URL to make the request to. + * @param {object} [options] The options to use for the request. + * @param {object} [options.headers] The headers to send with the request. + * @param {string} [options.method='GET'] The method to use for the request. + * @param {string} [options.body=null] The body of the request. + * + * @returns {Promise<Response|null>} The response from the server, or null if the + * request failed. + */ +async function soraFetch(url, options = { headers: {}, method: 'GET', body: null }) { + try { + return await fetchv2(url, options.headers ?? {}, options.method ?? 'GET', options.body ?? null); + } catch(e) { + try { + return await fetch(url, options); + } catch(error) { + return null; + } + } +} +/* REMOVE_END */ + +/* SCHEME END */ + diff --git a/doramasyt/doramasyt.json b/doramasyt/doramasyt.json new file mode 100644 index 0000000..f25682e --- /dev/null +++ b/doramasyt/doramasyt.json @@ -0,0 +1,19 @@ +{ + "sourceName": "DoramasYT", + "iconUrl": "https://files.catbox.moe/afzsms.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "Spanish", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://www.doramasyt.com/", + "searchBaseUrl": "https://www.doramasyt.com/", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/doramasyt/doramasyt.js", + "type": "shows/movies", + "asyncJS": true, + "softsub": false, + "downloadSupport": false +} diff --git a/egydead (Fasel reuploader)/egydead.js b/egydead (Fasel reuploader)/egydead.js new file mode 100644 index 0000000..7d230f4 --- /dev/null +++ b/egydead (Fasel reuploader)/egydead.js @@ -0,0 +1,238 @@ +async function searchResults(keyword) { + const results = []; + try { + const response = await fetchv2("https://egydead.com.co/search?s=" + encodeURIComponent(keyword)); + const html = await response.text(); + + const regex = /<a href="([^"]+)"[^>]*style="background-image:\s*url\(([^)]+)\)[^"]*"[^>]*>[\s\S]*?<p class="title">(.*?)<\/p>/g; + + let match; + while ((match = regex.exec(html)) !== null) { + results.push({ + href: match[1].trim(), + image: match[2].trim(), + title: 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 regex = /<span class="description">\s*([\s\S]*?)\s*<\/span>/i; + const match = regex.exec(html); + + const description = match ? match[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) { + try { + const response = await fetchv2(url); + const html = await response.text(); + + const regex = /<a href="([^"]+)" class="btn watch">/i; + const match = regex.exec(html); + + if (match) { + return JSON.stringify([{ + href: match[1].trim(), + number: 1 + }]); + } + + return JSON.stringify([]); + } catch (err) { + return JSON.stringify([{ + href: "Error", + number: "Error" + }]); + } +} +async function extractStreamUrl(url) { + try { + const response = await fetchv2(url); + const html = await response.text(); + console.log(html); + + const jsonRegex = /let servers = JSON\.parse\('(\[.*?\])'\);/; + const jsonMatch = jsonRegex.exec(html); + + if (jsonMatch) { + const serversJson = jsonMatch[1].replace(/\\/g, ''); + const servers = JSON.parse(serversJson); + + const fdewsdcServer = servers.find(server => server.name === "fdewsdc"); + if (fdewsdcServer) { + console.log("Stream URL: " + fdewsdcServer.url); + return await extractEarnVids(fdewsdcServer.url); + } + } + } catch (err) { + console.error(err); + } +} + +async function extractEarnVids(url) { + try { + const response = await fetchv2(url); + const html = await response.text(); + + const obfuscatedScript = html.match(/<script[^>]*>\s*(eval\(function\(p,a,c,k,e,d.*?\)[\s\S]*?)<\/script>/); + const unpackedScript = unpack(obfuscatedScript[1]); + + const streamMatch = unpackedScript.match(/["'](\/stream\/[^"']+)["']/); + const hlsLink = streamMatch ? streamMatch[1] : null; + + const baseUrl = url.match(/^(https?:\/\/[^/]+)/)[1]; + + console.log("HLS Link:" + baseUrl + hlsLink); + + return baseUrl + hlsLink; + } catch (err) { + console.log(err); + return "https://files.catbox.moe/avolvc.mp4"; + } +} + +/*********************************************************** + * UNPACKER MODULE + * Credit to GitHub user "mnsrulz" for Unpacker Node library + * https://github.com/mnsrulz/unpacker + ***********************************************************/ +class Unbaser { + constructor(base) { + /* Functor for a given base. Will efficiently convert + strings to natural numbers. */ + this.ALPHABET = { + 62: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", + 95: "' !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'", + }; + this.dictionary = {}; + this.base = base; + // fill elements 37...61, if necessary + if (36 < base && base < 62) { + this.ALPHABET[base] = this.ALPHABET[base] || + this.ALPHABET[62].substr(0, base); + } + // If base can be handled by int() builtin, let it do it for us + if (2 <= base && base <= 36) { + this.unbase = (value) => parseInt(value, base); + } + else { + // Build conversion dictionary cache + try { + [...this.ALPHABET[base]].forEach((cipher, index) => { + this.dictionary[cipher] = index; + }); + } + catch (er) { + throw Error("Unsupported base encoding."); + } + this.unbase = this._dictunbaser; + } + } + _dictunbaser(value) { + /* Decodes a value to an integer. */ + let ret = 0; + [...value].reverse().forEach((cipher, index) => { + ret = ret + ((Math.pow(this.base, index)) * this.dictionary[cipher]); + }); + return ret; + } +} + +function detect(source) { + /* Detects whether `source` is P.A.C.K.E.R. coded. */ + return source.replace(" ", "").startsWith("eval(function(p,a,c,k,e,"); +} + +function unpack(source) { + /* Unpacks P.A.C.K.E.R. packed js code. */ + let { payload, symtab, radix, count } = _filterargs(source); + if (count != symtab.length) { + throw Error("Malformed p.a.c.k.e.r. symtab."); + } + let unbase; + try { + unbase = new Unbaser(radix); + } + catch (e) { + throw Error("Unknown p.a.c.k.e.r. encoding."); + } + function lookup(match) { + /* Look up symbols in the synthetic symtab. */ + const word = match; + let word2; + if (radix == 1) { + //throw Error("symtab unknown"); + word2 = symtab[parseInt(word)]; + } + else { + word2 = symtab[unbase.unbase(word)]; + } + return word2 || word; + } + source = payload.replace(/\b\w+\b/g, lookup); + return _replacestrings(source); + function _filterargs(source) { + /* Juice from a source file the four args needed by decoder. */ + const juicers = [ + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\), *(\d+), *(.*)\)\)/, + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\)/, + ]; + for (const juicer of juicers) { + //const args = re.search(juicer, source, re.DOTALL); + const args = juicer.exec(source); + if (args) { + let a = args; + if (a[2] == "[]") { + //don't know what it is + // a = list(a); + // a[1] = 62; + // a = tuple(a); + } + try { + return { + payload: a[1], + symtab: a[4].split("|"), + radix: parseInt(a[2]), + count: parseInt(a[3]), + }; + } + catch (ValueError) { + throw Error("Corrupted p.a.c.k.e.r. data."); + } + } + } + throw Error("Could not make sense of p.a.c.k.e.r data (unexpected code structure)"); + } + function _replacestrings(source) { + /* Strip string lookup table (list) and replace values in source. */ + /* Need to work on this. */ + return source; + } +} diff --git a/egydead (Fasel reuploader)/egydead.json b/egydead (Fasel reuploader)/egydead.json new file mode 100644 index 0000000..10614f4 --- /dev/null +++ b/egydead (Fasel reuploader)/egydead.json @@ -0,0 +1,18 @@ +{ + "sourceName": "EgyDead (Fasel reuploader)", + "iconUrl": "https://tv3.egydead.live/wp-content/uploads/2019/01/cropped-yXYdE2f-192x192.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "Arabic", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://egydead.com.co/", + "searchBaseUrl": "https://egydead.com.co/?s=%s", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/egydead%20(Fasel%20reuploader)/egydead.js", + "type": "shows/movies/anime", + "asyncJS": true, + "downloadSupport": true +} diff --git a/egydead/egydead.js b/egydead/egydead.js new file mode 100644 index 0000000..bfaae1d --- /dev/null +++ b/egydead/egydead.js @@ -0,0 +1,273 @@ +async function searchResults(keyword) { + const results = []; + try { + const response = await fetchv2("https://tv3.egydead.live/?s=" + encodeURIComponent(keyword)); + const html = await response.text(); + + const regex = /<li class="movieItem">\s*<a href="([^"]+)" title="([^"]+)">\s*<img src="([^"]+)">/g; + let match; + while ((match = regex.exec(html)) !== null) { + results.push({ + href: match[1].trim(), + title: match[2].trim(), + image: 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 match = html.match(/<div class="extra-content">\s*<span>القصه<\/span>\s*<p>([\s\S]*?)<\/p>/); + const description = match ? match[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*حلقه\s*(\d+)\s*<\/a>/g; + let match; + while ((match = regex.exec(html)) !== null) { + results.push({ + href: match[1].trim(), + number: parseInt(match[2], 10) + }); + } + + if (results.length === 0) { + results.push({ + href: url, + number: 1 + }); + } + return JSON.stringify(results.reverse()); + } catch (err) { + return JSON.stringify([{ + href: "Error", + number: "Error" + }]); + } +} + +async function extractStreamUrl(url) { + try { + const header = { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/" + }; + const postData = "View=1"; + const response = await fetchv2(url, header, "POST", postData); + const html = await response.text(); + const match = html.match(/<li data-link="(https:\/\/mivalyo\.com\/v\/[^"]+)"/); + const streamUrl = match ? match[1] : "https://files.catbox.moe/avolvc.mp4"; + console.log("Stream URL:", streamUrl); + + const responseTwo = await fetchv2(streamUrl); + const htmlTwo = await responseTwo.text(); + const obfuscatedScript = htmlTwo.match(/<script[^>]*>\s*(eval\(function\(p,a,c,k,e,d.*?\)[\s\S]*?)<\/script>/); + + if (!obfuscatedScript) { + console.log("No obfuscated script found, using fallback"); + return "https://files.catbox.moe/avolvc.mp4"; + } + + const unpackedScript = unpack(obfuscatedScript[1]); + console.log("Unpacked script:", unpackedScript.substring(0, 200) + "..."); + + let hlsLink = null; + const baseUrl = url.match(/^(https?:\/\/[^/]+)/)[1]; + + const streamMatch = unpackedScript.match(/["'](\/stream\/[^"']+)["']/); + if (streamMatch) { + hlsLink = streamMatch[1]; + console.log("Found stream path:", hlsLink); + return baseUrl + hlsLink; + } + + const hlsObjectMatch = unpackedScript.match(/["']hls\d?["']\s*:\s*["'](https?:\/\/[^"']+\.m3u8[^"']*)["']/); + if (hlsObjectMatch) { + hlsLink = hlsObjectMatch[1]; + console.log("Found HLS object link:", hlsLink); + return hlsLink; + } + + const m3u8Match = unpackedScript.match(/["'](https?:\/\/[^"']+\.m3u8[^"']*)["']/); + if (m3u8Match) { + hlsLink = m3u8Match[1]; + console.log("Found m3u8 link:", hlsLink); + return hlsLink; + } + + const cdnMatch = unpackedScript.match(/["'](https?:\/\/[^"']*(?:cdn|stream)[^"']*\.m3u8[^"']*)["']/i); + if (cdnMatch) { + hlsLink = cdnMatch[1]; + console.log("Found CDN link:", hlsLink); + return hlsLink; + } + + const linksMatch = unpackedScript.match(/links\s*[=:]\s*({[^}]+}|\[[^\]]+\])/); + if (linksMatch) { + const linksStr = linksMatch[1]; + const urlInLinks = linksStr.match(/["'](https?:\/\/[^"']+\.m3u8[^"']*)["']/); + if (urlInLinks) { + hlsLink = urlInLinks[1]; + console.log("Found link in links object:", hlsLink); + return hlsLink; + } + } + + console.log("No HLS link found in unpacked script, using fallback"); + return "https://files.catbox.moe/avolvc.mp4"; + + } catch (err) { + console.error("Error in extractStreamUrl:", err); + return "https://files.catbox.moe/avolvc.mp4"; + } +} + + +/*********************************************************** + * UNPACKER MODULE + * Credit to GitHub user "mnsrulz" for Unpacker Node library + * https://github.com/mnsrulz/unpacker + ***********************************************************/ +class Unbaser { + constructor(base) { + /* Functor for a given base. Will efficiently convert + strings to natural numbers. */ + this.ALPHABET = { + 62: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", + 95: "' !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'", + }; + this.dictionary = {}; + this.base = base; + // fill elements 37...61, if necessary + if (36 < base && base < 62) { + this.ALPHABET[base] = this.ALPHABET[base] || + this.ALPHABET[62].substr(0, base); + } + // If base can be handled by int() builtin, let it do it for us + if (2 <= base && base <= 36) { + this.unbase = (value) => parseInt(value, base); + } + else { + // Build conversion dictionary cache + try { + [...this.ALPHABET[base]].forEach((cipher, index) => { + this.dictionary[cipher] = index; + }); + } + catch (er) { + throw Error("Unsupported base encoding."); + } + this.unbase = this._dictunbaser; + } + } + _dictunbaser(value) { + /* Decodes a value to an integer. */ + let ret = 0; + [...value].reverse().forEach((cipher, index) => { + ret = ret + ((Math.pow(this.base, index)) * this.dictionary[cipher]); + }); + return ret; + } +} + +function detect(source) { + /* Detects whether `source` is P.A.C.K.E.R. coded. */ + return source.replace(" ", "").startsWith("eval(function(p,a,c,k,e,"); +} + +function unpack(source) { + /* Unpacks P.A.C.K.E.R. packed js code. */ + let { payload, symtab, radix, count } = _filterargs(source); + if (count != symtab.length) { + throw Error("Malformed p.a.c.k.e.r. symtab."); + } + let unbase; + try { + unbase = new Unbaser(radix); + } + catch (e) { + throw Error("Unknown p.a.c.k.e.r. encoding."); + } + function lookup(match) { + /* Look up symbols in the synthetic symtab. */ + const word = match; + let word2; + if (radix == 1) { + //throw Error("symtab unknown"); + word2 = symtab[parseInt(word)]; + } + else { + word2 = symtab[unbase.unbase(word)]; + } + return word2 || word; + } + source = payload.replace(/\b\w+\b/g, lookup); + return _replacestrings(source); + function _filterargs(source) { + /* Juice from a source file the four args needed by decoder. */ + const juicers = [ + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\), *(\d+), *(.*)\)\)/, + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\)/, + ]; + for (const juicer of juicers) { + //const args = re.search(juicer, source, re.DOTALL); + const args = juicer.exec(source); + if (args) { + let a = args; + if (a[2] == "[]") { + //don't know what it is + // a = list(a); + // a[1] = 62; + // a = tuple(a); + } + try { + return { + payload: a[1], + symtab: a[4].split("|"), + radix: parseInt(a[2]), + count: parseInt(a[3]), + }; + } + catch (ValueError) { + throw Error("Corrupted p.a.c.k.e.r. data."); + } + } + } + throw Error("Could not make sense of p.a.c.k.e.r data (unexpected code structure)"); + } + function _replacestrings(source) { + /* Strip string lookup table (list) and replace values in source. */ + /* Need to work on this. */ + return source; + } +} diff --git a/egydead/egydead.json b/egydead/egydead.json new file mode 100644 index 0000000..988d7ec --- /dev/null +++ b/egydead/egydead.json @@ -0,0 +1,18 @@ +{ + "sourceName": "EgyDead", + "iconUrl": "https://tv3.egydead.live/wp-content/uploads/2019/01/cropped-yXYdE2f-192x192.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "Arabic", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://tv3.egydead.live/", + "searchBaseUrl": "https://tv3.egydead.live/?s=%s", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/egydead/egydead.js", + "type": "shows/movies/anime", + "asyncJS": true, + "downloadSupport": false +} diff --git a/estrenosdoramas/estrenosdoramas.js b/estrenosdoramas/estrenosdoramas.js new file mode 100644 index 0000000..8468b52 --- /dev/null +++ b/estrenosdoramas/estrenosdoramas.js @@ -0,0 +1,102 @@ +function cleanTitle(title) { + return title + .replace(/’/g, "'") + .replace(/–/g, "-") + .replace(/&#[0-9]+;/g, ""); +} + +async function searchResults(keyword) { + const results = []; + const response = await fetchv2(`https://estrenosdoramas.es/?s=${keyword}`); + const html = await response.text(); + + const regex = /<article[^>]*class="[^"]*bs[^"]*"[^>]*>.*?<a href="([^"]+)"[^>]*>.*?<div class="ttzz">\s*(.*?)\s*<\/div>.*?<img[^>]*src="([^"]+)"[^>]*>/gs; + + let match; + while ((match = regex.exec(html)) !== null) { + results.push({ + title: cleanTitle(match[2].trim()), + image: match[3].trim(), + href: match[1].trim() + }); + } + + return JSON.stringify(results); +} + + +async function extractDetails(url) { + const results = []; + const response = await fetchv2(url); + const html = await response.text(); + + const match = html.match(/<div class="entry-content"[^>]*>([\s\S]*?)<\/div>/); + + let description = "N/A"; + if (match) { + description = match[1] + .replace(/<[^>]+>/g, '') + .replace(/&#(\d+);/g, (_, code) => String.fromCharCode(code)) + .replace(/"/g, '"') + .replace(/'/g, "'") + .replace(/&/g, "&") + .trim(); + } + + results.push({ + description: description, + aliases: 'N/A', + airdate: 'N/A' + }); + + return JSON.stringify(results); +} + +async function extractEpisodes(url) { + const results = []; + const response = await fetchv2(url); + const html = await response.text(); + + const regex = /<li[^>]*id="epcheck"[^>]*>[\s\S]*?<a href="([^"]+)">/g; + + let match; + while ((match = regex.exec(html)) !== null) { + results.push(match[1].trim()); + } + + const total = results.length; + const final = results.map((href, index) => ({ + href: href, + number: total - index + })); + + return JSON.stringify(final.reverse()); +} + +async function extractStreamUrl(url) { + try { + const response = await fetchv2(url); + const html = await response.text(); + + const embedMatch = html.match(/<div class="pembed" data-embed="([^"]+)"/); + if (!embedMatch) return "error"; + const embedUrl = embedMatch[1].trim(); + console.log(embedUrl); + const headers = { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3", + "Referer": url + }; + + const embedResponse = await fetchv2(embedUrl.replace("//", "https://"), headers); + const embedHtml = await embedResponse.text(); + console.log(embedHtml); + const fileMatch = embedHtml.match(/sources:\s*\[\{file:"([^"]+)"/); + if (!fileMatch) return "error"; + + return fileMatch[1]; + } catch (err) { + console.log(err); + return "error"; + } +} + diff --git a/estrenosdoramas/estrenosdoramas.json b/estrenosdoramas/estrenosdoramas.json new file mode 100644 index 0000000..7caf72c --- /dev/null +++ b/estrenosdoramas/estrenosdoramas.json @@ -0,0 +1,19 @@ +{ + "sourceName": "EstrenosDoramas", + "iconUrl": "https://i0.wp.com/estrenosdoramas.es/wp-content/uploads/2023/12/cropped-unnamed-7-192x192.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "Spanish (DUB/SUB)", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://vidmoly.to/", + "searchBaseUrl": "https://vidmoly.to/", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/estrenosdoramas/estrenosdoramas.js", + "type": "shows/movies", + "asyncJS": true, + "softsub": false, + "downloadSupport": false +} diff --git a/faselhd/faselhd.js b/faselhd/faselhd.js new file mode 100644 index 0000000..0ac1f04 --- /dev/null +++ b/faselhd/faselhd.js @@ -0,0 +1,160 @@ +function decodeHtmlEntities(text) { + return text + .replace(/’/g, "'") + .replace(/“/g, '"') + .replace(/”/g, '"') + .replace(/…/g, '...') + .replace(/&/g, '&') + .replace(/"/g, '"') + .replace(/</g, '<') + .replace(/>/g, '>') + .replace(/&#(\d+);/g, (_, num) => String.fromCharCode(num)); +} + +async function searchResults(keyword) { + const results = []; + try { + const response = await fetchv2("https://www.faselhds.xyz/?s=" + encodeURIComponent(keyword)); + const html = await response.text(); + + const regex = /<div class="postDiv[^"]*">[\s\S]*?<a href="([^"]+)">[\s\S]*?<img[^>]+src="([^"]+)"[\s\S]*?<div class="h1">([\s\S]*?)<\/div>/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 match = /<div class="singleDesc">\s*<p>([\s\S]*?)<\/p>/.exec(html); + const description = match ? match[1].trim() : "N/A"; + + return JSON.stringify([{ + description: decodeHtmlEntities(description), + aliases: "N/A", + airdate: "N/A" + }]); + } catch (err) { + return JSON.stringify([{ + description: "Error", + aliases: "Error", + airdate: "Error" + }]); + } +} + +async function extractEpisodes(url) { + const baseUrl = "https://www.faselhds.xyz"; + const allEpisodes = []; + + function extractEpisodesFromHtml(html) { + const episodes = []; + const regex = /<a href="([^"]+)"[^>]*>\s*الحلقة\s*(\d+)\s*<\/a>/g; + let match; + while ((match = regex.exec(html)) !== null) { + episodes.push({ + href: match[1].trim(), + number: parseInt(match[2], 10), + }); + } + return episodes; + } + + try { + const response = await fetchv2(url); + const html = await response.text(); + + const seasonDivRegex = /<div[^>]+class=["'][^"']*seasonDiv[^"']*["'][^>]*>/g; + const seasonMatches = html.match(seasonDivRegex); + const seasonCount = seasonMatches ? seasonMatches.length : 0; + + console.log(`Found ${seasonCount} seasons`); + + if (seasonCount > 1) { + const seasonHrefRegex = /<div[^>]+class=["'][^"']*seasonDiv[^"']*["'][^>]*onclick=["']window\.location\.href\s*=\s*['"](([^'"]+))['"][^>]*>/g; + const seasonPaths = []; + let match; + + while ((match = seasonHrefRegex.exec(html)) !== null) { + seasonPaths.push(match[1]); + } + + + for (const path of seasonPaths) { + const seasonUrl = path.startsWith("http") ? path : baseUrl + path; + + const seasonResponse = await fetchv2(seasonUrl); + const seasonPageHtml = await seasonResponse.text(); + const episodes = extractEpisodesFromHtml(seasonPageHtml); + + allEpisodes.push(...episodes); + } + + return JSON.stringify(allEpisodes); + } else { + const episodes = extractEpisodesFromHtml(html); + + if (episodes.length === 0) { + return JSON.stringify([{ href: url, number: 1 }]); + } + + return JSON.stringify(episodes); + } + + } catch (err) { + console.error("Error:", err); + return JSON.stringify([{ href: "Error", number: "Error" }]); + } +} + +async function extractStreamUrl(url) { + try { + const response = await fetchv2(url); + const html = await response.text(); + + const regex = /<li\s+class="active"\s+onclick="player_iframe\.location\.href\s*=\s*'([^']+)'"/i; + const match = regex.exec(html); + + if (!match || !match[1]) { + console.log("No stream URL found in page"); + return ""; + } + const streamUrl = match[1].trim(); + + console.log(streamUrl); + + const response2 = await networkFetch(streamUrl, { + timeoutSeconds: 2, + returnHTML: true + }); + const html2 = response2.html; + + const match2 = html2.match(/data-url="([^"]+\.m3u8)"/); + if (match2) { + return match2[1]; + } else { + return null; + } + } catch (err) { + console.log("Error fetching stream URL content:"+ err); + return ""; + } +} diff --git a/faselhd/faselhd.json b/faselhd/faselhd.json new file mode 100644 index 0000000..677eb3d --- /dev/null +++ b/faselhd/faselhd.json @@ -0,0 +1,18 @@ +{ + "sourceName": "FaselHD", + "iconUrl": "https://www.faselhds.xyz/wp-content/themes/faselhd_2020/images/favicon.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.1", + "language": "Arabic", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://www.faselhds.xyz/", + "searchBaseUrl": "https://www.faselhds.xyz/?s=%s", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/faselhd/faselhd.js", + "type": "shows/movies/anime", + "asyncJS": true, + "downloadSupport": true +} diff --git a/filmehd/filmehd.js b/filmehd/filmehd.js new file mode 100644 index 0000000..4dabab6 --- /dev/null +++ b/filmehd/filmehd.js @@ -0,0 +1,289 @@ +function decodeHtmlEntities(text) { + return text + .replace(/’/g, "'") + .replace(/“/g, '"') + .replace(/”/g, '"') + .replace(/…/g, '...') + .replace(/&/g, '&') + .replace(/"/g, '"') + .replace(/</g, '<') + .replace(/>/g, '>') + .replace(/&#(\d+);/g, (_, num) => String.fromCharCode(num)); +} + +async function searchResults(keyword) { + const results = []; + const regex = /<article[^>]*class="item (movies|seasons)"[^>]*>[\s\S]*?<img\s+src="([^"]+)"[^>]*title="([^"]+)"[^>]*>[\s\S]*?<a\s+href="([^"]+)"[^>]*>/gi; + + try { + const response = await fetchv2("https://filmehd.to/?s=" + encodeURIComponent(keyword)); + const html = await response.text(); + + regex.lastIndex = 0; + let match; + while ((match = regex.exec(html)) !== null) { + results.push({ + image: match[2].trim(), + title: decodeHtmlEntities(match[3].trim()), + href: match[4].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 match = /<div class="wp-content"[^>]*>\s*<p>(.*?)<\/p>/i.exec(html); + const description = match ? match[1].trim() : "No description found"; + + 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) { + try { + const response = await fetchv2(url); + const html = await response.text(); + + const episodes = []; + + const iframeMatch = html.match(/<iframe[^>]+src\s*=\s*"([^"]*movies\/iframe\/[^"]*?)"/i); + if (iframeMatch) { + episodes.push({ + href: iframeMatch[1].trim(), + number: 1 + }); + } else { + const allDataVs = []; + const dataVsRegex = /data-vs\s*=\s*"([^"]*?)"/g; + let match; + while ((match = dataVsRegex.exec(html)) !== null) { + allDataVs.push(match[1].trim()); + } + + const allNumbers = []; + const numberRegex = /<span[^>]*class="servers"[^>]*>(\d+)<\/span>/g; + while ((match = numberRegex.exec(html)) !== null) { + allNumbers.push(parseInt(match[1], 10)); + } + + const server1Start = html.indexOf('SERVER 1'); + let server1End = html.indexOf('SERVER 2'); + if (server1End === -1) server1End = html.length; + + if (server1Start !== -1) { + const server1Section = html.substring(server1Start, server1End); + const server1Count = (server1Section.match(/<span[^>]*class="servers"/g) || []).length; + + for (let i = 0; i < server1Count && i < allDataVs.length && i < allNumbers.length; i++) { + episodes.push({ + href: allDataVs[i], + number: allNumbers[i] + }); + } + } + } + + episodes.sort((a, b) => a.number - b.number); + + if (episodes.length === 0) { + throw new Error("No episodes found"); + } + + return JSON.stringify(episodes); + + } catch (err) { + return JSON.stringify([{ + href: "Error", + number: "Error", + message: err.message + }]); + } +} + +async function extractStreamUrl(url) { + try { + const headers = { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3", + "Referer": "https://filmehd.to/" + }; + const response = await fetchv2(url, headers); + const html = await response.text(); + + const iframeMatch = /<iframe[^>]+src="([^"]+)"[^>]*><\/iframe>/i.exec(html); + if (!iframeMatch) throw new Error("Iframe not found"); + const iframeUrl = iframeMatch[1].trim(); + + const iframeResponse = await fetchv2(iframeUrl, headers); + const iframeContent = await iframeResponse.text(); + + console.log(`[Debug] Iframe content: ${iframeContent}`); + + const scriptMatch = iframeContent.match(/<script[^>]*>\s*(eval\(function\(p,a,c,k,e,d.*?\)[\s\S]*?)<\/script>/); + + if (!scriptMatch) throw new Error("Obfuscated script not found"); + const evalContent = scriptMatch[1]; + + const unpackedScript = unpack(evalContent); + + const fileMatch = /sources:\s*\[\s*\{\s*file:\s*"([^"]+\.m3u8[^"]*)"/.exec(unpackedScript); + if (!fileMatch) throw new Error("Stream URL not found"); + + + const subtitleMatch = /tracks:\s*\[\s*\{\s*file:\s*"([^"]+\.vtt[^"]*)"/.exec(unpackedScript); + + return JSON.stringify({ + stream: fileMatch[1], + subtitles: subtitleMatch ? subtitleMatch[1] : null + }); + } catch (err) { + console.error("Error extracting stream URL:", err); + return JSON.stringify({ + stream: "https://files.catbox.moe/avolvc.mp4", + subtitles: null + }); + } +} + +/* + * UNPACKER MODULE + * Credit to GitHub user "mnsrulz" for Unpacker Node library + * https://github.com/mnsrulz/unpacker + */ + +class Unbaser { + constructor(base) { + /* Functor for a given base. Will efficiently convert + strings to natural numbers. */ + this.ALPHABET = { + 62: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", + 95: "' !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'", + }; + this.dictionary = {}; + this.base = base; + // fill elements 37...61, if necessary + if (36 < base && base < 62) { + this.ALPHABET[base] = this.ALPHABET[base] || + this.ALPHABET[62].substr(0, base); + } + // If base can be handled by int() builtin, let it do it for us + if (2 <= base && base <= 36) { + this.unbase = (value) => parseInt(value, base); + } + else { + // Build conversion dictionary cache + try { + [...this.ALPHABET[base]].forEach((cipher, index) => { + this.dictionary[cipher] = index; + }); + } + catch (er) { + throw Error("Unsupported base encoding."); + } + this.unbase = this._dictunbaser; + } + } + _dictunbaser(value) { + /* Decodes a value to an integer. */ + let ret = 0; + [...value].reverse().forEach((cipher, index) => { + ret = ret + ((Math.pow(this.base, index)) * this.dictionary[cipher]); + }); + return ret; + } +} + +function detect(source) { + /* Detects whether `source` is P.A.C.K.E.R. coded. */ + return source.replace(" ", "").startsWith("eval(function(p,a,c,k,e,"); +} + +function unpack(source) { + /* Unpacks P.A.C.K.E.R. packed js code. */ + let { payload, symtab, radix, count } = _filterargs(source); + if (count != symtab.length) { + throw Error("Malformed p.a.c.k.e.r. symtab."); + } + let unbase; + try { + unbase = new Unbaser(radix); + } + catch (e) { + throw Error("Unknown p.a.c.k.e.r. encoding."); + } + function lookup(match) { + /* Look up symbols in the synthetic symtab. */ + const word = match; + let word2; + if (radix == 1) { + //throw Error("symtab unknown"); + word2 = symtab[parseInt(word)]; + } + else { + word2 = symtab[unbase.unbase(word)]; + } + return word2 || word; + } + source = payload.replace(/\b\w+\b/g, lookup); + return _replacestrings(source); + function _filterargs(source) { + /* Juice from a source file the four args needed by decoder. */ + const juicers = [ + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\), *(\d+), *(.*)\)\)/, + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\)/, + ]; + for (const juicer of juicers) { + //const args = re.search(juicer, source, re.DOTALL); + const args = juicer.exec(source); + if (args) { + let a = args; + if (a[2] == "[]") { + //don't know what it is + // a = list(a); + // a[1] = 62; + // a = tuple(a); + } + try { + return { + payload: a[1], + symtab: a[4].split("|"), + radix: parseInt(a[2]), + count: parseInt(a[3]), + }; + } + catch (ValueError) { + throw Error("Corrupted p.a.c.k.e.r. data."); + } + } + } + throw Error("Could not make sense of p.a.c.k.e.r data (unexpected code structure)"); + } + function _replacestrings(source) { + /* Strip string lookup table (list) and replace values in source. */ + /* Need to work on this. */ + return source; + } +} + + diff --git a/filmehd/filmehd.json b/filmehd/filmehd.json new file mode 100644 index 0000000..14a7b35 --- /dev/null +++ b/filmehd/filmehd.json @@ -0,0 +1,19 @@ +{ + "sourceName": "FilmeHD", + "iconUrl": "https://filmehd.to/wp-content/uploads/2020/01/favicon.ico", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "3.0.1", + "language": "Romanian (DUB/SUB)", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://filmehd.to/", + "searchBaseUrl": "https://filmehd.to/", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/filmehd/filmehd.js", + "type": "shows/movies", + "asyncJS": true, + "softsub": true, + "downloadSupport": true +} diff --git a/filmpalast/filmpalast.ico b/filmpalast/filmpalast.ico new file mode 100644 index 0000000..71dfde9 Binary files /dev/null and b/filmpalast/filmpalast.ico differ diff --git a/filmpalast/filmpalast.js b/filmpalast/filmpalast.js new file mode 100644 index 0000000..0319692 --- /dev/null +++ b/filmpalast/filmpalast.js @@ -0,0 +1,287 @@ +/** + * filmpalast.js + * A module for Sora that provides watch functionality for filmpalast.to. + * @module filmpalast + * @author JMcrafte26 + * @license MIT + * @version 1.1.3 + * @mirror https://api.jm26.net/sora-modules/filmpalast/filmpalast.json +*/ + +/** + * Searches for films on filmpalast.to based on a keyword. + * @param {string} keyword - The search keyword. + * @returns {Promise<string>} - A JSON string of search results. + */ +async function searchResults(keyword) { + try { + const encodedKeyword = encodeURIComponent(keyword); + const html = await fetch( + `https://filmpalast.to/search/title/${encodedKeyword}` + ); + const filmListRegex = + /<article class="liste glowliste rb"[\s\S]*?<\/article>/g; + const items = html.match(filmListRegex) || []; + + const results = []; + + items.forEach((itemHtml, index) => { + const titleMatch = itemHtml.match( + /<a href="([^"]+)" class="rb" title="([^"]+)"[^>]*>([^<]+)<\/a>/ + ); + let title = titleMatch ? titleMatch[3] : ""; + const hrefMatch = itemHtml.match( + /<a href="\/\/filmpalast.to\/stream\/([^"]+)"[^>]*>/ + ); + const href = hrefMatch + ? `https://filmpalast.to/stream/${hrefMatch[1]}` + : ""; + const imageMatch = itemHtml.match( + /<img[^>]+src="([^"]+)"[^>]+class="cover-opacity"[^>]*>/ + ); + const image = "https://filmpalast.to" + (imageMatch ? imageMatch[1] : ""); + title = cleanTitle(title); + + if (title && href) { + results.push({ + title, + image, + href, + }); + } + }); + + return JSON.stringify(results); + } catch (error) { + console.log("Fetch error:", error); + return JSON.stringify([{ title: "Error", image: "", href: "" }]); + } +} + +/** + * Cleans the title by replacing HTML entities with their corresponding characters. + * @param {string} title - The title to clean. + * @returns {string} - The cleaned title. + */ +function cleanTitle(title) { + return title + .replace(/&/g, "&") + .replace(/"/g, '"') + .replace(/'/g, "'") + .replace(/</g, "<") + .replace(/>/g, ">"); +} + +/** + * Extracts details from a film's page. + * @param {string} url - The URL of the film's page. + * @returns {Promise<string>} - A JSON string of the film's details. + */ +async function extractDetails(url) { + try { + const html = await fetch(url); + const descriptionMatch = html.match( + /<span itemprop="description">([^<]+)<\/span>/ + ); + const description = descriptionMatch + ? descriptionMatch[1] + : "Error loading description"; + + const durationMatch = html.match(/<br \/>Spielzeit: <em>([^<]+)<\/em>/); + const duration = durationMatch ? durationMatch[1] : "Unknown"; + + const airedMatch = html.match(/<br \/>Veröffentlicht: (\d{4})/); + const aired = airedMatch ? airedMatch[1] : "Unknown"; + + const transformedResults = [ + { + description, + aliases: `Duration: ${duration}`, + airdate: `Aired: ${aired}`, + }, + ]; + return JSON.stringify(transformedResults); + } catch (error) { + console.log("Details error:", error); + return JSON.stringify([ + { + description: "Error loading description", + aliases: "Duration: Unknown", + airdate: "Aired: Unknown", + }, + ]); + } +} + +/** + * Extracts episodes from a film's page. + * @param {string} url - The URL of the film's page. + * @returns {Promise<string>} - A JSON string of the episodes. + */ +async function extractEpisodes(url) { + try { + const match = url.match(/https:\/\/filmpalast\.to\/stream\/(.+)$/); + if (!match) { + return JSON.stringify([{ number: "0", href: "" }]); + } + + return JSON.stringify([{ number: "1", href: url }]); + } catch (error) { + console.log("Fetch error:", error); + } +} + +/** + * Extracts the stream URL from a film's page. + * @param {string} url - The URL of the film's page. + * @returns {Promise<string|null>} - The stream URL or null if not found. + * + */ +async function extractStreamUrl(url) { + try { + const response = await fetch(url); + const html = await response.text ? response.text() : response; + + let streamUrl = null; + try { + streamUrl = await voeExtract(html); + } catch (error) { + console.log('VOE HD extraction error:', error); + } + + console.log('Voe Stream URL: ' + streamUrl); + if (streamUrl && streamUrl !== false && streamUrl !== null) { + return streamUrl; + } + + + console.log('using alternative extraction method'); + try { + streamUrl = await bigWarpExtract(html); + } catch (error) { + console.log('BigWarp HD extraction error:', error); + } + + console.log('BigWarp Stream URL: ' + streamUrl); + if (streamUrl && streamUrl !== false && streamUrl !== null) { + return streamUrl; + } + + console.log('No stream URL found'); + + return null; + + } catch (error) { + console.log("Fetch error:", error); + return null; + } +} + +/** + * Extracts the stream URL from a film's page. + * @param {string} url - The URL of the film's page. + * @returns {Promise<string|null>} - The stream URL or null if not found. + * Thanks to @Hamzo for the Voe extraction code. + */ + +async function voeExtract(html) { + console.log('VOE HD extraction method'); + const voeRegex = /<ul class="currentStreamLinks"[\s\S]*?<p class="hostName">VOE HD<\/p>[\s\S]*?<a[^>]+class="button rb iconPlay"[^>]+href="([^"]+)"[^>]*>/; + const voeMatch = voeRegex.exec(html); + + if (!voeMatch || !voeMatch[1]) { + console.log('VOE HD stream URL not found'); + return false; + } + const voeUrl = voeMatch[1]; + + + console.log('VOE URL:', voeUrl); + + const videoPage = await fetch(voeUrl); + if (!videoPage) { + console.log('VOE HD video page not found'); + return false; + } + + + const scriptRegex = /window\.location\.href\s*=\s*['"]([^'"]+)['"]/; + const scriptMatch = scriptRegex.exec(videoPage); + const winLocUrl = scriptMatch ? scriptMatch[1] : ''; + + if (!winLocUrl) { + console.log('VOE HD window location URL not found'); + return false; + } + + const hlsSourceUrl = await fetch(winLocUrl); + + const sourcesRegex = /var\s+sources\s*=\s*({[^}]+})/; + const sourcesMatch = sourcesRegex.exec(hlsSourceUrl); + let sourcesString = sourcesMatch ? sourcesMatch[1].replace(/'/g, '"') : null; + + sourcesString = sourcesString ? sourcesString.replace(/,\s*}/g, '}').replace(/,\s*]/g, ']') : null; + + const sources = sourcesString ? JSON.parse(sourcesString) : null; + if (sources && sources.hls) { + const hlsBase64 = sources.hls; + const hlsDecoded = base64Decode(hlsBase64); + console.log('HLS Decoded:' + hlsDecoded); + return hlsDecoded; + } + + return false; +} + +/** + * Extracts the stream URL from a film's page. + * @param {string} url - The URL of the film's page. + * @returns {Promise<string|null>} - The stream URL or null if not found. + */ + +async function bigWarpExtract(html) { + console.log('BigWarp HD extraction method'); + const bwRegex = /<ul class="currentStreamLinks"[\s\S]*?<p class="hostName">BigWarp HD<\/p>[\s\S]*?<a[^>]+class="button rb iconPlay"[^>]+href="([^"]+)"[^>]*>/; + const bwMatch = bwRegex.exec(html); + + if (!bwMatch || !bwMatch[1]) { + console.log('BigWarp HD stream URL not found'); + return false; + } + + let bwUrl = bwMatch[1]; + + console.log('BigWarp URL:', bwUrl); + + const videoPage = await fetch(bwUrl); + + const scriptRegex = /jwplayer\("vplayer"\)\.setup\(\{[\s\S]*?sources:\s*\[\{file:"([^"]+)",label:"[^"]+"\}\]/; + const scriptMatch = scriptRegex.exec(videoPage); + const bwDecoded = scriptMatch ? scriptMatch[1] : false; + console.log('BigWarp HD Decoded:', bwDecoded); + return bwDecoded; +} + +/** + * Decodes a base64 encoded string. + * @param {string} str - The base64 encoded string. + * @returns {string} - The decoded string. + */ +function base64Decode(str) { + const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + let output = ''; + + str = String(str).replace(/=+$/, ''); + + if (str.length % 4 === 1) { + throw new Error("'atob' failed: The string to be decoded is not correctly encoded."); + } + + for (let bc = 0, bs, buffer, idx = 0; (buffer = str.charAt(idx++)); ~buffer && (bs = bc % 4 ? bs * 64 + buffer : buffer, bc++ % 4) ? output += String.fromCharCode(255 & bs >> (-2 * bc & 6)) : 0) { + buffer = chars.indexOf(buffer); + } + + return output; +} + +// Check out the Sora WebUI at https://api.jm26.net/sora-modules/ \ No newline at end of file diff --git a/filmpalast/filmpalast.json b/filmpalast/filmpalast.json new file mode 100644 index 0000000..6f19eb8 --- /dev/null +++ b/filmpalast/filmpalast.json @@ -0,0 +1,19 @@ +{ + "sourceName": "Filmpalast", + "iconUrl": "https://api.jm26.net/sora-modules/filmpalast/filmpalast.ico", + "author": { + "name": "Cufiy", + "icon": "https://cdn.discordapp.com/avatars/606801871189049344/d5aba1f20de41a14540e66f357d0707b.webp", + "url": "https://github.com/JMcrafter26" + }, + "version": "1.1.3", + "language": "German (DUB)", + "streamType": "HLS", + "quality": "720p", + "baseUrl": "https://filmpalast.to", + "searchBaseUrl": "https://filmpalast.to/search/title/%s", + "scriptUrl": "https://api.jm26.net/sora-modules/filmpalast/filmpalast.js", + "asyncJS": true, + "streamAsyncJS": false, + "type": "movies/shows" + } diff --git a/fireanime/FireAnimeGer.json b/fireanime/FireAnimeGer.json new file mode 100644 index 0000000..660cca7 --- /dev/null +++ b/fireanime/FireAnimeGer.json @@ -0,0 +1,17 @@ +{ + "sourceName": "FireAnime SUB", + "iconUrl": "https://i.ibb.co/dJ1SN5ch/favicon.png", + "author": { + "name": "50/50 & Cufiy", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.1.2", + "language": "German (SUB)", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://fireani.me/", + "searchBaseUrl": "https://fireani.me/api/anime/search?q=%s", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/fireanime/v2/FireAnimeGerSub.js", + "asyncJS": true, + "type": "anime" +} diff --git a/fireanime/FireAnimeGerDub.json b/fireanime/FireAnimeGerDub.json new file mode 100644 index 0000000..29078fe --- /dev/null +++ b/fireanime/FireAnimeGerDub.json @@ -0,0 +1,17 @@ +{ + "sourceName": "FireAnime DUB", + "iconUrl": "https://i.ibb.co/dJ1SN5ch/favicon.png", + "author": { + "name": "50/50 & Cufiy", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.1.2", + "language": "German (DUB)", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://fireani.me/", + "searchBaseUrl": "https://fireani.me/api/anime/search?q=%s", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/fireanime/v2/FireAnimeGerDub.js", + "asyncJS": true, + "type": "anime" +} diff --git a/fireanime/dub.png b/fireanime/dub.png new file mode 100644 index 0000000..9f48eb0 Binary files /dev/null and b/fireanime/dub.png differ diff --git a/fireanime/eng.png b/fireanime/eng.png new file mode 100644 index 0000000..998b6f3 Binary files /dev/null and b/fireanime/eng.png differ diff --git a/fireanime/fireanime.json b/fireanime/fireanime.json new file mode 100644 index 0000000..3517545 --- /dev/null +++ b/fireanime/fireanime.json @@ -0,0 +1,17 @@ +{ + "sourceName": "FireAnime English (SUB)", + "iconUrl": "https://i.ibb.co/dJ1SN5ch/favicon.png", + "author": { + "name": "50/50 & Cufiy", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.1.2", + "language": "English (SUB)", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://fireani.me/", + "searchBaseUrl": "https://fireani.me/api/anime/search?q=%s", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/fireanime/v2/FireAnimeEngSub.js", + "asyncJS": true, + "type": "anime" +} diff --git a/fireanime/sub.png b/fireanime/sub.png new file mode 100644 index 0000000..7296fc8 Binary files /dev/null and b/fireanime/sub.png differ diff --git a/fireanime/v1/FireAnimeGer.js b/fireanime/v1/FireAnimeGer.js new file mode 100644 index 0000000..46fd135 --- /dev/null +++ b/fireanime/v1/FireAnimeGer.js @@ -0,0 +1,130 @@ +async function searchResults(keyword) { + try { + const encodedKeyword = encodeURIComponent(keyword); + const responseText = await fetch(`https://fireani.me/api/anime/search?q=${encodedKeyword}`); + const data = await JSON.parse(responseText); + + const transformedResults = data.data.map(anime => ({ + title: anime.title, + image: `https://fireani.me/img/posters/${anime.poster}`, + href: anime.slug + })); + console.log(transformedResults); + return JSON.stringify(transformedResults); + } catch (error) { + console.log('Fetch error:', error); + return JSON.stringify([{ title: 'Error', image: '', href: '' }]); + } +} + +async function extractDetails(slug) { + try { + const encodedID = encodeURIComponent(slug); + const response = await fetch(`https://fireani.me/api/anime?slug=${encodedID}`); + const data = await JSON.parse(response); + + const animeInfo = data.data; + + const transformedResults = [{ + description: animeInfo.desc || 'No description available', + aliases: `Alternate Titles: ${animeInfo.alternate_titles || 'Unknown'}`, + airdate: `Aired: ${animeInfo.start ? animeInfo.start : 'Unknown'}` + }]; + + return JSON.stringify(transformedResults); + } catch (error) { + console.log('Details error:', error); + return JSON.stringify([{ + description: 'Error loading description', + aliases: 'Duration: Unknown', + airdate: 'Aired: Unknown' + }]); + } +} + +async function extractEpisodes(slug) { + try { + const encodedID = encodeURIComponent(slug); + const response = await fetch(`https://fireani.me/api/anime?slug=${encodedID}`); + const data = await JSON.parse(response); + + let episodeCounter = 1; + + const episodes = data.data.anime_seasons.reduce((acc, season) => { + if (season.season.toLowerCase() === "filme") return acc; // Skip "Filme" season + + const seasonEpisodes = season.anime_episodes || []; + seasonEpisodes.forEach(episode => { + acc.push({ + href: `${encodedID}&season=${season.season}&episode=${episode.episode}`, + number: episodeCounter + }); + episodeCounter++; + }); + return acc; + }, []); + + console.log(episodes); + return JSON.stringify(episodes); + } catch (error) { + console.log('Fetch error:', error); + } +} + +async function extractStreamUrl(id) { + try { + const encodedID = `https://fireani.me/api/anime/episode?slug=${id}`; + const response = await fetch(`${encodedID}`); + const data = await JSON.parse(response); + + const voeStream = data.data.anime_episode_links.find(link => link.name === 'VOE' && link.lang === 'ger-sub'); + + if (voeStream) { + const newLink = voeStream.link.replace('https://voe.sx/e/', 'https://alejandrocenturyoil.com/e/'); + const tempHTML = await fetch(newLink); + + const htmlContent = await tempHTML; + + const scriptMatch = htmlContent.match(/var\s+sources\s*=\s*({.*?});/s); + if (scriptMatch) { + let rawSourcesData = scriptMatch[1]; + const hlsMatch = rawSourcesData.match(/['"]hls['"]\s*:\s*['"]([^'"]+)['"]/); + if (hlsMatch) { + const hlsEncodedUrl = hlsMatch[1]; + + const decodedUrl = base64Decode(hlsEncodedUrl); + console.log(decodedUrl); + return decodedUrl; + } else { + console.log('HLS URL not found in the sources data.'); + } + } else { + console.log('No sources variable found in the page.'); + } + } + return null; + } catch (error) { + console.log('Fetch error:', error); + return null; + } +} + + +//Credits to @hamzenis for decoder <3 +function base64Decode(str) { + const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + let output = ''; + + str = String(str).replace(/=+$/, ''); + + if (str.length % 4 === 1) { + throw new Error("'atob' failed: The string to be decoded is not correctly encoded."); + } + + for (let bc = 0, bs, buffer, idx = 0; (buffer = str.charAt(idx++)); ~buffer && (bs = bc % 4 ? bs * 64 + buffer : buffer, bc++ % 4) ? output += String.fromCharCode(255 & bs >> (-2 * bc & 6)) : 0) { + buffer = chars.indexOf(buffer); + } + + return output; +} + diff --git a/fireanime/v1/FireAnimeGerDub.js b/fireanime/v1/FireAnimeGerDub.js new file mode 100644 index 0000000..b194217 --- /dev/null +++ b/fireanime/v1/FireAnimeGerDub.js @@ -0,0 +1,130 @@ +async function searchResults(keyword) { + try { + const encodedKeyword = encodeURIComponent(keyword); + const responseText = await fetch(`https://fireani.me/api/anime/search?q=${encodedKeyword}`); + const data = await JSON.parse(responseText); + + const transformedResults = data.data.map(anime => ({ + title: anime.title, + image: `https://fireani.me/img/posters/${anime.poster}`, + href: anime.slug + })); + console.log(transformedResults); + return JSON.stringify(transformedResults); + } catch (error) { + console.log('Fetch error:', error); + return JSON.stringify([{ title: 'Error', image: '', href: '' }]); + } +} + +async function extractDetails(slug) { + try { + const encodedID = encodeURIComponent(slug); + const response = await fetch(`https://fireani.me/api/anime?slug=${encodedID}`); + const data = await JSON.parse(response); + + const animeInfo = data.data; + + const transformedResults = [{ + description: animeInfo.desc || 'No description available', + aliases: `Alternate Titles: ${animeInfo.alternate_titles || 'Unknown'}`, + airdate: `Aired: ${animeInfo.start ? animeInfo.start : 'Unknown'}` + }]; + + return JSON.stringify(transformedResults); + } catch (error) { + console.log('Details error:', error); + return JSON.stringify([{ + description: 'Error loading description', + aliases: 'Duration: Unknown', + airdate: 'Aired: Unknown' + }]); + } +} + +async function extractEpisodes(slug) { + try { + const encodedID = encodeURIComponent(slug); + const response = await fetch(`https://fireani.me/api/anime?slug=${encodedID}`); + const data = await JSON.parse(response); + + let episodeCounter = 1; + + const episodes = data.data.anime_seasons.reduce((acc, season) => { + if (season.season.toLowerCase() === "filme") return acc; // Skip "Filme" season + + const seasonEpisodes = season.anime_episodes || []; + seasonEpisodes.forEach(episode => { + acc.push({ + href: `${encodedID}&season=${season.season}&episode=${episode.episode}`, + number: episodeCounter + }); + episodeCounter++; + }); + return acc; + }, []); + + console.log(episodes); + return JSON.stringify(episodes); + } catch (error) { + console.log('Fetch error:', error); + } +} + +async function extractStreamUrl(id) { + try { + const encodedID = `https://fireani.me/api/anime/episode?slug=${id}`; + const response = await fetch(`${encodedID}`); + const data = await JSON.parse(response); + + const voeStream = data.data.anime_episode_links.find(link => link.name === 'VOE' && link.lang === 'ger-dub'); + + if (voeStream) { + const newLink = voeStream.link.replace('https://voe.sx/e/', 'https://alejandrocenturyoil.com/e/'); + const tempHTML = await fetch(newLink); + + const htmlContent = await tempHTML; + + const scriptMatch = htmlContent.match(/var\s+sources\s*=\s*({.*?});/s); + if (scriptMatch) { + let rawSourcesData = scriptMatch[1]; + const hlsMatch = rawSourcesData.match(/['"]hls['"]\s*:\s*['"]([^'"]+)['"]/); + if (hlsMatch) { + const hlsEncodedUrl = hlsMatch[1]; + + const decodedUrl = base64Decode(hlsEncodedUrl); + console.log(decodedUrl); + return decodedUrl; + } else { + console.log('HLS URL not found in the sources data.'); + } + } else { + console.log('No sources variable found in the page.'); + } + } + return null; + } catch (error) { + console.log('Fetch error:', error); + return null; + } +} + + +//Credits to @hamzenis for decoder <3 +function base64Decode(str) { + const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + let output = ''; + + str = String(str).replace(/=+$/, ''); + + if (str.length % 4 === 1) { + throw new Error("'atob' failed: The string to be decoded is not correctly encoded."); + } + + for (let bc = 0, bs, buffer, idx = 0; (buffer = str.charAt(idx++)); ~buffer && (bs = bc % 4 ? bs * 64 + buffer : buffer, bc++ % 4) ? output += String.fromCharCode(255 & bs >> (-2 * bc & 6)) : 0) { + buffer = chars.indexOf(buffer); + } + + return output; +} + diff --git a/fireanime/v1/fireanime.js b/fireanime/v1/fireanime.js new file mode 100644 index 0000000..d63ac2d --- /dev/null +++ b/fireanime/v1/fireanime.js @@ -0,0 +1,130 @@ +async function searchResults(keyword) { + try { + const encodedKeyword = encodeURIComponent(keyword); + const responseText = await fetch(`https://fireani.me/api/anime/search?q=${encodedKeyword}`); + const data = await JSON.parse(responseText); + + const transformedResults = data.data.map(anime => ({ + title: anime.title, + image: `https://fireani.me/img/posters/${anime.poster}`, + href: anime.slug + })); + console.log(transformedResults); + return JSON.stringify(transformedResults); + } catch (error) { + console.log('Fetch error:', error); + return JSON.stringify([{ title: 'Error', image: '', href: '' }]); + } +} + +async function extractDetails(slug) { + try { + const encodedID = encodeURIComponent(slug); + const response = await fetch(`https://fireani.me/api/anime?slug=${encodedID}`); + const data = await JSON.parse(response); + + const animeInfo = data.data; + + const transformedResults = [{ + description: animeInfo.desc || 'No description available', + aliases: `Alternate Titles: ${animeInfo.alternate_titles || 'Unknown'}`, + airdate: `Aired: ${animeInfo.start ? animeInfo.start : 'Unknown'}` + }]; + + return JSON.stringify(transformedResults); + } catch (error) { + console.log('Details error:', error); + return JSON.stringify([{ + description: 'Error loading description', + aliases: 'Duration: Unknown', + airdate: 'Aired: Unknown' + }]); + } +} + +async function extractEpisodes(slug) { + try { + const encodedID = encodeURIComponent(slug); + const response = await fetch(`https://fireani.me/api/anime?slug=${encodedID}`); + const data = await JSON.parse(response); + + let episodeCounter = 1; + + const episodes = data.data.anime_seasons.reduce((acc, season) => { + if (season.season.toLowerCase() === "filme") return acc; // Skip "Filme" season + + const seasonEpisodes = season.anime_episodes || []; + seasonEpisodes.forEach(episode => { + acc.push({ + href: `${encodedID}&season=${season.season}&episode=${episode.episode}`, + number: episodeCounter + }); + episodeCounter++; + }); + return acc; + }, []); + + console.log(episodes); + return JSON.stringify(episodes); + } catch (error) { + console.log('Fetch error:', error); + } +} + +async function extractStreamUrl(id) { + try { + const encodedID = `https://fireani.me/api/anime/episode?slug=${id}`; + const response = await fetch(`${encodedID}`); + const data = await JSON.parse(response); + + const voeStream = data.data.anime_episode_links.find(link => link.name === 'VOE' && link.lang === 'eng-sub'); + + if (voeStream) { + const newLink = voeStream.link.replace('https://voe.sx/e/', 'https://alejandrocenturyoil.com/e/'); + const tempHTML = await fetch(newLink); + + const htmlContent = await tempHTML; + + const scriptMatch = htmlContent.match(/var\s+sources\s*=\s*({.*?});/s); + if (scriptMatch) { + let rawSourcesData = scriptMatch[1]; + const hlsMatch = rawSourcesData.match(/['"]hls['"]\s*:\s*['"]([^'"]+)['"]/); + if (hlsMatch) { + const hlsEncodedUrl = hlsMatch[1]; + + const decodedUrl = base64Decode(hlsEncodedUrl); + console.log(decodedUrl); + return decodedUrl; + } else { + console.log('HLS URL not found in the sources data.'); + } + } else { + console.log('No sources variable found in the page.'); + } + } + return null; + } catch (error) { + console.log('Fetch error:', error); + return null; + } +} + + +//Credits to @hamzenis for decoder <3 +function base64Decode(str) { + const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + let output = ''; + + str = String(str).replace(/=+$/, ''); + + if (str.length % 4 === 1) { + throw new Error("'atob' failed: The string to be decoded is not correctly encoded."); + } + + for (let bc = 0, bs, buffer, idx = 0; (buffer = str.charAt(idx++)); ~buffer && (bs = bc % 4 ? bs * 64 + buffer : buffer, bc++ % 4) ? output += String.fromCharCode(255 & bs >> (-2 * bc & 6)) : 0) { + buffer = chars.indexOf(buffer); + } + + return output; +} + diff --git a/fireanime/v2/FireAnimeEngSub.js b/fireanime/v2/FireAnimeEngSub.js new file mode 100644 index 0000000..53955b2 --- /dev/null +++ b/fireanime/v2/FireAnimeEngSub.js @@ -0,0 +1,833 @@ +async function searchResults(keyword) { + try { + const encodedKeyword = encodeURIComponent(keyword); + const responseText = await fetch(`https://fireani.me/api/anime/search?q=${encodedKeyword}`); + const data = await JSON.parse(responseText); + + const transformedResults = data.data.map(anime => ({ + title: anime.title, + image: `https://fireani.me/img/posters/${anime.poster}`, + href: anime.slug + })); + sendLog(transformedResults); + return JSON.stringify(transformedResults); + } catch (error) { + sendLog('Fetch error:', error); + return JSON.stringify([{ title: 'Error', image: '', href: '' }]); + } +} + +async function extractDetails(slug) { + try { + const encodedID = encodeURIComponent(slug); + const response = await fetch(`https://fireani.me/api/anime?slug=${encodedID}`); + const data = await JSON.parse(response); + + const animeInfo = data.data; + + const transformedResults = [{ + description: animeInfo.desc || 'No description available', + aliases: `Alternate Titles: ${animeInfo.alternate_titles || 'Unknown'}`, + airdate: `Aired: ${animeInfo.start ? animeInfo.start : 'Unknown'}` + }]; + + return JSON.stringify(transformedResults); + } catch (error) { + sendLog('Details error:', error); + return JSON.stringify([{ + description: 'Error loading description', + aliases: 'Duration: Unknown', + airdate: 'Aired: Unknown' + }]); + } +} + +async function extractEpisodes(slug) { + try { + const encodedID = encodeURIComponent(slug); + const response = await fetch(`https://fireani.me/api/anime?slug=${encodedID}`); + const data = await JSON.parse(response); + + let episodeCounter = 1; + + const episodes = data.data.anime_seasons.reduce((acc, season) => { + if (season.season.toLowerCase() === "filme") return acc; // Skip "Filme" season + + const seasonEpisodes = season.anime_episodes || []; + seasonEpisodes.forEach(episode => { + acc.push({ + href: `${encodedID}&season=${season.season}&episode=${episode.episode}`, + number: episodeCounter + }); + episodeCounter++; + }); + return acc; + }, []); + + sendLog(episodes); + return JSON.stringify(episodes); + } catch (error) { + sendLog('Fetch error:', error); + } +} + + + + +async function extractStreamUrl(id) { + try { + const encodedID = `https://fireani.me/api/anime/episode?slug=${id}`; + sendLog("Encoded ID: " + encodedID); + const response = await fetch(encodedID); + if (!_0xCheck()) return 'https://files.catbox.moe/avolvc.mp4'; + const data = await JSON.parse(response); + sendLog("Data received: " + JSON.stringify(data)); + let providers = {}; + + const language = "eng-sub"; // Default language, can be changed based on user preference + const fallbackLanguage = "ger-sub"; // Fallback language if the preferred one is not available + + + const episodeLinks = data.data.anime_episode_links || []; + episodeLinks.forEach(link => { + // Check if the link is valid and starts with http or https + if (link.link && (link.link.startsWith("http://") || link.link.startsWith("https://"))) { + // Check if the language matches the preferred one + if (link.lang === language) { + providers[link.link] = link.name.toLowerCase(); + sendLog(`Added provider: ${link.name.toLowerCase()} for link: ${link.link} in language: ${link.lang}`); + } else if (link.lang === fallbackLanguage) { + // If the preferred language is not available, use the fallback + providers[link.link] = link.name.toLowerCase(); + sendLog(`Added fallback provider: ${link.name.toLowerCase()} for link: ${link.link} in language: ${link.lang}`); + } + } else { + sendLog(`Invalid link found: ${link.link}`); + } + }); + + sendLog("Providers: " + JSON.stringify(providers)); + + + // E.g. + // providers = { + // "https://vidmoly.to/embed-preghvoypr2m.html": "vidmoly", + // "https://speedfiles.net/40d98cdccf9c": "speedfiles", + // "https://speedfiles.net/82346fs": "speedfiles", + // }; + + + let streams = []; + try { + streams = await multiExtractor(providers); + let returnedStreams = { + streams: streams, + } + + sendLog("Multi extractor streams: " + JSON.stringify(returnedStreams)); + return JSON.stringify(returnedStreams); + } catch (error) { + sendLog("Multi extractor error:" + error); + return JSON.stringify([{ provider: "Error2", link: "" }]); + } + + + if (!streams) { + throw new Error("Stream URL not found"); + } + return streams; + } catch (error) { + sendLog("Fetch error:", error); + return null; + } +} + +// if is node +if (typeof module !== 'undefined' && module.exports) { + let streamlinks = extractStreamUrl("sakamoto-days&season=1&episode=1"); + sendLog("Streamlinks: " + streamlinks); +} + +//Credits to @hamzenis for decoder <3 +function base64Decode(str) { + const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + let output = ''; + + str = String(str).replace(/=+$/, ''); + + if (str.length % 4 === 1) { + throw new Error("'atob' failed: The string to be decoded is not correctly encoded."); + } + + for (let bc = 0, bs, buffer, idx = 0; (buffer = str.charAt(idx++)); ~buffer && (bs = bc % 4 ? bs * 64 + buffer : buffer, bc++ % 4) ? output += String.fromCharCode(255 & bs >> (-2 * bc & 6)) : 0) { + buffer = chars.indexOf(buffer); + } + + return output; +} +function _0xCheck() { + var _0x1a = typeof _0xB4F2 === 'function'; + var _0x2b = typeof _0x7E9A === 'function'; + return _0x1a && _0x2b ? (function(_0x3c) { + return _0x7E9A(_0x3c); + })(_0xB4F2()) : !1; +} + +function _0x7E9A(_){return((___,____,_____,______,_______,________,_________,__________,___________,____________)=>(____=typeof ___,_____=___&&___[String.fromCharCode(...[108,101,110,103,116,104])],______=[...String.fromCharCode(...[99,114,97,110,99,105])],_______=___?[...___[String.fromCharCode(...[116,111,76,111,119,101,114,67,97,115,101])]()]:[],(________=______[String.fromCharCode(...[115,108,105,99,101])]())&&_______[String.fromCharCode(...[102,111,114,69,97,99,104])]((_________,__________)=>(___________=________[String.fromCharCode(...[105,110,100,101,120,79,102])](_________))>=0&&________[String.fromCharCode(...[115,112,108,105,99,101])](___________,1)),____===String.fromCharCode(...[115,116,114,105,110,103])&&_____===16&&________[String.fromCharCode(...[108,101,110,103,116,104])]===0))(_)} +// Local Debugging function to send logs +async function sendLog(message) { + // send http://192.168.2.130/sora-module/log.php?action=add&message=message + console.log(message); + return; + + await fetch('http://192.168.2.130/sora-module/log.php?action=add&message=' + encodeURIComponent(message)) + .catch(error => { + console.error('Error sending log:', error); + }); +} + +// ⚠️ DO NOT EDIT BELOW THIS LINE ⚠️ +// EDITING THIS FILE COULD BREAK THE UPDATER AND CAUSE ISSUES WITH THE EXTRACTOR + +/* {GE START} */ +/* {VERSION: 1.1.3} */ + +/** + * @name global_extractor.js + * @description A global extractor for various streaming providers to be used in Sora Modules. + * @author Cufiy + * @url https://github.com/JMcrafter26/sora-global-extractor + * @license CUSTOM LICENSE - see https://github.com/JMcrafter26/sora-global-extractor/blob/main/LICENSE + * @date 2025-07-23 17:47:48 + * @version 1.1.3 + * @note This file was generated automatically. + * The global extractor comes with an auto-updating feature, so you can always get the latest version. https://github.com/JMcrafter26/sora-global-extractor#-auto-updater + */ + + +function globalExtractor(providers) { + for (const [url, provider] of Object.entries(providers)) { + try { + const streamUrl = extractStreamUrlByProvider(url, provider); + // check if streamUrl is not null, a string, and starts with http or https + if (streamUrl && typeof streamUrl === "string" && (streamUrl.startsWith("http"))) { + return streamUrl; + } + } catch (error) { + // Ignore the error and try the next provider + } + } + return null; +} + +async function multiExtractor(providers) { + /* this scheme should be returned as a JSON object + { + "streams": [ + "FileMoon", + "https://filemoon.example/stream1.m3u8", + "StreamWish", + "https://streamwish.example/stream2.m3u8", + "Okru", + "https://okru.example/stream3.m3u8", + "MP4", + "https://mp4upload.example/stream4.mp4", + "Default", + "https://default.example/stream5.m3u8" + ] +} + */ + + const streams = []; + const providersCount = {}; + for (let [url, provider] of Object.entries(providers)) { + try { + // if provider starts with "direct-", then add the url to the streams array directly + if (provider.startsWith("direct-")) { + const directName = provider.slice(7); // remove "direct-" prefix + if (directName && directName.length > 0) { + streams.push(directName, url); + } else { + streams.push("Direct", url); // fallback to "Direct" if no name is provided + } + continue; // skip to the next provider + } + if (provider.startsWith("direct")) { + provider = provider.slice(7); // remove "direct-" prefix + if (provider && provider.length > 0) { + streams.push(provider, url); + } else { + streams.push("Direct", url); // fallback to "Direct" if no name is provided + } + } + + let customName = null; // to store the custom name if provided + + // if the provider has - then split it and use the first part as the provider name + if (provider.includes("-")) { + const parts = provider.split("-"); + provider = parts[0]; // use the first part as the provider name + customName = parts.slice(1).join("-"); // use the rest as the custom name + } + + // check if providercount is not bigger than 3 + if (providersCount[provider] && providersCount[provider] >= 3) { + console.log(`Skipping ${provider} as it has already 3 streams`); + continue; + } + const streamUrl = await extractStreamUrlByProvider(url, provider); + // check if streamUrl is not null, a string, and starts with http or https + // check if provider is already in streams, if it is, add a number to it + if ( + !streamUrl || + typeof streamUrl !== "string" || + !streamUrl.startsWith("http") + ) { + continue; // skip if streamUrl is not valid + } + + // if customName is defined, use it as the name + if (customName && customName.length > 0) { + provider = customName; + } + + if (providersCount[provider]) { + providersCount[provider]++; + streams.push( + provider.charAt(0).toUpperCase() + + provider.slice(1) + + "-" + + (providersCount[provider] - 1), // add a number to the provider name + streamUrl + ); + } else { + providersCount[provider] = 1; + streams.push( + provider.charAt(0).toUpperCase() + provider.slice(1), + streamUrl + ); + } + } catch (error) { + // Ignore the error and try the next provider + } + } + return streams; +} + +async function extractStreamUrlByProvider(url, provider) { + if (eval(`typeof ${provider}Extractor`) !== "function") { + // skip if the extractor is not defined + console.log(`Extractor for provider ${provider} is not defined, skipping...`); + return null; + } + let headers = { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3", + "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", + "Accept-Language": "en-US,en;q=0.5", + "Referer": url, + "Connection": "keep-alive", + "x-Requested-With": "XMLHttpRequest" + }; + if(provider == 'bigwarp') { + delete headers["User-Agent"]; + headers["x-requested-with"] = "XMLHttpRequest"; + } + // fetch the url + // and pass the response to the extractor function + console.log("Fetching URL: " + url); + const response = await soraFetch(url, { + headers + }); + + console.log("Response: " + response.status); + let html = response.text ? await response.text() : response; + // if title contains redirect, then get the redirect url + const title = html.match(/<title>(.*?)<\/title>/); + if (title && title[1].toLowerCase().includes("redirect")) { + const redirectUrl = html.match(/<meta http-equiv="refresh" content="0;url=(.*?)"/); + const redirectUrl2 = html.match(/window\.location\.href\s*=\s*["'](.*?)["']/); + const redirectUrl3 = html.match(/window\.location\.replace\s*\(\s*["'](.*?)["']\s*\)/); + if (redirectUrl) { + console.log("Redirect URL: " + redirectUrl[1]); + url = redirectUrl[1]; + html = await soraFetch(url, { + headers + }); + html = html.text ? await html.text() : html; + + } else if (redirectUrl2) { + console.log("Redirect URL 2: " + redirectUrl2[1]); + url = redirectUrl2[1]; + html = await soraFetch(url, { + headers + }); + html = html.text ? await html.text() : html; + } else if (redirectUrl3) { + console.log("Redirect URL 3: " + redirectUrl3[1]); + url = redirectUrl3[1]; + html = await soraFetch(url, { + headers + }); + html = html.text ? await html.text() : html; + } else { + console.log("No redirect URL found"); + } + } + + // console.log("HTML: " + html); + switch (provider) { + case "bigwarp": + try { + return await bigwarpExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from bigwarp:", error); + return null; + } + case "doodstream": + try { + return await doodstreamExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from doodstream:", error); + return null; + } + case "filemoon": + try { + return await filemoonExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from filemoon:", error); + return null; + } + case "mp4upload": + try { + return await mp4uploadExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from mp4upload:", error); + return null; + } + case "vidmoly": + try { + return await vidmolyExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from vidmoly:", error); + return null; + } + case "vidoza": + try { + return await vidozaExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from vidoza:", error); + return null; + } + case "voe": + try { + return await voeExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from voe:", error); + return null; + } + + default: + throw new Error(`Unknown provider: ${provider}`); + } +} + + +//////////////////////////////////////////////// +// EXTRACTORS // +//////////////////////////////////////////////// + +// DO NOT EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING // +/* --- bigwarp --- */ + +/** + * + * @name bigWarpExtractor + * @author Cufiy + */ +async function bigwarpExtractor(videoPage, url = null) { + + // regex get 'sources: [{file:"THIS_IS_THE_URL" ... ' + const scriptRegex = /sources:\s*\[\{file:"([^"]+)"/; + // const scriptRegex = + const scriptMatch = scriptRegex.exec(videoPage); + const bwDecoded = scriptMatch ? scriptMatch[1] : false; + console.log("BigWarp HD Decoded:", bwDecoded); + return bwDecoded; +} +/* --- doodstream --- */ + +/** + * @name doodstreamExtractor + * @author Cufiy + */ +async function doodstreamExtractor(html, url = null) { + console.log("DoodStream extractor called"); + console.log("DoodStream extractor URL: " + url); + const streamDomain = url.match(/https:\/\/(.*?)\//, url)[0].slice(8, -1); + const md5Path = html.match(/'\/pass_md5\/(.*?)',/, url)[0].slice(11, -2); + const token = md5Path.substring(md5Path.lastIndexOf("/") + 1); + const expiryTimestamp = new Date().valueOf(); + const random = randomStr(10); + const passResponse = await fetch(`https://${streamDomain}/pass_md5/${md5Path}`, { + headers: { + "Referer": url, + }, + }); + console.log("DoodStream extractor response: " + passResponse.status); + const responseData = await passResponse.text(); + const videoUrl = `${responseData}${random}?token=${token}&expiry=${expiryTimestamp}`; + console.log("DoodStream extractor video URL: " + videoUrl); + return videoUrl; +} +function randomStr(length) { + const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; + let result = ""; + for (let i = 0; i < length; i++) { + result += characters.charAt(Math.floor(Math.random() * characters.length)); + } + return result; +} +/* --- filemoon --- */ + +/* {REQUIRED PLUGINS: unbaser} */ +/** + * @name filemoonExtractor + * @author Cufiy - Inspired by Churly + */ +async function filemoonExtractor(html, url = null) { + // check if contains iframe, if does, extract the src and get the url + const regex = /<iframe[^>]+src="([^"]+)"[^>]*><\/iframe>/; + const match = html.match(regex); + if (match) { + console.log("Iframe URL: " + match[1]); + const iframeUrl = match[1]; + const iframeResponse = await soraFetch(iframeUrl, { + headers: { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3", + "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", + "Referer": url, + } + }); + console.log("Iframe Response: " + iframeResponse.status); + html = await iframeResponse.text(); + } + // console.log("HTML: " + html); + // get /<script[^>]*>([\s\S]*?)<\/script>/gi + const scriptRegex = /<script[^>]*>([\s\S]*?)<\/script>/gi; + const scripts = []; + let scriptMatch; + while ((scriptMatch = scriptRegex.exec(html)) !== null) { + scripts.push(scriptMatch[1]); + } + // get the script with eval and m3u8 + const evalRegex = /eval\((.*?)\)/; + const m3u8Regex = /m3u8/; + // console.log("Scripts: " + scripts); + const evalScript = scripts.find(script => evalRegex.test(script) && m3u8Regex.test(script)); + if (!evalScript) { + console.log("No eval script found"); + return null; + } + const unpackedScript = unpack(evalScript); + // get the m3u8 url + const m3u8Regex2 = /https?:\/\/[^\s]+master\.m3u8[^\s]*?(\?[^"]*)?/; + const m3u8Match = unpackedScript.match(m3u8Regex2); + if (m3u8Match) { + return m3u8Match[0]; + } else { + console.log("No M3U8 URL found"); + return null; + } +} + + +/* --- mp4upload --- */ + +/** + * @name mp4uploadExtractor + * @author Cufiy + */ +async function mp4uploadExtractor(html, url = null) { + // src: "https://a4.mp4upload.com:183/d/xkx3b4etz3b4quuo66rbmyqtjjoivahfxp27f35pti45rzapbvj5xwb4wuqtlpewdz4dirfp/video.mp4" + const regex = /src:\s*"([^"]+)"/; + const match = html.match(regex); + if (match) { + return match[1]; + } else { + console.log("No match found for mp4upload extractor"); + return null; + } +} +/* --- vidmoly --- */ + +/** + * @name vidmolyExtractor + * @author Ibro + */ +async function vidmolyExtractor(html, url = null) { + const regexSub = /<option value="([^"]+)"[^>]*>\s*SUB - Omega\s*<\/option>/; + const regexFallback = /<option value="([^"]+)"[^>]*>\s*Omega\s*<\/option>/; + const fallback = + /<option value="([^"]+)"[^>]*>\s*SUB v2 - Omega\s*<\/option>/; + let match = + html.match(regexSub) || html.match(regexFallback) || html.match(fallback); + if (match) { + const decodedHtml = atob(match[1]); // Decode base64 + const iframeMatch = decodedHtml.match(/<iframe\s+src="([^"]+)"/); + if (!iframeMatch) { + console.log("Vidmoly extractor: No iframe match found"); + return null; + } + const streamUrl = iframeMatch[1].startsWith("//") + ? "https:" + iframeMatch[1] + : iframeMatch[1]; + const responseTwo = await fetchv2(streamUrl); + const htmlTwo = await responseTwo.text(); + const m3u8Match = htmlTwo.match(/sources:\s*\[\{file:"([^"]+\.m3u8)"/); + return m3u8Match ? m3u8Match[1] : null; + } else { + console.log("Vidmoly extractor: No match found, using fallback"); + // regex the sources: [{file:"this_is_the_link"}] + const sourcesRegex = /sources:\s*\[\{file:"(https?:\/\/[^"]+)"\}/; + const sourcesMatch = html.match(sourcesRegex); + let sourcesString = sourcesMatch + ? sourcesMatch[1].replace(/'/g, '"') + : null; + return sourcesString; + } +} +/* --- vidoza --- */ + +/** + * @name vidozaExtractor + * @author Cufiy + */ +async function vidozaExtractor(html, url = null) { + const regex = /<source src="([^"]+)" type='video\/mp4'>/; + const match = html.match(regex); + if (match) { + return match[1]; + } else { + console.log("No match found for vidoza extractor"); + return null; + } +} +/* --- voe --- */ + +/** + * @name voeExtractor + * @author Cufiy + */ +function voeExtractor(html, url = null) { +// Extract the first <script type="application/json">...</script> + const jsonScriptMatch = html.match( + /<script[^>]+type=["']application\/json["'][^>]*>([\s\S]*?)<\/script>/i + ); + if (!jsonScriptMatch) { + console.log("No application/json script tag found"); + return null; + } + + const obfuscatedJson = jsonScriptMatch[1].trim(); + let data; + try { + data = JSON.parse(obfuscatedJson); + } catch (e) { + throw new Error("Invalid JSON input."); + } + if (!Array.isArray(data) || typeof data[0] !== "string") { + throw new Error("Input doesn't match expected format."); + } + let obfuscatedString = data[0]; + // Step 1: ROT13 + let step1 = voeRot13(obfuscatedString); + // Step 2: Remove patterns + let step2 = voeRemovePatterns(step1); + // Step 3: Base64 decode + let step3 = voeBase64Decode(step2); + // Step 4: Subtract 3 from each char code + let step4 = voeShiftChars(step3, 3); + // Step 5: Reverse string + let step5 = step4.split("").reverse().join(""); + // Step 6: Base64 decode again + let step6 = voeBase64Decode(step5); + // Step 7: Parse as JSON + let result; + try { + result = JSON.parse(step6); + } catch (e) { + throw new Error("Final JSON parse error: " + e.message); + } + // console.log("Decoded JSON:", result); + // check if direct_access_url is set, not null and starts with http + if (result && typeof result === "object") { + const streamUrl = + result.direct_access_url || + result.source + .map((source) => source.direct_access_url) + .find((url) => url && url.startsWith("http")); + if (streamUrl) { + console.log("Voe Stream URL: " + streamUrl); + return streamUrl; + } else { + console.log("No stream URL found in the decoded JSON"); + } + } + return result; +} +function voeRot13(str) { + return str.replace(/[a-zA-Z]/g, function (c) { + return String.fromCharCode( + (c <= "Z" ? 90 : 122) >= (c = c.charCodeAt(0) + 13) + ? c + : c - 26 + ); + }); +} +function voeRemovePatterns(str) { + const patterns = ["@$", "^^", "~@", "%?", "*~", "!!", "#&"]; + let result = str; + for (const pat of patterns) { + result = result.split(pat).join(""); + } + return result; +} +function voeBase64Decode(str) { + // atob is available in browsers and Node >= 16 + if (typeof atob === "function") { + return atob(str); + } + // Node.js fallback + return Buffer.from(str, "base64").toString("utf-8"); +} +function voeShiftChars(str, shift) { + return str + .split("") + .map((c) => String.fromCharCode(c.charCodeAt(0) - shift)) + .join(""); +} + +//////////////////////////////////////////////// +// PLUGINS // +//////////////////////////////////////////////// + +/** + * Uses Sora's fetchv2 on ipad, fallbacks to regular fetch on Windows + * @author ShadeOfChaos + * + * @param {string} url The URL to make the request to. + * @param {object} [options] The options to use for the request. + * @param {object} [options.headers] The headers to send with the request. + * @param {string} [options.method='GET'] The method to use for the request. + * @param {string} [options.body=null] The body of the request. + * + * @returns {Promise<Response|null>} The response from the server, or null if the + * request failed. + */ +async function soraFetch(url, options = { headers: {}, method: 'GET', body: null }) { + try { + return await fetchv2(url, options.headers ?? {}, options.method ?? 'GET', options.body ?? null); + } catch(e) { + try { + return await fetch(url, options); + } catch(error) { + await console.log('soraFetch error: ' + error.message); + return null; + } + } +} + +class Unbaser { + constructor(base) { + this.ALPHABET = { + 62: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", + 95: "' !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'", + }; + this.dictionary = {}; + this.base = base; + if (36 < base && base < 62) { + this.ALPHABET[base] = this.ALPHABET[base] || + this.ALPHABET[62].substr(0, base); + } + if (2 <= base && base <= 36) { + this.unbase = (value) => parseInt(value, base); + } + else { + try { + [...this.ALPHABET[base]].forEach((cipher, index) => { + this.dictionary[cipher] = index; + }); + } + catch (er) { + throw Error("Unsupported base encoding."); + } + this.unbase = this._dictunbaser; + } + } + _dictunbaser(value) { + let ret = 0; + [...value].reverse().forEach((cipher, index) => { + ret = ret + ((Math.pow(this.base, index)) * this.dictionary[cipher]); + }); + return ret; + } +} +function unpack(source) { + let { payload, symtab, radix, count } = _filterargs(source); + if (count != symtab.length) { + throw Error("Malformed p.a.c.k.e.r. symtab."); + } + let unbase; + try { + unbase = new Unbaser(radix); + } + catch (e) { + throw Error("Unknown p.a.c.k.e.r. encoding."); + } + function lookup(match) { + const word = match; + let word2; + if (radix == 1) { + word2 = symtab[parseInt(word)]; + } + else { + word2 = symtab[unbase.unbase(word)]; + } + return word2 || word; + } + source = payload.replace(/\b\w+\b/g, lookup); + return _replacestrings(source); + function _filterargs(source) { + const juicers = [ + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\), *(\d+), *(.*)\)\)/, + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\)/, + ]; + for (const juicer of juicers) { + const args = juicer.exec(source); + if (args) { + let a = args; + if (a[2] == "[]") { + } + try { + return { + payload: a[1], + symtab: a[4].split("|"), + radix: parseInt(a[2]), + count: parseInt(a[3]), + }; + } + catch (ValueError) { + throw Error("Corrupted p.a.c.k.e.r. data."); + } + } + } + throw Error("Could not make sense of p.a.c.k.e.r data (unexpected code structure)"); + } + function _replacestrings(source) { + return source; + } +} + + + +/* {GE END} */ diff --git a/fireanime/v2/FireAnimeGerDub.js b/fireanime/v2/FireAnimeGerDub.js new file mode 100644 index 0000000..3914bd1 --- /dev/null +++ b/fireanime/v2/FireAnimeGerDub.js @@ -0,0 +1,834 @@ +async function searchResults(keyword) { + try { + const encodedKeyword = encodeURIComponent(keyword); + const responseText = await fetch(`https://fireani.me/api/anime/search?q=${encodedKeyword}`); + const data = await JSON.parse(responseText); + + const transformedResults = data.data.map(anime => ({ + title: anime.title, + image: `https://fireani.me/img/posters/${anime.poster}`, + href: anime.slug + })); + sendLog(transformedResults); + return JSON.stringify(transformedResults); + } catch (error) { + sendLog('Fetch error:', error); + return JSON.stringify([{ title: 'Error', image: '', href: '' }]); + } +} + +async function extractDetails(slug) { + try { + const encodedID = encodeURIComponent(slug); + const response = await fetch(`https://fireani.me/api/anime?slug=${encodedID}`); + const data = await JSON.parse(response); + + const animeInfo = data.data; + + const transformedResults = [{ + description: animeInfo.desc || 'No description available', + aliases: `Alternate Titles: ${animeInfo.alternate_titles || 'Unknown'}`, + airdate: `Aired: ${animeInfo.start ? animeInfo.start : 'Unknown'}` + }]; + + return JSON.stringify(transformedResults); + } catch (error) { + sendLog('Details error:', error); + return JSON.stringify([{ + description: 'Error loading description', + aliases: 'Duration: Unknown', + airdate: 'Aired: Unknown' + }]); + } +} + +async function extractEpisodes(slug) { + try { + const encodedID = encodeURIComponent(slug); + const response = await fetch(`https://fireani.me/api/anime?slug=${encodedID}`); + const data = await JSON.parse(response); + + let episodeCounter = 1; + + const episodes = data.data.anime_seasons.reduce((acc, season) => { + if (season.season.toLowerCase() === "filme") return acc; // Skip "Filme" season + + const seasonEpisodes = season.anime_episodes || []; + seasonEpisodes.forEach(episode => { + acc.push({ + href: `${encodedID}&season=${season.season}&episode=${episode.episode}`, + number: episodeCounter + }); + episodeCounter++; + }); + return acc; + }, []); + + sendLog(episodes); + return JSON.stringify(episodes); + } catch (error) { + sendLog('Fetch error:', error); + } +} + + + + +async function extractStreamUrl(id) { + try { + const encodedID = `https://fireani.me/api/anime/episode?slug=${id}`; + sendLog("Encoded ID: " + encodedID); + const response = await fetch(encodedID); + if (!_0xCheck()) return 'https://files.catbox.moe/avolvc.mp4'; + const data = await JSON.parse(response); + sendLog("Data received: " + JSON.stringify(data)); + let providers = {}; + + const language = "ger-dub"; // Default language, can be changed based on user preference + const fallbackLanguage = "ger-sub"; // Fallback language if the preferred one is not available + + + const episodeLinks = data.data.anime_episode_links || []; + episodeLinks.forEach(link => { + // Check if the link is valid and starts with http or https + if (link.link && (link.link.startsWith("http://") || link.link.startsWith("https://"))) { + // Check if the language matches the preferred one + if (link.lang === language) { + providers[link.link] = link.name.toLowerCase(); + sendLog(`Added provider: ${link.name.toLowerCase()} for link: ${link.link} in language: ${link.lang}`); + } else if (link.lang === fallbackLanguage) { + // If the preferred language is not available, use the fallback + providers[link.link] = link.name.toLowerCase(); + sendLog(`Added fallback provider: ${link.name.toLowerCase()} for link: ${link.link} in language: ${link.lang}`); + } + } else { + sendLog(`Invalid link found: ${link.link}`); + } + }); + + sendLog("Providers: " + JSON.stringify(providers)); + + + // E.g. + // providers = { + // "https://vidmoly.to/embed-preghvoypr2m.html": "vidmoly", + // "https://speedfiles.net/40d98cdccf9c": "speedfiles", + // "https://speedfiles.net/82346fs": "speedfiles", + // }; + + + let streams = []; + try { + streams = await multiExtractor(providers); + let returnedStreams = { + streams: streams, + } + + sendLog("Multi extractor streams: " + JSON.stringify(returnedStreams)); + return JSON.stringify(returnedStreams); + } catch (error) { + sendLog("Multi extractor error:" + error); + return JSON.stringify([{ provider: "Error2", link: "" }]); + } + + + if (!streams) { + throw new Error("Stream URL not found"); + } + return streams; + } catch (error) { + sendLog("Fetch error:", error); + return null; + } +} + +// if is node +if (typeof module !== 'undefined' && module.exports) { + let streamlinks = extractStreamUrl("sakamoto-days&season=1&episode=1"); + sendLog("Streamlinks: " + streamlinks); +} + +//Credits to @hamzenis for decoder <3 +function base64Decode(str) { + const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + let output = ''; + + str = String(str).replace(/=+$/, ''); + + if (str.length % 4 === 1) { + throw new Error("'atob' failed: The string to be decoded is not correctly encoded."); + } + + for (let bc = 0, bs, buffer, idx = 0; (buffer = str.charAt(idx++)); ~buffer && (bs = bc % 4 ? bs * 64 + buffer : buffer, bc++ % 4) ? output += String.fromCharCode(255 & bs >> (-2 * bc & 6)) : 0) { + buffer = chars.indexOf(buffer); + } + + return output; +} +function _0xCheck() { + var _0x1a = typeof _0xB4F2 === 'function'; + var _0x2b = typeof _0x7E9A === 'function'; + return _0x1a && _0x2b ? (function(_0x3c) { + return _0x7E9A(_0x3c); + })(_0xB4F2()) : !1; +} + +function _0x7E9A(_){return((___,____,_____,______,_______,________,_________,__________,___________,____________)=>(____=typeof ___,_____=___&&___[String.fromCharCode(...[108,101,110,103,116,104])],______=[...String.fromCharCode(...[99,114,97,110,99,105])],_______=___?[...___[String.fromCharCode(...[116,111,76,111,119,101,114,67,97,115,101])]()]:[],(________=______[String.fromCharCode(...[115,108,105,99,101])]())&&_______[String.fromCharCode(...[102,111,114,69,97,99,104])]((_________,__________)=>(___________=________[String.fromCharCode(...[105,110,100,101,120,79,102])](_________))>=0&&________[String.fromCharCode(...[115,112,108,105,99,101])](___________,1)),____===String.fromCharCode(...[115,116,114,105,110,103])&&_____===16&&________[String.fromCharCode(...[108,101,110,103,116,104])]===0))(_)} + +// Local Debugging function to send logs +async function sendLog(message) { + // send http://192.168.2.130/sora-module/log.php?action=add&message=message + console.log(message); + return; + + await fetch('http://192.168.2.130/sora-module/log.php?action=add&message=' + encodeURIComponent(message)) + .catch(error => { + console.error('Error sending log:', error); + }); +} + +// ⚠️ DO NOT EDIT BELOW THIS LINE ⚠️ +// EDITING THIS FILE COULD BREAK THE UPDATER AND CAUSE ISSUES WITH THE EXTRACTOR + +/* {GE START} */ +/* {VERSION: 1.1.3} */ + +/** + * @name global_extractor.js + * @description A global extractor for various streaming providers to be used in Sora Modules. + * @author Cufiy + * @url https://github.com/JMcrafter26/sora-global-extractor + * @license CUSTOM LICENSE - see https://github.com/JMcrafter26/sora-global-extractor/blob/main/LICENSE + * @date 2025-07-23 17:47:48 + * @version 1.1.3 + * @note This file was generated automatically. + * The global extractor comes with an auto-updating feature, so you can always get the latest version. https://github.com/JMcrafter26/sora-global-extractor#-auto-updater + */ + + +function globalExtractor(providers) { + for (const [url, provider] of Object.entries(providers)) { + try { + const streamUrl = extractStreamUrlByProvider(url, provider); + // check if streamUrl is not null, a string, and starts with http or https + if (streamUrl && typeof streamUrl === "string" && (streamUrl.startsWith("http"))) { + return streamUrl; + } + } catch (error) { + // Ignore the error and try the next provider + } + } + return null; +} + +async function multiExtractor(providers) { + /* this scheme should be returned as a JSON object + { + "streams": [ + "FileMoon", + "https://filemoon.example/stream1.m3u8", + "StreamWish", + "https://streamwish.example/stream2.m3u8", + "Okru", + "https://okru.example/stream3.m3u8", + "MP4", + "https://mp4upload.example/stream4.mp4", + "Default", + "https://default.example/stream5.m3u8" + ] +} + */ + + const streams = []; + const providersCount = {}; + for (let [url, provider] of Object.entries(providers)) { + try { + // if provider starts with "direct-", then add the url to the streams array directly + if (provider.startsWith("direct-")) { + const directName = provider.slice(7); // remove "direct-" prefix + if (directName && directName.length > 0) { + streams.push(directName, url); + } else { + streams.push("Direct", url); // fallback to "Direct" if no name is provided + } + continue; // skip to the next provider + } + if (provider.startsWith("direct")) { + provider = provider.slice(7); // remove "direct-" prefix + if (provider && provider.length > 0) { + streams.push(provider, url); + } else { + streams.push("Direct", url); // fallback to "Direct" if no name is provided + } + } + + let customName = null; // to store the custom name if provided + + // if the provider has - then split it and use the first part as the provider name + if (provider.includes("-")) { + const parts = provider.split("-"); + provider = parts[0]; // use the first part as the provider name + customName = parts.slice(1).join("-"); // use the rest as the custom name + } + + // check if providercount is not bigger than 3 + if (providersCount[provider] && providersCount[provider] >= 3) { + console.log(`Skipping ${provider} as it has already 3 streams`); + continue; + } + const streamUrl = await extractStreamUrlByProvider(url, provider); + // check if streamUrl is not null, a string, and starts with http or https + // check if provider is already in streams, if it is, add a number to it + if ( + !streamUrl || + typeof streamUrl !== "string" || + !streamUrl.startsWith("http") + ) { + continue; // skip if streamUrl is not valid + } + + // if customName is defined, use it as the name + if (customName && customName.length > 0) { + provider = customName; + } + + if (providersCount[provider]) { + providersCount[provider]++; + streams.push( + provider.charAt(0).toUpperCase() + + provider.slice(1) + + "-" + + (providersCount[provider] - 1), // add a number to the provider name + streamUrl + ); + } else { + providersCount[provider] = 1; + streams.push( + provider.charAt(0).toUpperCase() + provider.slice(1), + streamUrl + ); + } + } catch (error) { + // Ignore the error and try the next provider + } + } + return streams; +} + +async function extractStreamUrlByProvider(url, provider) { + if (eval(`typeof ${provider}Extractor`) !== "function") { + // skip if the extractor is not defined + console.log(`Extractor for provider ${provider} is not defined, skipping...`); + return null; + } + let headers = { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3", + "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", + "Accept-Language": "en-US,en;q=0.5", + "Referer": url, + "Connection": "keep-alive", + "x-Requested-With": "XMLHttpRequest" + }; + if(provider == 'bigwarp') { + delete headers["User-Agent"]; + headers["x-requested-with"] = "XMLHttpRequest"; + } + // fetch the url + // and pass the response to the extractor function + console.log("Fetching URL: " + url); + const response = await soraFetch(url, { + headers + }); + + console.log("Response: " + response.status); + let html = response.text ? await response.text() : response; + // if title contains redirect, then get the redirect url + const title = html.match(/<title>(.*?)<\/title>/); + if (title && title[1].toLowerCase().includes("redirect")) { + const redirectUrl = html.match(/<meta http-equiv="refresh" content="0;url=(.*?)"/); + const redirectUrl2 = html.match(/window\.location\.href\s*=\s*["'](.*?)["']/); + const redirectUrl3 = html.match(/window\.location\.replace\s*\(\s*["'](.*?)["']\s*\)/); + if (redirectUrl) { + console.log("Redirect URL: " + redirectUrl[1]); + url = redirectUrl[1]; + html = await soraFetch(url, { + headers + }); + html = html.text ? await html.text() : html; + + } else if (redirectUrl2) { + console.log("Redirect URL 2: " + redirectUrl2[1]); + url = redirectUrl2[1]; + html = await soraFetch(url, { + headers + }); + html = html.text ? await html.text() : html; + } else if (redirectUrl3) { + console.log("Redirect URL 3: " + redirectUrl3[1]); + url = redirectUrl3[1]; + html = await soraFetch(url, { + headers + }); + html = html.text ? await html.text() : html; + } else { + console.log("No redirect URL found"); + } + } + + // console.log("HTML: " + html); + switch (provider) { + case "bigwarp": + try { + return await bigwarpExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from bigwarp:", error); + return null; + } + case "doodstream": + try { + return await doodstreamExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from doodstream:", error); + return null; + } + case "filemoon": + try { + return await filemoonExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from filemoon:", error); + return null; + } + case "mp4upload": + try { + return await mp4uploadExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from mp4upload:", error); + return null; + } + case "vidmoly": + try { + return await vidmolyExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from vidmoly:", error); + return null; + } + case "vidoza": + try { + return await vidozaExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from vidoza:", error); + return null; + } + case "voe": + try { + return await voeExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from voe:", error); + return null; + } + + default: + throw new Error(`Unknown provider: ${provider}`); + } +} + + +//////////////////////////////////////////////// +// EXTRACTORS // +//////////////////////////////////////////////// + +// DO NOT EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING // +/* --- bigwarp --- */ + +/** + * + * @name bigWarpExtractor + * @author Cufiy + */ +async function bigwarpExtractor(videoPage, url = null) { + + // regex get 'sources: [{file:"THIS_IS_THE_URL" ... ' + const scriptRegex = /sources:\s*\[\{file:"([^"]+)"/; + // const scriptRegex = + const scriptMatch = scriptRegex.exec(videoPage); + const bwDecoded = scriptMatch ? scriptMatch[1] : false; + console.log("BigWarp HD Decoded:", bwDecoded); + return bwDecoded; +} +/* --- doodstream --- */ + +/** + * @name doodstreamExtractor + * @author Cufiy + */ +async function doodstreamExtractor(html, url = null) { + console.log("DoodStream extractor called"); + console.log("DoodStream extractor URL: " + url); + const streamDomain = url.match(/https:\/\/(.*?)\//, url)[0].slice(8, -1); + const md5Path = html.match(/'\/pass_md5\/(.*?)',/, url)[0].slice(11, -2); + const token = md5Path.substring(md5Path.lastIndexOf("/") + 1); + const expiryTimestamp = new Date().valueOf(); + const random = randomStr(10); + const passResponse = await fetch(`https://${streamDomain}/pass_md5/${md5Path}`, { + headers: { + "Referer": url, + }, + }); + console.log("DoodStream extractor response: " + passResponse.status); + const responseData = await passResponse.text(); + const videoUrl = `${responseData}${random}?token=${token}&expiry=${expiryTimestamp}`; + console.log("DoodStream extractor video URL: " + videoUrl); + return videoUrl; +} +function randomStr(length) { + const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; + let result = ""; + for (let i = 0; i < length; i++) { + result += characters.charAt(Math.floor(Math.random() * characters.length)); + } + return result; +} +/* --- filemoon --- */ + +/* {REQUIRED PLUGINS: unbaser} */ +/** + * @name filemoonExtractor + * @author Cufiy - Inspired by Churly + */ +async function filemoonExtractor(html, url = null) { + // check if contains iframe, if does, extract the src and get the url + const regex = /<iframe[^>]+src="([^"]+)"[^>]*><\/iframe>/; + const match = html.match(regex); + if (match) { + console.log("Iframe URL: " + match[1]); + const iframeUrl = match[1]; + const iframeResponse = await soraFetch(iframeUrl, { + headers: { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3", + "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", + "Referer": url, + } + }); + console.log("Iframe Response: " + iframeResponse.status); + html = await iframeResponse.text(); + } + // console.log("HTML: " + html); + // get /<script[^>]*>([\s\S]*?)<\/script>/gi + const scriptRegex = /<script[^>]*>([\s\S]*?)<\/script>/gi; + const scripts = []; + let scriptMatch; + while ((scriptMatch = scriptRegex.exec(html)) !== null) { + scripts.push(scriptMatch[1]); + } + // get the script with eval and m3u8 + const evalRegex = /eval\((.*?)\)/; + const m3u8Regex = /m3u8/; + // console.log("Scripts: " + scripts); + const evalScript = scripts.find(script => evalRegex.test(script) && m3u8Regex.test(script)); + if (!evalScript) { + console.log("No eval script found"); + return null; + } + const unpackedScript = unpack(evalScript); + // get the m3u8 url + const m3u8Regex2 = /https?:\/\/[^\s]+master\.m3u8[^\s]*?(\?[^"]*)?/; + const m3u8Match = unpackedScript.match(m3u8Regex2); + if (m3u8Match) { + return m3u8Match[0]; + } else { + console.log("No M3U8 URL found"); + return null; + } +} + + +/* --- mp4upload --- */ + +/** + * @name mp4uploadExtractor + * @author Cufiy + */ +async function mp4uploadExtractor(html, url = null) { + // src: "https://a4.mp4upload.com:183/d/xkx3b4etz3b4quuo66rbmyqtjjoivahfxp27f35pti45rzapbvj5xwb4wuqtlpewdz4dirfp/video.mp4" + const regex = /src:\s*"([^"]+)"/; + const match = html.match(regex); + if (match) { + return match[1]; + } else { + console.log("No match found for mp4upload extractor"); + return null; + } +} +/* --- vidmoly --- */ + +/** + * @name vidmolyExtractor + * @author Ibro + */ +async function vidmolyExtractor(html, url = null) { + const regexSub = /<option value="([^"]+)"[^>]*>\s*SUB - Omega\s*<\/option>/; + const regexFallback = /<option value="([^"]+)"[^>]*>\s*Omega\s*<\/option>/; + const fallback = + /<option value="([^"]+)"[^>]*>\s*SUB v2 - Omega\s*<\/option>/; + let match = + html.match(regexSub) || html.match(regexFallback) || html.match(fallback); + if (match) { + const decodedHtml = atob(match[1]); // Decode base64 + const iframeMatch = decodedHtml.match(/<iframe\s+src="([^"]+)"/); + if (!iframeMatch) { + console.log("Vidmoly extractor: No iframe match found"); + return null; + } + const streamUrl = iframeMatch[1].startsWith("//") + ? "https:" + iframeMatch[1] + : iframeMatch[1]; + const responseTwo = await fetchv2(streamUrl); + const htmlTwo = await responseTwo.text(); + const m3u8Match = htmlTwo.match(/sources:\s*\[\{file:"([^"]+\.m3u8)"/); + return m3u8Match ? m3u8Match[1] : null; + } else { + console.log("Vidmoly extractor: No match found, using fallback"); + // regex the sources: [{file:"this_is_the_link"}] + const sourcesRegex = /sources:\s*\[\{file:"(https?:\/\/[^"]+)"\}/; + const sourcesMatch = html.match(sourcesRegex); + let sourcesString = sourcesMatch + ? sourcesMatch[1].replace(/'/g, '"') + : null; + return sourcesString; + } +} +/* --- vidoza --- */ + +/** + * @name vidozaExtractor + * @author Cufiy + */ +async function vidozaExtractor(html, url = null) { + const regex = /<source src="([^"]+)" type='video\/mp4'>/; + const match = html.match(regex); + if (match) { + return match[1]; + } else { + console.log("No match found for vidoza extractor"); + return null; + } +} +/* --- voe --- */ + +/** + * @name voeExtractor + * @author Cufiy + */ +function voeExtractor(html, url = null) { +// Extract the first <script type="application/json">...</script> + const jsonScriptMatch = html.match( + /<script[^>]+type=["']application\/json["'][^>]*>([\s\S]*?)<\/script>/i + ); + if (!jsonScriptMatch) { + console.log("No application/json script tag found"); + return null; + } + + const obfuscatedJson = jsonScriptMatch[1].trim(); + let data; + try { + data = JSON.parse(obfuscatedJson); + } catch (e) { + throw new Error("Invalid JSON input."); + } + if (!Array.isArray(data) || typeof data[0] !== "string") { + throw new Error("Input doesn't match expected format."); + } + let obfuscatedString = data[0]; + // Step 1: ROT13 + let step1 = voeRot13(obfuscatedString); + // Step 2: Remove patterns + let step2 = voeRemovePatterns(step1); + // Step 3: Base64 decode + let step3 = voeBase64Decode(step2); + // Step 4: Subtract 3 from each char code + let step4 = voeShiftChars(step3, 3); + // Step 5: Reverse string + let step5 = step4.split("").reverse().join(""); + // Step 6: Base64 decode again + let step6 = voeBase64Decode(step5); + // Step 7: Parse as JSON + let result; + try { + result = JSON.parse(step6); + } catch (e) { + throw new Error("Final JSON parse error: " + e.message); + } + // console.log("Decoded JSON:", result); + // check if direct_access_url is set, not null and starts with http + if (result && typeof result === "object") { + const streamUrl = + result.direct_access_url || + result.source + .map((source) => source.direct_access_url) + .find((url) => url && url.startsWith("http")); + if (streamUrl) { + console.log("Voe Stream URL: " + streamUrl); + return streamUrl; + } else { + console.log("No stream URL found in the decoded JSON"); + } + } + return result; +} +function voeRot13(str) { + return str.replace(/[a-zA-Z]/g, function (c) { + return String.fromCharCode( + (c <= "Z" ? 90 : 122) >= (c = c.charCodeAt(0) + 13) + ? c + : c - 26 + ); + }); +} +function voeRemovePatterns(str) { + const patterns = ["@$", "^^", "~@", "%?", "*~", "!!", "#&"]; + let result = str; + for (const pat of patterns) { + result = result.split(pat).join(""); + } + return result; +} +function voeBase64Decode(str) { + // atob is available in browsers and Node >= 16 + if (typeof atob === "function") { + return atob(str); + } + // Node.js fallback + return Buffer.from(str, "base64").toString("utf-8"); +} +function voeShiftChars(str, shift) { + return str + .split("") + .map((c) => String.fromCharCode(c.charCodeAt(0) - shift)) + .join(""); +} + +//////////////////////////////////////////////// +// PLUGINS // +//////////////////////////////////////////////// + +/** + * Uses Sora's fetchv2 on ipad, fallbacks to regular fetch on Windows + * @author ShadeOfChaos + * + * @param {string} url The URL to make the request to. + * @param {object} [options] The options to use for the request. + * @param {object} [options.headers] The headers to send with the request. + * @param {string} [options.method='GET'] The method to use for the request. + * @param {string} [options.body=null] The body of the request. + * + * @returns {Promise<Response|null>} The response from the server, or null if the + * request failed. + */ +async function soraFetch(url, options = { headers: {}, method: 'GET', body: null }) { + try { + return await fetchv2(url, options.headers ?? {}, options.method ?? 'GET', options.body ?? null); + } catch(e) { + try { + return await fetch(url, options); + } catch(error) { + await console.log('soraFetch error: ' + error.message); + return null; + } + } +} + +class Unbaser { + constructor(base) { + this.ALPHABET = { + 62: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", + 95: "' !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'", + }; + this.dictionary = {}; + this.base = base; + if (36 < base && base < 62) { + this.ALPHABET[base] = this.ALPHABET[base] || + this.ALPHABET[62].substr(0, base); + } + if (2 <= base && base <= 36) { + this.unbase = (value) => parseInt(value, base); + } + else { + try { + [...this.ALPHABET[base]].forEach((cipher, index) => { + this.dictionary[cipher] = index; + }); + } + catch (er) { + throw Error("Unsupported base encoding."); + } + this.unbase = this._dictunbaser; + } + } + _dictunbaser(value) { + let ret = 0; + [...value].reverse().forEach((cipher, index) => { + ret = ret + ((Math.pow(this.base, index)) * this.dictionary[cipher]); + }); + return ret; + } +} +function unpack(source) { + let { payload, symtab, radix, count } = _filterargs(source); + if (count != symtab.length) { + throw Error("Malformed p.a.c.k.e.r. symtab."); + } + let unbase; + try { + unbase = new Unbaser(radix); + } + catch (e) { + throw Error("Unknown p.a.c.k.e.r. encoding."); + } + function lookup(match) { + const word = match; + let word2; + if (radix == 1) { + word2 = symtab[parseInt(word)]; + } + else { + word2 = symtab[unbase.unbase(word)]; + } + return word2 || word; + } + source = payload.replace(/\b\w+\b/g, lookup); + return _replacestrings(source); + function _filterargs(source) { + const juicers = [ + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\), *(\d+), *(.*)\)\)/, + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\)/, + ]; + for (const juicer of juicers) { + const args = juicer.exec(source); + if (args) { + let a = args; + if (a[2] == "[]") { + } + try { + return { + payload: a[1], + symtab: a[4].split("|"), + radix: parseInt(a[2]), + count: parseInt(a[3]), + }; + } + catch (ValueError) { + throw Error("Corrupted p.a.c.k.e.r. data."); + } + } + } + throw Error("Could not make sense of p.a.c.k.e.r data (unexpected code structure)"); + } + function _replacestrings(source) { + return source; + } +} + + + +/* {GE END} */ \ No newline at end of file diff --git a/fireanime/v2/FireAnimeGerSub.js b/fireanime/v2/FireAnimeGerSub.js new file mode 100644 index 0000000..ae37264 --- /dev/null +++ b/fireanime/v2/FireAnimeGerSub.js @@ -0,0 +1,833 @@ +async function searchResults(keyword) { + try { + const encodedKeyword = encodeURIComponent(keyword); + const responseText = await fetch(`https://fireani.me/api/anime/search?q=${encodedKeyword}`); + const data = await JSON.parse(responseText); + + const transformedResults = data.data.map(anime => ({ + title: anime.title, + image: `https://fireani.me/img/posters/${anime.poster}`, + href: anime.slug + })); + sendLog(transformedResults); + return JSON.stringify(transformedResults); + } catch (error) { + sendLog('Fetch error:', error); + return JSON.stringify([{ title: 'Error', image: '', href: '' }]); + } +} + +async function extractDetails(slug) { + try { + const encodedID = encodeURIComponent(slug); + const response = await fetch(`https://fireani.me/api/anime?slug=${encodedID}`); + const data = await JSON.parse(response); + + const animeInfo = data.data; + + const transformedResults = [{ + description: animeInfo.desc || 'No description available', + aliases: `Alternate Titles: ${animeInfo.alternate_titles || 'Unknown'}`, + airdate: `Aired: ${animeInfo.start ? animeInfo.start : 'Unknown'}` + }]; + + return JSON.stringify(transformedResults); + } catch (error) { + sendLog('Details error:', error); + return JSON.stringify([{ + description: 'Error loading description', + aliases: 'Duration: Unknown', + airdate: 'Aired: Unknown' + }]); + } +} + +async function extractEpisodes(slug) { + try { + const encodedID = encodeURIComponent(slug); + const response = await fetch(`https://fireani.me/api/anime?slug=${encodedID}`); + const data = await JSON.parse(response); + + let episodeCounter = 1; + + const episodes = data.data.anime_seasons.reduce((acc, season) => { + if (season.season.toLowerCase() === "filme") return acc; // Skip "Filme" season + + const seasonEpisodes = season.anime_episodes || []; + seasonEpisodes.forEach(episode => { + acc.push({ + href: `${encodedID}&season=${season.season}&episode=${episode.episode}`, + number: episodeCounter + }); + episodeCounter++; + }); + return acc; + }, []); + + sendLog(episodes); + return JSON.stringify(episodes); + } catch (error) { + sendLog('Fetch error:', error); + } +} + + + + +async function extractStreamUrl(id) { + try { + const encodedID = `https://fireani.me/api/anime/episode?slug=${id}`; + sendLog("Encoded ID: " + encodedID); + const response = await fetch(encodedID); + if (!_0xCheck()) return 'https://files.catbox.moe/avolvc.mp4'; + const data = await JSON.parse(response); + sendLog("Data received: " + JSON.stringify(data)); + let providers = {}; + + const language = "ger-sub"; // Default language, can be changed based on user preference + const fallbackLanguage = "ger-dub"; // Fallback language if the preferred one is not available + + + const episodeLinks = data.data.anime_episode_links || []; + episodeLinks.forEach(link => { + // Check if the link is valid and starts with http or https + if (link.link && (link.link.startsWith("http://") || link.link.startsWith("https://"))) { + // Check if the language matches the preferred one + if (link.lang === language) { + providers[link.link] = link.name.toLowerCase(); + sendLog(`Added provider: ${link.name.toLowerCase()} for link: ${link.link} in language: ${link.lang}`); + } else if (link.lang === fallbackLanguage) { + // If the preferred language is not available, use the fallback + providers[link.link] = link.name.toLowerCase(); + sendLog(`Added fallback provider: ${link.name.toLowerCase()} for link: ${link.link} in language: ${link.lang}`); + } + } else { + sendLog(`Invalid link found: ${link.link}`); + } + }); + + sendLog("Providers: " + JSON.stringify(providers)); + + + // E.g. + // providers = { + // "https://vidmoly.to/embed-preghvoypr2m.html": "vidmoly", + // "https://speedfiles.net/40d98cdccf9c": "speedfiles", + // "https://speedfiles.net/82346fs": "speedfiles", + // }; + + + let streams = []; + try { + streams = await multiExtractor(providers); + let returnedStreams = { + streams: streams, + } + + sendLog("Multi extractor streams: " + JSON.stringify(returnedStreams)); + return JSON.stringify(returnedStreams); + } catch (error) { + sendLog("Multi extractor error:" + error); + return JSON.stringify([{ provider: "Error2", link: "" }]); + } + + + if (!streams) { + throw new Error("Stream URL not found"); + } + return streams; + } catch (error) { + sendLog("Fetch error:", error); + return null; + } +} + +// if is node +if (typeof module !== 'undefined' && module.exports) { + let streamlinks = extractStreamUrl("sakamoto-days&season=1&episode=1"); + sendLog("Streamlinks: " + streamlinks); +} + +//Credits to @hamzenis for decoder <3 +function base64Decode(str) { + const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + let output = ''; + + str = String(str).replace(/=+$/, ''); + + if (str.length % 4 === 1) { + throw new Error("'atob' failed: The string to be decoded is not correctly encoded."); + } + + for (let bc = 0, bs, buffer, idx = 0; (buffer = str.charAt(idx++)); ~buffer && (bs = bc % 4 ? bs * 64 + buffer : buffer, bc++ % 4) ? output += String.fromCharCode(255 & bs >> (-2 * bc & 6)) : 0) { + buffer = chars.indexOf(buffer); + } + + return output; +} +function _0xCheck() { + var _0x1a = typeof _0xB4F2 === 'function'; + var _0x2b = typeof _0x7E9A === 'function'; + return _0x1a && _0x2b ? (function(_0x3c) { + return _0x7E9A(_0x3c); + })(_0xB4F2()) : !1; +} + +function _0x7E9A(_){return((___,____,_____,______,_______,________,_________,__________,___________,____________)=>(____=typeof ___,_____=___&&___[String.fromCharCode(...[108,101,110,103,116,104])],______=[...String.fromCharCode(...[99,114,97,110,99,105])],_______=___?[...___[String.fromCharCode(...[116,111,76,111,119,101,114,67,97,115,101])]()]:[],(________=______[String.fromCharCode(...[115,108,105,99,101])]())&&_______[String.fromCharCode(...[102,111,114,69,97,99,104])]((_________,__________)=>(___________=________[String.fromCharCode(...[105,110,100,101,120,79,102])](_________))>=0&&________[String.fromCharCode(...[115,112,108,105,99,101])](___________,1)),____===String.fromCharCode(...[115,116,114,105,110,103])&&_____===16&&________[String.fromCharCode(...[108,101,110,103,116,104])]===0))(_)} +// Local Debugging function to send logs +async function sendLog(message) { + // send http://192.168.2.130/sora-module/log.php?action=add&message=message + console.log(message); + return; + + await fetch('http://192.168.2.130/sora-module/log.php?action=add&message=' + encodeURIComponent(message)) + .catch(error => { + console.error('Error sending log:', error); + }); +} + +// ⚠️ DO NOT EDIT BELOW THIS LINE ⚠️ +// EDITING THIS FILE COULD BREAK THE UPDATER AND CAUSE ISSUES WITH THE EXTRACTOR + +/* {GE START} */ +/* {VERSION: 1.1.3} */ + +/** + * @name global_extractor.js + * @description A global extractor for various streaming providers to be used in Sora Modules. + * @author Cufiy + * @url https://github.com/JMcrafter26/sora-global-extractor + * @license CUSTOM LICENSE - see https://github.com/JMcrafter26/sora-global-extractor/blob/main/LICENSE + * @date 2025-07-23 17:47:48 + * @version 1.1.3 + * @note This file was generated automatically. + * The global extractor comes with an auto-updating feature, so you can always get the latest version. https://github.com/JMcrafter26/sora-global-extractor#-auto-updater + */ + + +function globalExtractor(providers) { + for (const [url, provider] of Object.entries(providers)) { + try { + const streamUrl = extractStreamUrlByProvider(url, provider); + // check if streamUrl is not null, a string, and starts with http or https + if (streamUrl && typeof streamUrl === "string" && (streamUrl.startsWith("http"))) { + return streamUrl; + } + } catch (error) { + // Ignore the error and try the next provider + } + } + return null; +} + +async function multiExtractor(providers) { + /* this scheme should be returned as a JSON object + { + "streams": [ + "FileMoon", + "https://filemoon.example/stream1.m3u8", + "StreamWish", + "https://streamwish.example/stream2.m3u8", + "Okru", + "https://okru.example/stream3.m3u8", + "MP4", + "https://mp4upload.example/stream4.mp4", + "Default", + "https://default.example/stream5.m3u8" + ] +} + */ + + const streams = []; + const providersCount = {}; + for (let [url, provider] of Object.entries(providers)) { + try { + // if provider starts with "direct-", then add the url to the streams array directly + if (provider.startsWith("direct-")) { + const directName = provider.slice(7); // remove "direct-" prefix + if (directName && directName.length > 0) { + streams.push(directName, url); + } else { + streams.push("Direct", url); // fallback to "Direct" if no name is provided + } + continue; // skip to the next provider + } + if (provider.startsWith("direct")) { + provider = provider.slice(7); // remove "direct-" prefix + if (provider && provider.length > 0) { + streams.push(provider, url); + } else { + streams.push("Direct", url); // fallback to "Direct" if no name is provided + } + } + + let customName = null; // to store the custom name if provided + + // if the provider has - then split it and use the first part as the provider name + if (provider.includes("-")) { + const parts = provider.split("-"); + provider = parts[0]; // use the first part as the provider name + customName = parts.slice(1).join("-"); // use the rest as the custom name + } + + // check if providercount is not bigger than 3 + if (providersCount[provider] && providersCount[provider] >= 3) { + console.log(`Skipping ${provider} as it has already 3 streams`); + continue; + } + const streamUrl = await extractStreamUrlByProvider(url, provider); + // check if streamUrl is not null, a string, and starts with http or https + // check if provider is already in streams, if it is, add a number to it + if ( + !streamUrl || + typeof streamUrl !== "string" || + !streamUrl.startsWith("http") + ) { + continue; // skip if streamUrl is not valid + } + + // if customName is defined, use it as the name + if (customName && customName.length > 0) { + provider = customName; + } + + if (providersCount[provider]) { + providersCount[provider]++; + streams.push( + provider.charAt(0).toUpperCase() + + provider.slice(1) + + "-" + + (providersCount[provider] - 1), // add a number to the provider name + streamUrl + ); + } else { + providersCount[provider] = 1; + streams.push( + provider.charAt(0).toUpperCase() + provider.slice(1), + streamUrl + ); + } + } catch (error) { + // Ignore the error and try the next provider + } + } + return streams; +} + +async function extractStreamUrlByProvider(url, provider) { + if (eval(`typeof ${provider}Extractor`) !== "function") { + // skip if the extractor is not defined + console.log(`Extractor for provider ${provider} is not defined, skipping...`); + return null; + } + let headers = { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3", + "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", + "Accept-Language": "en-US,en;q=0.5", + "Referer": url, + "Connection": "keep-alive", + "x-Requested-With": "XMLHttpRequest" + }; + if(provider == 'bigwarp') { + delete headers["User-Agent"]; + headers["x-requested-with"] = "XMLHttpRequest"; + } + // fetch the url + // and pass the response to the extractor function + console.log("Fetching URL: " + url); + const response = await soraFetch(url, { + headers + }); + + console.log("Response: " + response.status); + let html = response.text ? await response.text() : response; + // if title contains redirect, then get the redirect url + const title = html.match(/<title>(.*?)<\/title>/); + if (title && title[1].toLowerCase().includes("redirect")) { + const redirectUrl = html.match(/<meta http-equiv="refresh" content="0;url=(.*?)"/); + const redirectUrl2 = html.match(/window\.location\.href\s*=\s*["'](.*?)["']/); + const redirectUrl3 = html.match(/window\.location\.replace\s*\(\s*["'](.*?)["']\s*\)/); + if (redirectUrl) { + console.log("Redirect URL: " + redirectUrl[1]); + url = redirectUrl[1]; + html = await soraFetch(url, { + headers + }); + html = html.text ? await html.text() : html; + + } else if (redirectUrl2) { + console.log("Redirect URL 2: " + redirectUrl2[1]); + url = redirectUrl2[1]; + html = await soraFetch(url, { + headers + }); + html = html.text ? await html.text() : html; + } else if (redirectUrl3) { + console.log("Redirect URL 3: " + redirectUrl3[1]); + url = redirectUrl3[1]; + html = await soraFetch(url, { + headers + }); + html = html.text ? await html.text() : html; + } else { + console.log("No redirect URL found"); + } + } + + // console.log("HTML: " + html); + switch (provider) { + case "bigwarp": + try { + return await bigwarpExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from bigwarp:", error); + return null; + } + case "doodstream": + try { + return await doodstreamExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from doodstream:", error); + return null; + } + case "filemoon": + try { + return await filemoonExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from filemoon:", error); + return null; + } + case "mp4upload": + try { + return await mp4uploadExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from mp4upload:", error); + return null; + } + case "vidmoly": + try { + return await vidmolyExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from vidmoly:", error); + return null; + } + case "vidoza": + try { + return await vidozaExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from vidoza:", error); + return null; + } + case "voe": + try { + return await voeExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from voe:", error); + return null; + } + + default: + throw new Error(`Unknown provider: ${provider}`); + } +} + + +//////////////////////////////////////////////// +// EXTRACTORS // +//////////////////////////////////////////////// + +// DO NOT EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING // +/* --- bigwarp --- */ + +/** + * + * @name bigWarpExtractor + * @author Cufiy + */ +async function bigwarpExtractor(videoPage, url = null) { + + // regex get 'sources: [{file:"THIS_IS_THE_URL" ... ' + const scriptRegex = /sources:\s*\[\{file:"([^"]+)"/; + // const scriptRegex = + const scriptMatch = scriptRegex.exec(videoPage); + const bwDecoded = scriptMatch ? scriptMatch[1] : false; + console.log("BigWarp HD Decoded:", bwDecoded); + return bwDecoded; +} +/* --- doodstream --- */ + +/** + * @name doodstreamExtractor + * @author Cufiy + */ +async function doodstreamExtractor(html, url = null) { + console.log("DoodStream extractor called"); + console.log("DoodStream extractor URL: " + url); + const streamDomain = url.match(/https:\/\/(.*?)\//, url)[0].slice(8, -1); + const md5Path = html.match(/'\/pass_md5\/(.*?)',/, url)[0].slice(11, -2); + const token = md5Path.substring(md5Path.lastIndexOf("/") + 1); + const expiryTimestamp = new Date().valueOf(); + const random = randomStr(10); + const passResponse = await fetch(`https://${streamDomain}/pass_md5/${md5Path}`, { + headers: { + "Referer": url, + }, + }); + console.log("DoodStream extractor response: " + passResponse.status); + const responseData = await passResponse.text(); + const videoUrl = `${responseData}${random}?token=${token}&expiry=${expiryTimestamp}`; + console.log("DoodStream extractor video URL: " + videoUrl); + return videoUrl; +} +function randomStr(length) { + const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; + let result = ""; + for (let i = 0; i < length; i++) { + result += characters.charAt(Math.floor(Math.random() * characters.length)); + } + return result; +} +/* --- filemoon --- */ + +/* {REQUIRED PLUGINS: unbaser} */ +/** + * @name filemoonExtractor + * @author Cufiy - Inspired by Churly + */ +async function filemoonExtractor(html, url = null) { + // check if contains iframe, if does, extract the src and get the url + const regex = /<iframe[^>]+src="([^"]+)"[^>]*><\/iframe>/; + const match = html.match(regex); + if (match) { + console.log("Iframe URL: " + match[1]); + const iframeUrl = match[1]; + const iframeResponse = await soraFetch(iframeUrl, { + headers: { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3", + "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", + "Referer": url, + } + }); + console.log("Iframe Response: " + iframeResponse.status); + html = await iframeResponse.text(); + } + // console.log("HTML: " + html); + // get /<script[^>]*>([\s\S]*?)<\/script>/gi + const scriptRegex = /<script[^>]*>([\s\S]*?)<\/script>/gi; + const scripts = []; + let scriptMatch; + while ((scriptMatch = scriptRegex.exec(html)) !== null) { + scripts.push(scriptMatch[1]); + } + // get the script with eval and m3u8 + const evalRegex = /eval\((.*?)\)/; + const m3u8Regex = /m3u8/; + // console.log("Scripts: " + scripts); + const evalScript = scripts.find(script => evalRegex.test(script) && m3u8Regex.test(script)); + if (!evalScript) { + console.log("No eval script found"); + return null; + } + const unpackedScript = unpack(evalScript); + // get the m3u8 url + const m3u8Regex2 = /https?:\/\/[^\s]+master\.m3u8[^\s]*?(\?[^"]*)?/; + const m3u8Match = unpackedScript.match(m3u8Regex2); + if (m3u8Match) { + return m3u8Match[0]; + } else { + console.log("No M3U8 URL found"); + return null; + } +} + + +/* --- mp4upload --- */ + +/** + * @name mp4uploadExtractor + * @author Cufiy + */ +async function mp4uploadExtractor(html, url = null) { + // src: "https://a4.mp4upload.com:183/d/xkx3b4etz3b4quuo66rbmyqtjjoivahfxp27f35pti45rzapbvj5xwb4wuqtlpewdz4dirfp/video.mp4" + const regex = /src:\s*"([^"]+)"/; + const match = html.match(regex); + if (match) { + return match[1]; + } else { + console.log("No match found for mp4upload extractor"); + return null; + } +} +/* --- vidmoly --- */ + +/** + * @name vidmolyExtractor + * @author Ibro + */ +async function vidmolyExtractor(html, url = null) { + const regexSub = /<option value="([^"]+)"[^>]*>\s*SUB - Omega\s*<\/option>/; + const regexFallback = /<option value="([^"]+)"[^>]*>\s*Omega\s*<\/option>/; + const fallback = + /<option value="([^"]+)"[^>]*>\s*SUB v2 - Omega\s*<\/option>/; + let match = + html.match(regexSub) || html.match(regexFallback) || html.match(fallback); + if (match) { + const decodedHtml = atob(match[1]); // Decode base64 + const iframeMatch = decodedHtml.match(/<iframe\s+src="([^"]+)"/); + if (!iframeMatch) { + console.log("Vidmoly extractor: No iframe match found"); + return null; + } + const streamUrl = iframeMatch[1].startsWith("//") + ? "https:" + iframeMatch[1] + : iframeMatch[1]; + const responseTwo = await fetchv2(streamUrl); + const htmlTwo = await responseTwo.text(); + const m3u8Match = htmlTwo.match(/sources:\s*\[\{file:"([^"]+\.m3u8)"/); + return m3u8Match ? m3u8Match[1] : null; + } else { + console.log("Vidmoly extractor: No match found, using fallback"); + // regex the sources: [{file:"this_is_the_link"}] + const sourcesRegex = /sources:\s*\[\{file:"(https?:\/\/[^"]+)"\}/; + const sourcesMatch = html.match(sourcesRegex); + let sourcesString = sourcesMatch + ? sourcesMatch[1].replace(/'/g, '"') + : null; + return sourcesString; + } +} +/* --- vidoza --- */ + +/** + * @name vidozaExtractor + * @author Cufiy + */ +async function vidozaExtractor(html, url = null) { + const regex = /<source src="([^"]+)" type='video\/mp4'>/; + const match = html.match(regex); + if (match) { + return match[1]; + } else { + console.log("No match found for vidoza extractor"); + return null; + } +} +/* --- voe --- */ + +/** + * @name voeExtractor + * @author Cufiy + */ +function voeExtractor(html, url = null) { +// Extract the first <script type="application/json">...</script> + const jsonScriptMatch = html.match( + /<script[^>]+type=["']application\/json["'][^>]*>([\s\S]*?)<\/script>/i + ); + if (!jsonScriptMatch) { + console.log("No application/json script tag found"); + return null; + } + + const obfuscatedJson = jsonScriptMatch[1].trim(); + let data; + try { + data = JSON.parse(obfuscatedJson); + } catch (e) { + throw new Error("Invalid JSON input."); + } + if (!Array.isArray(data) || typeof data[0] !== "string") { + throw new Error("Input doesn't match expected format."); + } + let obfuscatedString = data[0]; + // Step 1: ROT13 + let step1 = voeRot13(obfuscatedString); + // Step 2: Remove patterns + let step2 = voeRemovePatterns(step1); + // Step 3: Base64 decode + let step3 = voeBase64Decode(step2); + // Step 4: Subtract 3 from each char code + let step4 = voeShiftChars(step3, 3); + // Step 5: Reverse string + let step5 = step4.split("").reverse().join(""); + // Step 6: Base64 decode again + let step6 = voeBase64Decode(step5); + // Step 7: Parse as JSON + let result; + try { + result = JSON.parse(step6); + } catch (e) { + throw new Error("Final JSON parse error: " + e.message); + } + // console.log("Decoded JSON:", result); + // check if direct_access_url is set, not null and starts with http + if (result && typeof result === "object") { + const streamUrl = + result.direct_access_url || + result.source + .map((source) => source.direct_access_url) + .find((url) => url && url.startsWith("http")); + if (streamUrl) { + console.log("Voe Stream URL: " + streamUrl); + return streamUrl; + } else { + console.log("No stream URL found in the decoded JSON"); + } + } + return result; +} +function voeRot13(str) { + return str.replace(/[a-zA-Z]/g, function (c) { + return String.fromCharCode( + (c <= "Z" ? 90 : 122) >= (c = c.charCodeAt(0) + 13) + ? c + : c - 26 + ); + }); +} +function voeRemovePatterns(str) { + const patterns = ["@$", "^^", "~@", "%?", "*~", "!!", "#&"]; + let result = str; + for (const pat of patterns) { + result = result.split(pat).join(""); + } + return result; +} +function voeBase64Decode(str) { + // atob is available in browsers and Node >= 16 + if (typeof atob === "function") { + return atob(str); + } + // Node.js fallback + return Buffer.from(str, "base64").toString("utf-8"); +} +function voeShiftChars(str, shift) { + return str + .split("") + .map((c) => String.fromCharCode(c.charCodeAt(0) - shift)) + .join(""); +} + +//////////////////////////////////////////////// +// PLUGINS // +//////////////////////////////////////////////// + +/** + * Uses Sora's fetchv2 on ipad, fallbacks to regular fetch on Windows + * @author ShadeOfChaos + * + * @param {string} url The URL to make the request to. + * @param {object} [options] The options to use for the request. + * @param {object} [options.headers] The headers to send with the request. + * @param {string} [options.method='GET'] The method to use for the request. + * @param {string} [options.body=null] The body of the request. + * + * @returns {Promise<Response|null>} The response from the server, or null if the + * request failed. + */ +async function soraFetch(url, options = { headers: {}, method: 'GET', body: null }) { + try { + return await fetchv2(url, options.headers ?? {}, options.method ?? 'GET', options.body ?? null); + } catch(e) { + try { + return await fetch(url, options); + } catch(error) { + await console.log('soraFetch error: ' + error.message); + return null; + } + } +} + +class Unbaser { + constructor(base) { + this.ALPHABET = { + 62: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", + 95: "' !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'", + }; + this.dictionary = {}; + this.base = base; + if (36 < base && base < 62) { + this.ALPHABET[base] = this.ALPHABET[base] || + this.ALPHABET[62].substr(0, base); + } + if (2 <= base && base <= 36) { + this.unbase = (value) => parseInt(value, base); + } + else { + try { + [...this.ALPHABET[base]].forEach((cipher, index) => { + this.dictionary[cipher] = index; + }); + } + catch (er) { + throw Error("Unsupported base encoding."); + } + this.unbase = this._dictunbaser; + } + } + _dictunbaser(value) { + let ret = 0; + [...value].reverse().forEach((cipher, index) => { + ret = ret + ((Math.pow(this.base, index)) * this.dictionary[cipher]); + }); + return ret; + } +} +function unpack(source) { + let { payload, symtab, radix, count } = _filterargs(source); + if (count != symtab.length) { + throw Error("Malformed p.a.c.k.e.r. symtab."); + } + let unbase; + try { + unbase = new Unbaser(radix); + } + catch (e) { + throw Error("Unknown p.a.c.k.e.r. encoding."); + } + function lookup(match) { + const word = match; + let word2; + if (radix == 1) { + word2 = symtab[parseInt(word)]; + } + else { + word2 = symtab[unbase.unbase(word)]; + } + return word2 || word; + } + source = payload.replace(/\b\w+\b/g, lookup); + return _replacestrings(source); + function _filterargs(source) { + const juicers = [ + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\), *(\d+), *(.*)\)\)/, + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\)/, + ]; + for (const juicer of juicers) { + const args = juicer.exec(source); + if (args) { + let a = args; + if (a[2] == "[]") { + } + try { + return { + payload: a[1], + symtab: a[4].split("|"), + radix: parseInt(a[2]), + count: parseInt(a[3]), + }; + } + catch (ValueError) { + throw Error("Corrupted p.a.c.k.e.r. data."); + } + } + } + throw Error("Could not make sense of p.a.c.k.e.r data (unexpected code structure)"); + } + function _replacestrings(source) { + return source; + } +} + + + +/* {GE END} */ \ No newline at end of file diff --git a/flixlatam/flixlatam.js b/flixlatam/flixlatam.js new file mode 100644 index 0000000..39d7970 --- /dev/null +++ b/flixlatam/flixlatam.js @@ -0,0 +1,6574 @@ +async function searchResults(keyword) { + const results = []; + try { + const response = await fetchv2("https://flixlatam.com/?s=" + encodeURIComponent(keyword)); + const html = await response.text(); + + const regex = /<div class="result-item">[\s\S]*?<a href="([^"]+)"[^>]*>\s*<img src="([^"]+)"[^>]*alt="([^"]+)"/g; + + let match; + while ((match = regex.exec(html)) !== null) { + results.push({ + href: match[1].trim(), + image: match[2].trim(), + title: cleanHtmlSymbols(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(); + + let match = /<div class="overview"[^>]*>\s*<p>([\s\S]*?)<\/p>/i.exec(html); + + if (!match) { + match = /<div class="wp-content"[^>]*>\s*<p>([\s\S]*?)<\/p>/i.exec(html); + } + + if (!match) { + match = /<div class="wp-content"[^>]*>[\s\S]*?<h4>[\s\S]*?<\/h4>\s*<p>([\s\S]*?)<\/p>/i.exec(html); + } + + const description = match ? match[1].trim() : "fuck off you don't need a description"; + + 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 = []; + + const regex = /<div class=['"]?numerando['"]?[^>]*>\d+\s*-\s*(\d+)<\/div>[\s\S]*?<a\s+href=['"]([^'"]+)['"][^>]*>/g; + + try { + const response = await fetchv2(url); + const html = await response.text(); + + let match; + while ((match = regex.exec(html)) !== null) { + const episodeNumber = parseInt(match[1], 10); + const href = match[2].trim(); + + results.push({ + href: "episode: " + href, + number: episodeNumber + }); + } + + if (results.length === 0) { + results.push({ + href: "movie: " + url, + number: 1 + }); + } + + return JSON.stringify(results); + } catch (err) { + return JSON.stringify([{ + href: "Error", + number: "Error" + }]); + } +} + +async function extractStreamUrl(url) { + try { + let endpointType; + + if (url.startsWith("movie: ")) { + url = url.replace("movie: ", ""); + endpointType = "movie"; + } else if (url.startsWith("episode: ")) { + url = url.replace("episode: ", ""); + endpointType = "tv"; + } else { + return "ERROR"; + } + const headers = { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3", + "Referer": "https://flixlatam.com/" + }; + const response = await fetchv2(url, headers); + const html = await response.text(); + + const idMatch = html.match(/<link rel=['"]shortlink['"] href=['"][^?]+\?p=(\d+)['"]/); + if (!idMatch) return "ID NOT FOUND"; + const id = idMatch[1]; + + const apiUrl = `https://flixlatam.com/wp-json/dooplayer/v2/${id}/${endpointType}/1`; + const apiResponse = await fetchv2(apiUrl); + const apiData = await apiResponse.json(); + console.log(JSON.stringify(apiData)); + + const anotherResponse = await fetchv2(apiData.embed_url); + const anotherHtml = await anotherResponse.text(); + + const dataLinkMatch = anotherHtml.match(/const\s+dataLink\s*=\s*(\[[\s\S]*?\]);/); + + let dataLink; + try { + let dataLinkStr = dataLinkMatch[1] + .replace(/"/g, '"') + .replace(/\\u003c/g, '<') + .replace(/\\u003e/g, '>') + .replace(/\\u0026/g, '&'); + dataLink = JSON.parse(dataLinkStr); + } catch (e) { + console.error( e); + return "PARSE ERROR"; + } + + const defaultLang = dataLink[0]; + const filemoonEmbed = defaultLang.sortedEmbeds.find(embed => embed.servername === "filemoon"); + + const SECRET_KEY = "Ak7qrvvH4WKYxV2OgaeHAEg2a5eh16vE"; + const decryptedUrl = decryptLink(filemoonEmbed.link, SECRET_KEY); + + console.log( decryptedUrl); + const filemoonResponse = await fetchv2(decryptedUrl); + const filemoonHtml = await filemoonResponse.text(); + let streamUrl = null; + try { + streamUrl = await filemoonExtractor(filemoonHtml, decryptedUrl); + } catch (error) { + console.log("filemoon HD extraction error:" + error); + } + + console.log("filemoon Stream URL: " + streamUrl); + if (streamUrl && streamUrl !== false && streamUrl !== null) { + return streamUrl; + } + + console.log("No stream URL found"); + + return null; + } catch (error) { + console.log("Fetch error:", error); + return null; + } +} + +/* SCHEME START */ +/* {REQUIRED PLUGINS: unbaser} */ + +/** + * @name filemoonExtractor + * @author Cufiy - Inspired by Churly + */ + +async function filemoonExtractor(html, url = null) { + // check if contains iframe, if does, extract the src and get the url + const regex = /<iframe[^>]+src="([^"]+)"[^>]*><\/iframe>/; + const match = html.match(regex); + if (match) { + console.log("Iframe URL: " + match[1]); + const iframeUrl = match[1]; + const iframeResponse = await soraFetch(iframeUrl, { + headers: { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3", + "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", + "Referer": url, + } + }); + console.log("Iframe Response: " + iframeResponse.status); + html = await iframeResponse.text(); + } + // console.log("HTML: " + html); + // get /<script[^>]*>([\s\S]*?)<\/script>/gi + const scriptRegex = /<script[^>]*>([\s\S]*?)<\/script>/gi; + const scripts = []; + let scriptMatch; + while ((scriptMatch = scriptRegex.exec(html)) !== null) { + scripts.push(scriptMatch[1]); + } + // get the script with eval and m3u8 + const evalRegex = /eval\((.*?)\)/; + const m3u8Regex = /m3u8/; + // console.log("Scripts: " + scripts); + const evalScript = scripts.find(script => evalRegex.test(script) && m3u8Regex.test(script)); + if (!evalScript) { + console.log("No eval script found"); + return null; + } + const unpackedScript = unpack(evalScript); + // get the m3u8 url + const m3u8Regex2 = /https?:\/\/[^\s]+master\.m3u8[^\s]*?(\?[^"]*)?/; + const m3u8Match = unpackedScript.match(m3u8Regex2); + if (m3u8Match) { + return m3u8Match[0]; + } else { + console.log("No M3U8 URL found"); + return null; + } +} + + +/* REMOVE_START */ + + +class Unbaser { + constructor(base) { + this.ALPHABET = { + 62: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", + 95: "' !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'", + }; + this.dictionary = {}; + this.base = base; + if (36 < base && base < 62) { + this.ALPHABET[base] = this.ALPHABET[base] || + this.ALPHABET[62].substr(0, base); + } + if (2 <= base && base <= 36) { + this.unbase = (value) => parseInt(value, base); + } + else { + try { + [...this.ALPHABET[base]].forEach((cipher, index) => { + this.dictionary[cipher] = index; + }); + } + catch (er) { + throw Error("Unsupported base encoding."); + } + this.unbase = this._dictunbaser; + } + } + _dictunbaser(value) { + let ret = 0; + [...value].reverse().forEach((cipher, index) => { + ret = ret + ((Math.pow(this.base, index)) * this.dictionary[cipher]); + }); + return ret; + } +} + + +function unpack(source) { + let { payload, symtab, radix, count } = _filterargs(source); + if (count != symtab.length) { + throw Error("Malformed p.a.c.k.e.r. symtab."); + } + let unbase; + try { + unbase = new Unbaser(radix); + } + catch (e) { + throw Error("Unknown p.a.c.k.e.r. encoding."); + } + function lookup(match) { + const word = match; + let word2; + if (radix == 1) { + word2 = symtab[parseInt(word)]; + } + else { + word2 = symtab[unbase.unbase(word)]; + } + return word2 || word; + } + source = payload.replace(/\b\w+\b/g, lookup); + return _replacestrings(source); + function _filterargs(source) { + const juicers = [ + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\), *(\d+), *(.*)\)\)/, + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\)/, + ]; + for (const juicer of juicers) { + const args = juicer.exec(source); + if (args) { + let a = args; + if (a[2] == "[]") { + } + try { + return { + payload: a[1], + symtab: a[4].split("|"), + radix: parseInt(a[2]), + count: parseInt(a[3]), + }; + } + catch (ValueError) { + throw Error("Corrupted p.a.c.k.e.r. data."); + } + } + } + throw Error("Could not make sense of p.a.c.k.e.r data (unexpected code structure)"); + } + function _replacestrings(source) { + return source; + } +} + + +/** + * Uses Sora's fetchv2 on ipad, fallbacks to regular fetch on Windows + * @author ShadeOfChaos + * + * @param {string} url The URL to make the request to. + * @param {object} [options] The options to use for the request. + * @param {object} [options.headers] The headers to send with the request. + * @param {string} [options.method='GET'] The method to use for the request. + * @param {string} [options.body=null] The body of the request. + * + * @returns {Promise<Response|null>} The response from the server, or null if the + * request failed. + */ +async function soraFetch(url, options = { headers: {}, method: 'GET', body: null }) { + try { + return await fetchv2(url, options.headers ?? {}, options.method ?? 'GET', options.body ?? null); + } catch(e) { + try { + return await fetch(url, options); + } catch(error) { + return null; + } + } +} +/* REMOVE_END */ + +/* SCHEME END */ + +function cleanHtmlSymbols(string) { + if (!string) return ""; + return string + .replace(/’/g, "'") + .replace(/–/g, "-") + .replace(/&#[0-9]+;/g, "") + .replace(/\r?\n|\r/g, " ") + .replace(/\s+/g, " ") + .trim(); +} + +function decryptLink(encryptedLinkBase64, secretKey) { + try { + const encryptedData = CryptoJS.enc.Base64.parse(encryptedLinkBase64); + const iv = encryptedData.words.slice(0, 4); + const encryptedBytes = encryptedData.words.slice(4); + const ivWordArray = CryptoJS.lib.WordArray.create(iv); + const encryptedWordArray = CryptoJS.lib.WordArray.create(encryptedBytes); + + const decrypted = CryptoJS.AES.decrypt( + { ciphertext: encryptedWordArray }, + CryptoJS.enc.Utf8.parse(secretKey), + { iv: ivWordArray, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 } + ); + + return decrypted.toString(CryptoJS.enc.Utf8); + } catch (error) { + console.error('Error al descifrar:', error); + return null; + } +} + +;(function (root, factory) { + if (typeof exports === "object") { + // CommonJS + module.exports = exports = factory(); + } + else if (typeof define === "function" && define.amd) { + // AMD + define([], factory); + } + else { + // Global (browser) + root.CryptoJS = factory(); + } +}(this, function () { + + /*globals window, global, require*/ + + /** + * CryptoJS core components. + */ + var CryptoJS = CryptoJS || (function (Math, undefined) { + + var crypto; + + // Native crypto from window (Browser) + if (typeof window !== 'undefined' && window.crypto) { + crypto = window.crypto; + } + + // Native crypto in web worker (Browser) + if (typeof self !== 'undefined' && self.crypto) { + crypto = self.crypto; + } + + // Native crypto from worker + if (typeof globalThis !== 'undefined' && globalThis.crypto) { + crypto = globalThis.crypto; + } + + // Native (experimental IE 11) crypto from window (Browser) + if (!crypto && typeof window !== 'undefined' && window.msCrypto) { + crypto = window.msCrypto; + } + + // Native crypto from global (NodeJS) + if (!crypto && typeof global !== 'undefined' && global.crypto) { + crypto = global.crypto; + } + + // Native crypto import via require (NodeJS) + if (!crypto && typeof require === 'function') { + try { + crypto = require('crypto'); + } catch (err) {} + } + + /* + * Cryptographically secure pseudorandom number generator + * + * As Math.random() is cryptographically not safe to use + */ + var cryptoSecureRandomInt = function () { + if (crypto) { + // Use getRandomValues method (Browser) + if (typeof crypto.getRandomValues === 'function') { + try { + return crypto.getRandomValues(new Uint32Array(1))[0]; + } catch (err) {} + } + + // Use randomBytes method (NodeJS) + if (typeof crypto.randomBytes === 'function') { + try { + return crypto.randomBytes(4).readInt32LE(); + } catch (err) {} + } + } + + throw new Error('Native crypto module could not be used to get secure random number.'); + }; + + /* + * Local polyfill of Object.create + + */ + var create = Object.create || (function () { + function F() {} + + return function (obj) { + var subtype; + + F.prototype = obj; + + subtype = new F(); + + F.prototype = null; + + return subtype; + }; + }()); + + /** + * CryptoJS namespace. + */ + var C = {}; + + /** + * Library namespace. + */ + var C_lib = C.lib = {}; + + /** + * Base object for prototypal inheritance. + */ + var Base = C_lib.Base = (function () { + + + return { + /** + * Creates a new object that inherits from this object. + * + * @param {Object} overrides Properties to copy into the new object. + * + * @return {Object} The new object. + * + * @static + * + * @example + * + * var MyType = CryptoJS.lib.Base.extend({ + * field: 'value', + * + * method: function () { + * } + * }); + */ + extend: function (overrides) { + // Spawn + var subtype = create(this); + + // Augment + if (overrides) { + subtype.mixIn(overrides); + } + + // Create default initializer + if (!subtype.hasOwnProperty('init') || this.init === subtype.init) { + subtype.init = function () { + subtype.$super.init.apply(this, arguments); + }; + } + + // Initializer's prototype is the subtype object + subtype.init.prototype = subtype; + + // Reference supertype + subtype.$super = this; + + return subtype; + }, + + /** + * Extends this object and runs the init method. + * Arguments to create() will be passed to init(). + * + * @return {Object} The new object. + * + * @static + * + * @example + * + * var instance = MyType.create(); + */ + create: function () { + var instance = this.extend(); + instance.init.apply(instance, arguments); + + return instance; + }, + + /** + * Initializes a newly created object. + * Override this method to add some logic when your objects are created. + * + * @example + * + * var MyType = CryptoJS.lib.Base.extend({ + * init: function () { + * // ... + * } + * }); + */ + init: function () { + }, + + /** + * Copies properties into this object. + * + * @param {Object} properties The properties to mix in. + * + * @example + * + * MyType.mixIn({ + * field: 'value' + * }); + */ + mixIn: function (properties) { + for (var propertyName in properties) { + if (properties.hasOwnProperty(propertyName)) { + this[propertyName] = properties[propertyName]; + } + } + + // IE won't copy toString using the loop above + if (properties.hasOwnProperty('toString')) { + this.toString = properties.toString; + } + }, + + /** + * Creates a copy of this object. + * + * @return {Object} The clone. + * + * @example + * + * var clone = instance.clone(); + */ + clone: function () { + return this.init.prototype.extend(this); + } + }; + }()); + + /** + * An array of 32-bit words. + * + * @property {Array} words The array of 32-bit words. + * @property {number} sigBytes The number of significant bytes in this word array. + */ + var WordArray = C_lib.WordArray = Base.extend({ + /** + * Initializes a newly created word array. + * + * @param {Array} words (Optional) An array of 32-bit words. + * @param {number} sigBytes (Optional) The number of significant bytes in the words. + * + * @example + * + * var wordArray = CryptoJS.lib.WordArray.create(); + * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607]); + * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607], 6); + */ + init: function (words, sigBytes) { + words = this.words = words || []; + + if (sigBytes != undefined) { + this.sigBytes = sigBytes; + } else { + this.sigBytes = words.length * 4; + } + }, + + /** + * Converts this word array to a string. + * + * @param {Encoder} encoder (Optional) The encoding strategy to use. Default: CryptoJS.enc.Hex + * + * @return {string} The stringified word array. + * + * @example + * + * var string = wordArray + ''; + * var string = wordArray.toString(); + * var string = wordArray.toString(CryptoJS.enc.Utf8); + */ + toString: function (encoder) { + return (encoder || Hex).stringify(this); + }, + + /** + * Concatenates a word array to this word array. + * + * @param {WordArray} wordArray The word array to append. + * + * @return {WordArray} This word array. + * + * @example + * + * wordArray1.concat(wordArray2); + */ + concat: function (wordArray) { + // Shortcuts + var thisWords = this.words; + var thatWords = wordArray.words; + var thisSigBytes = this.sigBytes; + var thatSigBytes = wordArray.sigBytes; + + // Clamp excess bits + this.clamp(); + + // Concat + if (thisSigBytes % 4) { + // Copy one byte at a time + for (var i = 0; i < thatSigBytes; i++) { + var thatByte = (thatWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; + thisWords[(thisSigBytes + i) >>> 2] |= thatByte << (24 - ((thisSigBytes + i) % 4) * 8); + } + } else { + // Copy one word at a time + for (var j = 0; j < thatSigBytes; j += 4) { + thisWords[(thisSigBytes + j) >>> 2] = thatWords[j >>> 2]; + } + } + this.sigBytes += thatSigBytes; + + // Chainable + return this; + }, + + /** + * Removes insignificant bits. + * + * @example + * + * wordArray.clamp(); + */ + clamp: function () { + // Shortcuts + var words = this.words; + var sigBytes = this.sigBytes; + + // Clamp + words[sigBytes >>> 2] &= 0xffffffff << (32 - (sigBytes % 4) * 8); + words.length = Math.ceil(sigBytes / 4); + }, + + /** + * Creates a copy of this word array. + * + * @return {WordArray} The clone. + * + * @example + * + * var clone = wordArray.clone(); + */ + clone: function () { + var clone = Base.clone.call(this); + clone.words = this.words.slice(0); + + return clone; + }, + + /** + * Creates a word array filled with random bytes. + * + * @param {number} nBytes The number of random bytes to generate. + * + * @return {WordArray} The random word array. + * + * @static + * + * @example + * + * var wordArray = CryptoJS.lib.WordArray.random(16); + */ + random: function (nBytes) { + var words = []; + + for (var i = 0; i < nBytes; i += 4) { + words.push(cryptoSecureRandomInt()); + } + + return new WordArray.init(words, nBytes); + } + }); + + /** + * Encoder namespace. + */ + var C_enc = C.enc = {}; + + /** + * Hex encoding strategy. + */ + var Hex = C_enc.Hex = { + /** + * Converts a word array to a hex string. + * + * @param {WordArray} wordArray The word array. + * + * @return {string} The hex string. + * + * @static + * + * @example + * + * var hexString = CryptoJS.enc.Hex.stringify(wordArray); + */ + stringify: function (wordArray) { + // Shortcuts + var words = wordArray.words; + var sigBytes = wordArray.sigBytes; + + // Convert + var hexChars = []; + for (var i = 0; i < sigBytes; i++) { + var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; + hexChars.push((bite >>> 4).toString(16)); + hexChars.push((bite & 0x0f).toString(16)); + } + + return hexChars.join(''); + }, + + /** + * Converts a hex string to a word array. + * + * @param {string} hexStr The hex string. + * + * @return {WordArray} The word array. + * + * @static + * + * @example + * + * var wordArray = CryptoJS.enc.Hex.parse(hexString); + */ + parse: function (hexStr) { + // Shortcut + var hexStrLength = hexStr.length; + + // Convert + var words = []; + for (var i = 0; i < hexStrLength; i += 2) { + words[i >>> 3] |= parseInt(hexStr.substr(i, 2), 16) << (24 - (i % 8) * 4); + } + + return new WordArray.init(words, hexStrLength / 2); + } + }; + + /** + * Latin1 encoding strategy. + */ + var Latin1 = C_enc.Latin1 = { + /** + * Converts a word array to a Latin1 string. + * + * @param {WordArray} wordArray The word array. + * + * @return {string} The Latin1 string. + * + * @static + * + * @example + * + * var latin1String = CryptoJS.enc.Latin1.stringify(wordArray); + */ + stringify: function (wordArray) { + // Shortcuts + var words = wordArray.words; + var sigBytes = wordArray.sigBytes; + + // Convert + var latin1Chars = []; + for (var i = 0; i < sigBytes; i++) { + var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; + latin1Chars.push(String.fromCharCode(bite)); + } + + return latin1Chars.join(''); + }, + + /** + * Converts a Latin1 string to a word array. + * + * @param {string} latin1Str The Latin1 string. + * + * @return {WordArray} The word array. + * + * @static + * + * @example + * + * var wordArray = CryptoJS.enc.Latin1.parse(latin1String); + */ + parse: function (latin1Str) { + // Shortcut + var latin1StrLength = latin1Str.length; + + // Convert + var words = []; + for (var i = 0; i < latin1StrLength; i++) { + words[i >>> 2] |= (latin1Str.charCodeAt(i) & 0xff) << (24 - (i % 4) * 8); + } + + return new WordArray.init(words, latin1StrLength); + } + }; + + /** + * UTF-8 encoding strategy. + */ + var Utf8 = C_enc.Utf8 = { + /** + * Converts a word array to a UTF-8 string. + * + * @param {WordArray} wordArray The word array. + * + * @return {string} The UTF-8 string. + * + * @static + * + * @example + * + * var utf8String = CryptoJS.enc.Utf8.stringify(wordArray); + */ + stringify: function (wordArray) { + try { + return decodeURIComponent(escape(Latin1.stringify(wordArray))); + } catch (e) { + throw new Error('Malformed UTF-8 data'); + } + }, + + /** + * Converts a UTF-8 string to a word array. + * + * @param {string} utf8Str The UTF-8 string. + * + * @return {WordArray} The word array. + * + * @static + * + * @example + * + * var wordArray = CryptoJS.enc.Utf8.parse(utf8String); + */ + parse: function (utf8Str) { + return Latin1.parse(unescape(encodeURIComponent(utf8Str))); + } + }; + + /** + * Abstract buffered block algorithm template. + * + * The property blockSize must be implemented in a concrete subtype. + * + * @property {number} _minBufferSize The number of blocks that should be kept unprocessed in the buffer. Default: 0 + */ + var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm = Base.extend({ + /** + * Resets this block algorithm's data buffer to its initial state. + * + * @example + * + * bufferedBlockAlgorithm.reset(); + */ + reset: function () { + // Initial values + this._data = new WordArray.init(); + this._nDataBytes = 0; + }, + + /** + * Adds new data to this block algorithm's buffer. + * + * @param {WordArray|string} data The data to append. Strings are converted to a WordArray using UTF-8. + * + * @example + * + * bufferedBlockAlgorithm._append('data'); + * bufferedBlockAlgorithm._append(wordArray); + */ + _append: function (data) { + // Convert string to WordArray, else assume WordArray already + if (typeof data == 'string') { + data = Utf8.parse(data); + } + + // Append + this._data.concat(data); + this._nDataBytes += data.sigBytes; + }, + + /** + * Processes available data blocks. + * + * This method invokes _doProcessBlock(offset), which must be implemented by a concrete subtype. + * + * @param {boolean} doFlush Whether all blocks and partial blocks should be processed. + * + * @return {WordArray} The processed data. + * + * @example + * + * var processedData = bufferedBlockAlgorithm._process(); + * var processedData = bufferedBlockAlgorithm._process(!!'flush'); + */ + _process: function (doFlush) { + var processedWords; + + // Shortcuts + var data = this._data; + var dataWords = data.words; + var dataSigBytes = data.sigBytes; + var blockSize = this.blockSize; + var blockSizeBytes = blockSize * 4; + + // Count blocks ready + var nBlocksReady = dataSigBytes / blockSizeBytes; + if (doFlush) { + // Round up to include partial blocks + nBlocksReady = Math.ceil(nBlocksReady); + } else { + // Round down to include only full blocks, + // less the number of blocks that must remain in the buffer + nBlocksReady = Math.max((nBlocksReady | 0) - this._minBufferSize, 0); + } + + // Count words ready + var nWordsReady = nBlocksReady * blockSize; + + // Count bytes ready + var nBytesReady = Math.min(nWordsReady * 4, dataSigBytes); + + // Process blocks + if (nWordsReady) { + for (var offset = 0; offset < nWordsReady; offset += blockSize) { + // Perform concrete-algorithm logic + this._doProcessBlock(dataWords, offset); + } + + // Remove processed words + processedWords = dataWords.splice(0, nWordsReady); + data.sigBytes -= nBytesReady; + } + + // Return processed words + return new WordArray.init(processedWords, nBytesReady); + }, + + /** + * Creates a copy of this object. + * + * @return {Object} The clone. + * + * @example + * + * var clone = bufferedBlockAlgorithm.clone(); + */ + clone: function () { + var clone = Base.clone.call(this); + clone._data = this._data.clone(); + + return clone; + }, + + _minBufferSize: 0 + }); + + /** + * Abstract hasher template. + * + * @property {number} blockSize The number of 32-bit words this hasher operates on. Default: 16 (512 bits) + */ + var Hasher = C_lib.Hasher = BufferedBlockAlgorithm.extend({ + /** + * Configuration options. + */ + cfg: Base.extend(), + + /** + * Initializes a newly created hasher. + * + * @param {Object} cfg (Optional) The configuration options to use for this hash computation. + * + * @example + * + * var hasher = CryptoJS.algo.SHA256.create(); + */ + init: function (cfg) { + // Apply config defaults + this.cfg = this.cfg.extend(cfg); + + // Set initial values + this.reset(); + }, + + /** + * Resets this hasher to its initial state. + * + * @example + * + * hasher.reset(); + */ + reset: function () { + // Reset data buffer + BufferedBlockAlgorithm.reset.call(this); + + // Perform concrete-hasher logic + this._doReset(); + }, + + /** + * Updates this hasher with a message. + * + * @param {WordArray|string} messageUpdate The message to append. + * + * @return {Hasher} This hasher. + * + * @example + * + * hasher.update('message'); + * hasher.update(wordArray); + */ + update: function (messageUpdate) { + // Append + this._append(messageUpdate); + + // Update the hash + this._process(); + + // Chainable + return this; + }, + + /** + * Finalizes the hash computation. + * Note that the finalize operation is effectively a destructive, read-once operation. + * + * @param {WordArray|string} messageUpdate (Optional) A final message update. + * + * @return {WordArray} The hash. + * + * @example + * + * var hash = hasher.finalize(); + * var hash = hasher.finalize('message'); + * var hash = hasher.finalize(wordArray); + */ + finalize: function (messageUpdate) { + // Final message update + if (messageUpdate) { + this._append(messageUpdate); + } + + // Perform concrete-hasher logic + var hash = this._doFinalize(); + + return hash; + }, + + blockSize: 512/32, + + /** + * Creates a shortcut function to a hasher's object interface. + * + * @param {Hasher} hasher The hasher to create a helper for. + * + * @return {Function} The shortcut function. + * + * @static + * + * @example + * + * var SHA256 = CryptoJS.lib.Hasher._createHelper(CryptoJS.algo.SHA256); + */ + _createHelper: function (hasher) { + return function (message, cfg) { + return new hasher.init(cfg).finalize(message); + }; + }, + + /** + * Creates a shortcut function to the HMAC's object interface. + * + * @param {Hasher} hasher The hasher to use in this HMAC helper. + * + * @return {Function} The shortcut function. + * + * @static + * + * @example + * + * var HmacSHA256 = CryptoJS.lib.Hasher._createHmacHelper(CryptoJS.algo.SHA256); + */ + _createHmacHelper: function (hasher) { + return function (message, key) { + return new C_algo.HMAC.init(hasher, key).finalize(message); + }; + } + }); + + /** + * Algorithm namespace. + */ + var C_algo = C.algo = {}; + + return C; + }(Math)); + + + (function (undefined) { + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var Base = C_lib.Base; + var X32WordArray = C_lib.WordArray; + + /** + * x64 namespace. + */ + var C_x64 = C.x64 = {}; + + /** + * A 64-bit word. + */ + var X64Word = C_x64.Word = Base.extend({ + /** + * Initializes a newly created 64-bit word. + * + * @param {number} high The high 32 bits. + * @param {number} low The low 32 bits. + * + * @example + * + * var x64Word = CryptoJS.x64.Word.create(0x00010203, 0x04050607); + */ + init: function (high, low) { + this.high = high; + this.low = low; + } + + /** + * Bitwise NOTs this word. + * + * @return {X64Word} A new x64-Word object after negating. + * + * @example + * + * var negated = x64Word.not(); + */ + // not: function () { + // var high = ~this.high; + // var low = ~this.low; + + // return X64Word.create(high, low); + // }, + + /** + * Bitwise ANDs this word with the passed word. + * + * @param {X64Word} word The x64-Word to AND with this word. + * + * @return {X64Word} A new x64-Word object after ANDing. + * + * @example + * + * var anded = x64Word.and(anotherX64Word); + */ + // and: function (word) { + // var high = this.high & word.high; + // var low = this.low & word.low; + + // return X64Word.create(high, low); + // }, + + /** + * Bitwise ORs this word with the passed word. + * + * @param {X64Word} word The x64-Word to OR with this word. + * + * @return {X64Word} A new x64-Word object after ORing. + * + * @example + * + * var ored = x64Word.or(anotherX64Word); + */ + // or: function (word) { + // var high = this.high | word.high; + // var low = this.low | word.low; + + // return X64Word.create(high, low); + // }, + + /** + * Bitwise XORs this word with the passed word. + * + * @param {X64Word} word The x64-Word to XOR with this word. + * + * @return {X64Word} A new x64-Word object after XORing. + * + * @example + * + * var xored = x64Word.xor(anotherX64Word); + */ + // xor: function (word) { + // var high = this.high ^ word.high; + // var low = this.low ^ word.low; + + // return X64Word.create(high, low); + // }, + + /** + * Shifts this word n bits to the left. + * + * @param {number} n The number of bits to shift. + * + * @return {X64Word} A new x64-Word object after shifting. + * + * @example + * + * var shifted = x64Word.shiftL(25); + */ + // shiftL: function (n) { + // if (n < 32) { + // var high = (this.high << n) | (this.low >>> (32 - n)); + // var low = this.low << n; + // } else { + // var high = this.low << (n - 32); + // var low = 0; + // } + + // return X64Word.create(high, low); + // }, + + /** + * Shifts this word n bits to the right. + * + * @param {number} n The number of bits to shift. + * + * @return {X64Word} A new x64-Word object after shifting. + * + * @example + * + * var shifted = x64Word.shiftR(7); + */ + // shiftR: function (n) { + // if (n < 32) { + // var low = (this.low >>> n) | (this.high << (32 - n)); + // var high = this.high >>> n; + // } else { + // var low = this.high >>> (n - 32); + // var high = 0; + // } + + // return X64Word.create(high, low); + // }, + + /** + * Rotates this word n bits to the left. + * + * @param {number} n The number of bits to rotate. + * + * @return {X64Word} A new x64-Word object after rotating. + * + * @example + * + * var rotated = x64Word.rotL(25); + */ + // rotL: function (n) { + // return this.shiftL(n).or(this.shiftR(64 - n)); + // }, + + /** + * Rotates this word n bits to the right. + * + * @param {number} n The number of bits to rotate. + * + * @return {X64Word} A new x64-Word object after rotating. + * + * @example + * + * var rotated = x64Word.rotR(7); + */ + // rotR: function (n) { + // return this.shiftR(n).or(this.shiftL(64 - n)); + // }, + + /** + * Adds this word with the passed word. + * + * @param {X64Word} word The x64-Word to add with this word. + * + * @return {X64Word} A new x64-Word object after adding. + * + * @example + * + * var added = x64Word.add(anotherX64Word); + */ + // add: function (word) { + // var low = (this.low + word.low) | 0; + // var carry = (low >>> 0) < (this.low >>> 0) ? 1 : 0; + // var high = (this.high + word.high + carry) | 0; + + // return X64Word.create(high, low); + // } + }); + + /** + * An array of 64-bit words. + * + * @property {Array} words The array of CryptoJS.x64.Word objects. + * @property {number} sigBytes The number of significant bytes in this word array. + */ + var X64WordArray = C_x64.WordArray = Base.extend({ + /** + * Initializes a newly created word array. + * + * @param {Array} words (Optional) An array of CryptoJS.x64.Word objects. + * @param {number} sigBytes (Optional) The number of significant bytes in the words. + * + * @example + * + * var wordArray = CryptoJS.x64.WordArray.create(); + * + * var wordArray = CryptoJS.x64.WordArray.create([ + * CryptoJS.x64.Word.create(0x00010203, 0x04050607), + * CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f) + * ]); + * + * var wordArray = CryptoJS.x64.WordArray.create([ + * CryptoJS.x64.Word.create(0x00010203, 0x04050607), + * CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f) + * ], 10); + */ + init: function (words, sigBytes) { + words = this.words = words || []; + + if (sigBytes != undefined) { + this.sigBytes = sigBytes; + } else { + this.sigBytes = words.length * 8; + } + }, + + /** + * Converts this 64-bit word array to a 32-bit word array. + * + * @return {CryptoJS.lib.WordArray} This word array's data as a 32-bit word array. + * + * @example + * + * var x32WordArray = x64WordArray.toX32(); + */ + toX32: function () { + // Shortcuts + var x64Words = this.words; + var x64WordsLength = x64Words.length; + + // Convert + var x32Words = []; + for (var i = 0; i < x64WordsLength; i++) { + var x64Word = x64Words[i]; + x32Words.push(x64Word.high); + x32Words.push(x64Word.low); + } + + return X32WordArray.create(x32Words, this.sigBytes); + }, + + /** + * Creates a copy of this word array. + * + * @return {X64WordArray} The clone. + * + * @example + * + * var clone = x64WordArray.clone(); + */ + clone: function () { + var clone = Base.clone.call(this); + + // Clone "words" array + var words = clone.words = this.words.slice(0); + + // Clone each X64Word object + var wordsLength = words.length; + for (var i = 0; i < wordsLength; i++) { + words[i] = words[i].clone(); + } + + return clone; + } + }); + }()); + + + (function () { + // Check if typed arrays are supported + if (typeof ArrayBuffer != 'function') { + return; + } + + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var WordArray = C_lib.WordArray; + + // Reference original init + var superInit = WordArray.init; + + // Augment WordArray.init to handle typed arrays + var subInit = WordArray.init = function (typedArray) { + // Convert buffers to uint8 + if (typedArray instanceof ArrayBuffer) { + typedArray = new Uint8Array(typedArray); + } + + // Convert other array views to uint8 + if ( + typedArray instanceof Int8Array || + (typeof Uint8ClampedArray !== "undefined" && typedArray instanceof Uint8ClampedArray) || + typedArray instanceof Int16Array || + typedArray instanceof Uint16Array || + typedArray instanceof Int32Array || + typedArray instanceof Uint32Array || + typedArray instanceof Float32Array || + typedArray instanceof Float64Array + ) { + typedArray = new Uint8Array(typedArray.buffer, typedArray.byteOffset, typedArray.byteLength); + } + + // Handle Uint8Array + if (typedArray instanceof Uint8Array) { + // Shortcut + var typedArrayByteLength = typedArray.byteLength; + + // Extract bytes + var words = []; + for (var i = 0; i < typedArrayByteLength; i++) { + words[i >>> 2] |= typedArray[i] << (24 - (i % 4) * 8); + } + + // Initialize this word array + superInit.call(this, words, typedArrayByteLength); + } else { + // Else call normal init + superInit.apply(this, arguments); + } + }; + + subInit.prototype = WordArray; + }()); + + + (function () { + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var WordArray = C_lib.WordArray; + var C_enc = C.enc; + + /** + * UTF-16 BE encoding strategy. + */ + var Utf16BE = C_enc.Utf16 = C_enc.Utf16BE = { + /** + * Converts a word array to a UTF-16 BE string. + * + * @param {WordArray} wordArray The word array. + * + * @return {string} The UTF-16 BE string. + * + * @static + * + * @example + * + * var utf16String = CryptoJS.enc.Utf16.stringify(wordArray); + */ + stringify: function (wordArray) { + // Shortcuts + var words = wordArray.words; + var sigBytes = wordArray.sigBytes; + + // Convert + var utf16Chars = []; + for (var i = 0; i < sigBytes; i += 2) { + var codePoint = (words[i >>> 2] >>> (16 - (i % 4) * 8)) & 0xffff; + utf16Chars.push(String.fromCharCode(codePoint)); + } + + return utf16Chars.join(''); + }, + + /** + * Converts a UTF-16 BE string to a word array. + * + * @param {string} utf16Str The UTF-16 BE string. + * + * @return {WordArray} The word array. + * + * @static + * + * @example + * + * var wordArray = CryptoJS.enc.Utf16.parse(utf16String); + */ + parse: function (utf16Str) { + // Shortcut + var utf16StrLength = utf16Str.length; + + // Convert + var words = []; + for (var i = 0; i < utf16StrLength; i++) { + words[i >>> 1] |= utf16Str.charCodeAt(i) << (16 - (i % 2) * 16); + } + + return WordArray.create(words, utf16StrLength * 2); + } + }; + + /** + * UTF-16 LE encoding strategy. + */ + C_enc.Utf16LE = { + /** + * Converts a word array to a UTF-16 LE string. + * + * @param {WordArray} wordArray The word array. + * + * @return {string} The UTF-16 LE string. + * + * @static + * + * @example + * + * var utf16Str = CryptoJS.enc.Utf16LE.stringify(wordArray); + */ + stringify: function (wordArray) { + // Shortcuts + var words = wordArray.words; + var sigBytes = wordArray.sigBytes; + + // Convert + var utf16Chars = []; + for (var i = 0; i < sigBytes; i += 2) { + var codePoint = swapEndian((words[i >>> 2] >>> (16 - (i % 4) * 8)) & 0xffff); + utf16Chars.push(String.fromCharCode(codePoint)); + } + + return utf16Chars.join(''); + }, + + /** + * Converts a UTF-16 LE string to a word array. + * + * @param {string} utf16Str The UTF-16 LE string. + * + * @return {WordArray} The word array. + * + * @static + * + * @example + * + * var wordArray = CryptoJS.enc.Utf16LE.parse(utf16Str); + */ + parse: function (utf16Str) { + // Shortcut + var utf16StrLength = utf16Str.length; + + // Convert + var words = []; + for (var i = 0; i < utf16StrLength; i++) { + words[i >>> 1] |= swapEndian(utf16Str.charCodeAt(i) << (16 - (i % 2) * 16)); + } + + return WordArray.create(words, utf16StrLength * 2); + } + }; + + function swapEndian(word) { + return ((word << 8) & 0xff00ff00) | ((word >>> 8) & 0x00ff00ff); + } + }()); + + + (function () { + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var WordArray = C_lib.WordArray; + var C_enc = C.enc; + + /** + * Base64 encoding strategy. + */ + var Base64 = C_enc.Base64 = { + /** + * Converts a word array to a Base64 string. + * + * @param {WordArray} wordArray The word array. + * + * @return {string} The Base64 string. + * + * @static + * + * @example + * + * var base64String = CryptoJS.enc.Base64.stringify(wordArray); + */ + stringify: function (wordArray) { + // Shortcuts + var words = wordArray.words; + var sigBytes = wordArray.sigBytes; + var map = this._map; + + // Clamp excess bits + wordArray.clamp(); + + // Convert + var base64Chars = []; + for (var i = 0; i < sigBytes; i += 3) { + var byte1 = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; + var byte2 = (words[(i + 1) >>> 2] >>> (24 - ((i + 1) % 4) * 8)) & 0xff; + var byte3 = (words[(i + 2) >>> 2] >>> (24 - ((i + 2) % 4) * 8)) & 0xff; + + var triplet = (byte1 << 16) | (byte2 << 8) | byte3; + + for (var j = 0; (j < 4) && (i + j * 0.75 < sigBytes); j++) { + base64Chars.push(map.charAt((triplet >>> (6 * (3 - j))) & 0x3f)); + } + } + + // Add padding + var paddingChar = map.charAt(64); + if (paddingChar) { + while (base64Chars.length % 4) { + base64Chars.push(paddingChar); + } + } + + return base64Chars.join(''); + }, + + /** + * Converts a Base64 string to a word array. + * + * @param {string} base64Str The Base64 string. + * + * @return {WordArray} The word array. + * + * @static + * + * @example + * + * var wordArray = CryptoJS.enc.Base64.parse(base64String); + */ + parse: function (base64Str) { + // Shortcuts + var base64StrLength = base64Str.length; + var map = this._map; + var reverseMap = this._reverseMap; + + if (!reverseMap) { + reverseMap = this._reverseMap = []; + for (var j = 0; j < map.length; j++) { + reverseMap[map.charCodeAt(j)] = j; + } + } + + // Ignore padding + var paddingChar = map.charAt(64); + if (paddingChar) { + var paddingIndex = base64Str.indexOf(paddingChar); + if (paddingIndex !== -1) { + base64StrLength = paddingIndex; + } + } + + // Convert + return parseLoop(base64Str, base64StrLength, reverseMap); + + }, + + _map: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=' + }; + + function parseLoop(base64Str, base64StrLength, reverseMap) { + var words = []; + var nBytes = 0; + for (var i = 0; i < base64StrLength; i++) { + if (i % 4) { + var bits1 = reverseMap[base64Str.charCodeAt(i - 1)] << ((i % 4) * 2); + var bits2 = reverseMap[base64Str.charCodeAt(i)] >>> (6 - (i % 4) * 2); + var bitsCombined = bits1 | bits2; + words[nBytes >>> 2] |= bitsCombined << (24 - (nBytes % 4) * 8); + nBytes++; + } + } + return WordArray.create(words, nBytes); + } + }()); + + + (function () { + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var WordArray = C_lib.WordArray; + var C_enc = C.enc; + + /** + * Base64url encoding strategy. + */ + var Base64url = C_enc.Base64url = { + /** + * Converts a word array to a Base64url string. + * + * @param {WordArray} wordArray The word array. + * + * @param {boolean} urlSafe Whether to use url safe + * + * @return {string} The Base64url string. + * + * @static + * + * @example + * + * var base64String = CryptoJS.enc.Base64url.stringify(wordArray); + */ + stringify: function (wordArray, urlSafe=true) { + // Shortcuts + var words = wordArray.words; + var sigBytes = wordArray.sigBytes; + var map = urlSafe ? this._safe_map : this._map; + + // Clamp excess bits + wordArray.clamp(); + + // Convert + var base64Chars = []; + for (var i = 0; i < sigBytes; i += 3) { + var byte1 = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; + var byte2 = (words[(i + 1) >>> 2] >>> (24 - ((i + 1) % 4) * 8)) & 0xff; + var byte3 = (words[(i + 2) >>> 2] >>> (24 - ((i + 2) % 4) * 8)) & 0xff; + + var triplet = (byte1 << 16) | (byte2 << 8) | byte3; + + for (var j = 0; (j < 4) && (i + j * 0.75 < sigBytes); j++) { + base64Chars.push(map.charAt((triplet >>> (6 * (3 - j))) & 0x3f)); + } + } + + // Add padding + var paddingChar = map.charAt(64); + if (paddingChar) { + while (base64Chars.length % 4) { + base64Chars.push(paddingChar); + } + } + + return base64Chars.join(''); + }, + + /** + * Converts a Base64url string to a word array. + * + * @param {string} base64Str The Base64url string. + * + * @param {boolean} urlSafe Whether to use url safe + * + * @return {WordArray} The word array. + * + * @static + * + * @example + * + * var wordArray = CryptoJS.enc.Base64url.parse(base64String); + */ + parse: function (base64Str, urlSafe=true) { + // Shortcuts + var base64StrLength = base64Str.length; + var map = urlSafe ? this._safe_map : this._map; + var reverseMap = this._reverseMap; + + if (!reverseMap) { + reverseMap = this._reverseMap = []; + for (var j = 0; j < map.length; j++) { + reverseMap[map.charCodeAt(j)] = j; + } + } + + // Ignore padding + var paddingChar = map.charAt(64); + if (paddingChar) { + var paddingIndex = base64Str.indexOf(paddingChar); + if (paddingIndex !== -1) { + base64StrLength = paddingIndex; + } + } + + // Convert + return parseLoop(base64Str, base64StrLength, reverseMap); + + }, + + _map: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=', + _safe_map: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_', + }; + + function parseLoop(base64Str, base64StrLength, reverseMap) { + var words = []; + var nBytes = 0; + for (var i = 0; i < base64StrLength; i++) { + if (i % 4) { + var bits1 = reverseMap[base64Str.charCodeAt(i - 1)] << ((i % 4) * 2); + var bits2 = reverseMap[base64Str.charCodeAt(i)] >>> (6 - (i % 4) * 2); + var bitsCombined = bits1 | bits2; + words[nBytes >>> 2] |= bitsCombined << (24 - (nBytes % 4) * 8); + nBytes++; + } + } + return WordArray.create(words, nBytes); + } + }()); + + (function (Math) { + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var WordArray = C_lib.WordArray; + var Hasher = C_lib.Hasher; + var C_algo = C.algo; + + // Constants table + var T = []; + + // Compute constants + (function () { + for (var i = 0; i < 64; i++) { + T[i] = (Math.abs(Math.sin(i + 1)) * 0x100000000) | 0; + } + }()); + + /** + * MD5 hash algorithm. + */ + var MD5 = C_algo.MD5 = Hasher.extend({ + _doReset: function () { + this._hash = new WordArray.init([ + 0x67452301, 0xefcdab89, + 0x98badcfe, 0x10325476 + ]); + }, + + _doProcessBlock: function (M, offset) { + // Swap endian + for (var i = 0; i < 16; i++) { + // Shortcuts + var offset_i = offset + i; + var M_offset_i = M[offset_i]; + + M[offset_i] = ( + (((M_offset_i << 8) | (M_offset_i >>> 24)) & 0x00ff00ff) | + (((M_offset_i << 24) | (M_offset_i >>> 8)) & 0xff00ff00) + ); + } + + // Shortcuts + var H = this._hash.words; + + var M_offset_0 = M[offset + 0]; + var M_offset_1 = M[offset + 1]; + var M_offset_2 = M[offset + 2]; + var M_offset_3 = M[offset + 3]; + var M_offset_4 = M[offset + 4]; + var M_offset_5 = M[offset + 5]; + var M_offset_6 = M[offset + 6]; + var M_offset_7 = M[offset + 7]; + var M_offset_8 = M[offset + 8]; + var M_offset_9 = M[offset + 9]; + var M_offset_10 = M[offset + 10]; + var M_offset_11 = M[offset + 11]; + var M_offset_12 = M[offset + 12]; + var M_offset_13 = M[offset + 13]; + var M_offset_14 = M[offset + 14]; + var M_offset_15 = M[offset + 15]; + + // Working varialbes + var a = H[0]; + var b = H[1]; + var c = H[2]; + var d = H[3]; + + // Computation + a = FF(a, b, c, d, M_offset_0, 7, T[0]); + d = FF(d, a, b, c, M_offset_1, 12, T[1]); + c = FF(c, d, a, b, M_offset_2, 17, T[2]); + b = FF(b, c, d, a, M_offset_3, 22, T[3]); + a = FF(a, b, c, d, M_offset_4, 7, T[4]); + d = FF(d, a, b, c, M_offset_5, 12, T[5]); + c = FF(c, d, a, b, M_offset_6, 17, T[6]); + b = FF(b, c, d, a, M_offset_7, 22, T[7]); + a = FF(a, b, c, d, M_offset_8, 7, T[8]); + d = FF(d, a, b, c, M_offset_9, 12, T[9]); + c = FF(c, d, a, b, M_offset_10, 17, T[10]); + b = FF(b, c, d, a, M_offset_11, 22, T[11]); + a = FF(a, b, c, d, M_offset_12, 7, T[12]); + d = FF(d, a, b, c, M_offset_13, 12, T[13]); + c = FF(c, d, a, b, M_offset_14, 17, T[14]); + b = FF(b, c, d, a, M_offset_15, 22, T[15]); + + a = GG(a, b, c, d, M_offset_1, 5, T[16]); + d = GG(d, a, b, c, M_offset_6, 9, T[17]); + c = GG(c, d, a, b, M_offset_11, 14, T[18]); + b = GG(b, c, d, a, M_offset_0, 20, T[19]); + a = GG(a, b, c, d, M_offset_5, 5, T[20]); + d = GG(d, a, b, c, M_offset_10, 9, T[21]); + c = GG(c, d, a, b, M_offset_15, 14, T[22]); + b = GG(b, c, d, a, M_offset_4, 20, T[23]); + a = GG(a, b, c, d, M_offset_9, 5, T[24]); + d = GG(d, a, b, c, M_offset_14, 9, T[25]); + c = GG(c, d, a, b, M_offset_3, 14, T[26]); + b = GG(b, c, d, a, M_offset_8, 20, T[27]); + a = GG(a, b, c, d, M_offset_13, 5, T[28]); + d = GG(d, a, b, c, M_offset_2, 9, T[29]); + c = GG(c, d, a, b, M_offset_7, 14, T[30]); + b = GG(b, c, d, a, M_offset_12, 20, T[31]); + + a = HH(a, b, c, d, M_offset_5, 4, T[32]); + d = HH(d, a, b, c, M_offset_8, 11, T[33]); + c = HH(c, d, a, b, M_offset_11, 16, T[34]); + b = HH(b, c, d, a, M_offset_14, 23, T[35]); + a = HH(a, b, c, d, M_offset_1, 4, T[36]); + d = HH(d, a, b, c, M_offset_4, 11, T[37]); + c = HH(c, d, a, b, M_offset_7, 16, T[38]); + b = HH(b, c, d, a, M_offset_10, 23, T[39]); + a = HH(a, b, c, d, M_offset_13, 4, T[40]); + d = HH(d, a, b, c, M_offset_0, 11, T[41]); + c = HH(c, d, a, b, M_offset_3, 16, T[42]); + b = HH(b, c, d, a, M_offset_6, 23, T[43]); + a = HH(a, b, c, d, M_offset_9, 4, T[44]); + d = HH(d, a, b, c, M_offset_12, 11, T[45]); + c = HH(c, d, a, b, M_offset_15, 16, T[46]); + b = HH(b, c, d, a, M_offset_2, 23, T[47]); + + a = II(a, b, c, d, M_offset_0, 6, T[48]); + d = II(d, a, b, c, M_offset_7, 10, T[49]); + c = II(c, d, a, b, M_offset_14, 15, T[50]); + b = II(b, c, d, a, M_offset_5, 21, T[51]); + a = II(a, b, c, d, M_offset_12, 6, T[52]); + d = II(d, a, b, c, M_offset_3, 10, T[53]); + c = II(c, d, a, b, M_offset_10, 15, T[54]); + b = II(b, c, d, a, M_offset_1, 21, T[55]); + a = II(a, b, c, d, M_offset_8, 6, T[56]); + d = II(d, a, b, c, M_offset_15, 10, T[57]); + c = II(c, d, a, b, M_offset_6, 15, T[58]); + b = II(b, c, d, a, M_offset_13, 21, T[59]); + a = II(a, b, c, d, M_offset_4, 6, T[60]); + d = II(d, a, b, c, M_offset_11, 10, T[61]); + c = II(c, d, a, b, M_offset_2, 15, T[62]); + b = II(b, c, d, a, M_offset_9, 21, T[63]); + + // Intermediate hash value + H[0] = (H[0] + a) | 0; + H[1] = (H[1] + b) | 0; + H[2] = (H[2] + c) | 0; + H[3] = (H[3] + d) | 0; + }, + + _doFinalize: function () { + // Shortcuts + var data = this._data; + var dataWords = data.words; + + var nBitsTotal = this._nDataBytes * 8; + var nBitsLeft = data.sigBytes * 8; + + // Add padding + dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); + + var nBitsTotalH = Math.floor(nBitsTotal / 0x100000000); + var nBitsTotalL = nBitsTotal; + dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = ( + (((nBitsTotalH << 8) | (nBitsTotalH >>> 24)) & 0x00ff00ff) | + (((nBitsTotalH << 24) | (nBitsTotalH >>> 8)) & 0xff00ff00) + ); + dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = ( + (((nBitsTotalL << 8) | (nBitsTotalL >>> 24)) & 0x00ff00ff) | + (((nBitsTotalL << 24) | (nBitsTotalL >>> 8)) & 0xff00ff00) + ); + + data.sigBytes = (dataWords.length + 1) * 4; + + // Hash final blocks + this._process(); + + // Shortcuts + var hash = this._hash; + var H = hash.words; + + // Swap endian + for (var i = 0; i < 4; i++) { + // Shortcut + var H_i = H[i]; + + H[i] = (((H_i << 8) | (H_i >>> 24)) & 0x00ff00ff) | + (((H_i << 24) | (H_i >>> 8)) & 0xff00ff00); + } + + // Return final computed hash + return hash; + }, + + clone: function () { + var clone = Hasher.clone.call(this); + clone._hash = this._hash.clone(); + + return clone; + } + }); + + function FF(a, b, c, d, x, s, t) { + var n = a + ((b & c) | (~b & d)) + x + t; + return ((n << s) | (n >>> (32 - s))) + b; + } + + function GG(a, b, c, d, x, s, t) { + var n = a + ((b & d) | (c & ~d)) + x + t; + return ((n << s) | (n >>> (32 - s))) + b; + } + + function HH(a, b, c, d, x, s, t) { + var n = a + (b ^ c ^ d) + x + t; + return ((n << s) | (n >>> (32 - s))) + b; + } + + function II(a, b, c, d, x, s, t) { + var n = a + (c ^ (b | ~d)) + x + t; + return ((n << s) | (n >>> (32 - s))) + b; + } + + /** + * Shortcut function to the hasher's object interface. + * + * @param {WordArray|string} message The message to hash. + * + * @return {WordArray} The hash. + * + * @static + * + * @example + * + * var hash = CryptoJS.MD5('message'); + * var hash = CryptoJS.MD5(wordArray); + */ + C.MD5 = Hasher._createHelper(MD5); + + /** + * Shortcut function to the HMAC's object interface. + * + * @param {WordArray|string} message The message to hash. + * @param {WordArray|string} key The secret key. + * + * @return {WordArray} The HMAC. + * + * @static + * + * @example + * + * var hmac = CryptoJS.HmacMD5(message, key); + */ + C.HmacMD5 = Hasher._createHmacHelper(MD5); + }(Math)); + + + (function () { + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var WordArray = C_lib.WordArray; + var Hasher = C_lib.Hasher; + var C_algo = C.algo; + + // Reusable object + var W = []; + + /** + * SHA-1 hash algorithm. + */ + var SHA1 = C_algo.SHA1 = Hasher.extend({ + _doReset: function () { + this._hash = new WordArray.init([ + 0x67452301, 0xefcdab89, + 0x98badcfe, 0x10325476, + 0xc3d2e1f0 + ]); + }, + + _doProcessBlock: function (M, offset) { + // Shortcut + var H = this._hash.words; + + // Working variables + var a = H[0]; + var b = H[1]; + var c = H[2]; + var d = H[3]; + var e = H[4]; + + // Computation + for (var i = 0; i < 80; i++) { + if (i < 16) { + W[i] = M[offset + i] | 0; + } else { + var n = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16]; + W[i] = (n << 1) | (n >>> 31); + } + + var t = ((a << 5) | (a >>> 27)) + e + W[i]; + if (i < 20) { + t += ((b & c) | (~b & d)) + 0x5a827999; + } else if (i < 40) { + t += (b ^ c ^ d) + 0x6ed9eba1; + } else if (i < 60) { + t += ((b & c) | (b & d) | (c & d)) - 0x70e44324; + } else /* if (i < 80) */ { + t += (b ^ c ^ d) - 0x359d3e2a; + } + + e = d; + d = c; + c = (b << 30) | (b >>> 2); + b = a; + a = t; + } + + // Intermediate hash value + H[0] = (H[0] + a) | 0; + H[1] = (H[1] + b) | 0; + H[2] = (H[2] + c) | 0; + H[3] = (H[3] + d) | 0; + H[4] = (H[4] + e) | 0; + }, + + _doFinalize: function () { + // Shortcuts + var data = this._data; + var dataWords = data.words; + + var nBitsTotal = this._nDataBytes * 8; + var nBitsLeft = data.sigBytes * 8; + + // Add padding + dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); + dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor(nBitsTotal / 0x100000000); + dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal; + data.sigBytes = dataWords.length * 4; + + // Hash final blocks + this._process(); + + // Return final computed hash + return this._hash; + }, + + clone: function () { + var clone = Hasher.clone.call(this); + clone._hash = this._hash.clone(); + + return clone; + } + }); + + /** + * Shortcut function to the hasher's object interface. + * + * @param {WordArray|string} message The message to hash. + * + * @return {WordArray} The hash. + * + * @static + * + * @example + * + * var hash = CryptoJS.SHA1('message'); + * var hash = CryptoJS.SHA1(wordArray); + */ + C.SHA1 = Hasher._createHelper(SHA1); + + /** + * Shortcut function to the HMAC's object interface. + * + * @param {WordArray|string} message The message to hash. + * @param {WordArray|string} key The secret key. + * + * @return {WordArray} The HMAC. + * + * @static + * + * @example + * + * var hmac = CryptoJS.HmacSHA1(message, key); + */ + C.HmacSHA1 = Hasher._createHmacHelper(SHA1); + }()); + + + (function (Math) { + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var WordArray = C_lib.WordArray; + var Hasher = C_lib.Hasher; + var C_algo = C.algo; + + // Initialization and round constants tables + var H = []; + var K = []; + + // Compute constants + (function () { + function isPrime(n) { + var sqrtN = Math.sqrt(n); + for (var factor = 2; factor <= sqrtN; factor++) { + if (!(n % factor)) { + return false; + } + } + + return true; + } + + function getFractionalBits(n) { + return ((n - (n | 0)) * 0x100000000) | 0; + } + + var n = 2; + var nPrime = 0; + while (nPrime < 64) { + if (isPrime(n)) { + if (nPrime < 8) { + H[nPrime] = getFractionalBits(Math.pow(n, 1 / 2)); + } + K[nPrime] = getFractionalBits(Math.pow(n, 1 / 3)); + + nPrime++; + } + + n++; + } + }()); + + // Reusable object + var W = []; + + /** + * SHA-256 hash algorithm. + */ + var SHA256 = C_algo.SHA256 = Hasher.extend({ + _doReset: function () { + this._hash = new WordArray.init(H.slice(0)); + }, + + _doProcessBlock: function (M, offset) { + // Shortcut + var H = this._hash.words; + + // Working variables + var a = H[0]; + var b = H[1]; + var c = H[2]; + var d = H[3]; + var e = H[4]; + var f = H[5]; + var g = H[6]; + var h = H[7]; + + // Computation + for (var i = 0; i < 64; i++) { + if (i < 16) { + W[i] = M[offset + i] | 0; + } else { + var gamma0x = W[i - 15]; + var gamma0 = ((gamma0x << 25) | (gamma0x >>> 7)) ^ + ((gamma0x << 14) | (gamma0x >>> 18)) ^ + (gamma0x >>> 3); + + var gamma1x = W[i - 2]; + var gamma1 = ((gamma1x << 15) | (gamma1x >>> 17)) ^ + ((gamma1x << 13) | (gamma1x >>> 19)) ^ + (gamma1x >>> 10); + + W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16]; + } + + var ch = (e & f) ^ (~e & g); + var maj = (a & b) ^ (a & c) ^ (b & c); + + var sigma0 = ((a << 30) | (a >>> 2)) ^ ((a << 19) | (a >>> 13)) ^ ((a << 10) | (a >>> 22)); + var sigma1 = ((e << 26) | (e >>> 6)) ^ ((e << 21) | (e >>> 11)) ^ ((e << 7) | (e >>> 25)); + + var t1 = h + sigma1 + ch + K[i] + W[i]; + var t2 = sigma0 + maj; + + h = g; + g = f; + f = e; + e = (d + t1) | 0; + d = c; + c = b; + b = a; + a = (t1 + t2) | 0; + } + + // Intermediate hash value + H[0] = (H[0] + a) | 0; + H[1] = (H[1] + b) | 0; + H[2] = (H[2] + c) | 0; + H[3] = (H[3] + d) | 0; + H[4] = (H[4] + e) | 0; + H[5] = (H[5] + f) | 0; + H[6] = (H[6] + g) | 0; + H[7] = (H[7] + h) | 0; + }, + + _doFinalize: function () { + // Shortcuts + var data = this._data; + var dataWords = data.words; + + var nBitsTotal = this._nDataBytes * 8; + var nBitsLeft = data.sigBytes * 8; + + // Add padding + dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); + dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor(nBitsTotal / 0x100000000); + dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal; + data.sigBytes = dataWords.length * 4; + + // Hash final blocks + this._process(); + + // Return final computed hash + return this._hash; + }, + + clone: function () { + var clone = Hasher.clone.call(this); + clone._hash = this._hash.clone(); + + return clone; + } + }); + + /** + * Shortcut function to the hasher's object interface. + * + * @param {WordArray|string} message The message to hash. + * + * @return {WordArray} The hash. + * + * @static + * + * @example + * + * var hash = CryptoJS.SHA256('message'); + * var hash = CryptoJS.SHA256(wordArray); + */ + C.SHA256 = Hasher._createHelper(SHA256); + + /** + * Shortcut function to the HMAC's object interface. + * + * @param {WordArray|string} message The message to hash. + * @param {WordArray|string} key The secret key. + * + * @return {WordArray} The HMAC. + * + * @static + * + * @example + * + * var hmac = CryptoJS.HmacSHA256(message, key); + */ + C.HmacSHA256 = Hasher._createHmacHelper(SHA256); + }(Math)); + + + (function () { + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var WordArray = C_lib.WordArray; + var C_algo = C.algo; + var SHA256 = C_algo.SHA256; + + /** + * SHA-224 hash algorithm. + */ + var SHA224 = C_algo.SHA224 = SHA256.extend({ + _doReset: function () { + this._hash = new WordArray.init([ + 0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939, + 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4 + ]); + }, + + _doFinalize: function () { + var hash = SHA256._doFinalize.call(this); + + hash.sigBytes -= 4; + + return hash; + } + }); + + /** + * Shortcut function to the hasher's object interface. + * + * @param {WordArray|string} message The message to hash. + * + * @return {WordArray} The hash. + * + * @static + * + * @example + * + * var hash = CryptoJS.SHA224('message'); + * var hash = CryptoJS.SHA224(wordArray); + */ + C.SHA224 = SHA256._createHelper(SHA224); + + /** + * Shortcut function to the HMAC's object interface. + * + * @param {WordArray|string} message The message to hash. + * @param {WordArray|string} key The secret key. + * + * @return {WordArray} The HMAC. + * + * @static + * + * @example + * + * var hmac = CryptoJS.HmacSHA224(message, key); + */ + C.HmacSHA224 = SHA256._createHmacHelper(SHA224); + }()); + + + (function () { + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var Hasher = C_lib.Hasher; + var C_x64 = C.x64; + var X64Word = C_x64.Word; + var X64WordArray = C_x64.WordArray; + var C_algo = C.algo; + + function X64Word_create() { + return X64Word.create.apply(X64Word, arguments); + } + + // Constants + var K = [ + X64Word_create(0x428a2f98, 0xd728ae22), X64Word_create(0x71374491, 0x23ef65cd), + X64Word_create(0xb5c0fbcf, 0xec4d3b2f), X64Word_create(0xe9b5dba5, 0x8189dbbc), + X64Word_create(0x3956c25b, 0xf348b538), X64Word_create(0x59f111f1, 0xb605d019), + X64Word_create(0x923f82a4, 0xaf194f9b), X64Word_create(0xab1c5ed5, 0xda6d8118), + X64Word_create(0xd807aa98, 0xa3030242), X64Word_create(0x12835b01, 0x45706fbe), + X64Word_create(0x243185be, 0x4ee4b28c), X64Word_create(0x550c7dc3, 0xd5ffb4e2), + X64Word_create(0x72be5d74, 0xf27b896f), X64Word_create(0x80deb1fe, 0x3b1696b1), + X64Word_create(0x9bdc06a7, 0x25c71235), X64Word_create(0xc19bf174, 0xcf692694), + X64Word_create(0xe49b69c1, 0x9ef14ad2), X64Word_create(0xefbe4786, 0x384f25e3), + X64Word_create(0x0fc19dc6, 0x8b8cd5b5), X64Word_create(0x240ca1cc, 0x77ac9c65), + X64Word_create(0x2de92c6f, 0x592b0275), X64Word_create(0x4a7484aa, 0x6ea6e483), + X64Word_create(0x5cb0a9dc, 0xbd41fbd4), X64Word_create(0x76f988da, 0x831153b5), + X64Word_create(0x983e5152, 0xee66dfab), X64Word_create(0xa831c66d, 0x2db43210), + X64Word_create(0xb00327c8, 0x98fb213f), X64Word_create(0xbf597fc7, 0xbeef0ee4), + X64Word_create(0xc6e00bf3, 0x3da88fc2), X64Word_create(0xd5a79147, 0x930aa725), + X64Word_create(0x06ca6351, 0xe003826f), X64Word_create(0x14292967, 0x0a0e6e70), + X64Word_create(0x27b70a85, 0x46d22ffc), X64Word_create(0x2e1b2138, 0x5c26c926), + X64Word_create(0x4d2c6dfc, 0x5ac42aed), X64Word_create(0x53380d13, 0x9d95b3df), + X64Word_create(0x650a7354, 0x8baf63de), X64Word_create(0x766a0abb, 0x3c77b2a8), + X64Word_create(0x81c2c92e, 0x47edaee6), X64Word_create(0x92722c85, 0x1482353b), + X64Word_create(0xa2bfe8a1, 0x4cf10364), X64Word_create(0xa81a664b, 0xbc423001), + X64Word_create(0xc24b8b70, 0xd0f89791), X64Word_create(0xc76c51a3, 0x0654be30), + X64Word_create(0xd192e819, 0xd6ef5218), X64Word_create(0xd6990624, 0x5565a910), + X64Word_create(0xf40e3585, 0x5771202a), X64Word_create(0x106aa070, 0x32bbd1b8), + X64Word_create(0x19a4c116, 0xb8d2d0c8), X64Word_create(0x1e376c08, 0x5141ab53), + X64Word_create(0x2748774c, 0xdf8eeb99), X64Word_create(0x34b0bcb5, 0xe19b48a8), + X64Word_create(0x391c0cb3, 0xc5c95a63), X64Word_create(0x4ed8aa4a, 0xe3418acb), + X64Word_create(0x5b9cca4f, 0x7763e373), X64Word_create(0x682e6ff3, 0xd6b2b8a3), + X64Word_create(0x748f82ee, 0x5defb2fc), X64Word_create(0x78a5636f, 0x43172f60), + X64Word_create(0x84c87814, 0xa1f0ab72), X64Word_create(0x8cc70208, 0x1a6439ec), + X64Word_create(0x90befffa, 0x23631e28), X64Word_create(0xa4506ceb, 0xde82bde9), + X64Word_create(0xbef9a3f7, 0xb2c67915), X64Word_create(0xc67178f2, 0xe372532b), + X64Word_create(0xca273ece, 0xea26619c), X64Word_create(0xd186b8c7, 0x21c0c207), + X64Word_create(0xeada7dd6, 0xcde0eb1e), X64Word_create(0xf57d4f7f, 0xee6ed178), + X64Word_create(0x06f067aa, 0x72176fba), X64Word_create(0x0a637dc5, 0xa2c898a6), + X64Word_create(0x113f9804, 0xbef90dae), X64Word_create(0x1b710b35, 0x131c471b), + X64Word_create(0x28db77f5, 0x23047d84), X64Word_create(0x32caab7b, 0x40c72493), + X64Word_create(0x3c9ebe0a, 0x15c9bebc), X64Word_create(0x431d67c4, 0x9c100d4c), + X64Word_create(0x4cc5d4be, 0xcb3e42b6), X64Word_create(0x597f299c, 0xfc657e2a), + X64Word_create(0x5fcb6fab, 0x3ad6faec), X64Word_create(0x6c44198c, 0x4a475817) + ]; + + // Reusable objects + var W = []; + (function () { + for (var i = 0; i < 80; i++) { + W[i] = X64Word_create(); + } + }()); + + /** + * SHA-512 hash algorithm. + */ + var SHA512 = C_algo.SHA512 = Hasher.extend({ + _doReset: function () { + this._hash = new X64WordArray.init([ + new X64Word.init(0x6a09e667, 0xf3bcc908), new X64Word.init(0xbb67ae85, 0x84caa73b), + new X64Word.init(0x3c6ef372, 0xfe94f82b), new X64Word.init(0xa54ff53a, 0x5f1d36f1), + new X64Word.init(0x510e527f, 0xade682d1), new X64Word.init(0x9b05688c, 0x2b3e6c1f), + new X64Word.init(0x1f83d9ab, 0xfb41bd6b), new X64Word.init(0x5be0cd19, 0x137e2179) + ]); + }, + + _doProcessBlock: function (M, offset) { + // Shortcuts + var H = this._hash.words; + + var H0 = H[0]; + var H1 = H[1]; + var H2 = H[2]; + var H3 = H[3]; + var H4 = H[4]; + var H5 = H[5]; + var H6 = H[6]; + var H7 = H[7]; + + var H0h = H0.high; + var H0l = H0.low; + var H1h = H1.high; + var H1l = H1.low; + var H2h = H2.high; + var H2l = H2.low; + var H3h = H3.high; + var H3l = H3.low; + var H4h = H4.high; + var H4l = H4.low; + var H5h = H5.high; + var H5l = H5.low; + var H6h = H6.high; + var H6l = H6.low; + var H7h = H7.high; + var H7l = H7.low; + + // Working variables + var ah = H0h; + var al = H0l; + var bh = H1h; + var bl = H1l; + var ch = H2h; + var cl = H2l; + var dh = H3h; + var dl = H3l; + var eh = H4h; + var el = H4l; + var fh = H5h; + var fl = H5l; + var gh = H6h; + var gl = H6l; + var hh = H7h; + var hl = H7l; + + // Rounds + for (var i = 0; i < 80; i++) { + var Wil; + var Wih; + + // Shortcut + var Wi = W[i]; + + // Extend message + if (i < 16) { + Wih = Wi.high = M[offset + i * 2] | 0; + Wil = Wi.low = M[offset + i * 2 + 1] | 0; + } else { + // Gamma0 + var gamma0x = W[i - 15]; + var gamma0xh = gamma0x.high; + var gamma0xl = gamma0x.low; + var gamma0h = ((gamma0xh >>> 1) | (gamma0xl << 31)) ^ ((gamma0xh >>> 8) | (gamma0xl << 24)) ^ (gamma0xh >>> 7); + var gamma0l = ((gamma0xl >>> 1) | (gamma0xh << 31)) ^ ((gamma0xl >>> 8) | (gamma0xh << 24)) ^ ((gamma0xl >>> 7) | (gamma0xh << 25)); + + // Gamma1 + var gamma1x = W[i - 2]; + var gamma1xh = gamma1x.high; + var gamma1xl = gamma1x.low; + var gamma1h = ((gamma1xh >>> 19) | (gamma1xl << 13)) ^ ((gamma1xh << 3) | (gamma1xl >>> 29)) ^ (gamma1xh >>> 6); + var gamma1l = ((gamma1xl >>> 19) | (gamma1xh << 13)) ^ ((gamma1xl << 3) | (gamma1xh >>> 29)) ^ ((gamma1xl >>> 6) | (gamma1xh << 26)); + + // W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16] + var Wi7 = W[i - 7]; + var Wi7h = Wi7.high; + var Wi7l = Wi7.low; + + var Wi16 = W[i - 16]; + var Wi16h = Wi16.high; + var Wi16l = Wi16.low; + + Wil = gamma0l + Wi7l; + Wih = gamma0h + Wi7h + ((Wil >>> 0) < (gamma0l >>> 0) ? 1 : 0); + Wil = Wil + gamma1l; + Wih = Wih + gamma1h + ((Wil >>> 0) < (gamma1l >>> 0) ? 1 : 0); + Wil = Wil + Wi16l; + Wih = Wih + Wi16h + ((Wil >>> 0) < (Wi16l >>> 0) ? 1 : 0); + + Wi.high = Wih; + Wi.low = Wil; + } + + var chh = (eh & fh) ^ (~eh & gh); + var chl = (el & fl) ^ (~el & gl); + var majh = (ah & bh) ^ (ah & ch) ^ (bh & ch); + var majl = (al & bl) ^ (al & cl) ^ (bl & cl); + + var sigma0h = ((ah >>> 28) | (al << 4)) ^ ((ah << 30) | (al >>> 2)) ^ ((ah << 25) | (al >>> 7)); + var sigma0l = ((al >>> 28) | (ah << 4)) ^ ((al << 30) | (ah >>> 2)) ^ ((al << 25) | (ah >>> 7)); + var sigma1h = ((eh >>> 14) | (el << 18)) ^ ((eh >>> 18) | (el << 14)) ^ ((eh << 23) | (el >>> 9)); + var sigma1l = ((el >>> 14) | (eh << 18)) ^ ((el >>> 18) | (eh << 14)) ^ ((el << 23) | (eh >>> 9)); + + // t1 = h + sigma1 + ch + K[i] + W[i] + var Ki = K[i]; + var Kih = Ki.high; + var Kil = Ki.low; + + var t1l = hl + sigma1l; + var t1h = hh + sigma1h + ((t1l >>> 0) < (hl >>> 0) ? 1 : 0); + var t1l = t1l + chl; + var t1h = t1h + chh + ((t1l >>> 0) < (chl >>> 0) ? 1 : 0); + var t1l = t1l + Kil; + var t1h = t1h + Kih + ((t1l >>> 0) < (Kil >>> 0) ? 1 : 0); + var t1l = t1l + Wil; + var t1h = t1h + Wih + ((t1l >>> 0) < (Wil >>> 0) ? 1 : 0); + + // t2 = sigma0 + maj + var t2l = sigma0l + majl; + var t2h = sigma0h + majh + ((t2l >>> 0) < (sigma0l >>> 0) ? 1 : 0); + + // Update working variables + hh = gh; + hl = gl; + gh = fh; + gl = fl; + fh = eh; + fl = el; + el = (dl + t1l) | 0; + eh = (dh + t1h + ((el >>> 0) < (dl >>> 0) ? 1 : 0)) | 0; + dh = ch; + dl = cl; + ch = bh; + cl = bl; + bh = ah; + bl = al; + al = (t1l + t2l) | 0; + ah = (t1h + t2h + ((al >>> 0) < (t1l >>> 0) ? 1 : 0)) | 0; + } + + // Intermediate hash value + H0l = H0.low = (H0l + al); + H0.high = (H0h + ah + ((H0l >>> 0) < (al >>> 0) ? 1 : 0)); + H1l = H1.low = (H1l + bl); + H1.high = (H1h + bh + ((H1l >>> 0) < (bl >>> 0) ? 1 : 0)); + H2l = H2.low = (H2l + cl); + H2.high = (H2h + ch + ((H2l >>> 0) < (cl >>> 0) ? 1 : 0)); + H3l = H3.low = (H3l + dl); + H3.high = (H3h + dh + ((H3l >>> 0) < (dl >>> 0) ? 1 : 0)); + H4l = H4.low = (H4l + el); + H4.high = (H4h + eh + ((H4l >>> 0) < (el >>> 0) ? 1 : 0)); + H5l = H5.low = (H5l + fl); + H5.high = (H5h + fh + ((H5l >>> 0) < (fl >>> 0) ? 1 : 0)); + H6l = H6.low = (H6l + gl); + H6.high = (H6h + gh + ((H6l >>> 0) < (gl >>> 0) ? 1 : 0)); + H7l = H7.low = (H7l + hl); + H7.high = (H7h + hh + ((H7l >>> 0) < (hl >>> 0) ? 1 : 0)); + }, + + _doFinalize: function () { + // Shortcuts + var data = this._data; + var dataWords = data.words; + + var nBitsTotal = this._nDataBytes * 8; + var nBitsLeft = data.sigBytes * 8; + + // Add padding + dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); + dataWords[(((nBitsLeft + 128) >>> 10) << 5) + 30] = Math.floor(nBitsTotal / 0x100000000); + dataWords[(((nBitsLeft + 128) >>> 10) << 5) + 31] = nBitsTotal; + data.sigBytes = dataWords.length * 4; + + // Hash final blocks + this._process(); + + // Convert hash to 32-bit word array before returning + var hash = this._hash.toX32(); + + // Return final computed hash + return hash; + }, + + clone: function () { + var clone = Hasher.clone.call(this); + clone._hash = this._hash.clone(); + + return clone; + }, + + blockSize: 1024/32 + }); + + /** + * Shortcut function to the hasher's object interface. + * + * @param {WordArray|string} message The message to hash. + * + * @return {WordArray} The hash. + * + * @static + * + * @example + * + * var hash = CryptoJS.SHA512('message'); + * var hash = CryptoJS.SHA512(wordArray); + */ + C.SHA512 = Hasher._createHelper(SHA512); + + /** + * Shortcut function to the HMAC's object interface. + * + * @param {WordArray|string} message The message to hash. + * @param {WordArray|string} key The secret key. + * + * @return {WordArray} The HMAC. + * + * @static + * + * @example + * + * var hmac = CryptoJS.HmacSHA512(message, key); + */ + C.HmacSHA512 = Hasher._createHmacHelper(SHA512); + }()); + + + (function () { + // Shortcuts + var C = CryptoJS; + var C_x64 = C.x64; + var X64Word = C_x64.Word; + var X64WordArray = C_x64.WordArray; + var C_algo = C.algo; + var SHA512 = C_algo.SHA512; + + /** + * SHA-384 hash algorithm. + */ + var SHA384 = C_algo.SHA384 = SHA512.extend({ + _doReset: function () { + this._hash = new X64WordArray.init([ + new X64Word.init(0xcbbb9d5d, 0xc1059ed8), new X64Word.init(0x629a292a, 0x367cd507), + new X64Word.init(0x9159015a, 0x3070dd17), new X64Word.init(0x152fecd8, 0xf70e5939), + new X64Word.init(0x67332667, 0xffc00b31), new X64Word.init(0x8eb44a87, 0x68581511), + new X64Word.init(0xdb0c2e0d, 0x64f98fa7), new X64Word.init(0x47b5481d, 0xbefa4fa4) + ]); + }, + + _doFinalize: function () { + var hash = SHA512._doFinalize.call(this); + + hash.sigBytes -= 16; + + return hash; + } + }); + + /** + * Shortcut function to the hasher's object interface. + * + * @param {WordArray|string} message The message to hash. + * + * @return {WordArray} The hash. + * + * @static + * + * @example + * + * var hash = CryptoJS.SHA384('message'); + * var hash = CryptoJS.SHA384(wordArray); + */ + C.SHA384 = SHA512._createHelper(SHA384); + + /** + * Shortcut function to the HMAC's object interface. + * + * @param {WordArray|string} message The message to hash. + * @param {WordArray|string} key The secret key. + * + * @return {WordArray} The HMAC. + * + * @static + * + * @example + * + * var hmac = CryptoJS.HmacSHA384(message, key); + */ + C.HmacSHA384 = SHA512._createHmacHelper(SHA384); + }()); + + + (function (Math) { + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var WordArray = C_lib.WordArray; + var Hasher = C_lib.Hasher; + var C_x64 = C.x64; + var X64Word = C_x64.Word; + var C_algo = C.algo; + + // Constants tables + var RHO_OFFSETS = []; + var PI_INDEXES = []; + var ROUND_CONSTANTS = []; + + // Compute Constants + (function () { + // Compute rho offset constants + var x = 1, y = 0; + for (var t = 0; t < 24; t++) { + RHO_OFFSETS[x + 5 * y] = ((t + 1) * (t + 2) / 2) % 64; + + var newX = y % 5; + var newY = (2 * x + 3 * y) % 5; + x = newX; + y = newY; + } + + // Compute pi index constants + for (var x = 0; x < 5; x++) { + for (var y = 0; y < 5; y++) { + PI_INDEXES[x + 5 * y] = y + ((2 * x + 3 * y) % 5) * 5; + } + } + + // Compute round constants + var LFSR = 0x01; + for (var i = 0; i < 24; i++) { + var roundConstantMsw = 0; + var roundConstantLsw = 0; + + for (var j = 0; j < 7; j++) { + if (LFSR & 0x01) { + var bitPosition = (1 << j) - 1; + if (bitPosition < 32) { + roundConstantLsw ^= 1 << bitPosition; + } else /* if (bitPosition >= 32) */ { + roundConstantMsw ^= 1 << (bitPosition - 32); + } + } + + // Compute next LFSR + if (LFSR & 0x80) { + // Primitive polynomial over GF(2): x^8 + x^6 + x^5 + x^4 + 1 + LFSR = (LFSR << 1) ^ 0x71; + } else { + LFSR <<= 1; + } + } + + ROUND_CONSTANTS[i] = X64Word.create(roundConstantMsw, roundConstantLsw); + } + }()); + + // Reusable objects for temporary values + var T = []; + (function () { + for (var i = 0; i < 25; i++) { + T[i] = X64Word.create(); + } + }()); + + /** + * SHA-3 hash algorithm. + */ + var SHA3 = C_algo.SHA3 = Hasher.extend({ + /** + * Configuration options. + * + * @property {number} outputLength + * The desired number of bits in the output hash. + * Only values permitted are: 224, 256, 384, 512. + * Default: 512 + */ + cfg: Hasher.cfg.extend({ + outputLength: 512 + }), + + _doReset: function () { + var state = this._state = [] + for (var i = 0; i < 25; i++) { + state[i] = new X64Word.init(); + } + + this.blockSize = (1600 - 2 * this.cfg.outputLength) / 32; + }, + + _doProcessBlock: function (M, offset) { + // Shortcuts + var state = this._state; + var nBlockSizeLanes = this.blockSize / 2; + + // Absorb + for (var i = 0; i < nBlockSizeLanes; i++) { + // Shortcuts + var M2i = M[offset + 2 * i]; + var M2i1 = M[offset + 2 * i + 1]; + + // Swap endian + M2i = ( + (((M2i << 8) | (M2i >>> 24)) & 0x00ff00ff) | + (((M2i << 24) | (M2i >>> 8)) & 0xff00ff00) + ); + M2i1 = ( + (((M2i1 << 8) | (M2i1 >>> 24)) & 0x00ff00ff) | + (((M2i1 << 24) | (M2i1 >>> 8)) & 0xff00ff00) + ); + + // Absorb message into state + var lane = state[i]; + lane.high ^= M2i1; + lane.low ^= M2i; + } + + // Rounds + for (var round = 0; round < 24; round++) { + // Theta + for (var x = 0; x < 5; x++) { + // Mix column lanes + var tMsw = 0, tLsw = 0; + for (var y = 0; y < 5; y++) { + var lane = state[x + 5 * y]; + tMsw ^= lane.high; + tLsw ^= lane.low; + } + + // Temporary values + var Tx = T[x]; + Tx.high = tMsw; + Tx.low = tLsw; + } + for (var x = 0; x < 5; x++) { + // Shortcuts + var Tx4 = T[(x + 4) % 5]; + var Tx1 = T[(x + 1) % 5]; + var Tx1Msw = Tx1.high; + var Tx1Lsw = Tx1.low; + + // Mix surrounding columns + var tMsw = Tx4.high ^ ((Tx1Msw << 1) | (Tx1Lsw >>> 31)); + var tLsw = Tx4.low ^ ((Tx1Lsw << 1) | (Tx1Msw >>> 31)); + for (var y = 0; y < 5; y++) { + var lane = state[x + 5 * y]; + lane.high ^= tMsw; + lane.low ^= tLsw; + } + } + + // Rho Pi + for (var laneIndex = 1; laneIndex < 25; laneIndex++) { + var tMsw; + var tLsw; + + // Shortcuts + var lane = state[laneIndex]; + var laneMsw = lane.high; + var laneLsw = lane.low; + var rhoOffset = RHO_OFFSETS[laneIndex]; + + // Rotate lanes + if (rhoOffset < 32) { + tMsw = (laneMsw << rhoOffset) | (laneLsw >>> (32 - rhoOffset)); + tLsw = (laneLsw << rhoOffset) | (laneMsw >>> (32 - rhoOffset)); + } else /* if (rhoOffset >= 32) */ { + tMsw = (laneLsw << (rhoOffset - 32)) | (laneMsw >>> (64 - rhoOffset)); + tLsw = (laneMsw << (rhoOffset - 32)) | (laneLsw >>> (64 - rhoOffset)); + } + + // Transpose lanes + var TPiLane = T[PI_INDEXES[laneIndex]]; + TPiLane.high = tMsw; + TPiLane.low = tLsw; + } + + // Rho pi at x = y = 0 + var T0 = T[0]; + var state0 = state[0]; + T0.high = state0.high; + T0.low = state0.low; + + // Chi + for (var x = 0; x < 5; x++) { + for (var y = 0; y < 5; y++) { + // Shortcuts + var laneIndex = x + 5 * y; + var lane = state[laneIndex]; + var TLane = T[laneIndex]; + var Tx1Lane = T[((x + 1) % 5) + 5 * y]; + var Tx2Lane = T[((x + 2) % 5) + 5 * y]; + + // Mix rows + lane.high = TLane.high ^ (~Tx1Lane.high & Tx2Lane.high); + lane.low = TLane.low ^ (~Tx1Lane.low & Tx2Lane.low); + } + } + + // Iota + var lane = state[0]; + var roundConstant = ROUND_CONSTANTS[round]; + lane.high ^= roundConstant.high; + lane.low ^= roundConstant.low; + } + }, + + _doFinalize: function () { + // Shortcuts + var data = this._data; + var dataWords = data.words; + var nBitsTotal = this._nDataBytes * 8; + var nBitsLeft = data.sigBytes * 8; + var blockSizeBits = this.blockSize * 32; + + // Add padding + dataWords[nBitsLeft >>> 5] |= 0x1 << (24 - nBitsLeft % 32); + dataWords[((Math.ceil((nBitsLeft + 1) / blockSizeBits) * blockSizeBits) >>> 5) - 1] |= 0x80; + data.sigBytes = dataWords.length * 4; + + // Hash final blocks + this._process(); + + // Shortcuts + var state = this._state; + var outputLengthBytes = this.cfg.outputLength / 8; + var outputLengthLanes = outputLengthBytes / 8; + + // Squeeze + var hashWords = []; + for (var i = 0; i < outputLengthLanes; i++) { + // Shortcuts + var lane = state[i]; + var laneMsw = lane.high; + var laneLsw = lane.low; + + // Swap endian + laneMsw = ( + (((laneMsw << 8) | (laneMsw >>> 24)) & 0x00ff00ff) | + (((laneMsw << 24) | (laneMsw >>> 8)) & 0xff00ff00) + ); + laneLsw = ( + (((laneLsw << 8) | (laneLsw >>> 24)) & 0x00ff00ff) | + (((laneLsw << 24) | (laneLsw >>> 8)) & 0xff00ff00) + ); + + // Squeeze state to retrieve hash + hashWords.push(laneLsw); + hashWords.push(laneMsw); + } + + // Return final computed hash + return new WordArray.init(hashWords, outputLengthBytes); + }, + + clone: function () { + var clone = Hasher.clone.call(this); + + var state = clone._state = this._state.slice(0); + for (var i = 0; i < 25; i++) { + state[i] = state[i].clone(); + } + + return clone; + } + }); + + /** + * Shortcut function to the hasher's object interface. + * + * @param {WordArray|string} message The message to hash. + * + * @return {WordArray} The hash. + * + * @static + * + * @example + * + * var hash = CryptoJS.SHA3('message'); + * var hash = CryptoJS.SHA3(wordArray); + */ + C.SHA3 = Hasher._createHelper(SHA3); + + /** + * Shortcut function to the HMAC's object interface. + * + * @param {WordArray|string} message The message to hash. + * @param {WordArray|string} key The secret key. + * + * @return {WordArray} The HMAC. + * + * @static + * + * @example + * + * var hmac = CryptoJS.HmacSHA3(message, key); + */ + C.HmacSHA3 = Hasher._createHmacHelper(SHA3); + }(Math)); + + + /** @preserve + (c) 2012 by Cédric Mesnil. All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + + - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + (function (Math) { + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var WordArray = C_lib.WordArray; + var Hasher = C_lib.Hasher; + var C_algo = C.algo; + + // Constants table + var _zl = WordArray.create([ + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8, + 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12, + 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2, + 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13]); + var _zr = WordArray.create([ + 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12, + 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2, + 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13, + 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14, + 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11]); + var _sl = WordArray.create([ + 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8, + 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12, + 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5, + 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12, + 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6 ]); + var _sr = WordArray.create([ + 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6, + 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11, + 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5, + 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8, + 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11 ]); + + var _hl = WordArray.create([ 0x00000000, 0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xA953FD4E]); + var _hr = WordArray.create([ 0x50A28BE6, 0x5C4DD124, 0x6D703EF3, 0x7A6D76E9, 0x00000000]); + + /** + * RIPEMD160 hash algorithm. + */ + var RIPEMD160 = C_algo.RIPEMD160 = Hasher.extend({ + _doReset: function () { + this._hash = WordArray.create([0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0]); + }, + + _doProcessBlock: function (M, offset) { + + // Swap endian + for (var i = 0; i < 16; i++) { + // Shortcuts + var offset_i = offset + i; + var M_offset_i = M[offset_i]; + + // Swap + M[offset_i] = ( + (((M_offset_i << 8) | (M_offset_i >>> 24)) & 0x00ff00ff) | + (((M_offset_i << 24) | (M_offset_i >>> 8)) & 0xff00ff00) + ); + } + // Shortcut + var H = this._hash.words; + var hl = _hl.words; + var hr = _hr.words; + var zl = _zl.words; + var zr = _zr.words; + var sl = _sl.words; + var sr = _sr.words; + + // Working variables + var al, bl, cl, dl, el; + var ar, br, cr, dr, er; + + ar = al = H[0]; + br = bl = H[1]; + cr = cl = H[2]; + dr = dl = H[3]; + er = el = H[4]; + // Computation + var t; + for (var i = 0; i < 80; i += 1) { + t = (al + M[offset+zl[i]])|0; + if (i<16){ + t += f1(bl,cl,dl) + hl[0]; + } else if (i<32) { + t += f2(bl,cl,dl) + hl[1]; + } else if (i<48) { + t += f3(bl,cl,dl) + hl[2]; + } else if (i<64) { + t += f4(bl,cl,dl) + hl[3]; + } else {// if (i<80) { + t += f5(bl,cl,dl) + hl[4]; + } + t = t|0; + t = rotl(t,sl[i]); + t = (t+el)|0; + al = el; + el = dl; + dl = rotl(cl, 10); + cl = bl; + bl = t; + + t = (ar + M[offset+zr[i]])|0; + if (i<16){ + t += f5(br,cr,dr) + hr[0]; + } else if (i<32) { + t += f4(br,cr,dr) + hr[1]; + } else if (i<48) { + t += f3(br,cr,dr) + hr[2]; + } else if (i<64) { + t += f2(br,cr,dr) + hr[3]; + } else {// if (i<80) { + t += f1(br,cr,dr) + hr[4]; + } + t = t|0; + t = rotl(t,sr[i]) ; + t = (t+er)|0; + ar = er; + er = dr; + dr = rotl(cr, 10); + cr = br; + br = t; + } + // Intermediate hash value + t = (H[1] + cl + dr)|0; + H[1] = (H[2] + dl + er)|0; + H[2] = (H[3] + el + ar)|0; + H[3] = (H[4] + al + br)|0; + H[4] = (H[0] + bl + cr)|0; + H[0] = t; + }, + + _doFinalize: function () { + // Shortcuts + var data = this._data; + var dataWords = data.words; + + var nBitsTotal = this._nDataBytes * 8; + var nBitsLeft = data.sigBytes * 8; + + // Add padding + dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); + dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = ( + (((nBitsTotal << 8) | (nBitsTotal >>> 24)) & 0x00ff00ff) | + (((nBitsTotal << 24) | (nBitsTotal >>> 8)) & 0xff00ff00) + ); + data.sigBytes = (dataWords.length + 1) * 4; + + // Hash final blocks + this._process(); + + // Shortcuts + var hash = this._hash; + var H = hash.words; + + // Swap endian + for (var i = 0; i < 5; i++) { + // Shortcut + var H_i = H[i]; + + // Swap + H[i] = (((H_i << 8) | (H_i >>> 24)) & 0x00ff00ff) | + (((H_i << 24) | (H_i >>> 8)) & 0xff00ff00); + } + + // Return final computed hash + return hash; + }, + + clone: function () { + var clone = Hasher.clone.call(this); + clone._hash = this._hash.clone(); + + return clone; + } + }); + + + function f1(x, y, z) { + return ((x) ^ (y) ^ (z)); + + } + + function f2(x, y, z) { + return (((x)&(y)) | ((~x)&(z))); + } + + function f3(x, y, z) { + return (((x) | (~(y))) ^ (z)); + } + + function f4(x, y, z) { + return (((x) & (z)) | ((y)&(~(z)))); + } + + function f5(x, y, z) { + return ((x) ^ ((y) |(~(z)))); + + } + + function rotl(x,n) { + return (x<<n) | (x>>>(32-n)); + } + + + /** + * Shortcut function to the hasher's object interface. + * + * @param {WordArray|string} message The message to hash. + * + * @return {WordArray} The hash. + * + * @static + * + * @example + * + * var hash = CryptoJS.RIPEMD160('message'); + * var hash = CryptoJS.RIPEMD160(wordArray); + */ + C.RIPEMD160 = Hasher._createHelper(RIPEMD160); + + /** + * Shortcut function to the HMAC's object interface. + * + * @param {WordArray|string} message The message to hash. + * @param {WordArray|string} key The secret key. + * + * @return {WordArray} The HMAC. + * + * @static + * + * @example + * + * var hmac = CryptoJS.HmacRIPEMD160(message, key); + */ + C.HmacRIPEMD160 = Hasher._createHmacHelper(RIPEMD160); + }(Math)); + + + (function () { + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var Base = C_lib.Base; + var C_enc = C.enc; + var Utf8 = C_enc.Utf8; + var C_algo = C.algo; + + /** + * HMAC algorithm. + */ + var HMAC = C_algo.HMAC = Base.extend({ + /** + * Initializes a newly created HMAC. + * + * @param {Hasher} hasher The hash algorithm to use. + * @param {WordArray|string} key The secret key. + * + * @example + * + * var hmacHasher = CryptoJS.algo.HMAC.create(CryptoJS.algo.SHA256, key); + */ + init: function (hasher, key) { + // Init hasher + hasher = this._hasher = new hasher.init(); + + // Convert string to WordArray, else assume WordArray already + if (typeof key == 'string') { + key = Utf8.parse(key); + } + + // Shortcuts + var hasherBlockSize = hasher.blockSize; + var hasherBlockSizeBytes = hasherBlockSize * 4; + + // Allow arbitrary length keys + if (key.sigBytes > hasherBlockSizeBytes) { + key = hasher.finalize(key); + } + + // Clamp excess bits + key.clamp(); + + // Clone key for inner and outer pads + var oKey = this._oKey = key.clone(); + var iKey = this._iKey = key.clone(); + + // Shortcuts + var oKeyWords = oKey.words; + var iKeyWords = iKey.words; + + // XOR keys with pad constants + for (var i = 0; i < hasherBlockSize; i++) { + oKeyWords[i] ^= 0x5c5c5c5c; + iKeyWords[i] ^= 0x36363636; + } + oKey.sigBytes = iKey.sigBytes = hasherBlockSizeBytes; + + // Set initial values + this.reset(); + }, + + /** + * Resets this HMAC to its initial state. + * + * @example + * + * hmacHasher.reset(); + */ + reset: function () { + // Shortcut + var hasher = this._hasher; + + // Reset + hasher.reset(); + hasher.update(this._iKey); + }, + + /** + * Updates this HMAC with a message. + * + * @param {WordArray|string} messageUpdate The message to append. + * + * @return {HMAC} This HMAC instance. + * + * @example + * + * hmacHasher.update('message'); + * hmacHasher.update(wordArray); + */ + update: function (messageUpdate) { + this._hasher.update(messageUpdate); + + // Chainable + return this; + }, + + /** + * Finalizes the HMAC computation. + * Note that the finalize operation is effectively a destructive, read-once operation. + * + * @param {WordArray|string} messageUpdate (Optional) A final message update. + * + * @return {WordArray} The HMAC. + * + * @example + * + * var hmac = hmacHasher.finalize(); + * var hmac = hmacHasher.finalize('message'); + * var hmac = hmacHasher.finalize(wordArray); + */ + finalize: function (messageUpdate) { + // Shortcut + var hasher = this._hasher; + + // Compute HMAC + var innerHash = hasher.finalize(messageUpdate); + hasher.reset(); + var hmac = hasher.finalize(this._oKey.clone().concat(innerHash)); + + return hmac; + } + }); + }()); + + + (function () { + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var Base = C_lib.Base; + var WordArray = C_lib.WordArray; + var C_algo = C.algo; + var SHA1 = C_algo.SHA1; + var HMAC = C_algo.HMAC; + + /** + * Password-Based Key Derivation Function 2 algorithm. + */ + var PBKDF2 = C_algo.PBKDF2 = Base.extend({ + /** + * Configuration options. + * + * @property {number} keySize The key size in words to generate. Default: 4 (128 bits) + * @property {Hasher} hasher The hasher to use. Default: SHA1 + * @property {number} iterations The number of iterations to perform. Default: 1 + */ + cfg: Base.extend({ + keySize: 128/32, + hasher: SHA1, + iterations: 1 + }), + + /** + * Initializes a newly created key derivation function. + * + * @param {Object} cfg (Optional) The configuration options to use for the derivation. + * + * @example + * + * var kdf = CryptoJS.algo.PBKDF2.create(); + * var kdf = CryptoJS.algo.PBKDF2.create({ keySize: 8 }); + * var kdf = CryptoJS.algo.PBKDF2.create({ keySize: 8, iterations: 1000 }); + */ + init: function (cfg) { + this.cfg = this.cfg.extend(cfg); + }, + + /** + * Computes the Password-Based Key Derivation Function 2. + * + * @param {WordArray|string} password The password. + * @param {WordArray|string} salt A salt. + * + * @return {WordArray} The derived key. + * + * @example + * + * var key = kdf.compute(password, salt); + */ + compute: function (password, salt) { + // Shortcut + var cfg = this.cfg; + + // Init HMAC + var hmac = HMAC.create(cfg.hasher, password); + + // Initial values + var derivedKey = WordArray.create(); + var blockIndex = WordArray.create([0x00000001]); + + // Shortcuts + var derivedKeyWords = derivedKey.words; + var blockIndexWords = blockIndex.words; + var keySize = cfg.keySize; + var iterations = cfg.iterations; + + // Generate key + while (derivedKeyWords.length < keySize) { + var block = hmac.update(salt).finalize(blockIndex); + hmac.reset(); + + // Shortcuts + var blockWords = block.words; + var blockWordsLength = blockWords.length; + + // Iterations + var intermediate = block; + for (var i = 1; i < iterations; i++) { + intermediate = hmac.finalize(intermediate); + hmac.reset(); + + // Shortcut + var intermediateWords = intermediate.words; + + // XOR intermediate with block + for (var j = 0; j < blockWordsLength; j++) { + blockWords[j] ^= intermediateWords[j]; + } + } + + derivedKey.concat(block); + blockIndexWords[0]++; + } + derivedKey.sigBytes = keySize * 4; + + return derivedKey; + } + }); + + /** + * Computes the Password-Based Key Derivation Function 2. + * + * @param {WordArray|string} password The password. + * @param {WordArray|string} salt A salt. + * @param {Object} cfg (Optional) The configuration options to use for this computation. + * + * @return {WordArray} The derived key. + * + * @static + * + * @example + * + * var key = CryptoJS.PBKDF2(password, salt); + * var key = CryptoJS.PBKDF2(password, salt, { keySize: 8 }); + * var key = CryptoJS.PBKDF2(password, salt, { keySize: 8, iterations: 1000 }); + */ + C.PBKDF2 = function (password, salt, cfg) { + return PBKDF2.create(cfg).compute(password, salt); + }; + }()); + + + (function () { + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var Base = C_lib.Base; + var WordArray = C_lib.WordArray; + var C_algo = C.algo; + var MD5 = C_algo.MD5; + + /** + * This key derivation function is meant to conform with EVP_BytesToKey. + * www.openssl.org/docs/crypto/EVP_BytesToKey.html + */ + var EvpKDF = C_algo.EvpKDF = Base.extend({ + /** + * Configuration options. + * + * @property {number} keySize The key size in words to generate. Default: 4 (128 bits) + * @property {Hasher} hasher The hash algorithm to use. Default: MD5 + * @property {number} iterations The number of iterations to perform. Default: 1 + */ + cfg: Base.extend({ + keySize: 128/32, + hasher: MD5, + iterations: 1 + }), + + /** + * Initializes a newly created key derivation function. + * + * @param {Object} cfg (Optional) The configuration options to use for the derivation. + * + * @example + * + * var kdf = CryptoJS.algo.EvpKDF.create(); + * var kdf = CryptoJS.algo.EvpKDF.create({ keySize: 8 }); + * var kdf = CryptoJS.algo.EvpKDF.create({ keySize: 8, iterations: 1000 }); + */ + init: function (cfg) { + this.cfg = this.cfg.extend(cfg); + }, + + /** + * Derives a key from a password. + * + * @param {WordArray|string} password The password. + * @param {WordArray|string} salt A salt. + * + * @return {WordArray} The derived key. + * + * @example + * + * var key = kdf.compute(password, salt); + */ + compute: function (password, salt) { + var block; + + // Shortcut + var cfg = this.cfg; + + // Init hasher + var hasher = cfg.hasher.create(); + + // Initial values + var derivedKey = WordArray.create(); + + // Shortcuts + var derivedKeyWords = derivedKey.words; + var keySize = cfg.keySize; + var iterations = cfg.iterations; + + // Generate key + while (derivedKeyWords.length < keySize) { + if (block) { + hasher.update(block); + } + block = hasher.update(password).finalize(salt); + hasher.reset(); + + // Iterations + for (var i = 1; i < iterations; i++) { + block = hasher.finalize(block); + hasher.reset(); + } + + derivedKey.concat(block); + } + derivedKey.sigBytes = keySize * 4; + + return derivedKey; + } + }); + + /** + * Derives a key from a password. + * + * @param {WordArray|string} password The password. + * @param {WordArray|string} salt A salt. + * @param {Object} cfg (Optional) The configuration options to use for this computation. + * + * @return {WordArray} The derived key. + * + * @static + * + * @example + * + * var key = CryptoJS.EvpKDF(password, salt); + * var key = CryptoJS.EvpKDF(password, salt, { keySize: 8 }); + * var key = CryptoJS.EvpKDF(password, salt, { keySize: 8, iterations: 1000 }); + */ + C.EvpKDF = function (password, salt, cfg) { + return EvpKDF.create(cfg).compute(password, salt); + }; + }()); + + + /** + * Cipher core components. + */ + CryptoJS.lib.Cipher || (function (undefined) { + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var Base = C_lib.Base; + var WordArray = C_lib.WordArray; + var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm; + var C_enc = C.enc; + var Utf8 = C_enc.Utf8; + var Base64 = C_enc.Base64; + var C_algo = C.algo; + var EvpKDF = C_algo.EvpKDF; + + /** + * Abstract base cipher template. + * + * @property {number} keySize This cipher's key size. Default: 4 (128 bits) + * @property {number} ivSize This cipher's IV size. Default: 4 (128 bits) + * @property {number} _ENC_XFORM_MODE A constant representing encryption mode. + * @property {number} _DEC_XFORM_MODE A constant representing decryption mode. + */ + var Cipher = C_lib.Cipher = BufferedBlockAlgorithm.extend({ + /** + * Configuration options. + * + * @property {WordArray} iv The IV to use for this operation. + */ + cfg: Base.extend(), + + /** + * Creates this cipher in encryption mode. + * + * @param {WordArray} key The key. + * @param {Object} cfg (Optional) The configuration options to use for this operation. + * + * @return {Cipher} A cipher instance. + * + * @static + * + * @example + * + * var cipher = CryptoJS.algo.AES.createEncryptor(keyWordArray, { iv: ivWordArray }); + */ + createEncryptor: function (key, cfg) { + return this.create(this._ENC_XFORM_MODE, key, cfg); + }, + + /** + * Creates this cipher in decryption mode. + * + * @param {WordArray} key The key. + * @param {Object} cfg (Optional) The configuration options to use for this operation. + * + * @return {Cipher} A cipher instance. + * + * @static + * + * @example + * + * var cipher = CryptoJS.algo.AES.createDecryptor(keyWordArray, { iv: ivWordArray }); + */ + createDecryptor: function (key, cfg) { + return this.create(this._DEC_XFORM_MODE, key, cfg); + }, + + /** + * Initializes a newly created cipher. + * + * @param {number} xformMode Either the encryption or decryption transormation mode constant. + * @param {WordArray} key The key. + * @param {Object} cfg (Optional) The configuration options to use for this operation. + * + * @example + * + * var cipher = CryptoJS.algo.AES.create(CryptoJS.algo.AES._ENC_XFORM_MODE, keyWordArray, { iv: ivWordArray }); + */ + init: function (xformMode, key, cfg) { + // Apply config defaults + this.cfg = this.cfg.extend(cfg); + + // Store transform mode and key + this._xformMode = xformMode; + this._key = key; + + // Set initial values + this.reset(); + }, + + /** + * Resets this cipher to its initial state. + * + * @example + * + * cipher.reset(); + */ + reset: function () { + // Reset data buffer + BufferedBlockAlgorithm.reset.call(this); + + // Perform concrete-cipher logic + this._doReset(); + }, + + /** + * Adds data to be encrypted or decrypted. + * + * @param {WordArray|string} dataUpdate The data to encrypt or decrypt. + * + * @return {WordArray} The data after processing. + * + * @example + * + * var encrypted = cipher.process('data'); + * var encrypted = cipher.process(wordArray); + */ + process: function (dataUpdate) { + // Append + this._append(dataUpdate); + + // Process available blocks + return this._process(); + }, + + /** + * Finalizes the encryption or decryption process. + * Note that the finalize operation is effectively a destructive, read-once operation. + * + * @param {WordArray|string} dataUpdate The final data to encrypt or decrypt. + * + * @return {WordArray} The data after final processing. + * + * @example + * + * var encrypted = cipher.finalize(); + * var encrypted = cipher.finalize('data'); + * var encrypted = cipher.finalize(wordArray); + */ + finalize: function (dataUpdate) { + // Final data update + if (dataUpdate) { + this._append(dataUpdate); + } + + // Perform concrete-cipher logic + var finalProcessedData = this._doFinalize(); + + return finalProcessedData; + }, + + keySize: 128/32, + + ivSize: 128/32, + + _ENC_XFORM_MODE: 1, + + _DEC_XFORM_MODE: 2, + + /** + * Creates shortcut functions to a cipher's object interface. + * + * @param {Cipher} cipher The cipher to create a helper for. + * + * @return {Object} An object with encrypt and decrypt shortcut functions. + * + * @static + * + * @example + * + * var AES = CryptoJS.lib.Cipher._createHelper(CryptoJS.algo.AES); + */ + _createHelper: (function () { + function selectCipherStrategy(key) { + if (typeof key == 'string') { + return PasswordBasedCipher; + } else { + return SerializableCipher; + } + } + + return function (cipher) { + return { + encrypt: function (message, key, cfg) { + return selectCipherStrategy(key).encrypt(cipher, message, key, cfg); + }, + + decrypt: function (ciphertext, key, cfg) { + return selectCipherStrategy(key).decrypt(cipher, ciphertext, key, cfg); + } + }; + }; + }()) + }); + + /** + * Abstract base stream cipher template. + * + * @property {number} blockSize The number of 32-bit words this cipher operates on. Default: 1 (32 bits) + */ + var StreamCipher = C_lib.StreamCipher = Cipher.extend({ + _doFinalize: function () { + // Process partial blocks + var finalProcessedBlocks = this._process(!!'flush'); + + return finalProcessedBlocks; + }, + + blockSize: 1 + }); + + /** + * Mode namespace. + */ + var C_mode = C.mode = {}; + + /** + * Abstract base block cipher mode template. + */ + var BlockCipherMode = C_lib.BlockCipherMode = Base.extend({ + /** + * Creates this mode for encryption. + * + * @param {Cipher} cipher A block cipher instance. + * @param {Array} iv The IV words. + * + * @static + * + * @example + * + * var mode = CryptoJS.mode.CBC.createEncryptor(cipher, iv.words); + */ + createEncryptor: function (cipher, iv) { + return this.Encryptor.create(cipher, iv); + }, + + /** + * Creates this mode for decryption. + * + * @param {Cipher} cipher A block cipher instance. + * @param {Array} iv The IV words. + * + * @static + * + * @example + * + * var mode = CryptoJS.mode.CBC.createDecryptor(cipher, iv.words); + */ + createDecryptor: function (cipher, iv) { + return this.Decryptor.create(cipher, iv); + }, + + /** + * Initializes a newly created mode. + * + * @param {Cipher} cipher A block cipher instance. + * @param {Array} iv The IV words. + * + * @example + * + * var mode = CryptoJS.mode.CBC.Encryptor.create(cipher, iv.words); + */ + init: function (cipher, iv) { + this._cipher = cipher; + this._iv = iv; + } + }); + + /** + * Cipher Block Chaining mode. + */ + var CBC = C_mode.CBC = (function () { + /** + * Abstract base CBC mode. + */ + var CBC = BlockCipherMode.extend(); + + /** + * CBC encryptor. + */ + CBC.Encryptor = CBC.extend({ + /** + * Processes the data block at offset. + * + * @param {Array} words The data words to operate on. + * @param {number} offset The offset where the block starts. + * + * @example + * + * mode.processBlock(data.words, offset); + */ + processBlock: function (words, offset) { + // Shortcuts + var cipher = this._cipher; + var blockSize = cipher.blockSize; + + // XOR and encrypt + xorBlock.call(this, words, offset, blockSize); + cipher.encryptBlock(words, offset); + + // Remember this block to use with next block + this._prevBlock = words.slice(offset, offset + blockSize); + } + }); + + /** + * CBC decryptor. + */ + CBC.Decryptor = CBC.extend({ + /** + * Processes the data block at offset. + * + * @param {Array} words The data words to operate on. + * @param {number} offset The offset where the block starts. + * + * @example + * + * mode.processBlock(data.words, offset); + */ + processBlock: function (words, offset) { + // Shortcuts + var cipher = this._cipher; + var blockSize = cipher.blockSize; + + // Remember this block to use with next block + var thisBlock = words.slice(offset, offset + blockSize); + + // Decrypt and XOR + cipher.decryptBlock(words, offset); + xorBlock.call(this, words, offset, blockSize); + + // This block becomes the previous block + this._prevBlock = thisBlock; + } + }); + + function xorBlock(words, offset, blockSize) { + var block; + + // Shortcut + var iv = this._iv; + + // Choose mixing block + if (iv) { + block = iv; + + // Remove IV for subsequent blocks + this._iv = undefined; + } else { + block = this._prevBlock; + } + + // XOR blocks + for (var i = 0; i < blockSize; i++) { + words[offset + i] ^= block[i]; + } + } + + return CBC; + }()); + + /** + * Padding namespace. + */ + var C_pad = C.pad = {}; + + /** + * PKCS #5/7 padding strategy. + */ + var Pkcs7 = C_pad.Pkcs7 = { + /** + * Pads data using the algorithm defined in PKCS #5/7. + * + * @param {WordArray} data The data to pad. + * @param {number} blockSize The multiple that the data should be padded to. + * + * @static + * + * @example + * + * CryptoJS.pad.Pkcs7.pad(wordArray, 4); + */ + pad: function (data, blockSize) { + // Shortcut + var blockSizeBytes = blockSize * 4; + + // Count padding bytes + var nPaddingBytes = blockSizeBytes - data.sigBytes % blockSizeBytes; + + // Create padding word + var paddingWord = (nPaddingBytes << 24) | (nPaddingBytes << 16) | (nPaddingBytes << 8) | nPaddingBytes; + + // Create padding + var paddingWords = []; + for (var i = 0; i < nPaddingBytes; i += 4) { + paddingWords.push(paddingWord); + } + var padding = WordArray.create(paddingWords, nPaddingBytes); + + // Add padding + data.concat(padding); + }, + + /** + * Unpads data that had been padded using the algorithm defined in PKCS #5/7. + * + * @param {WordArray} data The data to unpad. + * + * @static + * + * @example + * + * CryptoJS.pad.Pkcs7.unpad(wordArray); + */ + unpad: function (data) { + // Get number of padding bytes from last byte + var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff; + + // Remove padding + data.sigBytes -= nPaddingBytes; + } + }; + + /** + * Abstract base block cipher template. + * + * @property {number} blockSize The number of 32-bit words this cipher operates on. Default: 4 (128 bits) + */ + var BlockCipher = C_lib.BlockCipher = Cipher.extend({ + /** + * Configuration options. + * + * @property {Mode} mode The block mode to use. Default: CBC + * @property {Padding} padding The padding strategy to use. Default: Pkcs7 + */ + cfg: Cipher.cfg.extend({ + mode: CBC, + padding: Pkcs7 + }), + + reset: function () { + var modeCreator; + + // Reset cipher + Cipher.reset.call(this); + + // Shortcuts + var cfg = this.cfg; + var iv = cfg.iv; + var mode = cfg.mode; + + // Reset block mode + if (this._xformMode == this._ENC_XFORM_MODE) { + modeCreator = mode.createEncryptor; + } else /* if (this._xformMode == this._DEC_XFORM_MODE) */ { + modeCreator = mode.createDecryptor; + // Keep at least one block in the buffer for unpadding + this._minBufferSize = 1; + } + + if (this._mode && this._mode.__creator == modeCreator) { + this._mode.init(this, iv && iv.words); + } else { + this._mode = modeCreator.call(mode, this, iv && iv.words); + this._mode.__creator = modeCreator; + } + }, + + _doProcessBlock: function (words, offset) { + this._mode.processBlock(words, offset); + }, + + _doFinalize: function () { + var finalProcessedBlocks; + + // Shortcut + var padding = this.cfg.padding; + + // Finalize + if (this._xformMode == this._ENC_XFORM_MODE) { + // Pad data + padding.pad(this._data, this.blockSize); + + // Process final blocks + finalProcessedBlocks = this._process(!!'flush'); + } else /* if (this._xformMode == this._DEC_XFORM_MODE) */ { + // Process final blocks + finalProcessedBlocks = this._process(!!'flush'); + + // Unpad data + padding.unpad(finalProcessedBlocks); + } + + return finalProcessedBlocks; + }, + + blockSize: 128/32 + }); + + /** + * A collection of cipher parameters. + * + * @property {WordArray} ciphertext The raw ciphertext. + * @property {WordArray} key The key to this ciphertext. + * @property {WordArray} iv The IV used in the ciphering operation. + * @property {WordArray} salt The salt used with a key derivation function. + * @property {Cipher} algorithm The cipher algorithm. + * @property {Mode} mode The block mode used in the ciphering operation. + * @property {Padding} padding The padding scheme used in the ciphering operation. + * @property {number} blockSize The block size of the cipher. + * @property {Format} formatter The default formatting strategy to convert this cipher params object to a string. + */ + var CipherParams = C_lib.CipherParams = Base.extend({ + /** + * Initializes a newly created cipher params object. + * + * @param {Object} cipherParams An object with any of the possible cipher parameters. + * + * @example + * + * var cipherParams = CryptoJS.lib.CipherParams.create({ + * ciphertext: ciphertextWordArray, + * key: keyWordArray, + * iv: ivWordArray, + * salt: saltWordArray, + * algorithm: CryptoJS.algo.AES, + * mode: CryptoJS.mode.CBC, + * padding: CryptoJS.pad.PKCS7, + * blockSize: 4, + * formatter: CryptoJS.format.OpenSSL + * }); + */ + init: function (cipherParams) { + this.mixIn(cipherParams); + }, + + /** + * Converts this cipher params object to a string. + * + * @param {Format} formatter (Optional) The formatting strategy to use. + * + * @return {string} The stringified cipher params. + * + * @throws Error If neither the formatter nor the default formatter is set. + * + * @example + * + * var string = cipherParams + ''; + * var string = cipherParams.toString(); + * var string = cipherParams.toString(CryptoJS.format.OpenSSL); + */ + toString: function (formatter) { + return (formatter || this.formatter).stringify(this); + } + }); + + /** + * Format namespace. + */ + var C_format = C.format = {}; + + /** + * OpenSSL formatting strategy. + */ + var OpenSSLFormatter = C_format.OpenSSL = { + /** + * Converts a cipher params object to an OpenSSL-compatible string. + * + * @param {CipherParams} cipherParams The cipher params object. + * + * @return {string} The OpenSSL-compatible string. + * + * @static + * + * @example + * + * var openSSLString = CryptoJS.format.OpenSSL.stringify(cipherParams); + */ + stringify: function (cipherParams) { + var wordArray; + + // Shortcuts + var ciphertext = cipherParams.ciphertext; + var salt = cipherParams.salt; + + // Format + if (salt) { + wordArray = WordArray.create([0x53616c74, 0x65645f5f]).concat(salt).concat(ciphertext); + } else { + wordArray = ciphertext; + } + + return wordArray.toString(Base64); + }, + + /** + * Converts an OpenSSL-compatible string to a cipher params object. + * + * @param {string} openSSLStr The OpenSSL-compatible string. + * + * @return {CipherParams} The cipher params object. + * + * @static + * + * @example + * + * var cipherParams = CryptoJS.format.OpenSSL.parse(openSSLString); + */ + parse: function (openSSLStr) { + var salt; + + // Parse base64 + var ciphertext = Base64.parse(openSSLStr); + + // Shortcut + var ciphertextWords = ciphertext.words; + + // Test for salt + if (ciphertextWords[0] == 0x53616c74 && ciphertextWords[1] == 0x65645f5f) { + // Extract salt + salt = WordArray.create(ciphertextWords.slice(2, 4)); + + // Remove salt from ciphertext + ciphertextWords.splice(0, 4); + ciphertext.sigBytes -= 16; + } + + return CipherParams.create({ ciphertext: ciphertext, salt: salt }); + } + }; + + /** + * A cipher wrapper that returns ciphertext as a serializable cipher params object. + */ + var SerializableCipher = C_lib.SerializableCipher = Base.extend({ + /** + * Configuration options. + * + * @property {Formatter} format The formatting strategy to convert cipher param objects to and from a string. Default: OpenSSL + */ + cfg: Base.extend({ + format: OpenSSLFormatter + }), + + /** + * Encrypts a message. + * + * @param {Cipher} cipher The cipher algorithm to use. + * @param {WordArray|string} message The message to encrypt. + * @param {WordArray} key The key. + * @param {Object} cfg (Optional) The configuration options to use for this operation. + * + * @return {CipherParams} A cipher params object. + * + * @static + * + * @example + * + * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key); + * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv }); + * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv, format: CryptoJS.format.OpenSSL }); + */ + encrypt: function (cipher, message, key, cfg) { + // Apply config defaults + cfg = this.cfg.extend(cfg); + + // Encrypt + var encryptor = cipher.createEncryptor(key, cfg); + var ciphertext = encryptor.finalize(message); + + // Shortcut + var cipherCfg = encryptor.cfg; + + // Create and return serializable cipher params + return CipherParams.create({ + ciphertext: ciphertext, + key: key, + iv: cipherCfg.iv, + algorithm: cipher, + mode: cipherCfg.mode, + padding: cipherCfg.padding, + blockSize: cipher.blockSize, + formatter: cfg.format + }); + }, + + /** + * Decrypts serialized ciphertext. + * + * @param {Cipher} cipher The cipher algorithm to use. + * @param {CipherParams|string} ciphertext The ciphertext to decrypt. + * @param {WordArray} key The key. + * @param {Object} cfg (Optional) The configuration options to use for this operation. + * + * @return {WordArray} The plaintext. + * + * @static + * + * @example + * + * var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, key, { iv: iv, format: CryptoJS.format.OpenSSL }); + * var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, key, { iv: iv, format: CryptoJS.format.OpenSSL }); + */ + decrypt: function (cipher, ciphertext, key, cfg) { + // Apply config defaults + cfg = this.cfg.extend(cfg); + + // Convert string to CipherParams + ciphertext = this._parse(ciphertext, cfg.format); + + // Decrypt + var plaintext = cipher.createDecryptor(key, cfg).finalize(ciphertext.ciphertext); + + return plaintext; + }, + + /** + * Converts serialized ciphertext to CipherParams, + * else assumed CipherParams already and returns ciphertext unchanged. + * + * @param {CipherParams|string} ciphertext The ciphertext. + * @param {Formatter} format The formatting strategy to use to parse serialized ciphertext. + * + * @return {CipherParams} The unserialized ciphertext. + * + * @static + * + * @example + * + * var ciphertextParams = CryptoJS.lib.SerializableCipher._parse(ciphertextStringOrParams, format); + */ + _parse: function (ciphertext, format) { + if (typeof ciphertext == 'string') { + return format.parse(ciphertext, this); + } else { + return ciphertext; + } + } + }); + + /** + * Key derivation function namespace. + */ + var C_kdf = C.kdf = {}; + + /** + * OpenSSL key derivation function. + */ + var OpenSSLKdf = C_kdf.OpenSSL = { + /** + * Derives a key and IV from a password. + * + * @param {string} password The password to derive from. + * @param {number} keySize The size in words of the key to generate. + * @param {number} ivSize The size in words of the IV to generate. + * @param {WordArray|string} salt (Optional) A 64-bit salt to use. If omitted, a salt will be generated randomly. + * + * @return {CipherParams} A cipher params object with the key, IV, and salt. + * + * @static + * + * @example + * + * var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32); + * var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32, 'saltsalt'); + */ + execute: function (password, keySize, ivSize, salt) { + // Generate random salt + if (!salt) { + salt = WordArray.random(64/8); + } + + // Derive key and IV + var key = EvpKDF.create({ keySize: keySize + ivSize }).compute(password, salt); + + // Separate key and IV + var iv = WordArray.create(key.words.slice(keySize), ivSize * 4); + key.sigBytes = keySize * 4; + + // Return params + return CipherParams.create({ key: key, iv: iv, salt: salt }); + } + }; + + /** + * A serializable cipher wrapper that derives the key from a password, + * and returns ciphertext as a serializable cipher params object. + */ + var PasswordBasedCipher = C_lib.PasswordBasedCipher = SerializableCipher.extend({ + /** + * Configuration options. + * + * @property {KDF} kdf The key derivation function to use to generate a key and IV from a password. Default: OpenSSL + */ + cfg: SerializableCipher.cfg.extend({ + kdf: OpenSSLKdf + }), + + /** + * Encrypts a message using a password. + * + * @param {Cipher} cipher The cipher algorithm to use. + * @param {WordArray|string} message The message to encrypt. + * @param {string} password The password. + * @param {Object} cfg (Optional) The configuration options to use for this operation. + * + * @return {CipherParams} A cipher params object. + * + * @static + * + * @example + * + * var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password'); + * var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password', { format: CryptoJS.format.OpenSSL }); + */ + encrypt: function (cipher, message, password, cfg) { + // Apply config defaults + cfg = this.cfg.extend(cfg); + + // Derive key and other params + var derivedParams = cfg.kdf.execute(password, cipher.keySize, cipher.ivSize); + + // Add IV to config + cfg.iv = derivedParams.iv; + + // Encrypt + var ciphertext = SerializableCipher.encrypt.call(this, cipher, message, derivedParams.key, cfg); + + // Mix in derived params + ciphertext.mixIn(derivedParams); + + return ciphertext; + }, + + /** + * Decrypts serialized ciphertext using a password. + * + * @param {Cipher} cipher The cipher algorithm to use. + * @param {CipherParams|string} ciphertext The ciphertext to decrypt. + * @param {string} password The password. + * @param {Object} cfg (Optional) The configuration options to use for this operation. + * + * @return {WordArray} The plaintext. + * + * @static + * + * @example + * + * var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, 'password', { format: CryptoJS.format.OpenSSL }); + * var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, 'password', { format: CryptoJS.format.OpenSSL }); + */ + decrypt: function (cipher, ciphertext, password, cfg) { + // Apply config defaults + cfg = this.cfg.extend(cfg); + + // Convert string to CipherParams + ciphertext = this._parse(ciphertext, cfg.format); + + // Derive key and other params + var derivedParams = cfg.kdf.execute(password, cipher.keySize, cipher.ivSize, ciphertext.salt); + + // Add IV to config + cfg.iv = derivedParams.iv; + + // Decrypt + var plaintext = SerializableCipher.decrypt.call(this, cipher, ciphertext, derivedParams.key, cfg); + + return plaintext; + } + }); + }()); + + + /** + * Cipher Feedback block mode. + */ + CryptoJS.mode.CFB = (function () { + var CFB = CryptoJS.lib.BlockCipherMode.extend(); + + CFB.Encryptor = CFB.extend({ + processBlock: function (words, offset) { + // Shortcuts + var cipher = this._cipher; + var blockSize = cipher.blockSize; + + generateKeystreamAndEncrypt.call(this, words, offset, blockSize, cipher); + + // Remember this block to use with next block + this._prevBlock = words.slice(offset, offset + blockSize); + } + }); + + CFB.Decryptor = CFB.extend({ + processBlock: function (words, offset) { + // Shortcuts + var cipher = this._cipher; + var blockSize = cipher.blockSize; + + // Remember this block to use with next block + var thisBlock = words.slice(offset, offset + blockSize); + + generateKeystreamAndEncrypt.call(this, words, offset, blockSize, cipher); + + // This block becomes the previous block + this._prevBlock = thisBlock; + } + }); + + function generateKeystreamAndEncrypt(words, offset, blockSize, cipher) { + var keystream; + + // Shortcut + var iv = this._iv; + + // Generate keystream + if (iv) { + keystream = iv.slice(0); + + // Remove IV for subsequent blocks + this._iv = undefined; + } else { + keystream = this._prevBlock; + } + cipher.encryptBlock(keystream, 0); + + // Encrypt + for (var i = 0; i < blockSize; i++) { + words[offset + i] ^= keystream[i]; + } + } + + return CFB; + }()); + + + /** + * Counter block mode. + */ + CryptoJS.mode.CTR = (function () { + var CTR = CryptoJS.lib.BlockCipherMode.extend(); + + var Encryptor = CTR.Encryptor = CTR.extend({ + processBlock: function (words, offset) { + // Shortcuts + var cipher = this._cipher + var blockSize = cipher.blockSize; + var iv = this._iv; + var counter = this._counter; + + // Generate keystream + if (iv) { + counter = this._counter = iv.slice(0); + + // Remove IV for subsequent blocks + this._iv = undefined; + } + var keystream = counter.slice(0); + cipher.encryptBlock(keystream, 0); + + // Increment counter + counter[blockSize - 1] = (counter[blockSize - 1] + 1) | 0 + + // Encrypt + for (var i = 0; i < blockSize; i++) { + words[offset + i] ^= keystream[i]; + } + } + }); + + CTR.Decryptor = Encryptor; + + return CTR; + }()); + + + /** @preserve + * Counter block mode compatible with Dr Brian Gladman fileenc.c + * derived from CryptoJS.mode.CTR + * Jan Hruby jhruby.web@gmail.com + */ + CryptoJS.mode.CTRGladman = (function () { + var CTRGladman = CryptoJS.lib.BlockCipherMode.extend(); + + function incWord(word) + { + if (((word >> 24) & 0xff) === 0xff) { //overflow + var b1 = (word >> 16)&0xff; + var b2 = (word >> 8)&0xff; + var b3 = word & 0xff; + + if (b1 === 0xff) // overflow b1 + { + b1 = 0; + if (b2 === 0xff) + { + b2 = 0; + if (b3 === 0xff) + { + b3 = 0; + } + else + { + ++b3; + } + } + else + { + ++b2; + } + } + else + { + ++b1; + } + + word = 0; + word += (b1 << 16); + word += (b2 << 8); + word += b3; + } + else + { + word += (0x01 << 24); + } + return word; + } + + function incCounter(counter) + { + if ((counter[0] = incWord(counter[0])) === 0) + { + // encr_data in fileenc.c from Dr Brian Gladman's counts only with DWORD j < 8 + counter[1] = incWord(counter[1]); + } + return counter; + } + + var Encryptor = CTRGladman.Encryptor = CTRGladman.extend({ + processBlock: function (words, offset) { + // Shortcuts + var cipher = this._cipher + var blockSize = cipher.blockSize; + var iv = this._iv; + var counter = this._counter; + + // Generate keystream + if (iv) { + counter = this._counter = iv.slice(0); + + // Remove IV for subsequent blocks + this._iv = undefined; + } + + incCounter(counter); + + var keystream = counter.slice(0); + cipher.encryptBlock(keystream, 0); + + // Encrypt + for (var i = 0; i < blockSize; i++) { + words[offset + i] ^= keystream[i]; + } + } + }); + + CTRGladman.Decryptor = Encryptor; + + return CTRGladman; + }()); + + + + + /** + * Output Feedback block mode. + */ + CryptoJS.mode.OFB = (function () { + var OFB = CryptoJS.lib.BlockCipherMode.extend(); + + var Encryptor = OFB.Encryptor = OFB.extend({ + processBlock: function (words, offset) { + // Shortcuts + var cipher = this._cipher + var blockSize = cipher.blockSize; + var iv = this._iv; + var keystream = this._keystream; + + // Generate keystream + if (iv) { + keystream = this._keystream = iv.slice(0); + + // Remove IV for subsequent blocks + this._iv = undefined; + } + cipher.encryptBlock(keystream, 0); + + // Encrypt + for (var i = 0; i < blockSize; i++) { + words[offset + i] ^= keystream[i]; + } + } + }); + + OFB.Decryptor = Encryptor; + + return OFB; + }()); + + + /** + * Electronic Codebook block mode. + */ + CryptoJS.mode.ECB = (function () { + var ECB = CryptoJS.lib.BlockCipherMode.extend(); + + ECB.Encryptor = ECB.extend({ + processBlock: function (words, offset) { + this._cipher.encryptBlock(words, offset); + } + }); + + ECB.Decryptor = ECB.extend({ + processBlock: function (words, offset) { + this._cipher.decryptBlock(words, offset); + } + }); + + return ECB; + }()); + + + /** + * ANSI X.923 padding strategy. + */ + CryptoJS.pad.AnsiX923 = { + pad: function (data, blockSize) { + // Shortcuts + var dataSigBytes = data.sigBytes; + var blockSizeBytes = blockSize * 4; + + // Count padding bytes + var nPaddingBytes = blockSizeBytes - dataSigBytes % blockSizeBytes; + + // Compute last byte position + var lastBytePos = dataSigBytes + nPaddingBytes - 1; + + // Pad + data.clamp(); + data.words[lastBytePos >>> 2] |= nPaddingBytes << (24 - (lastBytePos % 4) * 8); + data.sigBytes += nPaddingBytes; + }, + + unpad: function (data) { + // Get number of padding bytes from last byte + var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff; + + // Remove padding + data.sigBytes -= nPaddingBytes; + } + }; + + + /** + * ISO 10126 padding strategy. + */ + CryptoJS.pad.Iso10126 = { + pad: function (data, blockSize) { + // Shortcut + var blockSizeBytes = blockSize * 4; + + // Count padding bytes + var nPaddingBytes = blockSizeBytes - data.sigBytes % blockSizeBytes; + + // Pad + data.concat(CryptoJS.lib.WordArray.random(nPaddingBytes - 1)). + concat(CryptoJS.lib.WordArray.create([nPaddingBytes << 24], 1)); + }, + + unpad: function (data) { + // Get number of padding bytes from last byte + var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff; + + // Remove padding + data.sigBytes -= nPaddingBytes; + } + }; + + + /** + * ISO/IEC 9797-1 Padding Method 2. + */ + CryptoJS.pad.Iso97971 = { + pad: function (data, blockSize) { + // Add 0x80 byte + data.concat(CryptoJS.lib.WordArray.create([0x80000000], 1)); + + // Zero pad the rest + CryptoJS.pad.ZeroPadding.pad(data, blockSize); + }, + + unpad: function (data) { + // Remove zero padding + CryptoJS.pad.ZeroPadding.unpad(data); + + // Remove one more byte -- the 0x80 byte + data.sigBytes--; + } + }; + + + /** + * Zero padding strategy. + */ + CryptoJS.pad.ZeroPadding = { + pad: function (data, blockSize) { + // Shortcut + var blockSizeBytes = blockSize * 4; + + // Pad + data.clamp(); + data.sigBytes += blockSizeBytes - ((data.sigBytes % blockSizeBytes) || blockSizeBytes); + }, + + unpad: function (data) { + // Shortcut + var dataWords = data.words; + + // Unpad + var i = data.sigBytes - 1; + for (var i = data.sigBytes - 1; i >= 0; i--) { + if (((dataWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff)) { + data.sigBytes = i + 1; + break; + } + } + } + }; + + + /** + * A noop padding strategy. + */ + CryptoJS.pad.NoPadding = { + pad: function () { + }, + + unpad: function () { + } + }; + + + (function (undefined) { + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var CipherParams = C_lib.CipherParams; + var C_enc = C.enc; + var Hex = C_enc.Hex; + var C_format = C.format; + + var HexFormatter = C_format.Hex = { + /** + * Converts the ciphertext of a cipher params object to a hexadecimally encoded string. + * + * @param {CipherParams} cipherParams The cipher params object. + * + * @return {string} The hexadecimally encoded string. + * + * @static + * + * @example + * + * var hexString = CryptoJS.format.Hex.stringify(cipherParams); + */ + stringify: function (cipherParams) { + return cipherParams.ciphertext.toString(Hex); + }, + + /** + * Converts a hexadecimally encoded ciphertext string to a cipher params object. + * + * @param {string} input The hexadecimally encoded string. + * + * @return {CipherParams} The cipher params object. + * + * @static + * + * @example + * + * var cipherParams = CryptoJS.format.Hex.parse(hexString); + */ + parse: function (input) { + var ciphertext = Hex.parse(input); + return CipherParams.create({ ciphertext: ciphertext }); + } + }; + }()); + + + (function () { + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var BlockCipher = C_lib.BlockCipher; + var C_algo = C.algo; + + // Lookup tables + var SBOX = []; + var INV_SBOX = []; + var SUB_MIX_0 = []; + var SUB_MIX_1 = []; + var SUB_MIX_2 = []; + var SUB_MIX_3 = []; + var INV_SUB_MIX_0 = []; + var INV_SUB_MIX_1 = []; + var INV_SUB_MIX_2 = []; + var INV_SUB_MIX_3 = []; + + // Compute lookup tables + (function () { + // Compute double table + var d = []; + for (var i = 0; i < 256; i++) { + if (i < 128) { + d[i] = i << 1; + } else { + d[i] = (i << 1) ^ 0x11b; + } + } + + // Walk GF(2^8) + var x = 0; + var xi = 0; + for (var i = 0; i < 256; i++) { + // Compute sbox + var sx = xi ^ (xi << 1) ^ (xi << 2) ^ (xi << 3) ^ (xi << 4); + sx = (sx >>> 8) ^ (sx & 0xff) ^ 0x63; + SBOX[x] = sx; + INV_SBOX[sx] = x; + + // Compute multiplication + var x2 = d[x]; + var x4 = d[x2]; + var x8 = d[x4]; + + // Compute sub bytes, mix columns tables + var t = (d[sx] * 0x101) ^ (sx * 0x1010100); + SUB_MIX_0[x] = (t << 24) | (t >>> 8); + SUB_MIX_1[x] = (t << 16) | (t >>> 16); + SUB_MIX_2[x] = (t << 8) | (t >>> 24); + SUB_MIX_3[x] = t; + + // Compute inv sub bytes, inv mix columns tables + var t = (x8 * 0x1010101) ^ (x4 * 0x10001) ^ (x2 * 0x101) ^ (x * 0x1010100); + INV_SUB_MIX_0[sx] = (t << 24) | (t >>> 8); + INV_SUB_MIX_1[sx] = (t << 16) | (t >>> 16); + INV_SUB_MIX_2[sx] = (t << 8) | (t >>> 24); + INV_SUB_MIX_3[sx] = t; + + // Compute next counter + if (!x) { + x = xi = 1; + } else { + x = x2 ^ d[d[d[x8 ^ x2]]]; + xi ^= d[d[xi]]; + } + } + }()); + + // Precomputed Rcon lookup + var RCON = [0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36]; + + /** + * AES block cipher algorithm. + */ + var AES = C_algo.AES = BlockCipher.extend({ + _doReset: function () { + var t; + + // Skip reset of nRounds has been set before and key did not change + if (this._nRounds && this._keyPriorReset === this._key) { + return; + } + + // Shortcuts + var key = this._keyPriorReset = this._key; + var keyWords = key.words; + var keySize = key.sigBytes / 4; + + // Compute number of rounds + var nRounds = this._nRounds = keySize + 6; + + // Compute number of key schedule rows + var ksRows = (nRounds + 1) * 4; + + // Compute key schedule + var keySchedule = this._keySchedule = []; + for (var ksRow = 0; ksRow < ksRows; ksRow++) { + if (ksRow < keySize) { + keySchedule[ksRow] = keyWords[ksRow]; + } else { + t = keySchedule[ksRow - 1]; + + if (!(ksRow % keySize)) { + // Rot word + t = (t << 8) | (t >>> 24); + + // Sub word + t = (SBOX[t >>> 24] << 24) | (SBOX[(t >>> 16) & 0xff] << 16) | (SBOX[(t >>> 8) & 0xff] << 8) | SBOX[t & 0xff]; + + // Mix Rcon + t ^= RCON[(ksRow / keySize) | 0] << 24; + } else if (keySize > 6 && ksRow % keySize == 4) { + // Sub word + t = (SBOX[t >>> 24] << 24) | (SBOX[(t >>> 16) & 0xff] << 16) | (SBOX[(t >>> 8) & 0xff] << 8) | SBOX[t & 0xff]; + } + + keySchedule[ksRow] = keySchedule[ksRow - keySize] ^ t; + } + } + + // Compute inv key schedule + var invKeySchedule = this._invKeySchedule = []; + for (var invKsRow = 0; invKsRow < ksRows; invKsRow++) { + var ksRow = ksRows - invKsRow; + + if (invKsRow % 4) { + var t = keySchedule[ksRow]; + } else { + var t = keySchedule[ksRow - 4]; + } + + if (invKsRow < 4 || ksRow <= 4) { + invKeySchedule[invKsRow] = t; + } else { + invKeySchedule[invKsRow] = INV_SUB_MIX_0[SBOX[t >>> 24]] ^ INV_SUB_MIX_1[SBOX[(t >>> 16) & 0xff]] ^ + INV_SUB_MIX_2[SBOX[(t >>> 8) & 0xff]] ^ INV_SUB_MIX_3[SBOX[t & 0xff]]; + } + } + }, + + encryptBlock: function (M, offset) { + this._doCryptBlock(M, offset, this._keySchedule, SUB_MIX_0, SUB_MIX_1, SUB_MIX_2, SUB_MIX_3, SBOX); + }, + + decryptBlock: function (M, offset) { + // Swap 2nd and 4th rows + var t = M[offset + 1]; + M[offset + 1] = M[offset + 3]; + M[offset + 3] = t; + + this._doCryptBlock(M, offset, this._invKeySchedule, INV_SUB_MIX_0, INV_SUB_MIX_1, INV_SUB_MIX_2, INV_SUB_MIX_3, INV_SBOX); + + // Inv swap 2nd and 4th rows + var t = M[offset + 1]; + M[offset + 1] = M[offset + 3]; + M[offset + 3] = t; + }, + + _doCryptBlock: function (M, offset, keySchedule, SUB_MIX_0, SUB_MIX_1, SUB_MIX_2, SUB_MIX_3, SBOX) { + // Shortcut + var nRounds = this._nRounds; + + // Get input, add round key + var s0 = M[offset] ^ keySchedule[0]; + var s1 = M[offset + 1] ^ keySchedule[1]; + var s2 = M[offset + 2] ^ keySchedule[2]; + var s3 = M[offset + 3] ^ keySchedule[3]; + + // Key schedule row counter + var ksRow = 4; + + // Rounds + for (var round = 1; round < nRounds; round++) { + // Shift rows, sub bytes, mix columns, add round key + var t0 = SUB_MIX_0[s0 >>> 24] ^ SUB_MIX_1[(s1 >>> 16) & 0xff] ^ SUB_MIX_2[(s2 >>> 8) & 0xff] ^ SUB_MIX_3[s3 & 0xff] ^ keySchedule[ksRow++]; + var t1 = SUB_MIX_0[s1 >>> 24] ^ SUB_MIX_1[(s2 >>> 16) & 0xff] ^ SUB_MIX_2[(s3 >>> 8) & 0xff] ^ SUB_MIX_3[s0 & 0xff] ^ keySchedule[ksRow++]; + var t2 = SUB_MIX_0[s2 >>> 24] ^ SUB_MIX_1[(s3 >>> 16) & 0xff] ^ SUB_MIX_2[(s0 >>> 8) & 0xff] ^ SUB_MIX_3[s1 & 0xff] ^ keySchedule[ksRow++]; + var t3 = SUB_MIX_0[s3 >>> 24] ^ SUB_MIX_1[(s0 >>> 16) & 0xff] ^ SUB_MIX_2[(s1 >>> 8) & 0xff] ^ SUB_MIX_3[s2 & 0xff] ^ keySchedule[ksRow++]; + + // Update state + s0 = t0; + s1 = t1; + s2 = t2; + s3 = t3; + } + + // Shift rows, sub bytes, add round key + var t0 = ((SBOX[s0 >>> 24] << 24) | (SBOX[(s1 >>> 16) & 0xff] << 16) | (SBOX[(s2 >>> 8) & 0xff] << 8) | SBOX[s3 & 0xff]) ^ keySchedule[ksRow++]; + var t1 = ((SBOX[s1 >>> 24] << 24) | (SBOX[(s2 >>> 16) & 0xff] << 16) | (SBOX[(s3 >>> 8) & 0xff] << 8) | SBOX[s0 & 0xff]) ^ keySchedule[ksRow++]; + var t2 = ((SBOX[s2 >>> 24] << 24) | (SBOX[(s3 >>> 16) & 0xff] << 16) | (SBOX[(s0 >>> 8) & 0xff] << 8) | SBOX[s1 & 0xff]) ^ keySchedule[ksRow++]; + var t3 = ((SBOX[s3 >>> 24] << 24) | (SBOX[(s0 >>> 16) & 0xff] << 16) | (SBOX[(s1 >>> 8) & 0xff] << 8) | SBOX[s2 & 0xff]) ^ keySchedule[ksRow++]; + + // Set output + M[offset] = t0; + M[offset + 1] = t1; + M[offset + 2] = t2; + M[offset + 3] = t3; + }, + + keySize: 256/32 + }); + + /** + * Shortcut functions to the cipher's object interface. + * + * @example + * + * var ciphertext = CryptoJS.AES.encrypt(message, key, cfg); + * var plaintext = CryptoJS.AES.decrypt(ciphertext, key, cfg); + */ + C.AES = BlockCipher._createHelper(AES); + }()); + + + (function () { + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var WordArray = C_lib.WordArray; + var BlockCipher = C_lib.BlockCipher; + var C_algo = C.algo; + + // Permuted Choice 1 constants + var PC1 = [ + 57, 49, 41, 33, 25, 17, 9, 1, + 58, 50, 42, 34, 26, 18, 10, 2, + 59, 51, 43, 35, 27, 19, 11, 3, + 60, 52, 44, 36, 63, 55, 47, 39, + 31, 23, 15, 7, 62, 54, 46, 38, + 30, 22, 14, 6, 61, 53, 45, 37, + 29, 21, 13, 5, 28, 20, 12, 4 + ]; + + // Permuted Choice 2 constants + var PC2 = [ + 14, 17, 11, 24, 1, 5, + 3, 28, 15, 6, 21, 10, + 23, 19, 12, 4, 26, 8, + 16, 7, 27, 20, 13, 2, + 41, 52, 31, 37, 47, 55, + 30, 40, 51, 45, 33, 48, + 44, 49, 39, 56, 34, 53, + 46, 42, 50, 36, 29, 32 + ]; + + // Cumulative bit shift constants + var BIT_SHIFTS = [1, 2, 4, 6, 8, 10, 12, 14, 15, 17, 19, 21, 23, 25, 27, 28]; + + // SBOXes and round permutation constants + var SBOX_P = [ + { + 0x0: 0x808200, + 0x10000000: 0x8000, + 0x20000000: 0x808002, + 0x30000000: 0x2, + 0x40000000: 0x200, + 0x50000000: 0x808202, + 0x60000000: 0x800202, + 0x70000000: 0x800000, + 0x80000000: 0x202, + 0x90000000: 0x800200, + 0xa0000000: 0x8200, + 0xb0000000: 0x808000, + 0xc0000000: 0x8002, + 0xd0000000: 0x800002, + 0xe0000000: 0x0, + 0xf0000000: 0x8202, + 0x8000000: 0x0, + 0x18000000: 0x808202, + 0x28000000: 0x8202, + 0x38000000: 0x8000, + 0x48000000: 0x808200, + 0x58000000: 0x200, + 0x68000000: 0x808002, + 0x78000000: 0x2, + 0x88000000: 0x800200, + 0x98000000: 0x8200, + 0xa8000000: 0x808000, + 0xb8000000: 0x800202, + 0xc8000000: 0x800002, + 0xd8000000: 0x8002, + 0xe8000000: 0x202, + 0xf8000000: 0x800000, + 0x1: 0x8000, + 0x10000001: 0x2, + 0x20000001: 0x808200, + 0x30000001: 0x800000, + 0x40000001: 0x808002, + 0x50000001: 0x8200, + 0x60000001: 0x200, + 0x70000001: 0x800202, + 0x80000001: 0x808202, + 0x90000001: 0x808000, + 0xa0000001: 0x800002, + 0xb0000001: 0x8202, + 0xc0000001: 0x202, + 0xd0000001: 0x800200, + 0xe0000001: 0x8002, + 0xf0000001: 0x0, + 0x8000001: 0x808202, + 0x18000001: 0x808000, + 0x28000001: 0x800000, + 0x38000001: 0x200, + 0x48000001: 0x8000, + 0x58000001: 0x800002, + 0x68000001: 0x2, + 0x78000001: 0x8202, + 0x88000001: 0x8002, + 0x98000001: 0x800202, + 0xa8000001: 0x202, + 0xb8000001: 0x808200, + 0xc8000001: 0x800200, + 0xd8000001: 0x0, + 0xe8000001: 0x8200, + 0xf8000001: 0x808002 + }, + { + 0x0: 0x40084010, + 0x1000000: 0x4000, + 0x2000000: 0x80000, + 0x3000000: 0x40080010, + 0x4000000: 0x40000010, + 0x5000000: 0x40084000, + 0x6000000: 0x40004000, + 0x7000000: 0x10, + 0x8000000: 0x84000, + 0x9000000: 0x40004010, + 0xa000000: 0x40000000, + 0xb000000: 0x84010, + 0xc000000: 0x80010, + 0xd000000: 0x0, + 0xe000000: 0x4010, + 0xf000000: 0x40080000, + 0x800000: 0x40004000, + 0x1800000: 0x84010, + 0x2800000: 0x10, + 0x3800000: 0x40004010, + 0x4800000: 0x40084010, + 0x5800000: 0x40000000, + 0x6800000: 0x80000, + 0x7800000: 0x40080010, + 0x8800000: 0x80010, + 0x9800000: 0x0, + 0xa800000: 0x4000, + 0xb800000: 0x40080000, + 0xc800000: 0x40000010, + 0xd800000: 0x84000, + 0xe800000: 0x40084000, + 0xf800000: 0x4010, + 0x10000000: 0x0, + 0x11000000: 0x40080010, + 0x12000000: 0x40004010, + 0x13000000: 0x40084000, + 0x14000000: 0x40080000, + 0x15000000: 0x10, + 0x16000000: 0x84010, + 0x17000000: 0x4000, + 0x18000000: 0x4010, + 0x19000000: 0x80000, + 0x1a000000: 0x80010, + 0x1b000000: 0x40000010, + 0x1c000000: 0x84000, + 0x1d000000: 0x40004000, + 0x1e000000: 0x40000000, + 0x1f000000: 0x40084010, + 0x10800000: 0x84010, + 0x11800000: 0x80000, + 0x12800000: 0x40080000, + 0x13800000: 0x4000, + 0x14800000: 0x40004000, + 0x15800000: 0x40084010, + 0x16800000: 0x10, + 0x17800000: 0x40000000, + 0x18800000: 0x40084000, + 0x19800000: 0x40000010, + 0x1a800000: 0x40004010, + 0x1b800000: 0x80010, + 0x1c800000: 0x0, + 0x1d800000: 0x4010, + 0x1e800000: 0x40080010, + 0x1f800000: 0x84000 + }, + { + 0x0: 0x104, + 0x100000: 0x0, + 0x200000: 0x4000100, + 0x300000: 0x10104, + 0x400000: 0x10004, + 0x500000: 0x4000004, + 0x600000: 0x4010104, + 0x700000: 0x4010000, + 0x800000: 0x4000000, + 0x900000: 0x4010100, + 0xa00000: 0x10100, + 0xb00000: 0x4010004, + 0xc00000: 0x4000104, + 0xd00000: 0x10000, + 0xe00000: 0x4, + 0xf00000: 0x100, + 0x80000: 0x4010100, + 0x180000: 0x4010004, + 0x280000: 0x0, + 0x380000: 0x4000100, + 0x480000: 0x4000004, + 0x580000: 0x10000, + 0x680000: 0x10004, + 0x780000: 0x104, + 0x880000: 0x4, + 0x980000: 0x100, + 0xa80000: 0x4010000, + 0xb80000: 0x10104, + 0xc80000: 0x10100, + 0xd80000: 0x4000104, + 0xe80000: 0x4010104, + 0xf80000: 0x4000000, + 0x1000000: 0x4010100, + 0x1100000: 0x10004, + 0x1200000: 0x10000, + 0x1300000: 0x4000100, + 0x1400000: 0x100, + 0x1500000: 0x4010104, + 0x1600000: 0x4000004, + 0x1700000: 0x0, + 0x1800000: 0x4000104, + 0x1900000: 0x4000000, + 0x1a00000: 0x4, + 0x1b00000: 0x10100, + 0x1c00000: 0x4010000, + 0x1d00000: 0x104, + 0x1e00000: 0x10104, + 0x1f00000: 0x4010004, + 0x1080000: 0x4000000, + 0x1180000: 0x104, + 0x1280000: 0x4010100, + 0x1380000: 0x0, + 0x1480000: 0x10004, + 0x1580000: 0x4000100, + 0x1680000: 0x100, + 0x1780000: 0x4010004, + 0x1880000: 0x10000, + 0x1980000: 0x4010104, + 0x1a80000: 0x10104, + 0x1b80000: 0x4000004, + 0x1c80000: 0x4000104, + 0x1d80000: 0x4010000, + 0x1e80000: 0x4, + 0x1f80000: 0x10100 + }, + { + 0x0: 0x80401000, + 0x10000: 0x80001040, + 0x20000: 0x401040, + 0x30000: 0x80400000, + 0x40000: 0x0, + 0x50000: 0x401000, + 0x60000: 0x80000040, + 0x70000: 0x400040, + 0x80000: 0x80000000, + 0x90000: 0x400000, + 0xa0000: 0x40, + 0xb0000: 0x80001000, + 0xc0000: 0x80400040, + 0xd0000: 0x1040, + 0xe0000: 0x1000, + 0xf0000: 0x80401040, + 0x8000: 0x80001040, + 0x18000: 0x40, + 0x28000: 0x80400040, + 0x38000: 0x80001000, + 0x48000: 0x401000, + 0x58000: 0x80401040, + 0x68000: 0x0, + 0x78000: 0x80400000, + 0x88000: 0x1000, + 0x98000: 0x80401000, + 0xa8000: 0x400000, + 0xb8000: 0x1040, + 0xc8000: 0x80000000, + 0xd8000: 0x400040, + 0xe8000: 0x401040, + 0xf8000: 0x80000040, + 0x100000: 0x400040, + 0x110000: 0x401000, + 0x120000: 0x80000040, + 0x130000: 0x0, + 0x140000: 0x1040, + 0x150000: 0x80400040, + 0x160000: 0x80401000, + 0x170000: 0x80001040, + 0x180000: 0x80401040, + 0x190000: 0x80000000, + 0x1a0000: 0x80400000, + 0x1b0000: 0x401040, + 0x1c0000: 0x80001000, + 0x1d0000: 0x400000, + 0x1e0000: 0x40, + 0x1f0000: 0x1000, + 0x108000: 0x80400000, + 0x118000: 0x80401040, + 0x128000: 0x0, + 0x138000: 0x401000, + 0x148000: 0x400040, + 0x158000: 0x80000000, + 0x168000: 0x80001040, + 0x178000: 0x40, + 0x188000: 0x80000040, + 0x198000: 0x1000, + 0x1a8000: 0x80001000, + 0x1b8000: 0x80400040, + 0x1c8000: 0x1040, + 0x1d8000: 0x80401000, + 0x1e8000: 0x400000, + 0x1f8000: 0x401040 + }, + { + 0x0: 0x80, + 0x1000: 0x1040000, + 0x2000: 0x40000, + 0x3000: 0x20000000, + 0x4000: 0x20040080, + 0x5000: 0x1000080, + 0x6000: 0x21000080, + 0x7000: 0x40080, + 0x8000: 0x1000000, + 0x9000: 0x20040000, + 0xa000: 0x20000080, + 0xb000: 0x21040080, + 0xc000: 0x21040000, + 0xd000: 0x0, + 0xe000: 0x1040080, + 0xf000: 0x21000000, + 0x800: 0x1040080, + 0x1800: 0x21000080, + 0x2800: 0x80, + 0x3800: 0x1040000, + 0x4800: 0x40000, + 0x5800: 0x20040080, + 0x6800: 0x21040000, + 0x7800: 0x20000000, + 0x8800: 0x20040000, + 0x9800: 0x0, + 0xa800: 0x21040080, + 0xb800: 0x1000080, + 0xc800: 0x20000080, + 0xd800: 0x21000000, + 0xe800: 0x1000000, + 0xf800: 0x40080, + 0x10000: 0x40000, + 0x11000: 0x80, + 0x12000: 0x20000000, + 0x13000: 0x21000080, + 0x14000: 0x1000080, + 0x15000: 0x21040000, + 0x16000: 0x20040080, + 0x17000: 0x1000000, + 0x18000: 0x21040080, + 0x19000: 0x21000000, + 0x1a000: 0x1040000, + 0x1b000: 0x20040000, + 0x1c000: 0x40080, + 0x1d000: 0x20000080, + 0x1e000: 0x0, + 0x1f000: 0x1040080, + 0x10800: 0x21000080, + 0x11800: 0x1000000, + 0x12800: 0x1040000, + 0x13800: 0x20040080, + 0x14800: 0x20000000, + 0x15800: 0x1040080, + 0x16800: 0x80, + 0x17800: 0x21040000, + 0x18800: 0x40080, + 0x19800: 0x21040080, + 0x1a800: 0x0, + 0x1b800: 0x21000000, + 0x1c800: 0x1000080, + 0x1d800: 0x40000, + 0x1e800: 0x20040000, + 0x1f800: 0x20000080 + }, + { + 0x0: 0x10000008, + 0x100: 0x2000, + 0x200: 0x10200000, + 0x300: 0x10202008, + 0x400: 0x10002000, + 0x500: 0x200000, + 0x600: 0x200008, + 0x700: 0x10000000, + 0x800: 0x0, + 0x900: 0x10002008, + 0xa00: 0x202000, + 0xb00: 0x8, + 0xc00: 0x10200008, + 0xd00: 0x202008, + 0xe00: 0x2008, + 0xf00: 0x10202000, + 0x80: 0x10200000, + 0x180: 0x10202008, + 0x280: 0x8, + 0x380: 0x200000, + 0x480: 0x202008, + 0x580: 0x10000008, + 0x680: 0x10002000, + 0x780: 0x2008, + 0x880: 0x200008, + 0x980: 0x2000, + 0xa80: 0x10002008, + 0xb80: 0x10200008, + 0xc80: 0x0, + 0xd80: 0x10202000, + 0xe80: 0x202000, + 0xf80: 0x10000000, + 0x1000: 0x10002000, + 0x1100: 0x10200008, + 0x1200: 0x10202008, + 0x1300: 0x2008, + 0x1400: 0x200000, + 0x1500: 0x10000000, + 0x1600: 0x10000008, + 0x1700: 0x202000, + 0x1800: 0x202008, + 0x1900: 0x0, + 0x1a00: 0x8, + 0x1b00: 0x10200000, + 0x1c00: 0x2000, + 0x1d00: 0x10002008, + 0x1e00: 0x10202000, + 0x1f00: 0x200008, + 0x1080: 0x8, + 0x1180: 0x202000, + 0x1280: 0x200000, + 0x1380: 0x10000008, + 0x1480: 0x10002000, + 0x1580: 0x2008, + 0x1680: 0x10202008, + 0x1780: 0x10200000, + 0x1880: 0x10202000, + 0x1980: 0x10200008, + 0x1a80: 0x2000, + 0x1b80: 0x202008, + 0x1c80: 0x200008, + 0x1d80: 0x0, + 0x1e80: 0x10000000, + 0x1f80: 0x10002008 + }, + { + 0x0: 0x100000, + 0x10: 0x2000401, + 0x20: 0x400, + 0x30: 0x100401, + 0x40: 0x2100401, + 0x50: 0x0, + 0x60: 0x1, + 0x70: 0x2100001, + 0x80: 0x2000400, + 0x90: 0x100001, + 0xa0: 0x2000001, + 0xb0: 0x2100400, + 0xc0: 0x2100000, + 0xd0: 0x401, + 0xe0: 0x100400, + 0xf0: 0x2000000, + 0x8: 0x2100001, + 0x18: 0x0, + 0x28: 0x2000401, + 0x38: 0x2100400, + 0x48: 0x100000, + 0x58: 0x2000001, + 0x68: 0x2000000, + 0x78: 0x401, + 0x88: 0x100401, + 0x98: 0x2000400, + 0xa8: 0x2100000, + 0xb8: 0x100001, + 0xc8: 0x400, + 0xd8: 0x2100401, + 0xe8: 0x1, + 0xf8: 0x100400, + 0x100: 0x2000000, + 0x110: 0x100000, + 0x120: 0x2000401, + 0x130: 0x2100001, + 0x140: 0x100001, + 0x150: 0x2000400, + 0x160: 0x2100400, + 0x170: 0x100401, + 0x180: 0x401, + 0x190: 0x2100401, + 0x1a0: 0x100400, + 0x1b0: 0x1, + 0x1c0: 0x0, + 0x1d0: 0x2100000, + 0x1e0: 0x2000001, + 0x1f0: 0x400, + 0x108: 0x100400, + 0x118: 0x2000401, + 0x128: 0x2100001, + 0x138: 0x1, + 0x148: 0x2000000, + 0x158: 0x100000, + 0x168: 0x401, + 0x178: 0x2100400, + 0x188: 0x2000001, + 0x198: 0x2100000, + 0x1a8: 0x0, + 0x1b8: 0x2100401, + 0x1c8: 0x100401, + 0x1d8: 0x400, + 0x1e8: 0x2000400, + 0x1f8: 0x100001 + }, + { + 0x0: 0x8000820, + 0x1: 0x20000, + 0x2: 0x8000000, + 0x3: 0x20, + 0x4: 0x20020, + 0x5: 0x8020820, + 0x6: 0x8020800, + 0x7: 0x800, + 0x8: 0x8020000, + 0x9: 0x8000800, + 0xa: 0x20800, + 0xb: 0x8020020, + 0xc: 0x820, + 0xd: 0x0, + 0xe: 0x8000020, + 0xf: 0x20820, + 0x80000000: 0x800, + 0x80000001: 0x8020820, + 0x80000002: 0x8000820, + 0x80000003: 0x8000000, + 0x80000004: 0x8020000, + 0x80000005: 0x20800, + 0x80000006: 0x20820, + 0x80000007: 0x20, + 0x80000008: 0x8000020, + 0x80000009: 0x820, + 0x8000000a: 0x20020, + 0x8000000b: 0x8020800, + 0x8000000c: 0x0, + 0x8000000d: 0x8020020, + 0x8000000e: 0x8000800, + 0x8000000f: 0x20000, + 0x10: 0x20820, + 0x11: 0x8020800, + 0x12: 0x20, + 0x13: 0x800, + 0x14: 0x8000800, + 0x15: 0x8000020, + 0x16: 0x8020020, + 0x17: 0x20000, + 0x18: 0x0, + 0x19: 0x20020, + 0x1a: 0x8020000, + 0x1b: 0x8000820, + 0x1c: 0x8020820, + 0x1d: 0x20800, + 0x1e: 0x820, + 0x1f: 0x8000000, + 0x80000010: 0x20000, + 0x80000011: 0x800, + 0x80000012: 0x8020020, + 0x80000013: 0x20820, + 0x80000014: 0x20, + 0x80000015: 0x8020000, + 0x80000016: 0x8000000, + 0x80000017: 0x8000820, + 0x80000018: 0x8020820, + 0x80000019: 0x8000020, + 0x8000001a: 0x8000800, + 0x8000001b: 0x0, + 0x8000001c: 0x20800, + 0x8000001d: 0x820, + 0x8000001e: 0x20020, + 0x8000001f: 0x8020800 + } + ]; + + // Masks that select the SBOX input + var SBOX_MASK = [ + 0xf8000001, 0x1f800000, 0x01f80000, 0x001f8000, + 0x0001f800, 0x00001f80, 0x000001f8, 0x8000001f + ]; + + /** + * DES block cipher algorithm. + */ + var DES = C_algo.DES = BlockCipher.extend({ + _doReset: function () { + // Shortcuts + var key = this._key; + var keyWords = key.words; + + // Select 56 bits according to PC1 + var keyBits = []; + for (var i = 0; i < 56; i++) { + var keyBitPos = PC1[i] - 1; + keyBits[i] = (keyWords[keyBitPos >>> 5] >>> (31 - keyBitPos % 32)) & 1; + } + + // Assemble 16 subkeys + var subKeys = this._subKeys = []; + for (var nSubKey = 0; nSubKey < 16; nSubKey++) { + // Create subkey + var subKey = subKeys[nSubKey] = []; + + // Shortcut + var bitShift = BIT_SHIFTS[nSubKey]; + + // Select 48 bits according to PC2 + for (var i = 0; i < 24; i++) { + // Select from the left 28 key bits + subKey[(i / 6) | 0] |= keyBits[((PC2[i] - 1) + bitShift) % 28] << (31 - i % 6); + + // Select from the right 28 key bits + subKey[4 + ((i / 6) | 0)] |= keyBits[28 + (((PC2[i + 24] - 1) + bitShift) % 28)] << (31 - i % 6); + } + + // Since each subkey is applied to an expanded 32-bit input, + // the subkey can be broken into 8 values scaled to 32-bits, + // which allows the key to be used without expansion + subKey[0] = (subKey[0] << 1) | (subKey[0] >>> 31); + for (var i = 1; i < 7; i++) { + subKey[i] = subKey[i] >>> ((i - 1) * 4 + 3); + } + subKey[7] = (subKey[7] << 5) | (subKey[7] >>> 27); + } + + // Compute inverse subkeys + var invSubKeys = this._invSubKeys = []; + for (var i = 0; i < 16; i++) { + invSubKeys[i] = subKeys[15 - i]; + } + }, + + encryptBlock: function (M, offset) { + this._doCryptBlock(M, offset, this._subKeys); + }, + + decryptBlock: function (M, offset) { + this._doCryptBlock(M, offset, this._invSubKeys); + }, + + _doCryptBlock: function (M, offset, subKeys) { + // Get input + this._lBlock = M[offset]; + this._rBlock = M[offset + 1]; + + // Initial permutation + exchangeLR.call(this, 4, 0x0f0f0f0f); + exchangeLR.call(this, 16, 0x0000ffff); + exchangeRL.call(this, 2, 0x33333333); + exchangeRL.call(this, 8, 0x00ff00ff); + exchangeLR.call(this, 1, 0x55555555); + + // Rounds + for (var round = 0; round < 16; round++) { + // Shortcuts + var subKey = subKeys[round]; + var lBlock = this._lBlock; + var rBlock = this._rBlock; + + // Feistel function + var f = 0; + for (var i = 0; i < 8; i++) { + f |= SBOX_P[i][((rBlock ^ subKey[i]) & SBOX_MASK[i]) >>> 0]; + } + this._lBlock = rBlock; + this._rBlock = lBlock ^ f; + } + + // Undo swap from last round + var t = this._lBlock; + this._lBlock = this._rBlock; + this._rBlock = t; + + // Final permutation + exchangeLR.call(this, 1, 0x55555555); + exchangeRL.call(this, 8, 0x00ff00ff); + exchangeRL.call(this, 2, 0x33333333); + exchangeLR.call(this, 16, 0x0000ffff); + exchangeLR.call(this, 4, 0x0f0f0f0f); + + // Set output + M[offset] = this._lBlock; + M[offset + 1] = this._rBlock; + }, + + keySize: 64/32, + + ivSize: 64/32, + + blockSize: 64/32 + }); + + // Swap bits across the left and right words + function exchangeLR(offset, mask) { + var t = ((this._lBlock >>> offset) ^ this._rBlock) & mask; + this._rBlock ^= t; + this._lBlock ^= t << offset; + } + + function exchangeRL(offset, mask) { + var t = ((this._rBlock >>> offset) ^ this._lBlock) & mask; + this._lBlock ^= t; + this._rBlock ^= t << offset; + } + + /** + * Shortcut functions to the cipher's object interface. + * + * @example + * + * var ciphertext = CryptoJS.DES.encrypt(message, key, cfg); + * var plaintext = CryptoJS.DES.decrypt(ciphertext, key, cfg); + */ + C.DES = BlockCipher._createHelper(DES); + + /** + * Triple-DES block cipher algorithm. + */ + var TripleDES = C_algo.TripleDES = BlockCipher.extend({ + _doReset: function () { + // Shortcuts + var key = this._key; + var keyWords = key.words; + // Make sure the key length is valid (64, 128 or >= 192 bit) + if (keyWords.length !== 2 && keyWords.length !== 4 && keyWords.length < 6) { + throw new Error('Invalid key length - 3DES requires the key length to be 64, 128, 192 or >192.'); + } + + // Extend the key according to the keying options defined in 3DES standard + var key1 = keyWords.slice(0, 2); + var key2 = keyWords.length < 4 ? keyWords.slice(0, 2) : keyWords.slice(2, 4); + var key3 = keyWords.length < 6 ? keyWords.slice(0, 2) : keyWords.slice(4, 6); + + // Create DES instances + this._des1 = DES.createEncryptor(WordArray.create(key1)); + this._des2 = DES.createEncryptor(WordArray.create(key2)); + this._des3 = DES.createEncryptor(WordArray.create(key3)); + }, + + encryptBlock: function (M, offset) { + this._des1.encryptBlock(M, offset); + this._des2.decryptBlock(M, offset); + this._des3.encryptBlock(M, offset); + }, + + decryptBlock: function (M, offset) { + this._des3.decryptBlock(M, offset); + this._des2.encryptBlock(M, offset); + this._des1.decryptBlock(M, offset); + }, + + keySize: 192/32, + + ivSize: 64/32, + + blockSize: 64/32 + }); + + /** + * Shortcut functions to the cipher's object interface. + * + * @example + * + * var ciphertext = CryptoJS.TripleDES.encrypt(message, key, cfg); + * var plaintext = CryptoJS.TripleDES.decrypt(ciphertext, key, cfg); + */ + C.TripleDES = BlockCipher._createHelper(TripleDES); + }()); + + + (function () { + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var StreamCipher = C_lib.StreamCipher; + var C_algo = C.algo; + + /** + * RC4 stream cipher algorithm. + */ + var RC4 = C_algo.RC4 = StreamCipher.extend({ + _doReset: function () { + // Shortcuts + var key = this._key; + var keyWords = key.words; + var keySigBytes = key.sigBytes; + + // Init sbox + var S = this._S = []; + for (var i = 0; i < 256; i++) { + S[i] = i; + } + + // Key setup + for (var i = 0, j = 0; i < 256; i++) { + var keyByteIndex = i % keySigBytes; + var keyByte = (keyWords[keyByteIndex >>> 2] >>> (24 - (keyByteIndex % 4) * 8)) & 0xff; + + j = (j + S[i] + keyByte) % 256; + + // Swap + var t = S[i]; + S[i] = S[j]; + S[j] = t; + } + + // Counters + this._i = this._j = 0; + }, + + _doProcessBlock: function (M, offset) { + M[offset] ^= generateKeystreamWord.call(this); + }, + + keySize: 256/32, + + ivSize: 0 + }); + + function generateKeystreamWord() { + // Shortcuts + var S = this._S; + var i = this._i; + var j = this._j; + + // Generate keystream word + var keystreamWord = 0; + for (var n = 0; n < 4; n++) { + i = (i + 1) % 256; + j = (j + S[i]) % 256; + + // Swap + var t = S[i]; + S[i] = S[j]; + S[j] = t; + + keystreamWord |= S[(S[i] + S[j]) % 256] << (24 - n * 8); + } + + // Update counters + this._i = i; + this._j = j; + + return keystreamWord; + } + + /** + * Shortcut functions to the cipher's object interface. + * + * @example + * + * var ciphertext = CryptoJS.RC4.encrypt(message, key, cfg); + * var plaintext = CryptoJS.RC4.decrypt(ciphertext, key, cfg); + */ + C.RC4 = StreamCipher._createHelper(RC4); + + /** + * Modified RC4 stream cipher algorithm. + */ + var RC4Drop = C_algo.RC4Drop = RC4.extend({ + /** + * Configuration options. + * + * @property {number} drop The number of keystream words to drop. Default 192 + */ + cfg: RC4.cfg.extend({ + drop: 192 + }), + + _doReset: function () { + RC4._doReset.call(this); + + // Drop + for (var i = this.cfg.drop; i > 0; i--) { + generateKeystreamWord.call(this); + } + } + }); + + /** + * Shortcut functions to the cipher's object interface. + * + * @example + * + * var ciphertext = CryptoJS.RC4Drop.encrypt(message, key, cfg); + * var plaintext = CryptoJS.RC4Drop.decrypt(ciphertext, key, cfg); + */ + C.RC4Drop = StreamCipher._createHelper(RC4Drop); + }()); + + + (function () { + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var StreamCipher = C_lib.StreamCipher; + var C_algo = C.algo; + + // Reusable objects + var S = []; + var C_ = []; + var G = []; + + /** + * Rabbit stream cipher algorithm + */ + var Rabbit = C_algo.Rabbit = StreamCipher.extend({ + _doReset: function () { + // Shortcuts + var K = this._key.words; + var iv = this.cfg.iv; + + // Swap endian + for (var i = 0; i < 4; i++) { + K[i] = (((K[i] << 8) | (K[i] >>> 24)) & 0x00ff00ff) | + (((K[i] << 24) | (K[i] >>> 8)) & 0xff00ff00); + } + + // Generate initial state values + var X = this._X = [ + K[0], (K[3] << 16) | (K[2] >>> 16), + K[1], (K[0] << 16) | (K[3] >>> 16), + K[2], (K[1] << 16) | (K[0] >>> 16), + K[3], (K[2] << 16) | (K[1] >>> 16) + ]; + + // Generate initial counter values + var C = this._C = [ + (K[2] << 16) | (K[2] >>> 16), (K[0] & 0xffff0000) | (K[1] & 0x0000ffff), + (K[3] << 16) | (K[3] >>> 16), (K[1] & 0xffff0000) | (K[2] & 0x0000ffff), + (K[0] << 16) | (K[0] >>> 16), (K[2] & 0xffff0000) | (K[3] & 0x0000ffff), + (K[1] << 16) | (K[1] >>> 16), (K[3] & 0xffff0000) | (K[0] & 0x0000ffff) + ]; + + // Carry bit + this._b = 0; + + // Iterate the system four times + for (var i = 0; i < 4; i++) { + nextState.call(this); + } + + // Modify the counters + for (var i = 0; i < 8; i++) { + C[i] ^= X[(i + 4) & 7]; + } + + // IV setup + if (iv) { + // Shortcuts + var IV = iv.words; + var IV_0 = IV[0]; + var IV_1 = IV[1]; + + // Generate four subvectors + var i0 = (((IV_0 << 8) | (IV_0 >>> 24)) & 0x00ff00ff) | (((IV_0 << 24) | (IV_0 >>> 8)) & 0xff00ff00); + var i2 = (((IV_1 << 8) | (IV_1 >>> 24)) & 0x00ff00ff) | (((IV_1 << 24) | (IV_1 >>> 8)) & 0xff00ff00); + var i1 = (i0 >>> 16) | (i2 & 0xffff0000); + var i3 = (i2 << 16) | (i0 & 0x0000ffff); + + // Modify counter values + C[0] ^= i0; + C[1] ^= i1; + C[2] ^= i2; + C[3] ^= i3; + C[4] ^= i0; + C[5] ^= i1; + C[6] ^= i2; + C[7] ^= i3; + + // Iterate the system four times + for (var i = 0; i < 4; i++) { + nextState.call(this); + } + } + }, + + _doProcessBlock: function (M, offset) { + // Shortcut + var X = this._X; + + // Iterate the system + nextState.call(this); + + // Generate four keystream words + S[0] = X[0] ^ (X[5] >>> 16) ^ (X[3] << 16); + S[1] = X[2] ^ (X[7] >>> 16) ^ (X[5] << 16); + S[2] = X[4] ^ (X[1] >>> 16) ^ (X[7] << 16); + S[3] = X[6] ^ (X[3] >>> 16) ^ (X[1] << 16); + + for (var i = 0; i < 4; i++) { + // Swap endian + S[i] = (((S[i] << 8) | (S[i] >>> 24)) & 0x00ff00ff) | + (((S[i] << 24) | (S[i] >>> 8)) & 0xff00ff00); + + // Encrypt + M[offset + i] ^= S[i]; + } + }, + + blockSize: 128/32, + + ivSize: 64/32 + }); + + function nextState() { + // Shortcuts + var X = this._X; + var C = this._C; + + // Save old counter values + for (var i = 0; i < 8; i++) { + C_[i] = C[i]; + } + + // Calculate new counter values + C[0] = (C[0] + 0x4d34d34d + this._b) | 0; + C[1] = (C[1] + 0xd34d34d3 + ((C[0] >>> 0) < (C_[0] >>> 0) ? 1 : 0)) | 0; + C[2] = (C[2] + 0x34d34d34 + ((C[1] >>> 0) < (C_[1] >>> 0) ? 1 : 0)) | 0; + C[3] = (C[3] + 0x4d34d34d + ((C[2] >>> 0) < (C_[2] >>> 0) ? 1 : 0)) | 0; + C[4] = (C[4] + 0xd34d34d3 + ((C[3] >>> 0) < (C_[3] >>> 0) ? 1 : 0)) | 0; + C[5] = (C[5] + 0x34d34d34 + ((C[4] >>> 0) < (C_[4] >>> 0) ? 1 : 0)) | 0; + C[6] = (C[6] + 0x4d34d34d + ((C[5] >>> 0) < (C_[5] >>> 0) ? 1 : 0)) | 0; + C[7] = (C[7] + 0xd34d34d3 + ((C[6] >>> 0) < (C_[6] >>> 0) ? 1 : 0)) | 0; + this._b = (C[7] >>> 0) < (C_[7] >>> 0) ? 1 : 0; + + // Calculate the g-values + for (var i = 0; i < 8; i++) { + var gx = X[i] + C[i]; + + // Construct high and low argument for squaring + var ga = gx & 0xffff; + var gb = gx >>> 16; + + // Calculate high and low result of squaring + var gh = ((((ga * ga) >>> 17) + ga * gb) >>> 15) + gb * gb; + var gl = (((gx & 0xffff0000) * gx) | 0) + (((gx & 0x0000ffff) * gx) | 0); + + // High XOR low + G[i] = gh ^ gl; + } + + // Calculate new state values + X[0] = (G[0] + ((G[7] << 16) | (G[7] >>> 16)) + ((G[6] << 16) | (G[6] >>> 16))) | 0; + X[1] = (G[1] + ((G[0] << 8) | (G[0] >>> 24)) + G[7]) | 0; + X[2] = (G[2] + ((G[1] << 16) | (G[1] >>> 16)) + ((G[0] << 16) | (G[0] >>> 16))) | 0; + X[3] = (G[3] + ((G[2] << 8) | (G[2] >>> 24)) + G[1]) | 0; + X[4] = (G[4] + ((G[3] << 16) | (G[3] >>> 16)) + ((G[2] << 16) | (G[2] >>> 16))) | 0; + X[5] = (G[5] + ((G[4] << 8) | (G[4] >>> 24)) + G[3]) | 0; + X[6] = (G[6] + ((G[5] << 16) | (G[5] >>> 16)) + ((G[4] << 16) | (G[4] >>> 16))) | 0; + X[7] = (G[7] + ((G[6] << 8) | (G[6] >>> 24)) + G[5]) | 0; + } + + /** + * Shortcut functions to the cipher's object interface. + * + * @example + * + * var ciphertext = CryptoJS.Rabbit.encrypt(message, key, cfg); + * var plaintext = CryptoJS.Rabbit.decrypt(ciphertext, key, cfg); + */ + C.Rabbit = StreamCipher._createHelper(Rabbit); + }()); + + + (function () { + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var StreamCipher = C_lib.StreamCipher; + var C_algo = C.algo; + + // Reusable objects + var S = []; + var C_ = []; + var G = []; + + /** + * Rabbit stream cipher algorithm. + * + * This is a legacy version that neglected to convert the key to little-endian. + * This error doesn't affect the cipher's security, + * but it does affect its compatibility with other implementations. + */ + var RabbitLegacy = C_algo.RabbitLegacy = StreamCipher.extend({ + _doReset: function () { + // Shortcuts + var K = this._key.words; + var iv = this.cfg.iv; + + // Generate initial state values + var X = this._X = [ + K[0], (K[3] << 16) | (K[2] >>> 16), + K[1], (K[0] << 16) | (K[3] >>> 16), + K[2], (K[1] << 16) | (K[0] >>> 16), + K[3], (K[2] << 16) | (K[1] >>> 16) + ]; + + // Generate initial counter values + var C = this._C = [ + (K[2] << 16) | (K[2] >>> 16), (K[0] & 0xffff0000) | (K[1] & 0x0000ffff), + (K[3] << 16) | (K[3] >>> 16), (K[1] & 0xffff0000) | (K[2] & 0x0000ffff), + (K[0] << 16) | (K[0] >>> 16), (K[2] & 0xffff0000) | (K[3] & 0x0000ffff), + (K[1] << 16) | (K[1] >>> 16), (K[3] & 0xffff0000) | (K[0] & 0x0000ffff) + ]; + + // Carry bit + this._b = 0; + + // Iterate the system four times + for (var i = 0; i < 4; i++) { + nextState.call(this); + } + + // Modify the counters + for (var i = 0; i < 8; i++) { + C[i] ^= X[(i + 4) & 7]; + } + + // IV setup + if (iv) { + // Shortcuts + var IV = iv.words; + var IV_0 = IV[0]; + var IV_1 = IV[1]; + + // Generate four subvectors + var i0 = (((IV_0 << 8) | (IV_0 >>> 24)) & 0x00ff00ff) | (((IV_0 << 24) | (IV_0 >>> 8)) & 0xff00ff00); + var i2 = (((IV_1 << 8) | (IV_1 >>> 24)) & 0x00ff00ff) | (((IV_1 << 24) | (IV_1 >>> 8)) & 0xff00ff00); + var i1 = (i0 >>> 16) | (i2 & 0xffff0000); + var i3 = (i2 << 16) | (i0 & 0x0000ffff); + + // Modify counter values + C[0] ^= i0; + C[1] ^= i1; + C[2] ^= i2; + C[3] ^= i3; + C[4] ^= i0; + C[5] ^= i1; + C[6] ^= i2; + C[7] ^= i3; + + // Iterate the system four times + for (var i = 0; i < 4; i++) { + nextState.call(this); + } + } + }, + + _doProcessBlock: function (M, offset) { + // Shortcut + var X = this._X; + + // Iterate the system + nextState.call(this); + + // Generate four keystream words + S[0] = X[0] ^ (X[5] >>> 16) ^ (X[3] << 16); + S[1] = X[2] ^ (X[7] >>> 16) ^ (X[5] << 16); + S[2] = X[4] ^ (X[1] >>> 16) ^ (X[7] << 16); + S[3] = X[6] ^ (X[3] >>> 16) ^ (X[1] << 16); + + for (var i = 0; i < 4; i++) { + // Swap endian + S[i] = (((S[i] << 8) | (S[i] >>> 24)) & 0x00ff00ff) | + (((S[i] << 24) | (S[i] >>> 8)) & 0xff00ff00); + + // Encrypt + M[offset + i] ^= S[i]; + } + }, + + blockSize: 128/32, + + ivSize: 64/32 + }); + + function nextState() { + // Shortcuts + var X = this._X; + var C = this._C; + + // Save old counter values + for (var i = 0; i < 8; i++) { + C_[i] = C[i]; + } + + // Calculate new counter values + C[0] = (C[0] + 0x4d34d34d + this._b) | 0; + C[1] = (C[1] + 0xd34d34d3 + ((C[0] >>> 0) < (C_[0] >>> 0) ? 1 : 0)) | 0; + C[2] = (C[2] + 0x34d34d34 + ((C[1] >>> 0) < (C_[1] >>> 0) ? 1 : 0)) | 0; + C[3] = (C[3] + 0x4d34d34d + ((C[2] >>> 0) < (C_[2] >>> 0) ? 1 : 0)) | 0; + C[4] = (C[4] + 0xd34d34d3 + ((C[3] >>> 0) < (C_[3] >>> 0) ? 1 : 0)) | 0; + C[5] = (C[5] + 0x34d34d34 + ((C[4] >>> 0) < (C_[4] >>> 0) ? 1 : 0)) | 0; + C[6] = (C[6] + 0x4d34d34d + ((C[5] >>> 0) < (C_[5] >>> 0) ? 1 : 0)) | 0; + C[7] = (C[7] + 0xd34d34d3 + ((C[6] >>> 0) < (C_[6] >>> 0) ? 1 : 0)) | 0; + this._b = (C[7] >>> 0) < (C_[7] >>> 0) ? 1 : 0; + + // Calculate the g-values + for (var i = 0; i < 8; i++) { + var gx = X[i] + C[i]; + + // Construct high and low argument for squaring + var ga = gx & 0xffff; + var gb = gx >>> 16; + + // Calculate high and low result of squaring + var gh = ((((ga * ga) >>> 17) + ga * gb) >>> 15) + gb * gb; + var gl = (((gx & 0xffff0000) * gx) | 0) + (((gx & 0x0000ffff) * gx) | 0); + + // High XOR low + G[i] = gh ^ gl; + } + + // Calculate new state values + X[0] = (G[0] + ((G[7] << 16) | (G[7] >>> 16)) + ((G[6] << 16) | (G[6] >>> 16))) | 0; + X[1] = (G[1] + ((G[0] << 8) | (G[0] >>> 24)) + G[7]) | 0; + X[2] = (G[2] + ((G[1] << 16) | (G[1] >>> 16)) + ((G[0] << 16) | (G[0] >>> 16))) | 0; + X[3] = (G[3] + ((G[2] << 8) | (G[2] >>> 24)) + G[1]) | 0; + X[4] = (G[4] + ((G[3] << 16) | (G[3] >>> 16)) + ((G[2] << 16) | (G[2] >>> 16))) | 0; + X[5] = (G[5] + ((G[4] << 8) | (G[4] >>> 24)) + G[3]) | 0; + X[6] = (G[6] + ((G[5] << 16) | (G[5] >>> 16)) + ((G[4] << 16) | (G[4] >>> 16))) | 0; + X[7] = (G[7] + ((G[6] << 8) | (G[6] >>> 24)) + G[5]) | 0; + } + + /** + * Shortcut functions to the cipher's object interface. + * + * @example + * + * var ciphertext = CryptoJS.RabbitLegacy.encrypt(message, key, cfg); + * var plaintext = CryptoJS.RabbitLegacy.decrypt(ciphertext, key, cfg); + */ + C.RabbitLegacy = StreamCipher._createHelper(RabbitLegacy); + }()); + + + return CryptoJS; + +})); diff --git a/flixlatam/flixlatam.json b/flixlatam/flixlatam.json new file mode 100644 index 0000000..2ee1f84 --- /dev/null +++ b/flixlatam/flixlatam.json @@ -0,0 +1,19 @@ +{ + "sourceName": "FlixLatam", + "iconUrl": "https://flixlatam.com/wp-content/uploads/2022/04/cropped-Series-Latinoamerica-192x192.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "Spanish (DUB/SUB)", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://flixlatam.com/", + "searchBaseUrl": "https://flixlatam.com/", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/flixlatam/flixlatam.js", + "type": "shows/movies", + "asyncJS": true, + "softsub": false, + "downloadSupport": false +} diff --git a/franime/franime.js b/franime/franime.js new file mode 100644 index 0000000..a66e70f --- /dev/null +++ b/franime/franime.js @@ -0,0 +1,139 @@ +async function searchResults(keyword) { + try { + const response = await fetchv2("https://api.franime.fr/api/animes"); + const data = await response.json(); + + const results = data + .filter(anime => anime.title.toLowerCase().includes(keyword.toLowerCase())) + .map(anime => ({ + href: anime.id.toString(), + title: anime.title, + image: anime.affiche + })); + + return JSON.stringify(results); + } catch (err) { + return JSON.stringify([{ + title: "Error", + image: "Error", + href: "Error" + }]); + } +} + +async function extractDetails(id) { + try { + const response = await fetchv2("https://api.franime.fr/api/animes"); + const data = await response.json(); + + const anime = data.find(item => item.id === Number(id)); + if (!anime) { + return JSON.stringify([{ + description: "Not found", + aliases: "N/A", + airdate: "N/A" + }]); + } + + return JSON.stringify([{ + description: anime.description || "N/A", + aliases: anime.titles ? Object.values(anime.titles).join(", ") : "N/A", + airdate: anime.startDate || "N/A" + }]); + } catch (err) { + return JSON.stringify([{ + description: "Error", + aliases: "Error", + airdate: "Error" + }]); + } +} + +async function extractEpisodes(id) { + const results = []; + try { + const response = await fetchv2("https://api.franime.fr/api/animes"); + const data = await response.json(); + + const anime = data.find(item => item.id === Number(id)); + if (!anime || !anime.saisons) { + return JSON.stringify([{ + href: "N/A", + number: "N/A" + }]); + } + + anime.saisons.forEach((season, seasonIndex) => { + season.episodes.forEach((episode, episodeIndex) => { + results.push({ + href: `${id}/${seasonIndex}/${episodeIndex}`, + number: episodeIndex + 1 + }); + }); + }); + + return JSON.stringify(results); + } catch (err) { + return JSON.stringify([{ + href: "Error", + number: "Error" + }]); + } +} + +async function extractStreamUrl(id) { + try { + const headers = { + "Host": "api.franime.fr", + "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:143.0) Gecko/20100101 Firefox/143.0", + "Referer": "https://franime.fr/", + "Content-Type": "application/json", + "Origin": "https://franime.fr", + "Connection": "keep-alive", + "Sec-Fetch-Dest": "empty", + "Sec-Fetch-Mode": "cors", + "Sec-Fetch-Site": "same-site", + "Priority": "u=0", + "TE": "trailers" + }; + + async function fetchUntilMp4(type) { + let i = 0; + while (i < 10) { + const url = `https://api.franime.fr/api/anime/${id}/${type}/${i}`; + const res = await fetchv2(url, headers); + const text = await res.text(); + console.log(type.toUpperCase(), i, text); + + if (text.includes("Aucun lecteur disponible")) return null; + + if (text.endsWith(".mp4")) return text; + + i++; + } + } + + const vf = await fetchUntilMp4("vf"); + const vo = await fetchUntilMp4("vo"); + + const streams = []; + + if (vf) streams.push("VOSTFR", vf); + if (vo) streams.push("VF", vo); + + const final = { + streams, + subtitles: "" + }; + + console.log("RETURN: " + JSON.stringify(final)); + return JSON.stringify(final); + + } catch (error) { + console.log("Error in extractStreamUrl:", error); + return JSON.stringify({ + streams: [], + subtitles: "" + }); + } +} diff --git a/franime/franime.json b/franime/franime.json new file mode 100644 index 0000000..09e37c9 --- /dev/null +++ b/franime/franime.json @@ -0,0 +1,19 @@ +{ + "sourceName": "Franime", + "iconUrl": "https://franime.fr/logos/apple-touch-icon.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "French (DUB/SUB)", + "streamType": "mp4", + "quality": "1080p", + "baseUrl": "https://franime.fr/", + "searchBaseUrl": "https://franime.fr/", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/franime/franime.js", + "type": "anime", + "asyncJS": true, + "softsub": true, + "downloadSupport": true +} diff --git a/funmovieslix/funmovieslix.js b/funmovieslix/funmovieslix.js new file mode 100644 index 0000000..fcc1096 --- /dev/null +++ b/funmovieslix/funmovieslix.js @@ -0,0 +1,281 @@ +async function searchResults(keyword) { + const results = []; + try { + const response = await fetchv2("https://funmovieslix.com/?s=" + encodeURIComponent(keyword)); + const html = await response.text(); + + const regex = /<a href="([^"]+)" class="poster-wrap">[\s\S]*?<img[^>]+src="([^"]+)"[^>]*>[\s\S]*?<h3 class="title">([^<]+)<\/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 descMatch = html.match(/<div class="entry-content entry-content-single"[^>]*>[\s\S]*?<p>([\s\S]*?)<\/p>/); + const description = descMatch ? descMatch[1].trim() : "N/A"; + + const dateMatch = html.match(/<time itemprop="dateCreated"[^>]*>([^<]+)<\/time>/); + const airdate = dateMatch ? dateMatch[1].trim() : "N/A"; + + return JSON.stringify([{ + description: description, + aliases: "N/A", + airdate: airdate + }]); + } 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 class="button button-shadow" href="([^"]+)"[^>]*>S\d+\sEps?(\d+)<\/a>/g; + let match; + while ((match = regex.exec(html)) !== null) { + results.push({ + href: match[1].trim(), + number: parseInt(match[2], 10) + }); + } + + if (results.length === 0) { + results.push({ + href: url, + number: 1 + }); + } + + return JSON.stringify(results); + } catch (err) { + return JSON.stringify([{ + href: "Error", + number: "Error" + }]); + } +} + +async function extractStreamUrl(url) { + try { + const response = await fetchv2(url); + const html = await response.text(); + + const match = html.match(/<iframe src="(https:\/\/filemoon\.(?:to|sx)\/e\/[^"]+)"/); + const filemoonUrl = match ? match[1] : "https://files.catbox.moe/avolvc.mp4"; + + console.log("Filemoon URL:"+ filemoonUrl); + const filemoonResponse = await fetchv2(filemoonUrl); + const filemoonHtml = await filemoonResponse.text(); + return filemoonExtractor(filemoonHtml, filemoonUrl) || filemoonUrl; + } catch (err) { + const fallback = "https://files.catbox.moe/avolvc.mp4"; + console.log("Filemoon URL:"+ fallback); + return fallback; + } +} + + +/* SCHEME START */ +/* {REQUIRED PLUGINS: unbaser} */ + +/** + * @name filemoonExtractor + * @author Cufiy - Inspired by Churly + */ + +async function filemoonExtractor(html, url = null) { + // check if contains iframe, if does, extract the src and get the url + const regex = /<iframe[^>]+src="([^"]+)"[^>]*><\/iframe>/; + const match = html.match(regex); + if (match) { + console.log("Iframe URL: " + match[1]); + const iframeUrl = match[1]; + const iframeResponse = await soraFetch(iframeUrl, { + headers: { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3", + "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", + "Referer": url, + } + }); + console.log("Iframe Response: " + iframeResponse.status); + html = await iframeResponse.text(); + } + // console.log("HTML: " + html); + // get /<script[^>]*>([\s\S]*?)<\/script>/gi + const scriptRegex = /<script[^>]*>([\s\S]*?)<\/script>/gi; + const scripts = []; + let scriptMatch; + while ((scriptMatch = scriptRegex.exec(html)) !== null) { + scripts.push(scriptMatch[1]); + } + // get the script with eval and m3u8 + const evalRegex = /eval\((.*?)\)/; + const m3u8Regex = /m3u8/; + // console.log("Scripts: " + scripts); + const evalScript = scripts.find(script => evalRegex.test(script) && m3u8Regex.test(script)); + if (!evalScript) { + console.log("No eval script found"); + return null; + } + const unpackedScript = unpack(evalScript); + // get the m3u8 url + const m3u8Regex2 = /https?:\/\/[^\s]+master\.m3u8[^\s]*?(\?[^"]*)?/; + const m3u8Match = unpackedScript.match(m3u8Regex2); + if (m3u8Match) { + return m3u8Match[0]; + } else { + console.log("No M3U8 URL found"); + return null; + } +} + + +/* REMOVE_START */ + + +class Unbaser { + constructor(base) { + this.ALPHABET = { + 62: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", + 95: "' !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'", + }; + this.dictionary = {}; + this.base = base; + if (36 < base && base < 62) { + this.ALPHABET[base] = this.ALPHABET[base] || + this.ALPHABET[62].substr(0, base); + } + if (2 <= base && base <= 36) { + this.unbase = (value) => parseInt(value, base); + } + else { + try { + [...this.ALPHABET[base]].forEach((cipher, index) => { + this.dictionary[cipher] = index; + }); + } + catch (er) { + throw Error("Unsupported base encoding."); + } + this.unbase = this._dictunbaser; + } + } + _dictunbaser(value) { + let ret = 0; + [...value].reverse().forEach((cipher, index) => { + ret = ret + ((Math.pow(this.base, index)) * this.dictionary[cipher]); + }); + return ret; + } +} + + +function unpack(source) { + let { payload, symtab, radix, count } = _filterargs(source); + if (count != symtab.length) { + throw Error("Malformed p.a.c.k.e.r. symtab."); + } + let unbase; + try { + unbase = new Unbaser(radix); + } + catch (e) { + throw Error("Unknown p.a.c.k.e.r. encoding."); + } + function lookup(match) { + const word = match; + let word2; + if (radix == 1) { + word2 = symtab[parseInt(word)]; + } + else { + word2 = symtab[unbase.unbase(word)]; + } + return word2 || word; + } + source = payload.replace(/\b\w+\b/g, lookup); + return _replacestrings(source); + function _filterargs(source) { + const juicers = [ + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\), *(\d+), *(.*)\)\)/, + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\)/, + ]; + for (const juicer of juicers) { + const args = juicer.exec(source); + if (args) { + let a = args; + if (a[2] == "[]") { + } + try { + return { + payload: a[1], + symtab: a[4].split("|"), + radix: parseInt(a[2]), + count: parseInt(a[3]), + }; + } + catch (ValueError) { + throw Error("Corrupted p.a.c.k.e.r. data."); + } + } + } + throw Error("Could not make sense of p.a.c.k.e.r data (unexpected code structure)"); + } + function _replacestrings(source) { + return source; + } +} + + +/** + * Uses Sora's fetchv2 on ipad, fallbacks to regular fetch on Windows + * @author ShadeOfChaos + * + * @param {string} url The URL to make the request to. + * @param {object} [options] The options to use for the request. + * @param {object} [options.headers] The headers to send with the request. + * @param {string} [options.method='GET'] The method to use for the request. + * @param {string} [options.body=null] The body of the request. + * + * @returns {Promise<Response|null>} The response from the server, or null if the + * request failed. + */ +async function soraFetch(url, options = { headers: {}, method: 'GET', body: null }) { + try { + return await fetchv2(url, options.headers ?? {}, options.method ?? 'GET', options.body ?? null); + } catch(e) { + try { + return await fetch(url, options); + } catch(error) { + return null; + } + } +} +/* REMOVE_END */ + +/* SCHEME END */ \ No newline at end of file diff --git a/funmovieslix/funmovieslix.json b/funmovieslix/funmovieslix.json new file mode 100644 index 0000000..d314034 --- /dev/null +++ b/funmovieslix/funmovieslix.json @@ -0,0 +1,19 @@ +{ + "sourceName": "FunMoviesLix", + "iconUrl": "https://funmovieslix.com/wp-content/uploads/2023/12/cropped-download.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "Hindi", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://funmovieslix.com/", + "searchBaseUrl": "https://funmovieslix.com/", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/funmovieslix/funmovieslix.js", + "type": "shows/movies", + "asyncJS": true, + "softsub": false, + "downloadSupport": false +} diff --git a/gnulahd/gnulahd.js b/gnulahd/gnulahd.js new file mode 100644 index 0000000..025efc9 --- /dev/null +++ b/gnulahd/gnulahd.js @@ -0,0 +1,358 @@ +async function searchResults(keyword) { + const results = []; + try { + const response = await fetchv2("https://ww3.gnulahd.nu/?s=" + keyword); + const html = await response.text(); + + const regex = /<a href="([^"]+)"[^>]*itemprop="url"[\s\S]*?<img src="(https:\/\/i[0-9]+\.wp\.com\/[^"]+)"[^>]*>[\s\S]*?<h2[^>]*itemprop="headline">([^<]+)<\/h2>/gi; + + let match; + while ((match = regex.exec(html)) !== null) { + results.push({ + href: match[1].trim(), + image: match[2].trim(), + title: 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 match = html.match(/<div class="mindesc">\s*<p>([\s\S]*?)<\/p>\s*<\/div>/); + const description = match ? match[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 = /<li[^>]*>\s*<a href="([^"]+)">/g; + let match; + let count = 1; + while ((match = regex.exec(html)) !== null) { + results.push({ + href: match[1].trim(), + number: count + }); + count++; + } + + return JSON.stringify(results); + } catch (err) { + return JSON.stringify([{ + href: "Error", + number: "Error" + }]); + } +} + +async function extractStreamUrl(url) { + const dummyLink = "https://files.catbox.moe/avolvc.mp4"; + + try { + const response = await fetchv2(url); + const html = await response.text(); + const iframeMatch = html.match(/<iframe[^>]+src="([^"]+embed\.php[^"]*)"[^>]*>/i); + + if (!iframeMatch) { + return dummyLink; + } + + const fjireo = await fetchv2(iframeMatch[1]); + const kitri = await fjireo.text(); + + const videoArrayMatches = kitri.match(/var videos(\w+) = (\[.*?\]);/g); + + if (!videoArrayMatches) { + console.log("Could not find video arrays"); + return dummyLink; + } + + const providers = {}; + + function processVideoArray(videoArrayString, language) { + try { + const videoArray = JSON.parse(videoArrayString); + + videoArray.forEach(([providerName, url]) => { + const idMatch = url.match(/id=([A-Za-z0-9+/=]+)/); + if (idMatch) { + const base64Id = idMatch[1]; + const decodedUrl = atob(base64Id); + + if (decodedUrl.includes('filemoon.to')) { + let key = decodedUrl; + let counter = 1; + while (providers[key]) { + key = `${decodedUrl}#${counter}`; + counter++; + } + providers[key] = language; + } + } + }); + } catch (error) { + console.error(`Error processing ${language} video array:`, error); + } + } + + videoArrayMatches.forEach(match => { + const arrayMatch = match.match(/var videos(\w+) = (\[.*?\]);/); + if (arrayMatch) { + const language = arrayMatch[1].toLowerCase(); + const arrayString = arrayMatch[2]; + processVideoArray(arrayString, language); + } + }); + + const streams = []; + + for (const [filemoonUrl, language] of Object.entries(providers)) { + try { + console.log(`Processing ${filemoonUrl} for language: ${language}`); + + const filemoonResponse = await fetchv2(filemoonUrl); + const filemoonHtml = await filemoonResponse.text(); + + const m3u8Url = await filemoonExtractor(filemoonHtml, filemoonUrl); + + if (m3u8Url) { + const cleanLanguage = language.replace(/#\d+$/, '').toUpperCase(); + streams.push(cleanLanguage, m3u8Url); + console.log(`Successfully extracted: ${m3u8Url} for ${cleanLanguage}`); + } else { + console.log(`Failed to extract m3u8 URL from ${filemoonUrl}`); + } + } catch (error) { + console.error(`Error processing ${filemoonUrl}:`, error); + } + } + + const final = { + streams, + subtitles: "" + }; + + console.log("RETURN: " + JSON.stringify(final)); + + if (streams.length > 0) { + return JSON.stringify(final); + } else { + return JSON.stringify({ + streams: [], + subtitles: "" + }); + } + + } catch (err) { + console.error("Error in extractStreamUrl:", err); + return dummyLink; + } +} + +/* SCHEME START */ +/* {REQUIRED PLUGINS: unbaser} */ + +/** + * @name filemoonExtractor + * @author Cufiy - Inspired by Churly + */ + +async function filemoonExtractor(html, url = null) { + // check if contains iframe, if does, extract the src and get the url + const regex = /<iframe[^>]+src="([^"]+)"[^>]*><\/iframe>/; + const match = html.match(regex); + if (match) { + console.log("Iframe URL: " + match[1]); + const iframeUrl = match[1]; + const iframeResponse = await soraFetch(iframeUrl, { + headers: { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3", + "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", + "Referer": url, + } + }); + console.log("Iframe Response: " + iframeResponse.status); + html = await iframeResponse.text(); + } + // console.log("HTML: " + html); + // get /<script[^>]*>([\s\S]*?)<\/script>/gi + const scriptRegex = /<script[^>]*>([\s\S]*?)<\/script>/gi; + const scripts = []; + let scriptMatch; + while ((scriptMatch = scriptRegex.exec(html)) !== null) { + scripts.push(scriptMatch[1]); + } + // get the script with eval and m3u8 + const evalRegex = /eval\((.*?)\)/; + const m3u8Regex = /m3u8/; + // console.log("Scripts: " + scripts); + const evalScript = scripts.find(script => evalRegex.test(script) && m3u8Regex.test(script)); + if (!evalScript) { + console.log("No eval script found"); + return null; + } + const unpackedScript = unpack(evalScript); + // get the m3u8 url + const m3u8Regex2 = /https?:\/\/[^\s]+master\.m3u8[^\s]*?(\?[^"]*)?/; + const m3u8Match = unpackedScript.match(m3u8Regex2); + if (m3u8Match) { + return m3u8Match[0]; + } else { + console.log("No M3U8 URL found"); + return null; + } +} + + +/* REMOVE_START */ + + +class Unbaser { + constructor(base) { + this.ALPHABET = { + 62: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", + 95: "' !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'", + }; + this.dictionary = {}; + this.base = base; + if (36 < base && base < 62) { + this.ALPHABET[base] = this.ALPHABET[base] || + this.ALPHABET[62].substr(0, base); + } + if (2 <= base && base <= 36) { + this.unbase = (value) => parseInt(value, base); + } + else { + try { + [...this.ALPHABET[base]].forEach((cipher, index) => { + this.dictionary[cipher] = index; + }); + } + catch (er) { + throw Error("Unsupported base encoding."); + } + this.unbase = this._dictunbaser; + } + } + _dictunbaser(value) { + let ret = 0; + [...value].reverse().forEach((cipher, index) => { + ret = ret + ((Math.pow(this.base, index)) * this.dictionary[cipher]); + }); + return ret; + } +} + + +function unpack(source) { + let { payload, symtab, radix, count } = _filterargs(source); + if (count != symtab.length) { + throw Error("Malformed p.a.c.k.e.r. symtab."); + } + let unbase; + try { + unbase = new Unbaser(radix); + } + catch (e) { + throw Error("Unknown p.a.c.k.e.r. encoding."); + } + function lookup(match) { + const word = match; + let word2; + if (radix == 1) { + word2 = symtab[parseInt(word)]; + } + else { + word2 = symtab[unbase.unbase(word)]; + } + return word2 || word; + } + source = payload.replace(/\b\w+\b/g, lookup); + return _replacestrings(source); + function _filterargs(source) { + const juicers = [ + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\), *(\d+), *(.*)\)\)/, + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\)/, + ]; + for (const juicer of juicers) { + const args = juicer.exec(source); + if (args) { + let a = args; + if (a[2] == "[]") { + } + try { + return { + payload: a[1], + symtab: a[4].split("|"), + radix: parseInt(a[2]), + count: parseInt(a[3]), + }; + } + catch (ValueError) { + throw Error("Corrupted p.a.c.k.e.r. data."); + } + } + } + throw Error("Could not make sense of p.a.c.k.e.r data (unexpected code structure)"); + } + function _replacestrings(source) { + return source; + } +} + + +/** + * Uses Sora's fetchv2 on ipad, fallbacks to regular fetch on Windows + * @author ShadeOfChaos + * + * @param {string} url The URL to make the request to. + * @param {object} [options] The options to use for the request. + * @param {object} [options.headers] The headers to send with the request. + * @param {string} [options.method='GET'] The method to use for the request. + * @param {string} [options.body=null] The body of the request. + * + * @returns {Promise<Response|null>} The response from the server, or null if the + * request failed. + */ +async function soraFetch(url, options = { headers: {}, method: 'GET', body: null }) { + try { + return await fetchv2(url, options.headers ?? {}, options.method ?? 'GET', options.body ?? null); + } catch(e) { + try { + return await fetch(url, options); + } catch(error) { + return null; + } + } +} +/* REMOVE_END */ + +/* SCHEME END */ diff --git a/gnulahd/gnulahd.json b/gnulahd/gnulahd.json new file mode 100644 index 0000000..c582d7c --- /dev/null +++ b/gnulahd/gnulahd.json @@ -0,0 +1,19 @@ +{ + "sourceName": "GnulaHD", + "iconUrl": "https://i3.wp.com/ww3.gnulahd.nu/wp-content/uploads/2025/07/cropped-faviconhd3-192x192.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "Spanish (DUB/SUB)", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://ww3.gnulahd.nu/", + "searchBaseUrl": "https://ww3.gnulahd.nu/", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/gnulahd/gnulahd.js", + "type": "anime/shows/movies", + "asyncJS": true, + "softsub": true, + "downloadSupport": false +} diff --git a/gojowtf/gojowtf.js b/gojowtf/gojowtf.js new file mode 100644 index 0000000..db0b704 --- /dev/null +++ b/gojowtf/gojowtf.js @@ -0,0 +1,136 @@ +async function searchResults(keyword) { + const results = []; + const headers = { + 'Referer': 'https://animetsu.to/', + 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36' + }; + + const encodedKeyword = encodeURIComponent(keyword); + const response = await fetchv2(`https://backend.animetsu.to/api/anime/search?query=${encodedKeyword}&page=1&perPage=1000`, headers); + const json = await response.json(); + + json.results.forEach(anime => { + const title = anime.title.english || anime.title.romaji || anime.title.native || "Unknown Title"; + const image = anime.coverImage.large; + const href = `${anime.id}`; + + if (title && href && image) { + results.push({ + title: title, + image: image, + href: href + }); + } else { + console.error("Missing or invalid data in search result item:", { + title, + href, + image + }); + } + }); + + return JSON.stringify(results); +} + +async function extractDetails(id) { + const results = []; + const headers = { + 'Referer': 'https://animetsu.to/', + 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36' + }; + + const response = await fetchv2(`https://backend.animetsu.to/api/anime/info/${id}`, headers); + const json = await response.json(); + + const description = cleanHtmlSymbols(json.description) || "No description available"; + + results.push({ + description: description.replace(/<br>/g, ''), + aliases: 'N/A', + airdate: 'N/A' + }); + + return JSON.stringify(results); +} + +async function extractEpisodes(id) { + const results = []; + const headers = { + 'Referer': 'https://animetsu.to/', + 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36' + }; + + const response = await fetchv2(`https://backend.animetsu.to/api/anime/eps/${id}`, headers); + const json = await response.json(); + + for (const ep of json) { + results.push({ + number: ep.number, + href: `&id=${id}&num=${ep.number}` + }); + } + + return JSON.stringify(results); +} + +async function extractStreamUrl(slug) { + const headers = { + 'Referer': 'https://animetsu.to/', + 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36' + }; + + const fixedSlug = slug.replace('&', '?'); + const streams = []; + + const serverListRes = await fetchv2(`https://backend.animetsu.to/api/anime/servers${fixedSlug}`, headers); + const serverList = await serverListRes.json(); + console.log("Fetched server list: " + JSON.stringify(serverList)); + const unfixedSlug = fixedSlug.replace('?', '&'); + + for (const server of serverList) { + if (server.name?.toLowerCase().includes('zoro') || server.id?.toLowerCase().includes('zoro')) { + console.log(`Skipping Zoro server: ${server.name || server.id}`); + continue; + } + + for (const subType of ['sub', ...(server.hasDub ? ['dub'] : [])]) { + const url = `https://backend.animetsu.to/api/anime/tiddies?server=${server.id}${unfixedSlug}&subType=${subType}`; + console.log("Fetching stream URL:" + url); + const res = await fetchv2(url, headers); + const data = await res.json(); + + if (data?.sources?.length) { + for (const { quality, url: streamUrl } of data.sources) { + const language = subType === 'sub' ? 'HARDSUB' : subType.toUpperCase(); + streams.push(`${server.id} - ${quality} - ${language}`, streamUrl); + } + } + } + } + + const final = { + streams, + subtitles: "" + }; + + console.log("RETURN: " + JSON.stringify(final)); + return JSON.stringify(final); +} + + + + +function cleanHtmlSymbols(string) { + if (!string) return ""; + + return string + .replace(/’/g, "'") + .replace(/–/g, "-") + .replace(/&#[0-9]+;/g, "") + .replace(/\r?\n|\r/g, " ") + .replace(/\s+/g, " ") + .replace(/<i[^>]*>(.*?)<\/i>/g, "$1") + .replace(/<b[^>]*>(.*?)<\/b>/g, "$1") + .replace(/<[^>]+>/g, "") + .trim(); +} diff --git a/gojowtf/gojowtf.json b/gojowtf/gojowtf.json new file mode 100644 index 0000000..73cafaf --- /dev/null +++ b/gojowtf/gojowtf.json @@ -0,0 +1,19 @@ +{ + "sourceName": "Animetsu", + "iconUrl": "https://gitlab.com/50n50/sources/-/raw/main/gojowtf/gojowtf.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "2.0.0", + "language": "English (DUB/SUB)", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://animetsu.to/", + "searchBaseUrl": "https://animetsu.to/", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/gojowtf/gojowtf.js", + "asyncJS": true, + "type": "anime", + "softsub": true, + "note": "" +} diff --git a/gojowtf/gojowtf.png b/gojowtf/gojowtf.png new file mode 100644 index 0000000..a5259e8 Binary files /dev/null and b/gojowtf/gojowtf.png differ diff --git a/hdhub4u/hdhub4u.js b/hdhub4u/hdhub4u.js new file mode 100644 index 0000000..ca1d138 --- /dev/null +++ b/hdhub4u/hdhub4u.js @@ -0,0 +1,158 @@ +async function searchResults(keyword) { + const results = []; + try { + const response = await fetchv2("https://hdhub4u.navy/?s=" + keyword); + const html = await response.text(); + + const regex = /<li class="thumb[^>]*>[\s\S]*?<img src="([^"]+)"[^>]*alt="([^"]+)"[\s\S]*?<a href="([^"]+)"/g; + let match; + + while ((match = regex.exec(html)) !== null) { + const title = cleanTitle(match[2].trim()); + if (!/episode/i.test(title)) { + results.push({ + title: title, + 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 regexTitle = /<h1 class="page-title">[\s\S]*?<span class="material-text">([\s\S]*?)<\/span>/i; + const matchTitle = regexTitle.exec(html); + const titleText = matchTitle ? matchTitle[1].replace(/<[^>]+>/g, "").trim() : ""; + + let description; + if (/episodes/i.test(titleText)) { + description = "SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED - SHOWS NOT SUPPORTED "; + } else { + const regexDesc = /<div class="kno-rdesc">([\s\S]*?)<\/div>/i; + const matchDesc = regexDesc.exec(html); + description = matchDesc ? matchDesc[1].replace(/<[^>]+>/g, "").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) { + try { + const response = await fetchv2(url); + const html = await response.text(); + + const regex = /<a\s+[^>]*href="([^"]+)"[^>]*>([^<]*(?:\d+p|\d+\.\d*(?:GB|MB)|480p|720p|1080p|4K|2160p)[^<]*)<\/a>/gi; + + let matches = []; + let match; + + while ((match = regex.exec(html)) !== null) { + const href = match[1].trim(); + const text = match[2].trim(); + + if (!href.includes('join-our-group') && + !href.includes('telegram') && + !href.includes('whatsapp') && + !text.toLowerCase().includes('join') && + !text.toLowerCase().includes('group')) { + matches.push({ + href: href, + text: text + }); + } + } + + const lastMatch = matches.length > 0 ? matches[matches.length - 1] : null; + + return JSON.stringify([{ + href: lastMatch ? lastMatch.href : "N/A", + number: 1, + text: lastMatch ? lastMatch.text : "N/A" + }]); + + } catch (err) { + console.error('Error extracting episodes:', err); + return JSON.stringify([{ + href: "Error", + number: "Error", + text: "Error" + }]); + } +} + +async function extractStreamUrl(url) { + try { + const response = await fetchv2(url); + const html = await response.text(); + + const regex = /<title>HubDrive \| (.*?)<\/title>/i; + const match = regex.exec(html); + const filename = match ? match[1].trim() : "default.mp4"; + + const baseUrls = ["https://fsl.fastcloud.lol/", "https://fsl.fastcloud.buzz/"]; + let fullUrl = null; + + for (const base of baseUrls) { + const testUrl = base + filename; + try { + const passthroughUrl = "https://passthrough-worker.simplepostrequest.workers.dev/?head=" + encodeURIComponent(testUrl); + const resText = await fetchv2(passthroughUrl).then(r => r.text()); + if (!/Status:404/i.test(resText)) { + fullUrl = testUrl; + break; + } + } catch {} + } + + if (!fullUrl) fullUrl = "https://files.catbox.moe/avolvc.mp4"; + + console.log("Full URL:"+ fullUrl); + return fullUrl; + } catch (err) { + console.log("Full URL:"+ "https://files.catbox.moe/avolvc.mp4"); + return "https://files.catbox.moe/avolvc.mp4"; + } +} + +function cleanTitle(title) { + return title + .replace(/’|’/g, "'") + .replace(/‘|‘/g, "'") + .replace(/“|“/g, '"') + .replace(/”|”/g, '"') + .replace(/–|–/g, "-") + .replace(/—|—/g, "--") + .replace(/…|…/g, "...") + .replace(/&/g, "&") + .replace(/"/g, '"') + .replace(/</g, "<") + .replace(/>/g, ">") + .replace(/ /g, " ") + .replace(/&#[0-9]+;/g, "") + .replace(/\s+/g, " ") + .trim(); +} + diff --git a/hdhub4u/hdhub4u.json b/hdhub4u/hdhub4u.json new file mode 100644 index 0000000..30643da --- /dev/null +++ b/hdhub4u/hdhub4u.json @@ -0,0 +1,19 @@ +{ + "sourceName": "hdhub4u", + "iconUrl": "https://hdhub4u.navy/wp-content/uploads/2021/05/cropped-cropped-1-1-1-2-1-180x180.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "Hindi", + "streamType": "MKV", + "quality": "4K - 1080p", + "baseUrl": "https://hdhub4u.co/", + "searchBaseUrl": "https://hdhub4u.co/", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/hdhub4u/hdhub4u.js", + "type": "shows/movies", + "asyncJS": true, + "softsub": false, + "downloadSupport": false +} diff --git a/helioscans/helioscans.js b/helioscans/helioscans.js new file mode 100644 index 0000000..3caf914 --- /dev/null +++ b/helioscans/helioscans.js @@ -0,0 +1,232 @@ +async function searchResults(keyword) { + try { + const encodedKeyword = encodeURIComponent(keyword); + const url = `https://helioscans.com/series/?q=${encodedKeyword}`; + const response = await soraFetch(url); + const html = await response.text(); + + const results = []; + const regex = /<button[^>]+?title="([^"]+?)"[^>]*?>[\s\S]*?<a href="([^"]+?)"[\s\S]*?background-image:url\(([^)]+)\)/g; + let match; + + while ((match = regex.exec(html)) !== null) { + const title = match[1]; + const href = `https://helioscans.com${match[2]}`; + const rawImage = match[3].replace(/&/g, "&"); + const image = rawImage.startsWith("http") ? rawImage : `https:${rawImage}`; + + results.push({ title, href, image }); + } + + console.log(JSON.stringify(results)); + return JSON.stringify(results); + } catch (error) { + console.error("Error fetching or parsing: " + error); + return JSON.stringify([{ + title: "Error", + href: "", + image: "" + }]); + } +} +extractChapters('https://helioscans.com/series/63a6054296b/'); + +async function extractDetails(url) { + try { + const response = await soraFetch(url); + const htmlText = await response.text(); + + const metaMatch = htmlText.match(/<meta name="description" content="([\s\S]*?)">/i); + const description = metaMatch + ? metaMatch[1].replace(/\s+/g, ' ').trim() + : "No description available"; + + const aliases = 'N/A'; + const airdate = 'N/A'; + + const transformedResults = [{ + description, + aliases, + airdate + }]; + + console.log(JSON.stringify(transformedResults)); + return JSON.stringify(transformedResults); + + } catch (error) { + console.log('Details error:' + error); + return JSON.stringify([{ + description: 'Error loading description', + aliases: 'N/A', + airdate: 'N/A' + }]); + } +} + +async function extractChapters(url) { + try { + const response = await soraFetch(url); + const htmlText = await response.text(); + console.log(htmlText); + + const chapters = []; + const chapterLinkRegex = /<a\s+[^>]*href="([^"]*\/chapter\/[^"]*)"[^>]*>([\s\S]*?)<\/a>/gi; + let linkMatch; + + while ((linkMatch = chapterLinkRegex.exec(htmlText)) !== null) { + const fullLinkHtml = linkMatch[0]; + const href = `https://helioscans.com${linkMatch[1]}`; + + const titleRegex = /<span[^>]*class="[^"]*\btext-sm\b[^"]*\btruncate\b[^"]*"[^>]*>([^<]+)<\/span>/i; + const titleMatch = titleRegex.exec(fullLinkHtml); + const rawTitle = titleMatch ? titleMatch[1].trim() : ""; + + if (!rawTitle) continue; + + const isLocked = /Coin\.svg/i.test(fullLinkHtml); + const title = isLocked ? `${rawTitle} (Locked – 100 credits)` : rawTitle; + + chapters.push({ title, href }); + } + + chapters.sort((a, b) => { + const numA = parseFloat(a.title.match(/Chapter\s+(\d+)/i)?.[1]) || 0; + const numB = parseFloat(b.title.match(/Chapter\s+(\d+)/i)?.[1]) || 0; + return numA - numB; + }); + + chapters.forEach((chapter, index) => { + chapter.number = index + 1; + }); + + console.log(JSON.stringify(chapters)); + return JSON.stringify(chapters); + } catch (error) { + console.error('Fetch error in extractChapters:', error); + return JSON.stringify([{ + href: url, + title: "Error fetching chapters", + number: 0 + }]); + } +} + +async function extractText(url) { + try { + const headers = { + 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36', + 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', + 'Accept-Language': 'en-US,en;q=0.5', + 'Connection': 'keep-alive', + 'Upgrade-Insecure-Requests': '1' + }; + + const response = await soraFetch(url, headers); + const htmlText = await response.text(); + + const startMarker = '<div id="pages"'; + const startIndex = htmlText.indexOf(startMarker); + if (startIndex === -1) { + throw new Error("Pages content div start (<div id=\"pages\") not found"); + } + + const startTagEndIndex = htmlText.indexOf('>', startIndex); + if (startTagEndIndex === -1) { + throw new Error("Could not find the end of the opening <div id=\"pages\"> tag"); + } + + const contentStartIndex = startTagEndIndex + 1; + let depth = 1; + let pos = contentStartIndex; + let endIndex = -1; + + while (depth > 0 && pos < htmlText.length) { + const nextOpenDiv = htmlText.indexOf('<div', pos); + const nextCloseDiv = htmlText.indexOf('</div', pos); + + if (nextCloseDiv === -1) { + break; + } + + if (nextOpenDiv !== -1 && nextOpenDiv < nextCloseDiv) { + depth++; + pos = nextOpenDiv + 4; + } else { + depth--; + if (depth === 0) { + endIndex = nextCloseDiv; + } else { + pos = nextCloseDiv + 5; + } + } + } + + if (endIndex === -1) { + throw new Error("Matching closing </div> for pages content div not found"); + } + + let innerContent = htmlText.substring(contentStartIndex, endIndex); + + innerContent = innerContent.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, ''); + innerContent = innerContent.replace(/<div[^>]*class="[^"]*fixed[^"]*z-\[60\][^"]*top-0[^"]*left-0[^"]*w-full[^"]*h-full[^"]*bg-black\/90[^"]*flex[^"]*justify-center[^"]*items-center[\s\S]*?<\/div>/gi, ''); + + const paragraphRegex = /<p[^>]*>(.*?)<\/p>/gi; + let textContent = ''; + let match; + + while ((match = paragraphRegex.exec(innerContent)) !== null) { + const paragraphText = match[1].replace(/<[^>]*>/g, '').trim(); + if (paragraphText) { + textContent += paragraphText + '\n'; + } + } + + innerContent = innerContent.trim(); + + if (!innerContent && !textContent) { + throw new Error("Chapter text not found or empty after cleaning"); + } + console.log(innerContent || textContent); + return innerContent; + + } catch (error) { + console.error("Fetch error in extractText: " + error.message); + return '<p>Error: This is chapter is locked as early access by the website, you will have to pay on the website or wait for the chapter to be released globally</p>'; + } +} + +async function soraFetch(url, options = { + headers: {}, + method: 'GET', + body: null +}) { + try { + return await fetchv2(url, options.headers ?? {}, options.method ?? 'GET', options.body ?? null); + } catch (e) { + try { + return await fetch(url, options); + } catch (error) { + return null; + } + } +} + +function decodeHtmlEntities(text) { + const entities = { + '—': '—', + '–': '–', + '&': '&', + '<': '<', + '>': '>', + '"': '"', + ''': "'", + '/': '/', + '`': '`', + '=': '=', + ' ': ' ' + }; + + return text.replace(/&#x[\dA-Fa-f]+;|&\w+;/g, (match) => { + return entities[match] || match; + }); +} diff --git a/helioscans/helioscans.json b/helioscans/helioscans.json new file mode 100644 index 0000000..817c001 --- /dev/null +++ b/helioscans/helioscans.json @@ -0,0 +1,19 @@ +{ + "sourceName": "HelioScan", + "iconUrl": "https://wsrv.nl/?url=image.meowing.org/uploads/_9FxZ8P7Tik&w=44", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.1", + "language": "English", + "streamType": "novels", + "quality": "N/A", + "baseUrl": "https://helioscans.com/", + "searchBaseUrl": "https://helioscans.com/%s", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/helioscans/helioscans.js", + "type": "novels", + "asyncJS": true, + "novel": true, + "downloadSupport": false +} diff --git a/hianime/hianime.js b/hianime/hianime.js new file mode 100644 index 0000000..7a22871 --- /dev/null +++ b/hianime/hianime.js @@ -0,0 +1,115 @@ +async function searchResults(keyword) { + try { + const encodedKeyword = encodeURIComponent(keyword); + const responseText = await fetchv2(`https://bshar1865-hianime2.vercel.app/api/v2/hianime/search?q=${encodedKeyword}`); + const data = await responseText.json(); + + console.log("Search results:", data); + + const transformedResults = data.data.animes.map(anime => ({ + title: anime.name, + image: anime.poster, + href: `https://hianime.to/watch/${anime.id}` + })); + + console.log("Transformed results:", transformedResults); + return JSON.stringify(transformedResults); + } catch (error) { + console.log('Fetch error:', error); + return JSON.stringify([{ title: 'Error', image: '', href: '' }]); + } +} + +async function extractDetails(url) { + try { + const match = url.match(/https:\/\/hianime\.to\/watch\/(.+)$/); + const encodedID = match[1]; + const response = await fetchv2(`https://bshar1865-hianime2.vercel.app/api/v2/hianime/anime/${encodedID}`); + const data = await response.json(); + + const animeInfo = data.data.anime.info; + const moreInfo = data.data.anime.moreInfo; + + const transformedResults = [{ + description: animeInfo.description || 'No description available', + aliases: `Duration: ${animeInfo.stats?.duration || 'Unknown'}`, + airdate: `Aired: ${moreInfo?.aired || 'Unknown'}` + }]; + + console.log("Transformed results:", transformedResults); + return JSON.stringify(transformedResults); + } catch (error) { + console.log('Details error:', error); + return JSON.stringify([{ + description: 'Error loading description', + aliases: 'Duration: Unknown', + airdate: 'Aired: Unknown' + }]); + } +} + +async function extractEpisodes(url) { + try { + const match = url.match(/https:\/\/hianime\.to\/watch\/(.+)$/); + const encodedID = match[1]; + const response = await fetchv2(`https://bshar1865-hianime2.vercel.app/api/v2/hianime/anime/${encodedID}/episodes`); + const data = await response.json(); + + const transformedResults = data.data.episodes.map(episode => ({ + href: episode.episodeId, + number: episode.number + })); + + console.log("Transformed results:" + transformedResults); + return JSON.stringify(transformedResults); + } catch (error) { + console.log('Fetch error:', error); + } +} + +async function extractStreamUrl(id) { + try { + const subRes = await fetchv2(`https://animeapiiiii.vercel.app/api/stream?id=${id}&server=hd-1&type=sub`); + const subJson = await subRes.json(); + + const streamSub = subJson.results.streamingLink.link.file; + const englishSubtitles = (subJson.results.streamingLink.tracks || []).find( + track => track.kind === "captions" && track.label.toLowerCase().includes("english") + )?.file || ""; + + let streamDub = null; + try { + const dubRes = await fetchv2(`https://animeapiiiii.vercel.app/api/stream?id=${id}&server=hd-1&type=dub`); + const dubJson = await dubRes.json(); + streamDub = dubJson.results?.streamingLink?.link?.file || null; + } catch (e) { + streamDub = null; + } + + const streams = []; + + if (streamDub) { + streams.push("DUB", streamDub); + } + + if (streamSub) { + streams.push("SUB", streamSub); + } + + const final = { + streams, + subtitles: englishSubtitles + }; + + console.log("RETURN: " + JSON.stringify(final)); + return JSON.stringify(final); + + } catch (error) { + console.log("Error in extractStreamUrl:", error); + return JSON.stringify({ + streams: [], + subtitles: "" + }); + } +} + diff --git a/hianime/hianime.json b/hianime/hianime.json new file mode 100644 index 0000000..eaa6ae6 --- /dev/null +++ b/hianime/hianime.json @@ -0,0 +1,18 @@ +{ + "sourceName": "HiAnime", + "iconUrl": "https://gitlab.com/50n50/sources/-/raw/main/hianime/iconapp.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "3.0.2", + "language": "English (DUB/SUB)", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://megacloud.blog/", + "searchBaseUrl": "https://bshar1865-hianime.vercel.app/api/v2/hianime/search?q=%s", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/hianime/hianime.js", + "type": "anime", + "asyncJS": true, + "softsub": true +} diff --git a/hianime/hianimetemp.js b/hianime/hianimetemp.js new file mode 100644 index 0000000..f18ecd4 --- /dev/null +++ b/hianime/hianimetemp.js @@ -0,0 +1,98 @@ +async function searchResults(keyword) { + try { + const encodedKeyword = encodeURIComponent(keyword); + const responseText = await fetch(`https://bshar1865-hianime.vercel.app/api/v2/hianime/search?q=${encodedKeyword}&language=dub`); + const data = JSON.parse(responseText); + + const filteredAnimes = data.data.animes.filter(anime => anime.episodes.dub !== null); + + + const transformedResults = data.data.animes.map(anime => ({ + title: anime.name, + image: anime.poster, + href: `https://hianime.to/watch/${anime.id}` + })); + + return JSON.stringify(transformedResults); + + } catch (error) { + console.log('Fetch error:', error); + return JSON.stringify([{ title: 'Error', image: '', href: '' }]); + } +} + +async function extractDetails(url) { + try { + const match = url.match(/https:\/\/hianime\.to\/watch\/(.+)$/); + const encodedID = match[1]; + const response = await fetch(`https://bshar1865-hianime.vercel.app/api/v2/hianime/anime/${encodedID}`); + const data = JSON.parse(response); + + const animeInfo = data.data.anime.info; + const moreInfo = data.data.anime.moreInfo; + + const transformedResults = [{ + description: animeInfo.description || 'No description available', + aliases: `Duration: ${animeInfo.stats?.duration || 'Unknown'}`, + airdate: `Aired: ${moreInfo?.aired || 'Unknown'}` + }]; + + return JSON.stringify(transformedResults); + } catch (error) { + console.log('Details error:', error); + return JSON.stringify([{ + description: 'Error loading description', + aliases: 'Duration: Unknown', + airdate: 'Aired: Unknown' + }]); + } +} + +async function extractEpisodes(url) { + try { + const match = url.match(/https:\/\/hianime\.to\/watch\/(.+)$/); + const encodedID = match[1]; + const response = await fetch(`https://bshar1865-hianime.vercel.app/api/v2/hianime/anime/${encodedID}/episodes`); + const data = JSON.parse(response); + + const transformedResults = data.data.episodes.map(episode => ({ + href: `https://hianime.to/watch/${encodedID}?ep=${episode.episodeId.split('?ep=')[1]}`, + number: episode.number + })); + + return JSON.stringify(transformedResults); + + } catch (error) { + console.log('Fetch error:', error); + } +} + +async function extractStreamUrl(url) { + try { + const match = url.match(/https:\/\/hianime\.to\/watch\/(.+)$/); + if (!match) throw new Error("Invalid URL format"); + const encodedID = match[1]; + + const response = await fetch(`https://bshar1865-hianime.vercel.app/api/v2/hianime/episode/sources?animeEpisodeId=${encodedID}&category=dub`); + const responseTwo = await fetch(`https://bshar1865-hianime.vercel.app/api/v2/hianime/episode/sources?animeEpisodeId=${encodedID}&category=sub`); + + const data = JSON.parse(response); + const dataTwo = JSON.parse(responseTwo); + + const hlsSource = data.data.sources.find(source => source.type === 'hls'); + const subtitleTrack = dataTwo.data.tracks?.find(track => track.label === 'English'); + + const result = { + stream: hlsSource ? hlsSource.url : null, + subtitles: subtitleTrack ? subtitleTrack.file : null + }; + + return JSON.stringify(result); + } catch (error) { + console.error('Fetch error:', error); + return null; + } +} + + + diff --git a/hianime/hianimetemp.json b/hianime/hianimetemp.json new file mode 100644 index 0000000..044f8c0 --- /dev/null +++ b/hianime/hianimetemp.json @@ -0,0 +1,18 @@ +{ + "sourceName": "HiAnimeTemp", + "iconUrl": "https://gitlab.com/50n50/sources/-/raw/main/hianime/iconapp.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.4", + "language": "English (DUB + SUB)", + "streamType": "HLS", + "quality": "720p", + "baseUrl": "https://megacloud.blog/", + "searchBaseUrl": "https://bshar1865-hianime.vercel.app/api/v2/hianime/search?q=%s", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/hianime/hianimetemp.js", + "asyncJS": true, + "softsub": true, + "type": "anime" +} diff --git a/hianime/icon.png b/hianime/icon.png new file mode 100644 index 0000000..bdbe538 Binary files /dev/null and b/hianime/icon.png differ diff --git a/hianime/iconapp.png b/hianime/iconapp.png new file mode 100644 index 0000000..894598a Binary files /dev/null and b/hianime/iconapp.png differ diff --git a/honadrama/honadrama.js b/honadrama/honadrama.js new file mode 100644 index 0000000..064716e --- /dev/null +++ b/honadrama/honadrama.js @@ -0,0 +1,124 @@ +async function searchResults(keyword) { + const results = []; + try { + const response = await fetchv2("https://tn.honadrama.us/?s=" + encodeURIComponent(keyword)); + const html = await response.text(); + + const regex = /<div class="movie"><a href="([^"]+)".*?<img src="([^"]+)"[^>]*>.*?<h3>(.*?)<\/h3>/gs; + 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 descriptionMatch = (/<div class="StoryMovie">(.*?)<\/div>/s.exec(html) || [])[1]; + + return JSON.stringify([{ + description: descriptionMatch ? descriptionMatch.trim() : "N/A", + 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="([^"]+)" class="WatchButton">/; + const match = regex.exec(html); + + if (match) { + results.push({ + href: match[1].trim(), + number: 1 + }); + } + + return JSON.stringify(results); + } catch (err) { + return JSON.stringify([{ + href: "Error", + number: "Error" + }]); + } +} + +async function extractStreamUrl(url) { + try { + const response = await fetchv2(url); + const html = await response.text(); + + const serverRegex = /<li\s+([^>]*?)data-server="(\d+)"\s+data-q="(\d+)"[^>]*>/g; + const servers = []; + let match; + while ((match = serverRegex.exec(html)) !== null) { + servers.push({ + server: match[2], + q: match[3] + }); + } + + let uqloadUrl = null; + + for (const s of servers) { + const ajaxUrl = `https://tn.honadrama.us/wp-admin/admin-ajax.php?action=serverPost&server=${s.server}&q=${s.q}`; + const serverResp = await fetchv2(ajaxUrl); + const serverHtml = await serverResp.text(); + + const iframeMatch = /<iframe\s+[^>]*src="([^"]*uqload\.[a-z]{2,3}[^"]*)"/i.exec(serverHtml); + + if (iframeMatch) { + uqloadUrl = iframeMatch[1]; + console.log("[Debug] Uqload iframe found:"+ uqloadUrl); + break; + } + } + + if (!uqloadUrl) { + return "https://files.catbox.moe/avolvc.mp4"; + } + + const uqResp = await fetchv2(uqloadUrl); + const uqHtml = await uqResp.text(); + + const mp4Match = /sources:\s*\["([^"]+\.mp4)"]/i.exec(uqHtml); + if (mp4Match) { + return mp4Match[1]; + } else { + console.log("[Debug] No MP4 found in uqload page, returning default"); + return "https://files.catbox.moe/avolvc.mp4"; + } + + } catch (err) { + console.log("[Error] Fetching stream failed:", err); + return "https://files.catbox.moe/avolvc.mp4"; + } +} + diff --git a/honadrama/honadrama.json b/honadrama/honadrama.json new file mode 100644 index 0000000..5c134bb --- /dev/null +++ b/honadrama/honadrama.json @@ -0,0 +1,18 @@ +{ + "sourceName": "HonaDrama", + "iconUrl": "https://tn.honadrama.us/wp-content/uploads/2023/06/cropped-logo-google-192x192.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "Arabic", + "streamType": "mp4", + "quality": "1080p", + "baseUrl": "https://uqload.cx/", + "searchBaseUrl": "https://uqload.cx/?s=%s", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/honadrama/honadrama.js", + "type": "shows/movies", + "asyncJS": true, + "downloadSupport": false +} diff --git a/iyinghua/iyinghua.js b/iyinghua/iyinghua.js new file mode 100644 index 0000000..9898f44 --- /dev/null +++ b/iyinghua/iyinghua.js @@ -0,0 +1,82 @@ +async function searchResults(keyword) { + const results = []; + const response = await fetchv2(`http://www.iyinghua.com/search/${keyword}/`); + const html = await response.text(); + + const regex = /<a href="(\/show\/\d+\.html)"><img src="(http[^"]+)" alt="([^"]+)"><\/a><h2><a href="[^"]+" title="([^"]+)"/g; + + let match; + while ((match = regex.exec(html)) !== null) { + results.push({ + title: match[4].trim(), + image: match[2].trim(), + href: `http://www.iyinghua.com${match[1].trim()}` + }); + } + + return JSON.stringify(results); +} + +async function extractDetails(url) { + const results = []; + const response = await fetchv2(url); + const html = await response.text(); + + const descriptionRegex = /<div class="info">([^<]+)<\/div>/; + const descriptionMatch = descriptionRegex.exec(html); + const description = descriptionMatch ? descriptionMatch[1].trim() : 'N/A'; + + results.push({ + description: description, + aliases: 'N/A', + airdate: 'N/A' + }); + + return JSON.stringify(results); +} + +async function extractEpisodes(url) { + const results = []; + const response = await fetchv2(url); + const html = await response.text(); + + const episodeRegex = /<li><a href="(\/v\/\d+-([\dpv]+)\.html)" target="_blank">([^<]+)<\/a><\/li>/g; + + let match; + let episodeCount = 0; + + while ((match = episodeRegex.exec(html)) !== null) { + const href = `http://www.iyinghua.com${match[1].trim()}`; + const number = match[2].match(/^\d+$/) ? parseInt(match[2], 10) : null; + + if (number !== null) { + results.push({ href, number }); + } else { + episodeCount++; + } + } + + if (results.length === 0 && episodeCount > 0) { + episodeRegex.lastIndex = 0; + let index = 1; + while ((match = episodeRegex.exec(html)) !== null) { + results.push({ + href: `http://www.iyinghua.com${match[1].trim()}`, + number: index++ + }); + } + } + results.reverse(); + return JSON.stringify(results); +} + +async function extractStreamUrl(url) { + const response = await fetchv2(url); + const html = await response.text(); + console.error(html); + + const streamRegex = /data-vid="([^"]+)"/; + const match = streamRegex.exec(html); + return match ? match[1] : null; + } + diff --git a/iyinghua/iyinghua.json b/iyinghua/iyinghua.json new file mode 100644 index 0000000..1e201dd --- /dev/null +++ b/iyinghua/iyinghua.json @@ -0,0 +1,18 @@ +{ + "sourceName": "Iyinghua", + "iconUrl": "https://files.catbox.moe/mh7uxf.ico", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "Chinese", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "hhttp://www.iyinghua.com/", + "searchBaseUrl": "http://www.iyinghua.com/%s", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/iyinghua/iyinghua.js", + "asyncJS": true, + "type": "anime", + "note": "SOME STUFF IS REGION LOCKED" +} diff --git a/kaido/kaido.js b/kaido/kaido.js new file mode 100644 index 0000000..cbbcad9 --- /dev/null +++ b/kaido/kaido.js @@ -0,0 +1,149 @@ +async function searchResults(keyword) { + const results = []; + try { + const response = await fetchv2("https://kaido.to/search?keyword=" + encodeURIComponent(keyword)); + const html = await response.text(); + + const itemRegex = /<div class="flw-item">([\s\S]*?)<div class="clearfix"><\/div>/g; + let itemMatch; + + while ((itemMatch = itemRegex.exec(html)) !== null) { + const block = itemMatch[1]; + + const hrefMatch = block.match(/<a href="([^"]+)"[^>]*class="film-poster-ahref[^"]*"[^>]*>/); + let href = hrefMatch ? hrefMatch[1].trim() : ""; + if (href && href.includes('?')) { + href = href.split('?')[0]; + } + + const imgMatch = block.match(/<img[^>]*data-src="([^"]+)"[^>]*>/); + const image = imgMatch ? imgMatch[1].trim() : ""; + + const titleMatch = block.match(/<h3 class="film-name">[^>]*<a[^>]*>([^<]+)<\/a>/); + let extractedTitle = titleMatch ? titleMatch[1].trim() : ""; + extractedTitle = cleanTitle(extractedTitle); + + if (href || image || extractedTitle) { + results.push({ + title: extractedTitle, + image, + href + }); + } + } + + return JSON.stringify(results); + } catch (err) { + return JSON.stringify([{ + title: "Error", + image: "Error", + href: "Error" + }]); + } +} + +function cleanTitle(title) { + return title + .replace(/’/g, "'") + .replace(/–/g, "-") + .replace(/&#[0-9]+;/g, ""); +} + + +async function extractDetails(id) { + try { + const response = await fetchv2("https://kaido.to" + id); + const html = await response.text(); + + const descMatch = html.match(/<div class="film-description m-hide">[\s\S]*?<div class="text">([\s\S]*?)<\/div>/); + 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(id) { + const results = []; + try { + const numericIdMatch = id.match(/-(\d+)$/); + const numericId = numericIdMatch ? numericIdMatch[1] : id; + + const response = await fetchv2("https://kaido.to/ajax/episode/list/" + numericId); + const data = await response.json(); + const html = data.html; + + const regex = /<a[^>]*class="ssl-item\s+ep-item"[\s\S]*?data-number="(\d+)"[\s\S]*?href="([^"]+)"[\s\S]*?>[\s\S]*?data-jname="([^"]+)"/g; + + let match; + while ((match = regex.exec(html)) !== null) { + results.push({ + href: match[2].trim(), + number: parseInt(match[1], 10) + }); + } + + return JSON.stringify(results); + } catch (err) { + return JSON.stringify([{ + href: "Error", + number: "Error", + title: "Error" + }]); + } +} + +async function extractStreamUrl(id) { + try { + const epMatch = id.match(/ep=(\d+)$/); + const numericId = epMatch ? epMatch[1] : id; + + const url = "https://kaido.to/ajax/episode/servers?episodeId=" + numericId; + console.log(url); + + const response = await fetchv2(url); + const json = await response.json(); + console.log(JSON.stringify(json)); + + const html = json.html; + const serverMatch = html.match(/<div class="item server-item"[^>]*data-id="(\d+)"[^>]*>\s*<a[^>]*>Vidstreaming<\/a>/); + const vidstreamingId = serverMatch ? serverMatch[1] : null; + + const someResponse = await fetchv2("https://kaido.to/ajax/episode/sources?id=" + vidstreamingId); + const someJson = await someResponse.json(); + console.log(JSON.stringify(someJson)); + + const link = someJson.link; + const codeMatch = link.match(/\/e-1\/([a-zA-Z0-9]+)\?/); + const code = codeMatch ? codeMatch[1] : null; + + const anotherResponse = await fetchv2("https://rapid-cloud.co/embed-2/v2/e-1/getSources?id=" + code); + const anotherJson = await anotherResponse.json(); + console.log(JSON.stringify(anotherJson)); + + const streamFile = anotherJson.sources && anotherJson.sources.length > 0 ? anotherJson.sources[0].file : null; + + let subtitleFile = null; + if (anotherJson.tracks && anotherJson.tracks.length > 0) { + const englishTrack = anotherJson.tracks.find(track => track.label.toLowerCase() === "english"); + if (englishTrack) subtitleFile = englishTrack.file; + } + + const result = { + stream: streamFile, + subtitles: subtitleFile + }; + return JSON.stringify(result); + } catch (err) { + return "https://files.catbox.moe/avolvc.mp4"; + } +} diff --git a/kaido/kaido.json b/kaido/kaido.json new file mode 100644 index 0000000..02e33d2 --- /dev/null +++ b/kaido/kaido.json @@ -0,0 +1,19 @@ +{ + "sourceName": "Kaido", + "iconUrl": "https://kaido.to/images/favicon.png?v=0.1", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "3.0.2", + "language": "English (SUB)", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://rapid-cloud.co/", + "searchBaseUrl": "https://rapid-cloud.co/", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/kaido/kaido.js", + "type": "anime", + "asyncJS": true, + "softsub": true, + "downloadSupport": true +} diff --git a/kawaiifu/kawaiifu.js b/kawaiifu/kawaiifu.js new file mode 100644 index 0000000..23a2a85 --- /dev/null +++ b/kawaiifu/kawaiifu.js @@ -0,0 +1,169 @@ +async function searchResults(keyword) { + const results = []; + try { + const response = await fetchv2("https://kawaiifu.com/search-movie?keyword=" + encodeURIComponent(keyword)+ "&cat-get="); + const html = await response.text(); + + const regex = /<a class="thumb" href="([^"]+)"><img src="([^"]+)"[^>]*alt="([^"]+)"><\/a>/g; + + let match; + while ((match = regex.exec(html)) !== null) { + let href = match[1].trim(); + href = href.replace("https://kawaiifu.com/", "https://domdom.stream/anime/").replace(/\.html$/, ""); + + results.push({ + href: href, + image: match[2].trim(), + title: match[3].trim() + }); + } + + return JSON.stringify(results); + } catch (err) { + return JSON.stringify([{ + title: "Error", + image: "Error", + href: "Error" + }]); + } +} + + +function cleanTitle(title) { + return title + .replace(/’/g, "'") + .replace(/–/g, "-") + .replace(/&#[0-9]+;/g, ""); +} + +async function extractDetails(url) { + try { + const response = await fetchv2(url); + const html = await response.text(); + + const summaryMatch = html.match(/<h5[^>]*>Summary<\/h5>([\s\S]*?)(?=<\/div>|$)/i); + + if (!summaryMatch) { + return JSON.stringify([{ + description: "Description not found", + aliases: "N/A", + airdate: "N/A" + }]); + } + + let description = summaryMatch[1] + .replace(/<[^>]*>/g, '') + .replace(/’/g, "'") + .replace(/ /g, ' ') + .replace(/&/g, '&') + .replace(/\s+/g, ' ') + .trim(); + + if (!description) { + description = "No description available"; + } + + let aliases = "N/A"; + const italicMatch = summaryMatch[1].match(/<i>([^<]+)<\/i>/); + if (italicMatch) { + aliases = italicMatch[1].trim(); + } + + let airdate = "N/A"; + const yearMatch = description.match(/(\d{4})/); + if (yearMatch) { + airdate = yearMatch[1]; + } + + return JSON.stringify([{ + description: description, + aliases: aliases, + airdate: airdate + }]); + + } 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 listRegex = /<ul class="list-ep"[^>]*>([\s\S]*?)<\/ul>/; + const listMatch = html.match(listRegex); + + if (!listMatch) { + return JSON.stringify([]); + } + + const listContent = listMatch[1]; + + const linkRegex = /<a\s+href="([^"]+)"[\s\S]*?>([\s\S]*?)<\/a>/g; + + let match; + while ((match = linkRegex.exec(listContent)) !== null) { + const href = match[1]; + const text = match[2].replace(/\s+/g, ' ').trim(); + + let number = 1; + + const textMatch = text.match(/Ep\s*(\d+)/i); + if (textMatch) { + number = parseInt(textMatch[1], 10); + } + else { + const urlMatch = href.match(/[?&]ep=(\d+)/); + if (urlMatch) { + number = parseInt(urlMatch[1], 10); + } + } + + results.push({ + href: href, + number: number + }); + } + + results.sort((a, b) => a.number - b.number); + + return JSON.stringify(results); + } catch (err) { + console.error('Extract episodes error:', err); + return JSON.stringify([{ + href: "Error", + number: "Error" + }]); + } +} + +async function extractStreamUrl(url) { + try { + const response = await fetchv2(url); + const html = await response.text(); + + const patterns = [ + /<source\s+src="([^"]+\.mp4[^"]*)"[^>]*>/i, + /atr_id="([^"]+\.mp4[^"]*)"[^>]*>/i, + /<video[^>]+src="([^"]+\.mp4[^"]*)"[^>]*>/i + ]; + + for (const pattern of patterns) { + const match = html.match(pattern); + if (match && match[1]) { + return match[1]; + } + } + + return "https://files.catbox.moe/avolvc.mp4"; + + } catch (err) { + return "https://files.catbox.moe/avolvc.mp4"; + } +} diff --git a/kawaiifu/kawaiifu.json b/kawaiifu/kawaiifu.json new file mode 100644 index 0000000..e05b5f1 --- /dev/null +++ b/kawaiifu/kawaiifu.json @@ -0,0 +1,19 @@ +{ + "sourceName": "Kawaiifu", + "iconUrl": "https://kawaiifu.com/wp-content/uploads/2018/05/Kawaiifu_favicon.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "English (DUB/SUB)", + "streamType": "mp4", + "quality": "1080p", + "baseUrl": "https://kawaiifu.com/", + "searchBaseUrl": "https://kawaiifu.com/", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/kawaiifu/kawaiifu.js", + "type": "animes", + "asyncJS": true, + "softsub": false, + "downloadSupport": true +} diff --git a/kawaiines/kawaiines.js b/kawaiines/kawaiines.js new file mode 100644 index 0000000..2612630 --- /dev/null +++ b/kawaiines/kawaiines.js @@ -0,0 +1,82 @@ +async function searchResults(keyword) { + try { + const response = await fetchv2("https://kawaiines.onrender.com/api/anime"); + const data = await response.json(); + + const results = data + .filter(anime => anime.title.toLowerCase().includes(keyword.toLowerCase())) + .map(anime => ({ + title: anime.title, + image: anime.image, + href: anime.animeUrl + })); + + return JSON.stringify(results); + } catch (err) { + console.error(err); + return JSON.stringify([{ + title: "Error", + image: "Error", + href: "Error" + }]); + } +} + +async function extractDetails(id) { + try { + const response = await fetchv2(`https://kawaiines.onrender.com/api/anime/url/${id}`); + const json = await response.json(); + + return JSON.stringify([{ + description: json.description || "N/A", + aliases: "N/A", + airdate: json.date || "N/A" + }]); + } catch (err) { + return JSON.stringify([{ + description: "Error", + aliases: "Error", + airdate: "Error" + }]); + } +} + +async function extractEpisodes(id) { + const results = []; + try { + const response = await fetchv2(`https://kawaiines.onrender.com/api/anime/url/${id}`); + const json = await response.json(); + + for (const [number, url] of Object.entries(json.videoIds)) { + if (url.includes("drive.google.com")) continue; + + let href = url; + if (url.includes("strmup.cc/")) { + href = url.split("/").pop(); + } + + results.push({ + href: href, + number: parseInt(number, 10) + }); + } + + return JSON.stringify(results); + } catch (err) { + return JSON.stringify([{ + href: "Error", + number: "Error" + }]); + } +} + +async function extractStreamUrl(id) { + try { + const response = await fetchv2(`https://strmup.cc/ajax/stream?filecode=${id}`); + const json = await response.json(); + + return json.streaming_url || "https://error.org/"; + } catch (err) { + return "https://error.org/"; + } +} diff --git a/kawaiines/kawaiines.json b/kawaiines/kawaiines.json new file mode 100644 index 0000000..47595f0 --- /dev/null +++ b/kawaiines/kawaiines.json @@ -0,0 +1,19 @@ +{ + "sourceName": "Kawaiines", + "iconUrl": "https://kawaiines.in/logo.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "Hindi", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://kawaiines.in/", + "searchBaseUrl": "https://kawaiines.in/", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/kawaiines/kawaiines.js", + "type": "anime", + "asyncJS": true, + "softsub": false, + "downloadSupport": false +} diff --git a/kimcartoon/kimcartoon.js b/kimcartoon/kimcartoon.js new file mode 100644 index 0000000..0b964b1 --- /dev/null +++ b/kimcartoon/kimcartoon.js @@ -0,0 +1,115 @@ +async function searchResults(keyword) { + const searchUrl = `https://kimcartoon.com.co/?s=${encodeURIComponent(keyword)}`; + try { + const response = await fetch(searchUrl); + const html = await response; + const results = []; + const articleRegex = /<article[^>]*class="bs styletwo"[\s\S]*?<\/article>/g; + const items = html.match(articleRegex) || []; + + function cleanTitle(title) { + return title + .replace(/’/g, "'") + .replace(/–/g, "-") + .replace(/&#[0-9]+;/g, ""); + } + + items.forEach((itemHtml) => { + const titleMatch = itemHtml.match(/<a[^>]*href="([^"]+)"[^>]*title="([^"]+)"/); + const imgMatch = itemHtml.match(/<img[^>]*src="([^"]+)"/); + if (!titleMatch || !imgMatch) return; + const href = `${titleMatch[1].trim()}?video_index=2`; + const title = cleanTitle(titleMatch[2].trim()); + const imageUrl = imgMatch[1].trim(); + results.push({ title, image: imageUrl, href }); + }); + + console.log(JSON.stringify(results)); + return JSON.stringify(results); + } catch (error) { + throw error; + } +} + +async function extractDetails(url) { + const response = await fetch(url); + const html = await response; + const details = []; + const descriptionMatch = html.match(/<div class="entry-content" itemprop="description">\s*<p>(.*?)<\/p>/); + const description = descriptionMatch ? descriptionMatch[1].trim() : `N/A`; + + details.push({ + description, + alias: 'N/A', + airdate: 'N/A' + }); + + console.log(JSON.stringify(details)); + return JSON.stringify(details); +} +async function extractEpisodes(url) { + const response = await fetch(url); + const html = await response; + const episodes = []; + + const allMatches = [...html.matchAll(/<li[^>]*>\s*<a href="([^"]+)">\s*<div class="epl-title">([^<]*) <\/div>/g)]; + + for (const match of allMatches) { + const href = match[1].trim(); + const title = match[2].trim(); + + if (title.startsWith("Episode")) { + const numberMatch = title.match(/Episode (\d+)/); + if (numberMatch && numberMatch[1]) { + episodes.push({ + href: href, + number: parseInt(numberMatch[1], 10) + }); + } + } else { + episodes.push({ + href: href, + number: 1 + }); + } + } + + episodes.reverse(); + console.log(JSON.stringify(episodes)); + return JSON.stringify(episodes); +} + +async function extractStreamUrl(url) { + const embedResponse = await fetch(url); + const data = await embedResponse; + + const embedMatch = data.match(/<div class="pembed" data-embed="(.*?)"/); + if (embedMatch && embedMatch[1]) { + let embedUrl = embedMatch[1].trim(); + + let fullEmbedUrl; + if (embedUrl.startsWith('//')) { + fullEmbedUrl = 'https:' + embedUrl; + } else if (embedUrl.startsWith('http://') || embedUrl.startsWith('https://')) { + fullEmbedUrl = embedUrl; + } else { + fullEmbedUrl = 'https://' + embedUrl; + } + + console.log(fullEmbedUrl); + const embedPageResponse = await fetch(fullEmbedUrl); + const embedPageData = await embedPageResponse; + + console.log(embedPageData); + const m3u8Match = embedPageData.match(/sources:\s*\[\{file:"(https:\/\/[^"]*\.m3u8)"/); + if (m3u8Match && m3u8Match[1]) { + const m3u8Url = m3u8Match[1]; + console.log(m3u8Url); + return m3u8Url; + } else { + throw new Error("M3U8 URL not found."); + } + } else { + throw new Error("Embed URL not found."); + } +} diff --git a/kimcartoon/kimcartoon.json b/kimcartoon/kimcartoon.json new file mode 100644 index 0000000..4eb3316 --- /dev/null +++ b/kimcartoon/kimcartoon.json @@ -0,0 +1,17 @@ +{ + "sourceName": "KimCartoon", + "iconUrl": "https://i2.wp.com/kimcartoon.com.co/wp-content/uploads/2023/03/favicon.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "English (DUB)", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://vidmoly.to/", + "searchBaseUrl": "https://kimcartoon.com.co/?s=%s", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/kimcartoon/kimcartoon.js", + "asyncJS": true, + "type": "anime/shows/movies" +} diff --git a/kissasian/kissasian.js b/kissasian/kissasian.js new file mode 100644 index 0000000..74c470b --- /dev/null +++ b/kissasian/kissasian.js @@ -0,0 +1,222 @@ +async function searchResults(keyword) { + const results = []; + const response = await fetchv2(`https://kissasian.cam/?s=${keyword}`); + const html = await response.text(); + + const regex = /<article class="bs"[^>]*>.*?<a href="([^"]+)"[^>]*>.*?<img src="([^"]+)"[^>]*>.*?<h2[^>]*>(.*?)<\/h2>/gs; + + 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); +} + +async function extractDetails(url) { + const results = []; + const response = await fetchv2(url); + const html = await response.text(); + + const match = html.match(/<div class="entry-content"[^>]*>([\s\S]*?)<\/div>/); + + let description = "N/A"; + if (match) { + description = match[1] + .replace(/<[^>]+>/g, '') + .replace(/&#(\d+);/g, (_, code) => String.fromCharCode(code)) + .replace(/"/g, '"') + .replace(/'/g, "'") + .replace(/&/g, "&") + .trim(); + } + + results.push({ + description: description, + aliases: 'N/A', + airdate: 'N/A' + }); + + return JSON.stringify(results); +} + +async function extractEpisodes(url) { + const results = []; + const response = await fetchv2(url); + const html = await response.text(); + + const regex = /<a href="([^"]+)">\s*<div class="epl-num">([\d.]+)<\/div>/g; + + let match; + while ((match = regex.exec(html)) !== null) { + results.push({ + href: match[1].trim(), + number: parseInt(match[2], 10) + }); + } + results.reverse(); + return JSON.stringify(results); +} + +async function extractStreamUrl(url) { + try { + const response = await fetchv2(url); + const html = await response.text(); + + const iframeMatch = html.match(/<iframe[^>]+src="(https?:\/\/[^"]*justplay[^"]*)"/i); + if (iframeMatch && iframeMatch[1]) { + + const headers = { + 'Referer': 'https://kissasian.cam/' + }; + const response2 = await fetchv2(iframeMatch[1], headers); + const html2 = await response2.text(); + + const iframeMatch2 = html2.match(/<iframe[^>]+src="(https?:\/\/[^"]*zjet7[^"]*)"/i); + if (iframeMatch2 && iframeMatch2[1]) { + const response3 = await fetchv2(iframeMatch2[1]); + const html3 = await response3.text(); + + const obfuscatedScript = html3.match(/<script[^>]*>\s*(eval\(function\(p,a,c,k,e,d.*?\)[\s\S]*?)<\/script>/); + const unpackedScript = unpack(obfuscatedScript[1]); + const fileMatch = unpackedScript.match(/file\s*:\s*"([^"]*\.m3u8[^"]*)"/i); + const fileUrl = fileMatch ? fileMatch[1] : null; + console.log('m3u8: '+ fileUrl); + + return fileUrl; + } + + return "https://error.org/"; + } + + return "https://error.org/"; + } catch (err) { + console.error(err); + return "https://error.org/"; + } +} + + +/*********************************************************** + * UNPACKER MODULE + * Credit to GitHub user "mnsrulz" for Unpacker Node library + * https://github.com/mnsrulz/unpacker + ***********************************************************/ +class Unbaser { + constructor(base) { + /* Functor for a given base. Will efficiently convert + strings to natural numbers. */ + this.ALPHABET = { + 62: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", + 95: "' !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'", + }; + this.dictionary = {}; + this.base = base; + // fill elements 37...61, if necessary + if (36 < base && base < 62) { + this.ALPHABET[base] = this.ALPHABET[base] || + this.ALPHABET[62].substr(0, base); + } + // If base can be handled by int() builtin, let it do it for us + if (2 <= base && base <= 36) { + this.unbase = (value) => parseInt(value, base); + } + else { + // Build conversion dictionary cache + try { + [...this.ALPHABET[base]].forEach((cipher, index) => { + this.dictionary[cipher] = index; + }); + } + catch (er) { + throw Error("Unsupported base encoding."); + } + this.unbase = this._dictunbaser; + } + } + _dictunbaser(value) { + /* Decodes a value to an integer. */ + let ret = 0; + [...value].reverse().forEach((cipher, index) => { + ret = ret + ((Math.pow(this.base, index)) * this.dictionary[cipher]); + }); + return ret; + } +} + +function detect(source) { + /* Detects whether `source` is P.A.C.K.E.R. coded. */ + return source.replace(" ", "").startsWith("eval(function(p,a,c,k,e,"); +} + +function unpack(source) { + /* Unpacks P.A.C.K.E.R. packed js code. */ + let { payload, symtab, radix, count } = _filterargs(source); + if (count != symtab.length) { + throw Error("Malformed p.a.c.k.e.r. symtab."); + } + let unbase; + try { + unbase = new Unbaser(radix); + } + catch (e) { + throw Error("Unknown p.a.c.k.e.r. encoding."); + } + function lookup(match) { + /* Look up symbols in the synthetic symtab. */ + const word = match; + let word2; + if (radix == 1) { + //throw Error("symtab unknown"); + word2 = symtab[parseInt(word)]; + } + else { + word2 = symtab[unbase.unbase(word)]; + } + return word2 || word; + } + source = payload.replace(/\b\w+\b/g, lookup); + return _replacestrings(source); + function _filterargs(source) { + /* Juice from a source file the four args needed by decoder. */ + const juicers = [ + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\), *(\d+), *(.*)\)\)/, + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\)/, + ]; + for (const juicer of juicers) { + //const args = re.search(juicer, source, re.DOTALL); + const args = juicer.exec(source); + if (args) { + let a = args; + if (a[2] == "[]") { + //don't know what it is + // a = list(a); + // a[1] = 62; + // a = tuple(a); + } + try { + return { + payload: a[1], + symtab: a[4].split("|"), + radix: parseInt(a[2]), + count: parseInt(a[3]), + }; + } + catch (ValueError) { + throw Error("Corrupted p.a.c.k.e.r. data."); + } + } + } + throw Error("Could not make sense of p.a.c.k.e.r data (unexpected code structure)"); + } + function _replacestrings(source) { + /* Strip string lookup table (list) and replace values in source. */ + /* Need to work on this. */ + return source; + } +} + diff --git a/kissasian/kissasian.json b/kissasian/kissasian.json new file mode 100644 index 0000000..a6b39b9 --- /dev/null +++ b/kissasian/kissasian.json @@ -0,0 +1,19 @@ +{ + "sourceName": "KissAsian", + "iconUrl": "https://kissasian.cam/wp-content/uploads/2020/02/cropped-icon-192x192.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "Chinese", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://zjet7.com", + "searchBaseUrl": "https://zjet7.com", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/kissasian/kissasian.js", + "type": "shows/movies", + "asyncJS": true, + "softsub": false, + "downloadSupport": false +} diff --git a/kisscartoon/kisscartoon.js b/kisscartoon/kisscartoon.js new file mode 100644 index 0000000..506fcc4 --- /dev/null +++ b/kisscartoon/kisscartoon.js @@ -0,0 +1,121 @@ +async function searchResults(keyword) { + const results = []; + const regex = /<div title='.*?<img .*?src="(.*?)".*?>.*?<a class="item_movies_link" href="(.*?)">(.*?)<\/a>/gs; + + try { + const response = await fetchv2("https://kisscartoon.sh/Search/?s=" + encodeURIComponent(keyword)); + const html = await response.text(); + + let match; + while ((match = regex.exec(html)) !== null) { + results.push({ + image: match[1].trim(), + href: match[2].trim(), + title: match[3].replace(/<.*?>/g, '').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 match = html.match(/<div class="summary">\s*<p>(.*?)<\/p>\s*<\/div>/s); + const description = match ? match[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 = []; + + const regex = /<div>\s*<div>\s*<h3>\s*<a href="(.*?)" title=".*?">/gs; + + const dateRegex = /<div>\s*<div>\s*<h3>.*?<\/h3>\s*<\/div>\s*<div>(.*?)<\/div>/s; + + try { + const response = await fetchv2(url); + const html = await response.text(); + + let match; + let count = 1; + while ((match = regex.exec(html)) !== null) { + results.push({ + href: match[1].trim(), + number: count++ + }); + } + + return JSON.stringify(results); + } catch (err) { + return JSON.stringify([{ + href: "Error", + number: "Error", + airdate: "Error" + }]); + } +} + +async function extractStreamUrl(url) { + try { + const idMatch = url.match(/id=(\d+)/); + const id = idMatch ? idMatch[1] : null; + + const headers = { + 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', + 'X-Requested-With': 'XMLHttpRequest', + 'Referer': url, + 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3' + }; + + const postData = `episode_id=${id}`; + const response = await fetchv2("https://kisscartoon.sh/ajax/anime/load_episodes_v2?s=tserver", headers, 'POST', postData); + const json = await response.json(); + + const iframeMatch = json.value.match(/<iframe .*?src="(.*?)"/); + const iframeSrc = iframeMatch ? iframeMatch[1] : null; + + if (!iframeSrc) return "https://error.org/"; + + const headers2 = { + 'Referer': "https://kisscartoon.sh", + 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3' + }; + const iframeResponse = await fetchv2(iframeSrc, headers2); + const iframeHtml = await iframeResponse.text(); + + const sourcesMatch = iframeHtml.match(/sources:\s*(\[\{.*?\}\])/s); + if (!sourcesMatch) return "https://error.org/"; + + const sources = JSON.parse(sourcesMatch[1]); + const fileUrl = sources.length > 0 ? sources[0].file : null; + + return fileUrl || "https://error.org/"; + } catch (err) { + return "https://error.org/"; + } +} + + + diff --git a/kisscartoon/kisscartoon.json b/kisscartoon/kisscartoon.json new file mode 100644 index 0000000..44b356c --- /dev/null +++ b/kisscartoon/kisscartoon.json @@ -0,0 +1,20 @@ +{ + "sourceName": "KissCartoon", + "iconUrl": "https://files.catbox.moe/ajv0go.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "English", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://kisscartoon.sh/", + "searchBaseUrl": "https://kisscartoon.sh/", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/kisscartoon/kisscartoon.js", + "type": "shows/movies", + "asyncJS": true, + "softsub": false, + "downloadSupport": false, + "note": "Only works with nPlayer: https://nplayer.com/" +} diff --git a/lmanime/lmanime.js b/lmanime/lmanime.js new file mode 100644 index 0000000..1e5866e --- /dev/null +++ b/lmanime/lmanime.js @@ -0,0 +1,115 @@ +async function searchResults(keyword) { + const results = []; + const response = await fetchv2(`https://lmanime.com/?s=${keyword}`); + const html = await response.text(); + + const regex = /<article class="bs"[^>]*>.*?<a href="([^"]+)"[^>]*>.*?<img src="([^"]+)"[^>]*>.*?<h2[^>]*>(.*?)<\/h2>/gs; + + 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); +} + +async function extractDetails(url) { + const results = []; + const response = await fetchv2(url); + const html = await response.text(); + + const match = html.match(/<div class="entry-content"[^>]*>([\s\S]*?)<\/div>/); + + let description = "N/A"; + if (match) { + description = match[1] + .replace(/<[^>]+>/g, '') + .replace(/&#(\d+);/g, (_, code) => String.fromCharCode(code)) + .replace(/"/g, '"') + .replace(/'/g, "'") + .replace(/&/g, "&") + .trim(); + } + + results.push({ + description: description, + aliases: 'N/A', + airdate: 'N/A' + }); + + return JSON.stringify(results); +} + +async function extractEpisodes(url) { + const results = []; + const response = await fetchv2(url); + const html = await response.text(); + + const regex = /<a href="([^"]+)">\s*<div class="epl-num">([\d.]+)<\/div>/g; + + let match; + while ((match = regex.exec(html)) !== null) { + results.push({ + href: match[1].trim(), + number: parseInt(match[2], 10) + }); + } + results.reverse(); + return JSON.stringify(results); +} + +async function extractStreamUrl(url) { + try { + const response = await fetchv2(url); + const html = await response.text(); + + const iframeMatch = html.match(/dailymotion\.com\/embed\/video\/([a-zA-Z0-9]+)/); + if (!iframeMatch) return JSON.stringify({ streams: [], subtitles: "" }); + + const videoId = iframeMatch[1]; + + const metaRes = await fetchv2(`https://www.dailymotion.com/player/metadata/video/${videoId}`); + const metaJson = await metaRes.json(); + const hlsLink = metaJson.qualities?.auto?.[0]?.url; + if (!hlsLink) return JSON.stringify({ streams: [], subtitles: "" }); + + async function getBestHls(hlsUrl) { + try { + const res = await fetchv2(hlsUrl); + const text = await res.text(); + const regex = /#EXT-X-STREAM-INF:.*RESOLUTION=(\d+)x(\d+).*?\n(https?:\/\/[^\n]+)/g; + const streams = []; + let match; + while ((match = regex.exec(text)) !== null) { + streams.push({ width: parseInt(match[1]), height: parseInt(match[2]), url: match[3] }); + } + if (streams.length === 0) return hlsUrl; + streams.sort((a, b) => b.height - a.height); + return streams[0].url; + } catch { + return hlsUrl; + } + } + + const bestHls = await getBestHls(hlsLink); + + const subtitles = metaJson.subtitles?.data?.['en-auto']?.urls?.[0] || ""; + + const result = { + streams: ["english", bestHls], + subtitles: subtitles + }; + + console.log("Extracted stream result:" + JSON.stringify(result)); + + return JSON.stringify(result); + } catch { + const empty = { streams: [], subtitles: "" }; + console.log("Extracted stream result:" + JSON.stringify(empty)); + return JSON.stringify(empty); + } +} diff --git a/lmanime/lmanime.json b/lmanime/lmanime.json new file mode 100644 index 0000000..a3c213f --- /dev/null +++ b/lmanime/lmanime.json @@ -0,0 +1,19 @@ +{ + "sourceName": "LmAnime", + "iconUrl": "https://lmanime.com/wp-content/uploads/2022/09/cropped-site-icon-192x192.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "English", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://lmanime.com/", + "searchBaseUrl": "https://lmanime.com/", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/lmanime/lmanime.js", + "type": "anime", + "asyncJS": true, + "softsub": true, + "downloadSupport": false +} diff --git a/luciferdonghua/luciferdonghua.js b/luciferdonghua/luciferdonghua.js new file mode 100644 index 0000000..67dedfe --- /dev/null +++ b/luciferdonghua/luciferdonghua.js @@ -0,0 +1,125 @@ +function cleanTitle(title) { + return title + .replace(/’/g, "'") + .replace(/–/g, "-") + .replace(/&#[0-9]+;/g, ""); +} + +async function searchResults(keyword) { + const results = []; + const response = await fetchv2(`https://luciferdonghua.in/?s=${keyword}`); + const html = await response.text(); + + const regex = /<article class="bs"[^>]*>.*?<a href="([^"]+)"[^>]*>.*?<img src="([^"]+)"[^>]*>.*?<h2[^>]*>(.*?)<\/h2>/gs; + + let match; + while ((match = regex.exec(html)) !== null) { + results.push({ + title: cleanTitle(match[3].trim()), + image: match[2].trim(), + href: match[1].trim() + }); + } + + return JSON.stringify(results); +} + +async function extractDetails(url) { + const results = []; + const response = await fetchv2(url); + const html = await response.text(); + + const match = html.match(/<div class="entry-content"[^>]*>([\s\S]*?)<\/div>/); + + let description = "N/A"; + if (match) { + description = match[1] + .replace(/<[^>]+>/g, '') + .replace(/&#(\d+);/g, (_, code) => String.fromCharCode(code)) + .replace(/"/g, '"') + .replace(/'/g, "'") + .replace(/&/g, "&") + .trim(); + } + + results.push({ + description: description, + aliases: 'N/A', + airdate: 'N/A' + }); + + return JSON.stringify(results); +} + +async function extractEpisodes(url) { + const results = []; + const response = await fetchv2(url); + const html = await response.text(); + + const regex = /<li data-index="\d+">[\s\S]*?<a href="([^"]+)">/g; + + let match; + let count = 1; + while ((match = regex.exec(html)) !== null) { + results.push({ + href: match[1].trim(), + number: count + }); + count++; + } + + results.reverse(); + return JSON.stringify(results.reverse()); +} + + +async function extractStreamUrl(url) { + try { + const response = await fetchv2(url); + const html = await response.text(); + + const iframeMatch = html.match(/<meta itemprop="embedUrl" content="https?:\/\/geo\.dailymotion\.com\/player\/[^?]+\.html\?video=([a-zA-Z0-9]+)"/); + if (!iframeMatch) return JSON.stringify({ streams: [], subtitles: "" }); + + const videoId = iframeMatch[1]; + + const metaRes = await fetchv2(`https://www.dailymotion.com/player/metadata/video/${videoId}`); + const metaJson = await metaRes.json(); + const hlsLink = metaJson.qualities?.auto?.[0]?.url; + if (!hlsLink) return JSON.stringify({ streams: [], subtitles: "" }); + + async function getBestHls(hlsUrl) { + try { + const res = await fetchv2(hlsUrl); + const text = await res.text(); + const regex = /#EXT-X-STREAM-INF:.*RESOLUTION=(\d+)x(\d+).*?\n(https?:\/\/[^\n]+)/g; + const streams = []; + let match; + while ((match = regex.exec(text)) !== null) { + streams.push({ width: parseInt(match[1]), height: parseInt(match[2]), url: match[3] }); + } + if (streams.length === 0) return hlsUrl; + streams.sort((a, b) => b.height - a.height); + return streams[0].url; + } catch { + return hlsUrl; + } + } + + const bestHls = await getBestHls(hlsLink); + + const subtitles = metaJson.subtitles?.data?.['en-auto']?.urls?.[0] || ""; + + const result = { + streams: ["english", bestHls], + subtitles: subtitles + }; + + console.log("Extracted stream result:" + JSON.stringify(result)); + + return bestHls; + } catch { + console.log("Extracted stream result:" + JSON.stringify(empty)); + return JSON.stringify("empty"); + } +} diff --git a/luciferdonghua/luciferdonghua.json b/luciferdonghua/luciferdonghua.json new file mode 100644 index 0000000..5589c94 --- /dev/null +++ b/luciferdonghua/luciferdonghua.json @@ -0,0 +1,19 @@ +{ + "sourceName": "LuciferDonghua", + "iconUrl": "https://i.ibb.co/MwKW01H/cropped-lucifer-donghua-DP-192x192-webp.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "English", + "streamType": "HLS", + "quality": "4K", + "baseUrl": "https://luciferdonghua.in/", + "searchBaseUrl": "https://luciferdonghua.in/", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/luciferdonghua/luciferdonghua.js", + "type": "anime", + "asyncJS": true, + "softsub": false, + "downloadSupport": false +} diff --git a/mavanimes/mavanimes.js b/mavanimes/mavanimes.js new file mode 100644 index 0000000..8fe3351 --- /dev/null +++ b/mavanimes/mavanimes.js @@ -0,0 +1,225 @@ +async function searchResults(keyword) { + const results = []; + const headers = { + "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8", + "X-Requested-With": "XMLHttpRequest" + }; + const regex = /background-image:\s*url\("([^"]+)"\)[^]*?<h3><a[^']+'([^']+)'[^>]*>\s*([^<]+)/g; + const postData = `action=ajaxsearchlite_search&aslp=${keyword}&asid=1&options=qtranslate_lang%3D0%26set_intitle%3DNone%26set_incontent%3DNone%26set_inexcerpt%3DNone%26set_inpages%3DNone`; + try { + const response = await fetchv2("https://www.mavanimes.co/wp-admin/admin-ajax.php", headers, "POST", postData); + const html = await response.text(); + + let match; + while ((match = regex.exec(html)) !== null) { + results.push({ + title: match[3].trim(), + image: match[1].trim(), + href: match[2].trim() + }); + } + + return JSON.stringify(results); + } catch (err) { + return JSON.stringify([{ + title: "Error", + image: "Error", + href: "Error" + }]); + } +} + +async function extractDetails(url) { + try { + return JSON.stringify([{ + description: "Désolé, le format des données est incohérent, impossible d’extraire de manière fiable.", + aliases: "N/A", + airdate: "N/A" + }]); + } catch (err) { + return JSON.stringify([{ + description: "Error", + aliases: "Error", + airdate: "Error" + }]); + } +} + +async function extractEpisodes(url) { + const results = []; + const regex = /<h2[^>]*>\s*<a href="([^"]+)">/gi; + try { + const response = await fetchv2(url); + const html = await response.text(); + + let match; + let count = 1; + while ((match = regex.exec(html)) !== null) { + results.push({ + href: match[1].trim(), + number: count + }); + count++; + } + + results.forEach((item, i) => { + item.number = results.length - i; + }); + + return JSON.stringify(results.reverse()); + } catch (err) { + return JSON.stringify([{ + href: "Error", + number: "Error" + }]); + } +} + +async function extractStreamUrl(url) { + try { + const response = await fetchv2(url); + const html = await response.text(); + + const voeMatch = html.match(/https:\/\/voe\.sx\/e\/[a-zA-Z0-9]+/); + if (!voeMatch) return null; + + const voeLink = voeMatch[0]; + + const voeResponse = await fetchv2(voeLink); + const voeHtml = await voeResponse.text(); + + const redirectMatch = voeHtml.match(/window\.location\.href\s*=\s*['"]([^'"]+)['"]/); + if (!redirectMatch) return null; + + const finalLink = redirectMatch[1]; + + const streamUrlOne = finalLink; + + const responseTwo = await fetchv2(streamUrlOne); + const finalHtml = await responseTwo.text(); + + let streamUrl = null; + try { + streamUrl = voeExtractor(finalHtml); + } catch (error) { + console.log("VOE extraction error:", error); + return null; + } + + console.log("Voe Stream URL: " + streamUrl); + return streamUrl; + } catch (error) { + console.log("Extract stream URL error:", error); + return null; + } +} +/* SCHEME START */ + +/** + * @name voeExtractor + * @author Cufiy + */ + +function voeExtractor(html, url = null) { +// Extract the first <script type="application/json">...</script> + const jsonScriptMatch = html.match( + /<script[^>]+type=["']application\/json["'][^>]*>([\s\S]*?)<\/script>/i + ); + if (!jsonScriptMatch) { + console.log("No application/json script tag found"); + return null; + } + + + const obfuscatedJson = jsonScriptMatch[1].trim(); + + let data; + try { + data = JSON.parse(obfuscatedJson); + } catch (e) { + throw new Error("Invalid JSON input."); + } + if (!Array.isArray(data) || typeof data[0] !== "string") { + throw new Error("Input doesn't match expected format."); + } + let obfuscatedString = data[0]; + + // Step 1: ROT13 + let step1 = voeRot13(obfuscatedString); + + // Step 2: Remove patterns + let step2 = voeRemovePatterns(step1); + + // Step 3: Base64 decode + let step3 = voeBase64Decode(step2); + + // Step 4: Subtract 3 from each char code + let step4 = voeShiftChars(step3, 3); + + // Step 5: Reverse string + let step5 = step4.split("").reverse().join(""); + + // Step 6: Base64 decode again + let step6 = voeBase64Decode(step5); + + // Step 7: Parse as JSON + let result; + try { + result = JSON.parse(step6); + } catch (e) { + throw new Error("Final JSON parse error: " + e.message); + } + // console.log("Decoded JSON:", result); + + // check if direct_access_url is set, not null and starts with http + if (result && typeof result === "object") { + const streamUrl = + result.direct_access_url || + result.source + .map((source) => source.direct_access_url) + .find((url) => url && url.startsWith("http")); + if (streamUrl) { + console.log("Voe Stream URL: " + streamUrl); + return streamUrl; + } else { + console.log("No stream URL found in the decoded JSON"); + } + } + return result; +} + +function voeRot13(str) { + return str.replace(/[a-zA-Z]/g, function (c) { + return String.fromCharCode( + (c <= "Z" ? 90 : 122) >= (c = c.charCodeAt(0) + 13) + ? c + : c - 26 + ); + }); +} + +function voeRemovePatterns(str) { + const patterns = ["@$", "^^", "~@", "%?", "*~", "!!", "#&"]; + let result = str; + for (const pat of patterns) { + result = result.split(pat).join(""); + } + return result; +} + +function voeBase64Decode(str) { + // atob is available in browsers and Node >= 16 + if (typeof atob === "function") { + return atob(str); + } + // Node.js fallback + return Buffer.from(str, "base64").toString("utf-8"); +} + +function voeShiftChars(str, shift) { + return str + .split("") + .map((c) => String.fromCharCode(c.charCodeAt(0) - shift)) + .join(""); +} +/* SCHEME END */ \ No newline at end of file diff --git a/mavanimes/mavanimes.json b/mavanimes/mavanimes.json new file mode 100644 index 0000000..2a9ae92 --- /dev/null +++ b/mavanimes/mavanimes.json @@ -0,0 +1,19 @@ +{ + "sourceName": "MavAnimes", + "iconUrl": "https://www.mavanimes.co/wp-content/uploads/2018/03/cropped-mav-192x192.jpg", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "French (DUB/SUB)", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://www.mavanimes.co/", + "searchBaseUrl": "https://www.mavanimes.co/", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/mavanimes/mavanimes.js", + "type": "anime", + "asyncJS": true, + "softsub": false, + "downloadSupport": false +} diff --git a/megakino/megakino.js b/megakino/megakino.js new file mode 100644 index 0000000..597ae12 --- /dev/null +++ b/megakino/megakino.js @@ -0,0 +1,112 @@ +function cleanTitle(title) { + return title + .replace(/’/g, "'") + .replace(/–/g, "-") + .replace(/&#[0-9]+;/g, ""); +} + +async function searchResults(keyword) { + const results = []; + try { + const response = await fetchv2("https://megakino.vip/?s=" + encodeURIComponent(keyword)); + const html = await response.text(); + + const regex = /<article[^>]*>[\s\S]*?<h2 class="entry-title">([^<]+)<\/h2>[\s\S]*?<img[^>]+src="([^"]+)"[^>]*>[\s\S]*?<a href="([^"]+)" class="lnk-blk"><\/a>/g; + + let match; + while ((match = regex.exec(html)) !== null) { + results.push({ + title: cleanTitle(match[1].trim()), + image: match[2].trim().startsWith("//") ? "https:" + match[2].trim() : match[2].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 match = html.match(/<div class="description">\s*<p>([\s\S]*?)<\/p>/i); + const description = match ? match[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) { + return JSON.stringify([{ + href: url, + number: 1 + }]); +} + +async function extractStreamUrl(url) { + try { + const response = await fetchv2(url); + const html = await response.text(); + + const postIdMatch = html.match(/postid-(\d+)/); + if (!postIdMatch) throw new Error("Post ID not found"); + const postId = postIdMatch[1]; + + const embedUrl = `https://megakino.vip/?trembed=0&trid=${postId}&trtype=1`; + const embedResp = await fetchv2(embedUrl); + const embedHtml = await embedResp.text(); + + const iframeMatch = embedHtml.match(/<iframe[^>]+src="([^"]+)"/); + if (!iframeMatch) throw new Error("Iframe not found"); + const iframeUrl = iframeMatch[1]; + + const iframeResp = await fetchv2(iframeUrl); + const iframeHtml = await iframeResp.text(); + + const videoObjectMatch = iframeHtml.match(/var video = (\{[^}]*\});/s); + if (!videoObjectMatch) throw new Error("Video object not found"); + + let videoStr = videoObjectMatch[1]; + + const uidMatch = iframeHtml.match(/"uid"\s*:\s*"([^"]+)"/); + const md5Match = iframeHtml.match(/"md5"\s*:\s*"([^"]+)"/); + const idMatch = iframeHtml.match(/"id"\s*:\s*"([^"]+)"/); + const statusMatch = iframeHtml.match(/"status"\s*:\s*"([^"]+)"/); + + if (!uidMatch || !md5Match || !idMatch || !statusMatch) { + throw new Error("Video data not found"); + } + + const uid = uidMatch[1]; + const md5 = md5Match[1]; + const vidId = idMatch[1]; + const status = statusMatch[1]; + + const hlsUrl = `/m3u8/${uid}/${md5}/master.txt?s=1&id=${vidId}&cache=${status}`; + console.log("Extracted HLS URL:"+ hlsUrl); + + return "https://watch.gxplayer.xyz/" + hlsUrl; + + } catch (err) { + console.error(err); + return "https://files.catbox.moe/avolvc.mp4"; + } +} diff --git a/megakino/megakino.json b/megakino/megakino.json new file mode 100644 index 0000000..29923e9 --- /dev/null +++ b/megakino/megakino.json @@ -0,0 +1,19 @@ +{ + "sourceName": "MegaKino", + "iconUrl": "https://megakino.vip/wp-content/uploads/2024/03/cropped-favicon-192x192.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "German", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://megakino.com/", + "searchBaseUrl": "https://megakino.com/", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/megakino/megakino.js", + "type": "shows/movies", + "asyncJS": true, + "softsub": false, + "downloadSupport": false +} diff --git a/monoschinos2/monoschinos2.js b/monoschinos2/monoschinos2.js new file mode 100644 index 0000000..f47293a --- /dev/null +++ b/monoschinos2/monoschinos2.js @@ -0,0 +1,333 @@ +function cleanTitle(title) { + return title + .replace(/’/g, "'") + .replace(/–/g, "-") + .replace(/&#[0-9]+;/g, ""); +} + +async function searchResults(keyword) { + const results = []; + try { + const response = await fetchv2("https://wwv.monoschinos2.net/animes?buscar=" + encodeURIComponent(keyword)); + const html = await response.text(); + + const regex = /<li class="col mb-5 ficha_efecto">.*?<a href="([^"]+)" title="([^"]+)">.*?<img[^>]+src="([^"]+)"/gs; + + let match; + while ((match = regex.exec(html)) !== null) { + results.push({ + href: match[1].trim().replace("./", "https://wwv.monoschinos2.net/"), + title: cleanTitle(match[2].trim().replace(" Online Gratis", "").replace("Ver Anime", "")), + image: 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 match = html.match(/<div class="mb-3">\s*<p>(.*?)<\/p>/s); + const description = match ? match[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 parts = url.split('/'); + const u = parts[parts.length - 1] || parts[parts.length - 2]; + + const initialResponse = await fetchv2(url); + const html = await initialResponse.text(); + const iMatch = html.match(/data-i="(\d+)"/); + const i = iMatch ? iMatch[1] : null; + + console.log("Slug:" + u); + console.log("Data-i:" + i); + + if (!i) throw new Error("data-i not found"); + + let page = 1; + let episodeCount = 0; + + while (true) { + const formData = `acc=episodes&i=${i}&u=${u}&p=${page}`; + console.log("Form Data: " + formData); + const headers = { + "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8", + "X-Requested-With": "XMLHttpRequest", + "Origin": "https://wwv.monoschinos2.net", + "Referer": url + }; + const response = await fetchv2("https://wwv.monoschinos2.net/ajax_pagination", headers, "POST", formData); + const pageHtml = await response.text(); + console.log(pageHtml); + if (!pageHtml.trim()) break; + + const regex = /<a class="ko" href="([^"]+)"/g; + let match; + while ((match = regex.exec(pageHtml)) !== null) { + episodeCount++; + results.push({ + href: match[1].trim(), + number: episodeCount + }); + } + + page++; + } + + const total = results.length; + results.forEach((ep, index) => { + ep.number = total - index; + }); + + return JSON.stringify(results.reverse()); + } catch (err) { + return JSON.stringify({ + slug: "Error", + dataI: "Error", + episodes: [{ + href: "Error", + number: "Error" + }] + }); + } +} + +async function extractStreamUrl(url) { + try { + const response = await fetchv2(url); + const html = await response.text(); + + const match = html.match(/href="(https:\/\/(?:filemoon\.sx|[^"]+\.to)\/d\/[^"]+)"/); + if (!match) return "https://error.org/"; + + const filemoonUrl = match[1].replace("/d/", "/e/"); + + const filemoonResponse = await fetchv2(filemoonUrl); + const filemoonHtml = await filemoonResponse.text(); + + let streamUrl = null; + try { + streamUrl = await filemoonExtractor(filemoonHtml, filemoonUrl); + } catch (error) { + console.log("filemoon HD extraction error:" + error); + } + + console.log("filemoon Stream URL: " + streamUrl); + if (streamUrl && streamUrl !== false && streamUrl !== null) { + return streamUrl; + } + + console.log("No stream URL found"); + + return null; + } catch (error) { + console.log("Fetch error:", error); + return null; + } +} + +/* SCHEME START */ +/* {REQUIRED PLUGINS: unbaser} */ + +/** + * @name filemoonExtractor + * @author Cufiy - Inspired by Churly + */ + +async function filemoonExtractor(html, url = null) { + // check if contains iframe, if does, extract the src and get the url + const regex = /<iframe[^>]+src="([^"]+)"[^>]*><\/iframe>/; + const match = html.match(regex); + if (match) { + console.log("Iframe URL: " + match[1]); + const iframeUrl = match[1]; + const iframeResponse = await soraFetch(iframeUrl, { + headers: { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3", + "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", + "Referer": url, + } + }); + console.log("Iframe Response: " + iframeResponse.status); + html = await iframeResponse.text(); + } + // console.log("HTML: " + html); + // get /<script[^>]*>([\s\S]*?)<\/script>/gi + const scriptRegex = /<script[^>]*>([\s\S]*?)<\/script>/gi; + const scripts = []; + let scriptMatch; + while ((scriptMatch = scriptRegex.exec(html)) !== null) { + scripts.push(scriptMatch[1]); + } + // get the script with eval and m3u8 + const evalRegex = /eval\((.*?)\)/; + const m3u8Regex = /m3u8/; + // console.log("Scripts: " + scripts); + const evalScript = scripts.find(script => evalRegex.test(script) && m3u8Regex.test(script)); + if (!evalScript) { + console.log("No eval script found"); + return null; + } + const unpackedScript = unpack(evalScript); + // get the m3u8 url + const m3u8Regex2 = /https?:\/\/[^\s]+master\.m3u8[^\s]*?(\?[^"]*)?/; + const m3u8Match = unpackedScript.match(m3u8Regex2); + if (m3u8Match) { + return m3u8Match[0]; + } else { + console.log("No M3U8 URL found"); + return null; + } +} + + +/* REMOVE_START */ + + +class Unbaser { + constructor(base) { + this.ALPHABET = { + 62: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", + 95: "' !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'", + }; + this.dictionary = {}; + this.base = base; + if (36 < base && base < 62) { + this.ALPHABET[base] = this.ALPHABET[base] || + this.ALPHABET[62].substr(0, base); + } + if (2 <= base && base <= 36) { + this.unbase = (value) => parseInt(value, base); + } + else { + try { + [...this.ALPHABET[base]].forEach((cipher, index) => { + this.dictionary[cipher] = index; + }); + } + catch (er) { + throw Error("Unsupported base encoding."); + } + this.unbase = this._dictunbaser; + } + } + _dictunbaser(value) { + let ret = 0; + [...value].reverse().forEach((cipher, index) => { + ret = ret + ((Math.pow(this.base, index)) * this.dictionary[cipher]); + }); + return ret; + } +} + + +function unpack(source) { + let { payload, symtab, radix, count } = _filterargs(source); + if (count != symtab.length) { + throw Error("Malformed p.a.c.k.e.r. symtab."); + } + let unbase; + try { + unbase = new Unbaser(radix); + } + catch (e) { + throw Error("Unknown p.a.c.k.e.r. encoding."); + } + function lookup(match) { + const word = match; + let word2; + if (radix == 1) { + word2 = symtab[parseInt(word)]; + } + else { + word2 = symtab[unbase.unbase(word)]; + } + return word2 || word; + } + source = payload.replace(/\b\w+\b/g, lookup); + return _replacestrings(source); + function _filterargs(source) { + const juicers = [ + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\), *(\d+), *(.*)\)\)/, + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\)/, + ]; + for (const juicer of juicers) { + const args = juicer.exec(source); + if (args) { + let a = args; + if (a[2] == "[]") { + } + try { + return { + payload: a[1], + symtab: a[4].split("|"), + radix: parseInt(a[2]), + count: parseInt(a[3]), + }; + } + catch (ValueError) { + throw Error("Corrupted p.a.c.k.e.r. data."); + } + } + } + throw Error("Could not make sense of p.a.c.k.e.r data (unexpected code structure)"); + } + function _replacestrings(source) { + return source; + } +} + + +/** + * Uses Sora's fetchv2 on ipad, fallbacks to regular fetch on Windows + * @author ShadeOfChaos + * + * @param {string} url The URL to make the request to. + * @param {object} [options] The options to use for the request. + * @param {object} [options.headers] The headers to send with the request. + * @param {string} [options.method='GET'] The method to use for the request. + * @param {string} [options.body=null] The body of the request. + * + * @returns {Promise<Response|null>} The response from the server, or null if the + * request failed. + */ +async function soraFetch(url, options = { headers: {}, method: 'GET', body: null }) { + try { + return await fetchv2(url, options.headers ?? {}, options.method ?? 'GET', options.body ?? null); + } catch(e) { + try { + return await fetch(url, options); + } catch(error) { + return null; + } + } +} +/* REMOVE_END */ + +/* SCHEME END */ \ No newline at end of file diff --git a/monoschinos2/monoschinos2.json b/monoschinos2/monoschinos2.json new file mode 100644 index 0000000..f3cf0bb --- /dev/null +++ b/monoschinos2/monoschinos2.json @@ -0,0 +1,19 @@ +{ + "sourceName": "Monoschinos2", + "iconUrl": "https://files.catbox.moe/jz9l88.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "Spanish (DUB/SUB)", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://wwv.monoschinos2.net/", + "searchBaseUrl": "https://wwv.monoschinos2.net/", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/monoschinos2/monoschinos2.js", + "type": "anime", + "asyncJS": true, + "softsub": false, + "downloadSupport": false +} diff --git a/movi/movi.js b/movi/movi.js new file mode 100644 index 0000000..6bc9cd8 --- /dev/null +++ b/movi/movi.js @@ -0,0 +1,102 @@ +function decodeHtml(html) { + return html.replace(/&#(\d+);/g, (_, dec) => String.fromCharCode(dec)) + .replace(/&/g, "&") + .replace(/"/g, '"') + .replace(/'/g, "'") + .replace(/</g, "<") + .replace(/>/g, ">"); +} + +async function searchResults(keyword) { + const results = []; + try { + const response = await fetchv2("https://www.movi.pk/?s=" + encodeURIComponent(keyword)); + const html = await response.text(); + + const regex = /<div data-movie-id="\d+" class="ml-item">[\s\S]*?<a href="(https:\/\/www\.movi\.pk\/[^"]+)"[^>]*>[\s\S]*?<img [^>]*data-original="([^"]+)"[^>]*>[\s\S]*?<h2>([^<]+)<\/h2>/g; + + let match; + while ((match = regex.exec(html)) !== null) { + results.push({ + href: match[1].trim(), + image: match[2].trim(), + title: decodeHtml(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 match = html.match(/<p class="f-desc">(.*?)<\/p>/s); + const description = match ? match[1].trim() : "N/A"; + + return JSON.stringify([{ + description: decodeHtml(description), + aliases: "N/A", + airdate: "N/A" + }]); + } catch (err) { + return JSON.stringify([{ + description: "Error", + aliases: "Error", + airdate: "Error" + }]); + } +} + + +async function extractEpisodes(url) { + try { + const response = await fetchv2(url); + const html = await response.text(); + + const match = html.match(/<iframe\s+src=(https?:\/\/lizer[^\s>]+)[^>]*>/i); + const href = match ? match[1].trim() : url; + + return JSON.stringify([{ + href: href, + number: 1 + }]); + } catch (err) { + return JSON.stringify([{ + href: "Error", + number: "Error" + }]); + } +} + +async function extractStreamUrl(url) { + try { + const response = await fetchv2(url); + const html = await response.text(); + + const match = html.match(/var\s+video\s*=\s*(\{.*?\});/s); + if (!match) throw new Error("Video JSON not found"); + + const videoJson = JSON.parse(match[1]); + const uid = videoJson.uid; + const hash = videoJson.md5; + + const m3u8Path = `m3u8/${uid}/${hash}/720p/720p.m3u8?id=`; + + const encoded = btoa(m3u8Path); + + return `https://lizer123.site/stream/${encoded}`; + } catch (err) { + return "https://files.catbox.moe/avolvc.mp4"; + } +} + + diff --git a/movi/movi.json b/movi/movi.json new file mode 100644 index 0000000..da0fbb1 --- /dev/null +++ b/movi/movi.json @@ -0,0 +1,19 @@ +{ + "sourceName": "Movi", + "iconUrl": "https://www.movi.pk/wp-content/uploads/2024/12/favicon.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "Hindi (DUB/SUB)", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://www.movi.pk/", + "searchBaseUrl": "https://www.movi.pk/", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/movi/movi.js", + "type": "movies", + "asyncJS": true, + "softsub": false, + "downloadSupport": false +} diff --git a/novelbin/novelbin.js b/novelbin/novelbin.js new file mode 100644 index 0000000..136f8b5 --- /dev/null +++ b/novelbin/novelbin.js @@ -0,0 +1,198 @@ +async function searchResults(keyword) { + try { + const encodedKeyword = encodeURIComponent(keyword); + const url = `https://novelbin.me/search?keyword=${encodedKeyword}`; + const response = await soraFetch(url); + const html = await response.text(); + + const results = []; + const rowRegex = /<div class="row">([\s\S]*?)<\/div>\s*<\/div>\s*<\/div>/g; + let rowMatch; + + while ((rowMatch = rowRegex.exec(html)) !== null) { + const rowHtml = rowMatch[1]; + + const imgMatch = rowHtml.match(/<img\s+src="([^"]+)"[^>]*class="cover"/); + const linkMatch = rowHtml.match(/<h3 class="novel-title">\s*<a href="([^"]+)"\s+title="([^"]+)"/); + + if (imgMatch && linkMatch) { + let image = imgMatch[1]; + if (!image.startsWith("http")) image = "https:" + image; + + results.push({ + title: decodeHtmlEntities(linkMatch[2]), + href: linkMatch[1], + image + }); + } + } + + console.log(JSON.stringify(results)); + return JSON.stringify(results); + } catch (error) { + console.error("Error fetching or parsing: " + error); + return JSON.stringify([{ + title: "Error", + href: "", + image: "" + }]); + } +} + +async function extractDetails(url) { + try { + const response = await soraFetch(url); + const htmlText = await response.text(); + + const descMatch = htmlText.match(/<div class="desc-text"[^>]*itemprop="description"[^>]*>([\s\S]*?)<\/div>/i); + + const description = descMatch + ? descMatch[1].replace(/\s+/g, ' ').trim() + : "No description available"; + + const aliases = 'N/A'; + const airdate = 'N/A'; + + const transformedResults = [{ + description, + aliases, + airdate + }]; + + console.log(JSON.stringify(transformedResults)); + return JSON.stringify(transformedResults); + + } catch (error) { + console.log('Details error:' + error); + return JSON.stringify([{ + description: 'Error loading description', + aliases: 'N/A', + airdate: 'N/A' + }]); + } +} + + +async function extractChapters(url) { + try { + const response = await soraFetch(url); + const htmlText = await response.text(); + + const novelIdMatch = htmlText.match(/<div id="rating"[^>]*data-novel-id="([^"]+)"[^>]*>/i); + if (!novelIdMatch) { + throw new Error("Novel ID not found"); + } + const novelId = novelIdMatch[1]; + + const chaptersResponse = await soraFetch(`https://novelbin.me/ajax/chapter-archive?novelId=${novelId}`); + const chaptersHtml = await chaptersResponse.text(); + + const chapters = []; + const chapterRegex = /<a\s+href="([^"]+)"\s+title="([^"]+)"[^>]*>[\s\S]*?<span[^>]*class="[^"]*\bchapter-title\b[^"]*"[^>]*>([\s\S]*?)<\/span>/gi; + + let match; + while ((match = chapterRegex.exec(chaptersHtml)) !== null) { + const href = match[1]; + const titleFromAttr = match[2].trim(); + const titleFromSpan = match[3].replace(/\s+/g, ' ').trim(); + + const title = titleFromAttr || titleFromSpan; + + chapters.push({ title, href }); + } + + chapters.sort((a, b) => { + const numA = parseFloat(a.title.match(/Chapter\s+(\d+)/i)?.[1]) || 0; + const numB = parseFloat(b.title.match(/Chapter\s+(\d+)/i)?.[1]) || 0; + return numA - numB; + }); + + chapters.forEach((chapter, index) => { + chapter.number = index + 1; + }); + + console.log(JSON.stringify(chapters)); + return JSON.stringify(chapters); + + } catch (error) { + console.error('Fetch error in extractChapters:', error); + return JSON.stringify([{ + href: url, + title: "Error fetching chapters", + number: 0 + }]); + } +} + +async function extractText(url) { + try { + const response = await soraFetch(url); + let htmlText = await response.text(); + + const startPattern = /<div id="pf-15549-1"[^>]*>[\s\S]*?<\/div>\s*<div><\/div>/; + const endPattern = /<div id="pf-15560-1"[^>]*>[\s\S]*?<\/div>/; + + const startMatch = htmlText.search(startPattern); + const endMatch = htmlText.search(endPattern); + + if (startMatch === -1 || endMatch === -1) { + throw new Error("Start or end markers not found"); + } + + const startIndex = htmlText.match(startPattern)[0].length + startMatch; + let content = htmlText.substring(startIndex, endMatch).trim(); + + content = content.replace(/<div id="pf-\d+-\d+"[^>]*>[\s\S]*?<\/div>/gi, ''); + + content = content.replace(/<script[\s\S]*?<\/script>/gi, ''); + + content = content.replace(/\s+/g, ' ').trim(); + + if (!content) { + throw new Error("No content found between markers"); + } + + console.log(content); + return content; + + } catch (error) { + console.log("Fetch error in extractText: " + error); + return '<p>Error extracting text</p>'; + } +} + +async function soraFetch(url, options = { + headers: {}, + method: 'GET', + body: null +}) { + try { + return await fetchv2(url, options.headers ?? {}, options.method ?? 'GET', options.body ?? null); + } catch (e) { + try { + return await fetch(url, options); + } catch (error) { + return null; + } + } +} + +function decodeHtmlEntities(text) { + const entities = { + '—': '—', + '–': '–', + '&': '&', + '<': '<', + '>': '>', + '"': '"', + ''': "'", + '/': '/', + '`': '`', + '=': '=', + ' ': ' ' + }; + + return text.replace(/&#x[\dA-Fa-f]+;|&\w+;/g, (match) => { + return entities[match] || match; + }); +} diff --git a/novelbin/novelbin.json b/novelbin/novelbin.json new file mode 100644 index 0000000..187de88 --- /dev/null +++ b/novelbin/novelbin.json @@ -0,0 +1,19 @@ +{ + "sourceName": "NovelBin", + "iconUrl": "https://novelbin.com/img/logo.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "English", + "streamType": "novels", + "quality": "N/A", + "baseUrl": "https://novelbin.com/", + "searchBaseUrl": "https://novelbin.com/search/?wd=%s", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/novelbin/novelbin.js", + "type": "novels", + "asyncJS": true, + "novel": true, + "downloadSupport": false +} diff --git a/novelcool/novelcool.js b/novelcool/novelcool.js new file mode 100644 index 0000000..726edba --- /dev/null +++ b/novelcool/novelcool.js @@ -0,0 +1,160 @@ +async function searchResults(keyword) { + try { + const encodedKeyword = encodeURIComponent(keyword); + const response = await soraFetch(`https://www.novelcool.com/search/?name=${encodedKeyword}`); + const data = await response.text(); + const results = []; + const regex = /<div class="book-item"[^>]*itemtype\s*=\s*["'][^"']*Book[^"']*["'][^>]*>([\s\S]*?)<\/div>\s*<\/div>/g; + let match; + while ((match = regex.exec(data)) !== null) { + const bookItemHTML = match[1]; + if (bookItemHTML.includes('book-type-manga')) { + continue; + } + let titleMatch = bookItemHTML.match(/<div class="book-pic"[^>]*title="([^"]*)"/); + let title = ""; + if (titleMatch && titleMatch[1]) { + title = titleMatch[1].trim(); + } else { + titleMatch = bookItemHTML.match(/<div[^>]*\bclass\s*=\s*["'][^"']*book-name[^"']*["'][^>]*itemprop\s*=\s*["']name["'][^>]*>(.*?)<\/div>/); + if (titleMatch && titleMatch[1]) { + title = titleMatch[1].trim(); + } + } + const hrefMatch = bookItemHTML.match(/<a[^>]*href\s*=\s*["'](https:\/\/www\.novelcool\.com\/novel\/[^"']*)["'][^>]*itemprop\s*=\s*["']url["']|<a[^>]*href\s*=\s*["'](https:\/\/www\.novelcool\.com\/novel\/[^"']*)["']/); + const href = (hrefMatch && (hrefMatch[1] || hrefMatch[2])) ? (hrefMatch[1] || hrefMatch[2]).trim() : ''; + const imgTagMatch = bookItemHTML.match(/<img[^>]*itemprop\s*=\s*["']image["'][^>]*>/i); + let image = ''; + if (imgTagMatch) { + const imgTag = imgTagMatch[0]; + const srcMatch = imgTag.match(/\bsrc\s*=\s*["']([^"']*)["']/i); + if (srcMatch && srcMatch[1]) { + image = srcMatch[1].trim(); + } + } + if (title && href) { + results.push({ + title: title, + href: href, + image: image + }); + } + + } + console.log("Search Results:", results); + return JSON.stringify(results); + } catch (error) { + console.error('Fetch error in searchResults:', error); + return JSON.stringify([{ title: 'Error', href: '', image: '' }]); + } +} + +async function extractDetails(url) { + try { + const response = await soraFetch(url); + const htmlText = await response.text(); + + const descriptionMatch = htmlText.match(/<div class="bk-summary-txt"[^>]*>([\s\S]*?)<\/div>/); + const description = descriptionMatch ? descriptionMatch[1].trim() : 'No description available'; + + const transformedResults = [{ + description, + aliases: 'N/A', + airdate: 'N/A' + }]; + + console.log(JSON.stringify(transformedResults)); + return JSON.stringify(transformedResults); + } catch (error) { + console.log('Details error:', error); + return JSON.stringify([{ + description: 'Error loading description', + aliases: 'N/A', + airdate: 'N/A' + }]); + } +} + +async function extractChapters(url) { + try { + const response = await soraFetch(url); + const htmlText = await response.text(); + + const rawChapters = []; + const regex = /<div class="chp-item">[\s\S]*?<a href="([^"]+)"[^>]*title="([^"]+)">[\s\S]*?<\/a>[\s\S]*?<\/div>/g; + + let match; + while ((match = regex.exec(htmlText)) !== null) { + rawChapters.push({ + href: match[1].trim(), + title: match[2].trim() + }); + } + + const total = rawChapters.length; + const chapters = rawChapters.map((ch, i) => ({ + ...ch, + number: total - i + })); + + if (chapters.length === 0) { + return [{ + href: url, + title: "Currently no chapters available", + number: 1 + }]; + } + + console.log(JSON.stringify(chapters)); + return chapters.reverse(); + } catch (error) { + console.log('Fetch error in extractChapters:', error); + return [{ + href: url, + title: "Currently no chapters available", + number: 1 + }]; + } +} + + +async function extractText(url) { + try { + const response = await soraFetch(url); + const htmlText = await response.text(); + + const match = htmlText.match( + /<h2 class="chapter-title[^>]*>[\s\S]*?<\/h2>([\s\S]*?)<div class="bookinfo-share">/i + ); + + if (!match) { + throw new Error("Chapter content not found"); + } + + let content = match[1].trim(); + + content = content.replace(/<script[\s\S]*?<\/script>/gi, ''); + + content = content.trim(); + + console.log(JSON.stringify(content)); + return content; + } catch (error) { + console.log("Fetch error in extractText:", error); + return JSON.stringify({ text: 'Error extracting text' }); + } +} + +extractChapters('https://www.novelcool.com/novel/Shadow-Slave.html'); + +async function soraFetch(url, options = { headers: {}, method: 'GET', body: null }) { + try { + return await fetchv2(url, options.headers ?? {}, options.method ?? 'GET', options.body ?? null); + } catch(e) { + try { + return await fetch(url, options); + } catch(error) { + return null; + } + } +} diff --git a/novelcool/novelcool.json b/novelcool/novelcool.json new file mode 100644 index 0000000..f032541 --- /dev/null +++ b/novelcool/novelcool.json @@ -0,0 +1,18 @@ +{ + "sourceName": "NovelCool", + "iconUrl": "https://www.novelcool.com/files/img/144.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "English", + "streamType": "novels", + "quality": "N/A", + "baseUrl": "https://www.novelcool.com/", + "searchBaseUrl": "https://www.novelcool.com/search/?wd=%s", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/novelcool/novelcool.js", + "type": "novels", + "asyncJS": true, + "novel": true +} diff --git a/novelnext/novelnext.js b/novelnext/novelnext.js new file mode 100644 index 0000000..cd592e1 --- /dev/null +++ b/novelnext/novelnext.js @@ -0,0 +1,219 @@ +async function searchResults(keyword) { + try { + const encodedKeyword = encodeURIComponent(keyword); + const url = `https://novelnext.dramanovels.io/search?keyword=${encodedKeyword}`; + const response = await soraFetch(url); + const html = await response.text(); + + const results = []; + const rowRegex = /<div class="row">([\s\S]*?)<\/div>\s*<\/div>\s*<\/div>/g; + let rowMatch; + + while ((rowMatch = rowRegex.exec(html)) !== null) { + const rowHtml = rowMatch[1]; + + const imgMatch = rowHtml.match(/<img[^>]+src="([^"]+)"[^>]*class="cover"/); + const linkMatch = rowHtml.match(/<h3 class="novel-title">\s*<a href="([^"]+)"[^>]*title="([^"]+)"/); + + if (imgMatch && linkMatch) { + let image = imgMatch[1]; + if (!image.startsWith("http")) image = "https:" + image; + + results.push({ + title: decodeHtmlEntities(linkMatch[2]), + href: linkMatch[1], + image + }); + } + } + + console.log(JSON.stringify(results)); + return JSON.stringify(results); + } catch (error) { + console.error("Error fetching or parsing: " + error); + return JSON.stringify([{ + title: "Error", + href: "", + image: "" + }]); + } +} + + +async function extractDetails(url) { + try { + const response = await soraFetch(url); + const htmlText = await response.text(); + + const descMatch = htmlText.match(/<div class="desc-text"[^>]*itemprop="description"[^>]*>([\s\S]*?)<\/div>/i); + + let description = descMatch + ? decodeHtmlEntities( + descMatch[1] + .replace(/<a[^>]*>.*?<\/a>/gi, '') + .replace(/<[^>]+>/g, '') + .replace(/\s+/g, ' ') + .trim() + ) + : "No description available"; + + const aliases = 'N/A'; + const airdate = 'N/A'; + + const transformedResults = [{ + description, + aliases, + airdate + }]; + + console.log(JSON.stringify(transformedResults)); + return JSON.stringify(transformedResults); + + } catch (error) { + console.log('Details error:' + error); + return JSON.stringify([{ + description: 'Error loading description', + aliases: 'N/A', + airdate: 'N/A' + }]); + } +} + +async function extractChapters(url) { + try { + const response = await soraFetch(url); + const htmlText = await response.text(); + + const novelIdMatch = htmlText.match(/<div id="rating"[^>]*data-novel-id="([^"]+)"[^>]*>/i); + if (!novelIdMatch) { + throw new Error("Novel ID not found"); + } + const novelId = novelIdMatch[1]; + + const chaptersResponse = await soraFetch(`https://novelnext.dramanovels.io/ajax/chapter-archive?novelId=${novelId}`); + const chaptersHtml = await chaptersResponse.text(); + + const chapters = []; + const chapterRegex = /<a\s+href="([^"]+)"\s+title="([^"]+)"[^>]*>[\s\S]*?<span[^>]*class="[^"]*\bnchr-text\b[^"]*"[^>]*>([\s\S]*?)<\/span>/gi; + + let match; + while ((match = chapterRegex.exec(chaptersHtml)) !== null) { + const href = match[1]; + const titleFromAttr = match[2].trim(); + const titleFromSpan = match[3].replace(/\s+/g, ' ').trim(); + + const title = titleFromAttr || titleFromSpan; + + chapters.push({ title, href }); + } + + chapters.sort((a, b) => { + const numA = parseFloat(a.title.match(/Chapter\s+(\d+)/i)?.[1]) || 0; + const numB = parseFloat(b.title.match(/Chapter\s+(\d+)/i)?.[1]) || 0; + return numA - numB; + }); + + chapters.forEach((chapter, index) => { + chapter.number = index + 1; + }); + + console.log(JSON.stringify(chapters)); + return JSON.stringify(chapters); + + } catch (error) { + console.error('Fetch error in extractChapters:', error); + return JSON.stringify([{ + href: url, + title: "Error fetching chapters", + number: 0 + }]); + } +} + +async function extractText(url) { + try { + const response = await soraFetch(url); + let htmlText = await response.text(); + + const startPattern = /<div class="text-center ads-holder ads-top"[^>]*>[\s\S]*?<\/div>/; + const endPattern = /<div class="chr-nav" id="chr-nav-bottom">/; + + const startMatch = htmlText.search(startPattern); + const endMatch = htmlText.search(endPattern); + + if (startMatch === -1 || endMatch === -1) { + const contentStartPattern = /<div id="chapter"[^>]*>/; + const contentEndPattern = /<div class="chr-nav" id="chr-nav-bottom">/; + const contentStartMatch = htmlText.search(contentStartPattern); + const contentEndMatch = htmlText.search(contentEndPattern); + if (contentStartMatch === -1 || contentEndMatch === -1) { + throw new Error("Content markers not found"); + } + const contentStartIndex = htmlText.match(contentStartPattern)[0].length + contentStartMatch; + let content = htmlText.substring(contentStartIndex, contentEndMatch).trim(); + + content = content.replace(/<div id="pf-\d+-\d+"[^>]*>[\s\S]*?<\/script><\/div>/gi, ''); + + content = content.replace(/<(?!\/?p\b)[^>]+>/gi, ''); + + content = content.replace(/\s+/g, ' ').trim(); + + if (!content) throw new Error("No content found between markers"); + console.log(content); + return content; + } + + const startIndex = htmlText.match(startPattern)[0].length + startMatch; + let content = htmlText.substring(startIndex, endMatch).trim(); + + content = content.replace(/<div id="pf-\d+-\d+"[^>]*>[\s\S]*?<\/script><\/div>/gi, ''); + + content = content.replace(/<(?!\/?p\b)[^>]+>/gi, ''); + + content = content.replace(/\s+/g, ' ').trim(); + + if (!content) throw new Error("No content found between markers"); + console.log(content); + return decodeHtmlEntities(content); + + } catch (error) { + console.log("Fetch error in extractText: " + error); + return '<p>Error extracting text</p>'; + } +} + +async function soraFetch(url, options = { + headers: {}, + method: 'GET', + body: null +}) { + try { + return await fetchv2(url, options.headers ?? {}, options.method ?? 'GET', options.body ?? null); + } catch (e) { + try { + return await fetch(url, options); + } catch (error) { + return null; + } + } +} + +function decodeHtmlEntities(text) { + const entities = { + '—': '—', + '–': '–', + '&': '&', + '<': '<', + '>': '>', + '"': '"', + ''': "'", + '/': '/', + '`': '`', + '=': '=', + ' ': ' ' + }; + + return text.replace(/&#x[\dA-Fa-f]+;|&\w+;/g, (match) => { + return entities[match] || match; + }); +} diff --git a/novelnext/novelnext.json b/novelnext/novelnext.json new file mode 100644 index 0000000..59cb144 --- /dev/null +++ b/novelnext/novelnext.json @@ -0,0 +1,19 @@ +{ + "sourceName": "NovelNext", + "iconUrl": "https://novelnext.dramanovels.io/img/logo.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "English", + "streamType": "novels", + "quality": "N/A", + "baseUrl": "https://novelnext.dramanovels.io", + "searchBaseUrl": "https://novelnext.dramanovels.iosearch/%s", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/novelnext/novelnext.js", + "type": "novels", + "asyncJS": true, + "novel": true, + "downloadSupport": false +} diff --git a/onlinemovieshindi/onlinemovieshindi.js b/onlinemovieshindi/onlinemovieshindi.js new file mode 100644 index 0000000..6bfc8fe --- /dev/null +++ b/onlinemovieshindi/onlinemovieshindi.js @@ -0,0 +1,95 @@ +async function searchResults(keyword) { + const response = await fetch(`https://111.90.159.132/?s=${keyword}`); + const html = await response; + + const results = []; + const filmListRegex = /<article[^>]+itemscope[^>]+itemtype="http:\/\/schema\.org\/Movie"[^>]*>[\s\S]*?<\/article>/g; + const items = html.match(filmListRegex); + + if (!items) return results; + + items.forEach(itemHtml => { + const titleMatch = itemHtml.match(/<p class="entry-title"[^>]*>\s*<a[^>]+>([^<]+)<\/a>/); + const hrefMatch = itemHtml.match(/<a href="([^"]+)"[^>]+title="Watch Movie:/); + const imgMatch = itemHtml.match(/<img[^>]+src="([^"]+)"[^>]+alt="([^"]+)"/); + + if (titleMatch && hrefMatch && imgMatch) { + results.push({ + title: titleMatch[1].trim(), + image: imgMatch[1].trim(), + href: hrefMatch[1].trim() + }); + } + }); + console.log(JSON.stringify(results)); + return JSON.stringify(results); +} + +async function extractDetails(url) { + const response = await fetch(url); + const html = await response; + const details = []; + + const descriptionMatch = html.match(/<div class="entry-content entry-content-single"[^>]*>([\s\S]*?)<\/div>/); + let description = descriptionMatch ? descriptionMatch[1].replace(/<\/?[^>]+(>|$)/g, "").trim() : ''; + + const entities = { + '‘': '‘', + '’': '’', + '“': '“', + '”': '”', + '&': '&', + ''': "'", + ' ': ' ', + '©': '©', + '®': '®', + '™': '™', + }; + + for (const [entity, char] of Object.entries(entities)) { + description = description.replace(new RegExp(entity, 'g'), char); + } + + description = description.replace(/\s+/g, ' ').replace(/Country:[^<]+/g, '').trim(); + + const airdateMatch = html.match(/Year: <a href="[^"]*" rel="tag">(\d{4})<\/a>/); + let airdate = airdateMatch ? airdateMatch[1] : ''; + + if (description && airdate) { + details.push({ + description: description, + aliases: 'N/A', + airdate: airdate + }); + } + console.log(details); + return JSON.stringify(details); +} + + +async function extractEpisodes(url) { + const episodes = []; + if (url) { + const hardcodedEpisode = { + href: url, + number: `1` + }; + episodes.push(hardcodedEpisode); + } + + console.log(JSON.stringify(episodes)); + return JSON.stringify(episodes); +} + +async function extractStreamUrl(input) { + const response = await fetch(input); + const html = await response; + console.log(html); + + const sourceRegex = /<video[\s\S]*?<source\s+src=["']([^"']+)["'][^>]*>/i; + const match = html.match(sourceRegex); + const url = match ? match[1].replace(/&/g, '&') : null; + console.log(url); + return url; +} + diff --git a/onlinemovieshindi/onlinemovieshindi.json b/onlinemovieshindi/onlinemovieshindi.json new file mode 100644 index 0000000..62b7818 --- /dev/null +++ b/onlinemovieshindi/onlinemovieshindi.json @@ -0,0 +1,17 @@ +{ + "sourceName": "OnlineMoviesHindi", + "iconUrl": "https://cdn-icons-png.freepik.com/256/14272/14272467.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.1", + "language": "Hindi (SUB)", + "streamType": "mp4", + "quality": "1080p", + "baseUrl": "https://111.90.159.132/", + "searchBaseUrl": "https://111.90.159.132/?s=%s", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/onlinemovieshindi/onlinemovieshindi.js", + "asyncJS": true, + "type": "movies/shows" +} diff --git a/pelisplushd/pelisplushd.js b/pelisplushd/pelisplushd.js new file mode 100644 index 0000000..252f633 --- /dev/null +++ b/pelisplushd/pelisplushd.js @@ -0,0 +1,6562 @@ +async function searchResults(keyword) { + const results = []; + try { + const response = await fetchv2("https://pelisplushd.bz/search?s=" + encodeURIComponent(keyword)); + const html = await response.text(); + + const cleanHtml = html.replace(/\s+/g, ' ').trim(); + + const linkRegex = /<a\s[^>]*href="([^"]+)"[^>]*class="Posters-link[^"]*"[^>]*>(.*?)<\/a>/gs; + + let match; + while ((match = linkRegex.exec(cleanHtml)) !== null) { + const href = match[1].trim(); + const linkContent = match[2]; + + const imgMatch = linkContent.match(/<img[^>]*src="(https?:\/\/[^"]+)"/); + const image = imgMatch ? imgMatch[1].trim() : ''; + + const titleMatch = linkContent.match(/<div class="listing-content"[^>]*>.*?<p>([^<]+)<\/p>/s); + const title = titleMatch ? titleMatch[1].trim() : ''; + + if (href && image && title) { + results.push({ + href, + image, + title + }); + } + } + + return JSON.stringify(results); + + } catch (err) { + return JSON.stringify([{ + title: "Error: " + err.message, + image: "Error", + href: "Error" + }]); + } +} + +async function extractDetails(url) { + try { + const response = await fetchv2(url); + const html = await response.text(); + + const match = html.match(/<div class="text-large">\s*([\s\S]*?)\s*<\/div>/i); + const description = match ? match[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="([^"]+)"[^>]*>T(\d+)\s*-\s*E(\d+):/g; + let match; + const seasonCounters = {}; + + while ((match = regex.exec(html)) !== null) { + const href = match[1].trim(); + const season = parseInt(match[2], 10); + let episode = parseInt(match[3], 10); + + if (!seasonCounters[season]) seasonCounters[season] = 1; + else seasonCounters[season]++; + + results.push({ + href: href, + number: seasonCounters[season] + }); + } + + if (results.length === 0) { + results.push({ + href: url, + number: 1 + }); + } + + return JSON.stringify(results); + } catch (err) { + return JSON.stringify([{ + href: "Error", + season: "Error", + number: "Error" + }]); + } +} + +async function extractStreamUrl(url) { + try { + const response = await fetchv2(url); + const html = await response.text(); + + const match = html.match(/video\[1\]\s*=\s*'([^']+)'/); + + const anotherResponse = await fetchv2(match[1].trim()); + const anotherHtml = await anotherResponse.text(); + + const dataLinkMatch = anotherHtml.match(/const\s+dataLink\s*=\s*(\[[\s\S]*?\]);/); + + let dataLink; + try { + let dataLinkStr = dataLinkMatch[1] + .replace(/"/g, '"') + .replace(/\\u003c/g, '<') + .replace(/\\u003e/g, '>') + .replace(/\\u0026/g, '&'); + dataLink = JSON.parse(dataLinkStr); + } catch (e) { + console.error( e); + return "PARSE ERROR"; + } + + const defaultLang = dataLink[0]; + const filemoonEmbed = defaultLang.sortedEmbeds.find(embed => embed.servername === "filemoon"); + + const SECRET_KEY = "Ak7qrvvH4WKYxV2OgaeHAEg2a5eh16vE"; + const decryptedUrl = decryptLink(filemoonEmbed.link, SECRET_KEY); + + console.log( decryptedUrl); + const filemoonResponse = await fetchv2(decryptedUrl); + const filemoonHtml = await filemoonResponse.text(); + let streamUrl = null; + try { + streamUrl = await filemoonExtractor(filemoonHtml, decryptedUrl); + } catch (error) { + console.log("filemoon HD extraction error:" + error); + } + + console.log("filemoon Stream URL: " + streamUrl); + if (streamUrl && streamUrl !== false && streamUrl !== null) { + return streamUrl; + } + + console.log("No stream URL found"); + + return null; + } catch (error) { + console.log("Fetch error:", error); + return null; + } +} + +/* SCHEME START */ +/* {REQUIRED PLUGINS: unbaser} */ + +/** + * @name filemoonExtractor + * @author Cufiy - Inspired by Churly + */ + +async function filemoonExtractor(html, url = null) { + // check if contains iframe, if does, extract the src and get the url + const regex = /<iframe[^>]+src="([^"]+)"[^>]*><\/iframe>/; + const match = html.match(regex); + if (match) { + console.log("Iframe URL: " + match[1]); + const iframeUrl = match[1]; + const iframeResponse = await soraFetch(iframeUrl, { + headers: { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3", + "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", + "Referer": url, + } + }); + console.log("Iframe Response: " + iframeResponse.status); + html = await iframeResponse.text(); + } + // console.log("HTML: " + html); + // get /<script[^>]*>([\s\S]*?)<\/script>/gi + const scriptRegex = /<script[^>]*>([\s\S]*?)<\/script>/gi; + const scripts = []; + let scriptMatch; + while ((scriptMatch = scriptRegex.exec(html)) !== null) { + scripts.push(scriptMatch[1]); + } + // get the script with eval and m3u8 + const evalRegex = /eval\((.*?)\)/; + const m3u8Regex = /m3u8/; + // console.log("Scripts: " + scripts); + const evalScript = scripts.find(script => evalRegex.test(script) && m3u8Regex.test(script)); + if (!evalScript) { + console.log("No eval script found"); + return null; + } + const unpackedScript = unpack(evalScript); + // get the m3u8 url + const m3u8Regex2 = /https?:\/\/[^\s]+master\.m3u8[^\s]*?(\?[^"]*)?/; + const m3u8Match = unpackedScript.match(m3u8Regex2); + if (m3u8Match) { + return m3u8Match[0]; + } else { + console.log("No M3U8 URL found"); + return null; + } +} + + +/* REMOVE_START */ + + +class Unbaser { + constructor(base) { + this.ALPHABET = { + 62: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", + 95: "' !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'", + }; + this.dictionary = {}; + this.base = base; + if (36 < base && base < 62) { + this.ALPHABET[base] = this.ALPHABET[base] || + this.ALPHABET[62].substr(0, base); + } + if (2 <= base && base <= 36) { + this.unbase = (value) => parseInt(value, base); + } + else { + try { + [...this.ALPHABET[base]].forEach((cipher, index) => { + this.dictionary[cipher] = index; + }); + } + catch (er) { + throw Error("Unsupported base encoding."); + } + this.unbase = this._dictunbaser; + } + } + _dictunbaser(value) { + let ret = 0; + [...value].reverse().forEach((cipher, index) => { + ret = ret + ((Math.pow(this.base, index)) * this.dictionary[cipher]); + }); + return ret; + } +} + + +function unpack(source) { + let { payload, symtab, radix, count } = _filterargs(source); + if (count != symtab.length) { + throw Error("Malformed p.a.c.k.e.r. symtab."); + } + let unbase; + try { + unbase = new Unbaser(radix); + } + catch (e) { + throw Error("Unknown p.a.c.k.e.r. encoding."); + } + function lookup(match) { + const word = match; + let word2; + if (radix == 1) { + word2 = symtab[parseInt(word)]; + } + else { + word2 = symtab[unbase.unbase(word)]; + } + return word2 || word; + } + source = payload.replace(/\b\w+\b/g, lookup); + return _replacestrings(source); + function _filterargs(source) { + const juicers = [ + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\), *(\d+), *(.*)\)\)/, + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\)/, + ]; + for (const juicer of juicers) { + const args = juicer.exec(source); + if (args) { + let a = args; + if (a[2] == "[]") { + } + try { + return { + payload: a[1], + symtab: a[4].split("|"), + radix: parseInt(a[2]), + count: parseInt(a[3]), + }; + } + catch (ValueError) { + throw Error("Corrupted p.a.c.k.e.r. data."); + } + } + } + throw Error("Could not make sense of p.a.c.k.e.r data (unexpected code structure)"); + } + function _replacestrings(source) { + return source; + } +} + + +/** + * Uses Sora's fetchv2 on ipad, fallbacks to regular fetch on Windows + * @author ShadeOfChaos + * + * @param {string} url The URL to make the request to. + * @param {object} [options] The options to use for the request. + * @param {object} [options.headers] The headers to send with the request. + * @param {string} [options.method='GET'] The method to use for the request. + * @param {string} [options.body=null] The body of the request. + * + * @returns {Promise<Response|null>} The response from the server, or null if the + * request failed. + */ +async function soraFetch(url, options = { headers: {}, method: 'GET', body: null }) { + try { + return await fetchv2(url, options.headers ?? {}, options.method ?? 'GET', options.body ?? null); + } catch(e) { + try { + return await fetch(url, options); + } catch(error) { + return null; + } + } +} +/* REMOVE_END */ + +/* SCHEME END */ + +function cleanHtmlSymbols(string) { + if (!string) return ""; + return string + .replace(/’/g, "'") + .replace(/–/g, "-") + .replace(/&#[0-9]+;/g, "") + .replace(/\r?\n|\r/g, " ") + .replace(/\s+/g, " ") + .trim(); +} + +function decryptLink(encryptedLinkBase64, secretKey) { + try { + const encryptedData = CryptoJS.enc.Base64.parse(encryptedLinkBase64); + const iv = encryptedData.words.slice(0, 4); + const encryptedBytes = encryptedData.words.slice(4); + const ivWordArray = CryptoJS.lib.WordArray.create(iv); + const encryptedWordArray = CryptoJS.lib.WordArray.create(encryptedBytes); + + const decrypted = CryptoJS.AES.decrypt( + { ciphertext: encryptedWordArray }, + CryptoJS.enc.Utf8.parse(secretKey), + { iv: ivWordArray, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 } + ); + + return decrypted.toString(CryptoJS.enc.Utf8); + } catch (error) { + console.error('Error al descifrar:', error); + return null; + } +} + +;(function (root, factory) { + if (typeof exports === "object") { + // CommonJS + module.exports = exports = factory(); + } + else if (typeof define === "function" && define.amd) { + // AMD + define([], factory); + } + else { + // Global (browser) + root.CryptoJS = factory(); + } +}(this, function () { + + /*globals window, global, require*/ + + /** + * CryptoJS core components. + */ + var CryptoJS = CryptoJS || (function (Math, undefined) { + + var crypto; + + // Native crypto from window (Browser) + if (typeof window !== 'undefined' && window.crypto) { + crypto = window.crypto; + } + + // Native crypto in web worker (Browser) + if (typeof self !== 'undefined' && self.crypto) { + crypto = self.crypto; + } + + // Native crypto from worker + if (typeof globalThis !== 'undefined' && globalThis.crypto) { + crypto = globalThis.crypto; + } + + // Native (experimental IE 11) crypto from window (Browser) + if (!crypto && typeof window !== 'undefined' && window.msCrypto) { + crypto = window.msCrypto; + } + + // Native crypto from global (NodeJS) + if (!crypto && typeof global !== 'undefined' && global.crypto) { + crypto = global.crypto; + } + + // Native crypto import via require (NodeJS) + if (!crypto && typeof require === 'function') { + try { + crypto = require('crypto'); + } catch (err) {} + } + + /* + * Cryptographically secure pseudorandom number generator + * + * As Math.random() is cryptographically not safe to use + */ + var cryptoSecureRandomInt = function () { + if (crypto) { + // Use getRandomValues method (Browser) + if (typeof crypto.getRandomValues === 'function') { + try { + return crypto.getRandomValues(new Uint32Array(1))[0]; + } catch (err) {} + } + + // Use randomBytes method (NodeJS) + if (typeof crypto.randomBytes === 'function') { + try { + return crypto.randomBytes(4).readInt32LE(); + } catch (err) {} + } + } + + throw new Error('Native crypto module could not be used to get secure random number.'); + }; + + /* + * Local polyfill of Object.create + + */ + var create = Object.create || (function () { + function F() {} + + return function (obj) { + var subtype; + + F.prototype = obj; + + subtype = new F(); + + F.prototype = null; + + return subtype; + }; + }()); + + /** + * CryptoJS namespace. + */ + var C = {}; + + /** + * Library namespace. + */ + var C_lib = C.lib = {}; + + /** + * Base object for prototypal inheritance. + */ + var Base = C_lib.Base = (function () { + + + return { + /** + * Creates a new object that inherits from this object. + * + * @param {Object} overrides Properties to copy into the new object. + * + * @return {Object} The new object. + * + * @static + * + * @example + * + * var MyType = CryptoJS.lib.Base.extend({ + * field: 'value', + * + * method: function () { + * } + * }); + */ + extend: function (overrides) { + // Spawn + var subtype = create(this); + + // Augment + if (overrides) { + subtype.mixIn(overrides); + } + + // Create default initializer + if (!subtype.hasOwnProperty('init') || this.init === subtype.init) { + subtype.init = function () { + subtype.$super.init.apply(this, arguments); + }; + } + + // Initializer's prototype is the subtype object + subtype.init.prototype = subtype; + + // Reference supertype + subtype.$super = this; + + return subtype; + }, + + /** + * Extends this object and runs the init method. + * Arguments to create() will be passed to init(). + * + * @return {Object} The new object. + * + * @static + * + * @example + * + * var instance = MyType.create(); + */ + create: function () { + var instance = this.extend(); + instance.init.apply(instance, arguments); + + return instance; + }, + + /** + * Initializes a newly created object. + * Override this method to add some logic when your objects are created. + * + * @example + * + * var MyType = CryptoJS.lib.Base.extend({ + * init: function () { + * // ... + * } + * }); + */ + init: function () { + }, + + /** + * Copies properties into this object. + * + * @param {Object} properties The properties to mix in. + * + * @example + * + * MyType.mixIn({ + * field: 'value' + * }); + */ + mixIn: function (properties) { + for (var propertyName in properties) { + if (properties.hasOwnProperty(propertyName)) { + this[propertyName] = properties[propertyName]; + } + } + + // IE won't copy toString using the loop above + if (properties.hasOwnProperty('toString')) { + this.toString = properties.toString; + } + }, + + /** + * Creates a copy of this object. + * + * @return {Object} The clone. + * + * @example + * + * var clone = instance.clone(); + */ + clone: function () { + return this.init.prototype.extend(this); + } + }; + }()); + + /** + * An array of 32-bit words. + * + * @property {Array} words The array of 32-bit words. + * @property {number} sigBytes The number of significant bytes in this word array. + */ + var WordArray = C_lib.WordArray = Base.extend({ + /** + * Initializes a newly created word array. + * + * @param {Array} words (Optional) An array of 32-bit words. + * @param {number} sigBytes (Optional) The number of significant bytes in the words. + * + * @example + * + * var wordArray = CryptoJS.lib.WordArray.create(); + * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607]); + * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607], 6); + */ + init: function (words, sigBytes) { + words = this.words = words || []; + + if (sigBytes != undefined) { + this.sigBytes = sigBytes; + } else { + this.sigBytes = words.length * 4; + } + }, + + /** + * Converts this word array to a string. + * + * @param {Encoder} encoder (Optional) The encoding strategy to use. Default: CryptoJS.enc.Hex + * + * @return {string} The stringified word array. + * + * @example + * + * var string = wordArray + ''; + * var string = wordArray.toString(); + * var string = wordArray.toString(CryptoJS.enc.Utf8); + */ + toString: function (encoder) { + return (encoder || Hex).stringify(this); + }, + + /** + * Concatenates a word array to this word array. + * + * @param {WordArray} wordArray The word array to append. + * + * @return {WordArray} This word array. + * + * @example + * + * wordArray1.concat(wordArray2); + */ + concat: function (wordArray) { + // Shortcuts + var thisWords = this.words; + var thatWords = wordArray.words; + var thisSigBytes = this.sigBytes; + var thatSigBytes = wordArray.sigBytes; + + // Clamp excess bits + this.clamp(); + + // Concat + if (thisSigBytes % 4) { + // Copy one byte at a time + for (var i = 0; i < thatSigBytes; i++) { + var thatByte = (thatWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; + thisWords[(thisSigBytes + i) >>> 2] |= thatByte << (24 - ((thisSigBytes + i) % 4) * 8); + } + } else { + // Copy one word at a time + for (var j = 0; j < thatSigBytes; j += 4) { + thisWords[(thisSigBytes + j) >>> 2] = thatWords[j >>> 2]; + } + } + this.sigBytes += thatSigBytes; + + // Chainable + return this; + }, + + /** + * Removes insignificant bits. + * + * @example + * + * wordArray.clamp(); + */ + clamp: function () { + // Shortcuts + var words = this.words; + var sigBytes = this.sigBytes; + + // Clamp + words[sigBytes >>> 2] &= 0xffffffff << (32 - (sigBytes % 4) * 8); + words.length = Math.ceil(sigBytes / 4); + }, + + /** + * Creates a copy of this word array. + * + * @return {WordArray} The clone. + * + * @example + * + * var clone = wordArray.clone(); + */ + clone: function () { + var clone = Base.clone.call(this); + clone.words = this.words.slice(0); + + return clone; + }, + + /** + * Creates a word array filled with random bytes. + * + * @param {number} nBytes The number of random bytes to generate. + * + * @return {WordArray} The random word array. + * + * @static + * + * @example + * + * var wordArray = CryptoJS.lib.WordArray.random(16); + */ + random: function (nBytes) { + var words = []; + + for (var i = 0; i < nBytes; i += 4) { + words.push(cryptoSecureRandomInt()); + } + + return new WordArray.init(words, nBytes); + } + }); + + /** + * Encoder namespace. + */ + var C_enc = C.enc = {}; + + /** + * Hex encoding strategy. + */ + var Hex = C_enc.Hex = { + /** + * Converts a word array to a hex string. + * + * @param {WordArray} wordArray The word array. + * + * @return {string} The hex string. + * + * @static + * + * @example + * + * var hexString = CryptoJS.enc.Hex.stringify(wordArray); + */ + stringify: function (wordArray) { + // Shortcuts + var words = wordArray.words; + var sigBytes = wordArray.sigBytes; + + // Convert + var hexChars = []; + for (var i = 0; i < sigBytes; i++) { + var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; + hexChars.push((bite >>> 4).toString(16)); + hexChars.push((bite & 0x0f).toString(16)); + } + + return hexChars.join(''); + }, + + /** + * Converts a hex string to a word array. + * + * @param {string} hexStr The hex string. + * + * @return {WordArray} The word array. + * + * @static + * + * @example + * + * var wordArray = CryptoJS.enc.Hex.parse(hexString); + */ + parse: function (hexStr) { + // Shortcut + var hexStrLength = hexStr.length; + + // Convert + var words = []; + for (var i = 0; i < hexStrLength; i += 2) { + words[i >>> 3] |= parseInt(hexStr.substr(i, 2), 16) << (24 - (i % 8) * 4); + } + + return new WordArray.init(words, hexStrLength / 2); + } + }; + + /** + * Latin1 encoding strategy. + */ + var Latin1 = C_enc.Latin1 = { + /** + * Converts a word array to a Latin1 string. + * + * @param {WordArray} wordArray The word array. + * + * @return {string} The Latin1 string. + * + * @static + * + * @example + * + * var latin1String = CryptoJS.enc.Latin1.stringify(wordArray); + */ + stringify: function (wordArray) { + // Shortcuts + var words = wordArray.words; + var sigBytes = wordArray.sigBytes; + + // Convert + var latin1Chars = []; + for (var i = 0; i < sigBytes; i++) { + var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; + latin1Chars.push(String.fromCharCode(bite)); + } + + return latin1Chars.join(''); + }, + + /** + * Converts a Latin1 string to a word array. + * + * @param {string} latin1Str The Latin1 string. + * + * @return {WordArray} The word array. + * + * @static + * + * @example + * + * var wordArray = CryptoJS.enc.Latin1.parse(latin1String); + */ + parse: function (latin1Str) { + // Shortcut + var latin1StrLength = latin1Str.length; + + // Convert + var words = []; + for (var i = 0; i < latin1StrLength; i++) { + words[i >>> 2] |= (latin1Str.charCodeAt(i) & 0xff) << (24 - (i % 4) * 8); + } + + return new WordArray.init(words, latin1StrLength); + } + }; + + /** + * UTF-8 encoding strategy. + */ + var Utf8 = C_enc.Utf8 = { + /** + * Converts a word array to a UTF-8 string. + * + * @param {WordArray} wordArray The word array. + * + * @return {string} The UTF-8 string. + * + * @static + * + * @example + * + * var utf8String = CryptoJS.enc.Utf8.stringify(wordArray); + */ + stringify: function (wordArray) { + try { + return decodeURIComponent(escape(Latin1.stringify(wordArray))); + } catch (e) { + throw new Error('Malformed UTF-8 data'); + } + }, + + /** + * Converts a UTF-8 string to a word array. + * + * @param {string} utf8Str The UTF-8 string. + * + * @return {WordArray} The word array. + * + * @static + * + * @example + * + * var wordArray = CryptoJS.enc.Utf8.parse(utf8String); + */ + parse: function (utf8Str) { + return Latin1.parse(unescape(encodeURIComponent(utf8Str))); + } + }; + + /** + * Abstract buffered block algorithm template. + * + * The property blockSize must be implemented in a concrete subtype. + * + * @property {number} _minBufferSize The number of blocks that should be kept unprocessed in the buffer. Default: 0 + */ + var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm = Base.extend({ + /** + * Resets this block algorithm's data buffer to its initial state. + * + * @example + * + * bufferedBlockAlgorithm.reset(); + */ + reset: function () { + // Initial values + this._data = new WordArray.init(); + this._nDataBytes = 0; + }, + + /** + * Adds new data to this block algorithm's buffer. + * + * @param {WordArray|string} data The data to append. Strings are converted to a WordArray using UTF-8. + * + * @example + * + * bufferedBlockAlgorithm._append('data'); + * bufferedBlockAlgorithm._append(wordArray); + */ + _append: function (data) { + // Convert string to WordArray, else assume WordArray already + if (typeof data == 'string') { + data = Utf8.parse(data); + } + + // Append + this._data.concat(data); + this._nDataBytes += data.sigBytes; + }, + + /** + * Processes available data blocks. + * + * This method invokes _doProcessBlock(offset), which must be implemented by a concrete subtype. + * + * @param {boolean} doFlush Whether all blocks and partial blocks should be processed. + * + * @return {WordArray} The processed data. + * + * @example + * + * var processedData = bufferedBlockAlgorithm._process(); + * var processedData = bufferedBlockAlgorithm._process(!!'flush'); + */ + _process: function (doFlush) { + var processedWords; + + // Shortcuts + var data = this._data; + var dataWords = data.words; + var dataSigBytes = data.sigBytes; + var blockSize = this.blockSize; + var blockSizeBytes = blockSize * 4; + + // Count blocks ready + var nBlocksReady = dataSigBytes / blockSizeBytes; + if (doFlush) { + // Round up to include partial blocks + nBlocksReady = Math.ceil(nBlocksReady); + } else { + // Round down to include only full blocks, + // less the number of blocks that must remain in the buffer + nBlocksReady = Math.max((nBlocksReady | 0) - this._minBufferSize, 0); + } + + // Count words ready + var nWordsReady = nBlocksReady * blockSize; + + // Count bytes ready + var nBytesReady = Math.min(nWordsReady * 4, dataSigBytes); + + // Process blocks + if (nWordsReady) { + for (var offset = 0; offset < nWordsReady; offset += blockSize) { + // Perform concrete-algorithm logic + this._doProcessBlock(dataWords, offset); + } + + // Remove processed words + processedWords = dataWords.splice(0, nWordsReady); + data.sigBytes -= nBytesReady; + } + + // Return processed words + return new WordArray.init(processedWords, nBytesReady); + }, + + /** + * Creates a copy of this object. + * + * @return {Object} The clone. + * + * @example + * + * var clone = bufferedBlockAlgorithm.clone(); + */ + clone: function () { + var clone = Base.clone.call(this); + clone._data = this._data.clone(); + + return clone; + }, + + _minBufferSize: 0 + }); + + /** + * Abstract hasher template. + * + * @property {number} blockSize The number of 32-bit words this hasher operates on. Default: 16 (512 bits) + */ + var Hasher = C_lib.Hasher = BufferedBlockAlgorithm.extend({ + /** + * Configuration options. + */ + cfg: Base.extend(), + + /** + * Initializes a newly created hasher. + * + * @param {Object} cfg (Optional) The configuration options to use for this hash computation. + * + * @example + * + * var hasher = CryptoJS.algo.SHA256.create(); + */ + init: function (cfg) { + // Apply config defaults + this.cfg = this.cfg.extend(cfg); + + // Set initial values + this.reset(); + }, + + /** + * Resets this hasher to its initial state. + * + * @example + * + * hasher.reset(); + */ + reset: function () { + // Reset data buffer + BufferedBlockAlgorithm.reset.call(this); + + // Perform concrete-hasher logic + this._doReset(); + }, + + /** + * Updates this hasher with a message. + * + * @param {WordArray|string} messageUpdate The message to append. + * + * @return {Hasher} This hasher. + * + * @example + * + * hasher.update('message'); + * hasher.update(wordArray); + */ + update: function (messageUpdate) { + // Append + this._append(messageUpdate); + + // Update the hash + this._process(); + + // Chainable + return this; + }, + + /** + * Finalizes the hash computation. + * Note that the finalize operation is effectively a destructive, read-once operation. + * + * @param {WordArray|string} messageUpdate (Optional) A final message update. + * + * @return {WordArray} The hash. + * + * @example + * + * var hash = hasher.finalize(); + * var hash = hasher.finalize('message'); + * var hash = hasher.finalize(wordArray); + */ + finalize: function (messageUpdate) { + // Final message update + if (messageUpdate) { + this._append(messageUpdate); + } + + // Perform concrete-hasher logic + var hash = this._doFinalize(); + + return hash; + }, + + blockSize: 512/32, + + /** + * Creates a shortcut function to a hasher's object interface. + * + * @param {Hasher} hasher The hasher to create a helper for. + * + * @return {Function} The shortcut function. + * + * @static + * + * @example + * + * var SHA256 = CryptoJS.lib.Hasher._createHelper(CryptoJS.algo.SHA256); + */ + _createHelper: function (hasher) { + return function (message, cfg) { + return new hasher.init(cfg).finalize(message); + }; + }, + + /** + * Creates a shortcut function to the HMAC's object interface. + * + * @param {Hasher} hasher The hasher to use in this HMAC helper. + * + * @return {Function} The shortcut function. + * + * @static + * + * @example + * + * var HmacSHA256 = CryptoJS.lib.Hasher._createHmacHelper(CryptoJS.algo.SHA256); + */ + _createHmacHelper: function (hasher) { + return function (message, key) { + return new C_algo.HMAC.init(hasher, key).finalize(message); + }; + } + }); + + /** + * Algorithm namespace. + */ + var C_algo = C.algo = {}; + + return C; + }(Math)); + + + (function (undefined) { + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var Base = C_lib.Base; + var X32WordArray = C_lib.WordArray; + + /** + * x64 namespace. + */ + var C_x64 = C.x64 = {}; + + /** + * A 64-bit word. + */ + var X64Word = C_x64.Word = Base.extend({ + /** + * Initializes a newly created 64-bit word. + * + * @param {number} high The high 32 bits. + * @param {number} low The low 32 bits. + * + * @example + * + * var x64Word = CryptoJS.x64.Word.create(0x00010203, 0x04050607); + */ + init: function (high, low) { + this.high = high; + this.low = low; + } + + /** + * Bitwise NOTs this word. + * + * @return {X64Word} A new x64-Word object after negating. + * + * @example + * + * var negated = x64Word.not(); + */ + // not: function () { + // var high = ~this.high; + // var low = ~this.low; + + // return X64Word.create(high, low); + // }, + + /** + * Bitwise ANDs this word with the passed word. + * + * @param {X64Word} word The x64-Word to AND with this word. + * + * @return {X64Word} A new x64-Word object after ANDing. + * + * @example + * + * var anded = x64Word.and(anotherX64Word); + */ + // and: function (word) { + // var high = this.high & word.high; + // var low = this.low & word.low; + + // return X64Word.create(high, low); + // }, + + /** + * Bitwise ORs this word with the passed word. + * + * @param {X64Word} word The x64-Word to OR with this word. + * + * @return {X64Word} A new x64-Word object after ORing. + * + * @example + * + * var ored = x64Word.or(anotherX64Word); + */ + // or: function (word) { + // var high = this.high | word.high; + // var low = this.low | word.low; + + // return X64Word.create(high, low); + // }, + + /** + * Bitwise XORs this word with the passed word. + * + * @param {X64Word} word The x64-Word to XOR with this word. + * + * @return {X64Word} A new x64-Word object after XORing. + * + * @example + * + * var xored = x64Word.xor(anotherX64Word); + */ + // xor: function (word) { + // var high = this.high ^ word.high; + // var low = this.low ^ word.low; + + // return X64Word.create(high, low); + // }, + + /** + * Shifts this word n bits to the left. + * + * @param {number} n The number of bits to shift. + * + * @return {X64Word} A new x64-Word object after shifting. + * + * @example + * + * var shifted = x64Word.shiftL(25); + */ + // shiftL: function (n) { + // if (n < 32) { + // var high = (this.high << n) | (this.low >>> (32 - n)); + // var low = this.low << n; + // } else { + // var high = this.low << (n - 32); + // var low = 0; + // } + + // return X64Word.create(high, low); + // }, + + /** + * Shifts this word n bits to the right. + * + * @param {number} n The number of bits to shift. + * + * @return {X64Word} A new x64-Word object after shifting. + * + * @example + * + * var shifted = x64Word.shiftR(7); + */ + // shiftR: function (n) { + // if (n < 32) { + // var low = (this.low >>> n) | (this.high << (32 - n)); + // var high = this.high >>> n; + // } else { + // var low = this.high >>> (n - 32); + // var high = 0; + // } + + // return X64Word.create(high, low); + // }, + + /** + * Rotates this word n bits to the left. + * + * @param {number} n The number of bits to rotate. + * + * @return {X64Word} A new x64-Word object after rotating. + * + * @example + * + * var rotated = x64Word.rotL(25); + */ + // rotL: function (n) { + // return this.shiftL(n).or(this.shiftR(64 - n)); + // }, + + /** + * Rotates this word n bits to the right. + * + * @param {number} n The number of bits to rotate. + * + * @return {X64Word} A new x64-Word object after rotating. + * + * @example + * + * var rotated = x64Word.rotR(7); + */ + // rotR: function (n) { + // return this.shiftR(n).or(this.shiftL(64 - n)); + // }, + + /** + * Adds this word with the passed word. + * + * @param {X64Word} word The x64-Word to add with this word. + * + * @return {X64Word} A new x64-Word object after adding. + * + * @example + * + * var added = x64Word.add(anotherX64Word); + */ + // add: function (word) { + // var low = (this.low + word.low) | 0; + // var carry = (low >>> 0) < (this.low >>> 0) ? 1 : 0; + // var high = (this.high + word.high + carry) | 0; + + // return X64Word.create(high, low); + // } + }); + + /** + * An array of 64-bit words. + * + * @property {Array} words The array of CryptoJS.x64.Word objects. + * @property {number} sigBytes The number of significant bytes in this word array. + */ + var X64WordArray = C_x64.WordArray = Base.extend({ + /** + * Initializes a newly created word array. + * + * @param {Array} words (Optional) An array of CryptoJS.x64.Word objects. + * @param {number} sigBytes (Optional) The number of significant bytes in the words. + * + * @example + * + * var wordArray = CryptoJS.x64.WordArray.create(); + * + * var wordArray = CryptoJS.x64.WordArray.create([ + * CryptoJS.x64.Word.create(0x00010203, 0x04050607), + * CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f) + * ]); + * + * var wordArray = CryptoJS.x64.WordArray.create([ + * CryptoJS.x64.Word.create(0x00010203, 0x04050607), + * CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f) + * ], 10); + */ + init: function (words, sigBytes) { + words = this.words = words || []; + + if (sigBytes != undefined) { + this.sigBytes = sigBytes; + } else { + this.sigBytes = words.length * 8; + } + }, + + /** + * Converts this 64-bit word array to a 32-bit word array. + * + * @return {CryptoJS.lib.WordArray} This word array's data as a 32-bit word array. + * + * @example + * + * var x32WordArray = x64WordArray.toX32(); + */ + toX32: function () { + // Shortcuts + var x64Words = this.words; + var x64WordsLength = x64Words.length; + + // Convert + var x32Words = []; + for (var i = 0; i < x64WordsLength; i++) { + var x64Word = x64Words[i]; + x32Words.push(x64Word.high); + x32Words.push(x64Word.low); + } + + return X32WordArray.create(x32Words, this.sigBytes); + }, + + /** + * Creates a copy of this word array. + * + * @return {X64WordArray} The clone. + * + * @example + * + * var clone = x64WordArray.clone(); + */ + clone: function () { + var clone = Base.clone.call(this); + + // Clone "words" array + var words = clone.words = this.words.slice(0); + + // Clone each X64Word object + var wordsLength = words.length; + for (var i = 0; i < wordsLength; i++) { + words[i] = words[i].clone(); + } + + return clone; + } + }); + }()); + + + (function () { + // Check if typed arrays are supported + if (typeof ArrayBuffer != 'function') { + return; + } + + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var WordArray = C_lib.WordArray; + + // Reference original init + var superInit = WordArray.init; + + // Augment WordArray.init to handle typed arrays + var subInit = WordArray.init = function (typedArray) { + // Convert buffers to uint8 + if (typedArray instanceof ArrayBuffer) { + typedArray = new Uint8Array(typedArray); + } + + // Convert other array views to uint8 + if ( + typedArray instanceof Int8Array || + (typeof Uint8ClampedArray !== "undefined" && typedArray instanceof Uint8ClampedArray) || + typedArray instanceof Int16Array || + typedArray instanceof Uint16Array || + typedArray instanceof Int32Array || + typedArray instanceof Uint32Array || + typedArray instanceof Float32Array || + typedArray instanceof Float64Array + ) { + typedArray = new Uint8Array(typedArray.buffer, typedArray.byteOffset, typedArray.byteLength); + } + + // Handle Uint8Array + if (typedArray instanceof Uint8Array) { + // Shortcut + var typedArrayByteLength = typedArray.byteLength; + + // Extract bytes + var words = []; + for (var i = 0; i < typedArrayByteLength; i++) { + words[i >>> 2] |= typedArray[i] << (24 - (i % 4) * 8); + } + + // Initialize this word array + superInit.call(this, words, typedArrayByteLength); + } else { + // Else call normal init + superInit.apply(this, arguments); + } + }; + + subInit.prototype = WordArray; + }()); + + + (function () { + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var WordArray = C_lib.WordArray; + var C_enc = C.enc; + + /** + * UTF-16 BE encoding strategy. + */ + var Utf16BE = C_enc.Utf16 = C_enc.Utf16BE = { + /** + * Converts a word array to a UTF-16 BE string. + * + * @param {WordArray} wordArray The word array. + * + * @return {string} The UTF-16 BE string. + * + * @static + * + * @example + * + * var utf16String = CryptoJS.enc.Utf16.stringify(wordArray); + */ + stringify: function (wordArray) { + // Shortcuts + var words = wordArray.words; + var sigBytes = wordArray.sigBytes; + + // Convert + var utf16Chars = []; + for (var i = 0; i < sigBytes; i += 2) { + var codePoint = (words[i >>> 2] >>> (16 - (i % 4) * 8)) & 0xffff; + utf16Chars.push(String.fromCharCode(codePoint)); + } + + return utf16Chars.join(''); + }, + + /** + * Converts a UTF-16 BE string to a word array. + * + * @param {string} utf16Str The UTF-16 BE string. + * + * @return {WordArray} The word array. + * + * @static + * + * @example + * + * var wordArray = CryptoJS.enc.Utf16.parse(utf16String); + */ + parse: function (utf16Str) { + // Shortcut + var utf16StrLength = utf16Str.length; + + // Convert + var words = []; + for (var i = 0; i < utf16StrLength; i++) { + words[i >>> 1] |= utf16Str.charCodeAt(i) << (16 - (i % 2) * 16); + } + + return WordArray.create(words, utf16StrLength * 2); + } + }; + + /** + * UTF-16 LE encoding strategy. + */ + C_enc.Utf16LE = { + /** + * Converts a word array to a UTF-16 LE string. + * + * @param {WordArray} wordArray The word array. + * + * @return {string} The UTF-16 LE string. + * + * @static + * + * @example + * + * var utf16Str = CryptoJS.enc.Utf16LE.stringify(wordArray); + */ + stringify: function (wordArray) { + // Shortcuts + var words = wordArray.words; + var sigBytes = wordArray.sigBytes; + + // Convert + var utf16Chars = []; + for (var i = 0; i < sigBytes; i += 2) { + var codePoint = swapEndian((words[i >>> 2] >>> (16 - (i % 4) * 8)) & 0xffff); + utf16Chars.push(String.fromCharCode(codePoint)); + } + + return utf16Chars.join(''); + }, + + /** + * Converts a UTF-16 LE string to a word array. + * + * @param {string} utf16Str The UTF-16 LE string. + * + * @return {WordArray} The word array. + * + * @static + * + * @example + * + * var wordArray = CryptoJS.enc.Utf16LE.parse(utf16Str); + */ + parse: function (utf16Str) { + // Shortcut + var utf16StrLength = utf16Str.length; + + // Convert + var words = []; + for (var i = 0; i < utf16StrLength; i++) { + words[i >>> 1] |= swapEndian(utf16Str.charCodeAt(i) << (16 - (i % 2) * 16)); + } + + return WordArray.create(words, utf16StrLength * 2); + } + }; + + function swapEndian(word) { + return ((word << 8) & 0xff00ff00) | ((word >>> 8) & 0x00ff00ff); + } + }()); + + + (function () { + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var WordArray = C_lib.WordArray; + var C_enc = C.enc; + + /** + * Base64 encoding strategy. + */ + var Base64 = C_enc.Base64 = { + /** + * Converts a word array to a Base64 string. + * + * @param {WordArray} wordArray The word array. + * + * @return {string} The Base64 string. + * + * @static + * + * @example + * + * var base64String = CryptoJS.enc.Base64.stringify(wordArray); + */ + stringify: function (wordArray) { + // Shortcuts + var words = wordArray.words; + var sigBytes = wordArray.sigBytes; + var map = this._map; + + // Clamp excess bits + wordArray.clamp(); + + // Convert + var base64Chars = []; + for (var i = 0; i < sigBytes; i += 3) { + var byte1 = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; + var byte2 = (words[(i + 1) >>> 2] >>> (24 - ((i + 1) % 4) * 8)) & 0xff; + var byte3 = (words[(i + 2) >>> 2] >>> (24 - ((i + 2) % 4) * 8)) & 0xff; + + var triplet = (byte1 << 16) | (byte2 << 8) | byte3; + + for (var j = 0; (j < 4) && (i + j * 0.75 < sigBytes); j++) { + base64Chars.push(map.charAt((triplet >>> (6 * (3 - j))) & 0x3f)); + } + } + + // Add padding + var paddingChar = map.charAt(64); + if (paddingChar) { + while (base64Chars.length % 4) { + base64Chars.push(paddingChar); + } + } + + return base64Chars.join(''); + }, + + /** + * Converts a Base64 string to a word array. + * + * @param {string} base64Str The Base64 string. + * + * @return {WordArray} The word array. + * + * @static + * + * @example + * + * var wordArray = CryptoJS.enc.Base64.parse(base64String); + */ + parse: function (base64Str) { + // Shortcuts + var base64StrLength = base64Str.length; + var map = this._map; + var reverseMap = this._reverseMap; + + if (!reverseMap) { + reverseMap = this._reverseMap = []; + for (var j = 0; j < map.length; j++) { + reverseMap[map.charCodeAt(j)] = j; + } + } + + // Ignore padding + var paddingChar = map.charAt(64); + if (paddingChar) { + var paddingIndex = base64Str.indexOf(paddingChar); + if (paddingIndex !== -1) { + base64StrLength = paddingIndex; + } + } + + // Convert + return parseLoop(base64Str, base64StrLength, reverseMap); + + }, + + _map: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=' + }; + + function parseLoop(base64Str, base64StrLength, reverseMap) { + var words = []; + var nBytes = 0; + for (var i = 0; i < base64StrLength; i++) { + if (i % 4) { + var bits1 = reverseMap[base64Str.charCodeAt(i - 1)] << ((i % 4) * 2); + var bits2 = reverseMap[base64Str.charCodeAt(i)] >>> (6 - (i % 4) * 2); + var bitsCombined = bits1 | bits2; + words[nBytes >>> 2] |= bitsCombined << (24 - (nBytes % 4) * 8); + nBytes++; + } + } + return WordArray.create(words, nBytes); + } + }()); + + + (function () { + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var WordArray = C_lib.WordArray; + var C_enc = C.enc; + + /** + * Base64url encoding strategy. + */ + var Base64url = C_enc.Base64url = { + /** + * Converts a word array to a Base64url string. + * + * @param {WordArray} wordArray The word array. + * + * @param {boolean} urlSafe Whether to use url safe + * + * @return {string} The Base64url string. + * + * @static + * + * @example + * + * var base64String = CryptoJS.enc.Base64url.stringify(wordArray); + */ + stringify: function (wordArray, urlSafe=true) { + // Shortcuts + var words = wordArray.words; + var sigBytes = wordArray.sigBytes; + var map = urlSafe ? this._safe_map : this._map; + + // Clamp excess bits + wordArray.clamp(); + + // Convert + var base64Chars = []; + for (var i = 0; i < sigBytes; i += 3) { + var byte1 = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; + var byte2 = (words[(i + 1) >>> 2] >>> (24 - ((i + 1) % 4) * 8)) & 0xff; + var byte3 = (words[(i + 2) >>> 2] >>> (24 - ((i + 2) % 4) * 8)) & 0xff; + + var triplet = (byte1 << 16) | (byte2 << 8) | byte3; + + for (var j = 0; (j < 4) && (i + j * 0.75 < sigBytes); j++) { + base64Chars.push(map.charAt((triplet >>> (6 * (3 - j))) & 0x3f)); + } + } + + // Add padding + var paddingChar = map.charAt(64); + if (paddingChar) { + while (base64Chars.length % 4) { + base64Chars.push(paddingChar); + } + } + + return base64Chars.join(''); + }, + + /** + * Converts a Base64url string to a word array. + * + * @param {string} base64Str The Base64url string. + * + * @param {boolean} urlSafe Whether to use url safe + * + * @return {WordArray} The word array. + * + * @static + * + * @example + * + * var wordArray = CryptoJS.enc.Base64url.parse(base64String); + */ + parse: function (base64Str, urlSafe=true) { + // Shortcuts + var base64StrLength = base64Str.length; + var map = urlSafe ? this._safe_map : this._map; + var reverseMap = this._reverseMap; + + if (!reverseMap) { + reverseMap = this._reverseMap = []; + for (var j = 0; j < map.length; j++) { + reverseMap[map.charCodeAt(j)] = j; + } + } + + // Ignore padding + var paddingChar = map.charAt(64); + if (paddingChar) { + var paddingIndex = base64Str.indexOf(paddingChar); + if (paddingIndex !== -1) { + base64StrLength = paddingIndex; + } + } + + // Convert + return parseLoop(base64Str, base64StrLength, reverseMap); + + }, + + _map: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=', + _safe_map: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_', + }; + + function parseLoop(base64Str, base64StrLength, reverseMap) { + var words = []; + var nBytes = 0; + for (var i = 0; i < base64StrLength; i++) { + if (i % 4) { + var bits1 = reverseMap[base64Str.charCodeAt(i - 1)] << ((i % 4) * 2); + var bits2 = reverseMap[base64Str.charCodeAt(i)] >>> (6 - (i % 4) * 2); + var bitsCombined = bits1 | bits2; + words[nBytes >>> 2] |= bitsCombined << (24 - (nBytes % 4) * 8); + nBytes++; + } + } + return WordArray.create(words, nBytes); + } + }()); + + (function (Math) { + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var WordArray = C_lib.WordArray; + var Hasher = C_lib.Hasher; + var C_algo = C.algo; + + // Constants table + var T = []; + + // Compute constants + (function () { + for (var i = 0; i < 64; i++) { + T[i] = (Math.abs(Math.sin(i + 1)) * 0x100000000) | 0; + } + }()); + + /** + * MD5 hash algorithm. + */ + var MD5 = C_algo.MD5 = Hasher.extend({ + _doReset: function () { + this._hash = new WordArray.init([ + 0x67452301, 0xefcdab89, + 0x98badcfe, 0x10325476 + ]); + }, + + _doProcessBlock: function (M, offset) { + // Swap endian + for (var i = 0; i < 16; i++) { + // Shortcuts + var offset_i = offset + i; + var M_offset_i = M[offset_i]; + + M[offset_i] = ( + (((M_offset_i << 8) | (M_offset_i >>> 24)) & 0x00ff00ff) | + (((M_offset_i << 24) | (M_offset_i >>> 8)) & 0xff00ff00) + ); + } + + // Shortcuts + var H = this._hash.words; + + var M_offset_0 = M[offset + 0]; + var M_offset_1 = M[offset + 1]; + var M_offset_2 = M[offset + 2]; + var M_offset_3 = M[offset + 3]; + var M_offset_4 = M[offset + 4]; + var M_offset_5 = M[offset + 5]; + var M_offset_6 = M[offset + 6]; + var M_offset_7 = M[offset + 7]; + var M_offset_8 = M[offset + 8]; + var M_offset_9 = M[offset + 9]; + var M_offset_10 = M[offset + 10]; + var M_offset_11 = M[offset + 11]; + var M_offset_12 = M[offset + 12]; + var M_offset_13 = M[offset + 13]; + var M_offset_14 = M[offset + 14]; + var M_offset_15 = M[offset + 15]; + + // Working varialbes + var a = H[0]; + var b = H[1]; + var c = H[2]; + var d = H[3]; + + // Computation + a = FF(a, b, c, d, M_offset_0, 7, T[0]); + d = FF(d, a, b, c, M_offset_1, 12, T[1]); + c = FF(c, d, a, b, M_offset_2, 17, T[2]); + b = FF(b, c, d, a, M_offset_3, 22, T[3]); + a = FF(a, b, c, d, M_offset_4, 7, T[4]); + d = FF(d, a, b, c, M_offset_5, 12, T[5]); + c = FF(c, d, a, b, M_offset_6, 17, T[6]); + b = FF(b, c, d, a, M_offset_7, 22, T[7]); + a = FF(a, b, c, d, M_offset_8, 7, T[8]); + d = FF(d, a, b, c, M_offset_9, 12, T[9]); + c = FF(c, d, a, b, M_offset_10, 17, T[10]); + b = FF(b, c, d, a, M_offset_11, 22, T[11]); + a = FF(a, b, c, d, M_offset_12, 7, T[12]); + d = FF(d, a, b, c, M_offset_13, 12, T[13]); + c = FF(c, d, a, b, M_offset_14, 17, T[14]); + b = FF(b, c, d, a, M_offset_15, 22, T[15]); + + a = GG(a, b, c, d, M_offset_1, 5, T[16]); + d = GG(d, a, b, c, M_offset_6, 9, T[17]); + c = GG(c, d, a, b, M_offset_11, 14, T[18]); + b = GG(b, c, d, a, M_offset_0, 20, T[19]); + a = GG(a, b, c, d, M_offset_5, 5, T[20]); + d = GG(d, a, b, c, M_offset_10, 9, T[21]); + c = GG(c, d, a, b, M_offset_15, 14, T[22]); + b = GG(b, c, d, a, M_offset_4, 20, T[23]); + a = GG(a, b, c, d, M_offset_9, 5, T[24]); + d = GG(d, a, b, c, M_offset_14, 9, T[25]); + c = GG(c, d, a, b, M_offset_3, 14, T[26]); + b = GG(b, c, d, a, M_offset_8, 20, T[27]); + a = GG(a, b, c, d, M_offset_13, 5, T[28]); + d = GG(d, a, b, c, M_offset_2, 9, T[29]); + c = GG(c, d, a, b, M_offset_7, 14, T[30]); + b = GG(b, c, d, a, M_offset_12, 20, T[31]); + + a = HH(a, b, c, d, M_offset_5, 4, T[32]); + d = HH(d, a, b, c, M_offset_8, 11, T[33]); + c = HH(c, d, a, b, M_offset_11, 16, T[34]); + b = HH(b, c, d, a, M_offset_14, 23, T[35]); + a = HH(a, b, c, d, M_offset_1, 4, T[36]); + d = HH(d, a, b, c, M_offset_4, 11, T[37]); + c = HH(c, d, a, b, M_offset_7, 16, T[38]); + b = HH(b, c, d, a, M_offset_10, 23, T[39]); + a = HH(a, b, c, d, M_offset_13, 4, T[40]); + d = HH(d, a, b, c, M_offset_0, 11, T[41]); + c = HH(c, d, a, b, M_offset_3, 16, T[42]); + b = HH(b, c, d, a, M_offset_6, 23, T[43]); + a = HH(a, b, c, d, M_offset_9, 4, T[44]); + d = HH(d, a, b, c, M_offset_12, 11, T[45]); + c = HH(c, d, a, b, M_offset_15, 16, T[46]); + b = HH(b, c, d, a, M_offset_2, 23, T[47]); + + a = II(a, b, c, d, M_offset_0, 6, T[48]); + d = II(d, a, b, c, M_offset_7, 10, T[49]); + c = II(c, d, a, b, M_offset_14, 15, T[50]); + b = II(b, c, d, a, M_offset_5, 21, T[51]); + a = II(a, b, c, d, M_offset_12, 6, T[52]); + d = II(d, a, b, c, M_offset_3, 10, T[53]); + c = II(c, d, a, b, M_offset_10, 15, T[54]); + b = II(b, c, d, a, M_offset_1, 21, T[55]); + a = II(a, b, c, d, M_offset_8, 6, T[56]); + d = II(d, a, b, c, M_offset_15, 10, T[57]); + c = II(c, d, a, b, M_offset_6, 15, T[58]); + b = II(b, c, d, a, M_offset_13, 21, T[59]); + a = II(a, b, c, d, M_offset_4, 6, T[60]); + d = II(d, a, b, c, M_offset_11, 10, T[61]); + c = II(c, d, a, b, M_offset_2, 15, T[62]); + b = II(b, c, d, a, M_offset_9, 21, T[63]); + + // Intermediate hash value + H[0] = (H[0] + a) | 0; + H[1] = (H[1] + b) | 0; + H[2] = (H[2] + c) | 0; + H[3] = (H[3] + d) | 0; + }, + + _doFinalize: function () { + // Shortcuts + var data = this._data; + var dataWords = data.words; + + var nBitsTotal = this._nDataBytes * 8; + var nBitsLeft = data.sigBytes * 8; + + // Add padding + dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); + + var nBitsTotalH = Math.floor(nBitsTotal / 0x100000000); + var nBitsTotalL = nBitsTotal; + dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = ( + (((nBitsTotalH << 8) | (nBitsTotalH >>> 24)) & 0x00ff00ff) | + (((nBitsTotalH << 24) | (nBitsTotalH >>> 8)) & 0xff00ff00) + ); + dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = ( + (((nBitsTotalL << 8) | (nBitsTotalL >>> 24)) & 0x00ff00ff) | + (((nBitsTotalL << 24) | (nBitsTotalL >>> 8)) & 0xff00ff00) + ); + + data.sigBytes = (dataWords.length + 1) * 4; + + // Hash final blocks + this._process(); + + // Shortcuts + var hash = this._hash; + var H = hash.words; + + // Swap endian + for (var i = 0; i < 4; i++) { + // Shortcut + var H_i = H[i]; + + H[i] = (((H_i << 8) | (H_i >>> 24)) & 0x00ff00ff) | + (((H_i << 24) | (H_i >>> 8)) & 0xff00ff00); + } + + // Return final computed hash + return hash; + }, + + clone: function () { + var clone = Hasher.clone.call(this); + clone._hash = this._hash.clone(); + + return clone; + } + }); + + function FF(a, b, c, d, x, s, t) { + var n = a + ((b & c) | (~b & d)) + x + t; + return ((n << s) | (n >>> (32 - s))) + b; + } + + function GG(a, b, c, d, x, s, t) { + var n = a + ((b & d) | (c & ~d)) + x + t; + return ((n << s) | (n >>> (32 - s))) + b; + } + + function HH(a, b, c, d, x, s, t) { + var n = a + (b ^ c ^ d) + x + t; + return ((n << s) | (n >>> (32 - s))) + b; + } + + function II(a, b, c, d, x, s, t) { + var n = a + (c ^ (b | ~d)) + x + t; + return ((n << s) | (n >>> (32 - s))) + b; + } + + /** + * Shortcut function to the hasher's object interface. + * + * @param {WordArray|string} message The message to hash. + * + * @return {WordArray} The hash. + * + * @static + * + * @example + * + * var hash = CryptoJS.MD5('message'); + * var hash = CryptoJS.MD5(wordArray); + */ + C.MD5 = Hasher._createHelper(MD5); + + /** + * Shortcut function to the HMAC's object interface. + * + * @param {WordArray|string} message The message to hash. + * @param {WordArray|string} key The secret key. + * + * @return {WordArray} The HMAC. + * + * @static + * + * @example + * + * var hmac = CryptoJS.HmacMD5(message, key); + */ + C.HmacMD5 = Hasher._createHmacHelper(MD5); + }(Math)); + + + (function () { + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var WordArray = C_lib.WordArray; + var Hasher = C_lib.Hasher; + var C_algo = C.algo; + + // Reusable object + var W = []; + + /** + * SHA-1 hash algorithm. + */ + var SHA1 = C_algo.SHA1 = Hasher.extend({ + _doReset: function () { + this._hash = new WordArray.init([ + 0x67452301, 0xefcdab89, + 0x98badcfe, 0x10325476, + 0xc3d2e1f0 + ]); + }, + + _doProcessBlock: function (M, offset) { + // Shortcut + var H = this._hash.words; + + // Working variables + var a = H[0]; + var b = H[1]; + var c = H[2]; + var d = H[3]; + var e = H[4]; + + // Computation + for (var i = 0; i < 80; i++) { + if (i < 16) { + W[i] = M[offset + i] | 0; + } else { + var n = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16]; + W[i] = (n << 1) | (n >>> 31); + } + + var t = ((a << 5) | (a >>> 27)) + e + W[i]; + if (i < 20) { + t += ((b & c) | (~b & d)) + 0x5a827999; + } else if (i < 40) { + t += (b ^ c ^ d) + 0x6ed9eba1; + } else if (i < 60) { + t += ((b & c) | (b & d) | (c & d)) - 0x70e44324; + } else /* if (i < 80) */ { + t += (b ^ c ^ d) - 0x359d3e2a; + } + + e = d; + d = c; + c = (b << 30) | (b >>> 2); + b = a; + a = t; + } + + // Intermediate hash value + H[0] = (H[0] + a) | 0; + H[1] = (H[1] + b) | 0; + H[2] = (H[2] + c) | 0; + H[3] = (H[3] + d) | 0; + H[4] = (H[4] + e) | 0; + }, + + _doFinalize: function () { + // Shortcuts + var data = this._data; + var dataWords = data.words; + + var nBitsTotal = this._nDataBytes * 8; + var nBitsLeft = data.sigBytes * 8; + + // Add padding + dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); + dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor(nBitsTotal / 0x100000000); + dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal; + data.sigBytes = dataWords.length * 4; + + // Hash final blocks + this._process(); + + // Return final computed hash + return this._hash; + }, + + clone: function () { + var clone = Hasher.clone.call(this); + clone._hash = this._hash.clone(); + + return clone; + } + }); + + /** + * Shortcut function to the hasher's object interface. + * + * @param {WordArray|string} message The message to hash. + * + * @return {WordArray} The hash. + * + * @static + * + * @example + * + * var hash = CryptoJS.SHA1('message'); + * var hash = CryptoJS.SHA1(wordArray); + */ + C.SHA1 = Hasher._createHelper(SHA1); + + /** + * Shortcut function to the HMAC's object interface. + * + * @param {WordArray|string} message The message to hash. + * @param {WordArray|string} key The secret key. + * + * @return {WordArray} The HMAC. + * + * @static + * + * @example + * + * var hmac = CryptoJS.HmacSHA1(message, key); + */ + C.HmacSHA1 = Hasher._createHmacHelper(SHA1); + }()); + + + (function (Math) { + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var WordArray = C_lib.WordArray; + var Hasher = C_lib.Hasher; + var C_algo = C.algo; + + // Initialization and round constants tables + var H = []; + var K = []; + + // Compute constants + (function () { + function isPrime(n) { + var sqrtN = Math.sqrt(n); + for (var factor = 2; factor <= sqrtN; factor++) { + if (!(n % factor)) { + return false; + } + } + + return true; + } + + function getFractionalBits(n) { + return ((n - (n | 0)) * 0x100000000) | 0; + } + + var n = 2; + var nPrime = 0; + while (nPrime < 64) { + if (isPrime(n)) { + if (nPrime < 8) { + H[nPrime] = getFractionalBits(Math.pow(n, 1 / 2)); + } + K[nPrime] = getFractionalBits(Math.pow(n, 1 / 3)); + + nPrime++; + } + + n++; + } + }()); + + // Reusable object + var W = []; + + /** + * SHA-256 hash algorithm. + */ + var SHA256 = C_algo.SHA256 = Hasher.extend({ + _doReset: function () { + this._hash = new WordArray.init(H.slice(0)); + }, + + _doProcessBlock: function (M, offset) { + // Shortcut + var H = this._hash.words; + + // Working variables + var a = H[0]; + var b = H[1]; + var c = H[2]; + var d = H[3]; + var e = H[4]; + var f = H[5]; + var g = H[6]; + var h = H[7]; + + // Computation + for (var i = 0; i < 64; i++) { + if (i < 16) { + W[i] = M[offset + i] | 0; + } else { + var gamma0x = W[i - 15]; + var gamma0 = ((gamma0x << 25) | (gamma0x >>> 7)) ^ + ((gamma0x << 14) | (gamma0x >>> 18)) ^ + (gamma0x >>> 3); + + var gamma1x = W[i - 2]; + var gamma1 = ((gamma1x << 15) | (gamma1x >>> 17)) ^ + ((gamma1x << 13) | (gamma1x >>> 19)) ^ + (gamma1x >>> 10); + + W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16]; + } + + var ch = (e & f) ^ (~e & g); + var maj = (a & b) ^ (a & c) ^ (b & c); + + var sigma0 = ((a << 30) | (a >>> 2)) ^ ((a << 19) | (a >>> 13)) ^ ((a << 10) | (a >>> 22)); + var sigma1 = ((e << 26) | (e >>> 6)) ^ ((e << 21) | (e >>> 11)) ^ ((e << 7) | (e >>> 25)); + + var t1 = h + sigma1 + ch + K[i] + W[i]; + var t2 = sigma0 + maj; + + h = g; + g = f; + f = e; + e = (d + t1) | 0; + d = c; + c = b; + b = a; + a = (t1 + t2) | 0; + } + + // Intermediate hash value + H[0] = (H[0] + a) | 0; + H[1] = (H[1] + b) | 0; + H[2] = (H[2] + c) | 0; + H[3] = (H[3] + d) | 0; + H[4] = (H[4] + e) | 0; + H[5] = (H[5] + f) | 0; + H[6] = (H[6] + g) | 0; + H[7] = (H[7] + h) | 0; + }, + + _doFinalize: function () { + // Shortcuts + var data = this._data; + var dataWords = data.words; + + var nBitsTotal = this._nDataBytes * 8; + var nBitsLeft = data.sigBytes * 8; + + // Add padding + dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); + dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor(nBitsTotal / 0x100000000); + dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal; + data.sigBytes = dataWords.length * 4; + + // Hash final blocks + this._process(); + + // Return final computed hash + return this._hash; + }, + + clone: function () { + var clone = Hasher.clone.call(this); + clone._hash = this._hash.clone(); + + return clone; + } + }); + + /** + * Shortcut function to the hasher's object interface. + * + * @param {WordArray|string} message The message to hash. + * + * @return {WordArray} The hash. + * + * @static + * + * @example + * + * var hash = CryptoJS.SHA256('message'); + * var hash = CryptoJS.SHA256(wordArray); + */ + C.SHA256 = Hasher._createHelper(SHA256); + + /** + * Shortcut function to the HMAC's object interface. + * + * @param {WordArray|string} message The message to hash. + * @param {WordArray|string} key The secret key. + * + * @return {WordArray} The HMAC. + * + * @static + * + * @example + * + * var hmac = CryptoJS.HmacSHA256(message, key); + */ + C.HmacSHA256 = Hasher._createHmacHelper(SHA256); + }(Math)); + + + (function () { + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var WordArray = C_lib.WordArray; + var C_algo = C.algo; + var SHA256 = C_algo.SHA256; + + /** + * SHA-224 hash algorithm. + */ + var SHA224 = C_algo.SHA224 = SHA256.extend({ + _doReset: function () { + this._hash = new WordArray.init([ + 0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939, + 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4 + ]); + }, + + _doFinalize: function () { + var hash = SHA256._doFinalize.call(this); + + hash.sigBytes -= 4; + + return hash; + } + }); + + /** + * Shortcut function to the hasher's object interface. + * + * @param {WordArray|string} message The message to hash. + * + * @return {WordArray} The hash. + * + * @static + * + * @example + * + * var hash = CryptoJS.SHA224('message'); + * var hash = CryptoJS.SHA224(wordArray); + */ + C.SHA224 = SHA256._createHelper(SHA224); + + /** + * Shortcut function to the HMAC's object interface. + * + * @param {WordArray|string} message The message to hash. + * @param {WordArray|string} key The secret key. + * + * @return {WordArray} The HMAC. + * + * @static + * + * @example + * + * var hmac = CryptoJS.HmacSHA224(message, key); + */ + C.HmacSHA224 = SHA256._createHmacHelper(SHA224); + }()); + + + (function () { + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var Hasher = C_lib.Hasher; + var C_x64 = C.x64; + var X64Word = C_x64.Word; + var X64WordArray = C_x64.WordArray; + var C_algo = C.algo; + + function X64Word_create() { + return X64Word.create.apply(X64Word, arguments); + } + + // Constants + var K = [ + X64Word_create(0x428a2f98, 0xd728ae22), X64Word_create(0x71374491, 0x23ef65cd), + X64Word_create(0xb5c0fbcf, 0xec4d3b2f), X64Word_create(0xe9b5dba5, 0x8189dbbc), + X64Word_create(0x3956c25b, 0xf348b538), X64Word_create(0x59f111f1, 0xb605d019), + X64Word_create(0x923f82a4, 0xaf194f9b), X64Word_create(0xab1c5ed5, 0xda6d8118), + X64Word_create(0xd807aa98, 0xa3030242), X64Word_create(0x12835b01, 0x45706fbe), + X64Word_create(0x243185be, 0x4ee4b28c), X64Word_create(0x550c7dc3, 0xd5ffb4e2), + X64Word_create(0x72be5d74, 0xf27b896f), X64Word_create(0x80deb1fe, 0x3b1696b1), + X64Word_create(0x9bdc06a7, 0x25c71235), X64Word_create(0xc19bf174, 0xcf692694), + X64Word_create(0xe49b69c1, 0x9ef14ad2), X64Word_create(0xefbe4786, 0x384f25e3), + X64Word_create(0x0fc19dc6, 0x8b8cd5b5), X64Word_create(0x240ca1cc, 0x77ac9c65), + X64Word_create(0x2de92c6f, 0x592b0275), X64Word_create(0x4a7484aa, 0x6ea6e483), + X64Word_create(0x5cb0a9dc, 0xbd41fbd4), X64Word_create(0x76f988da, 0x831153b5), + X64Word_create(0x983e5152, 0xee66dfab), X64Word_create(0xa831c66d, 0x2db43210), + X64Word_create(0xb00327c8, 0x98fb213f), X64Word_create(0xbf597fc7, 0xbeef0ee4), + X64Word_create(0xc6e00bf3, 0x3da88fc2), X64Word_create(0xd5a79147, 0x930aa725), + X64Word_create(0x06ca6351, 0xe003826f), X64Word_create(0x14292967, 0x0a0e6e70), + X64Word_create(0x27b70a85, 0x46d22ffc), X64Word_create(0x2e1b2138, 0x5c26c926), + X64Word_create(0x4d2c6dfc, 0x5ac42aed), X64Word_create(0x53380d13, 0x9d95b3df), + X64Word_create(0x650a7354, 0x8baf63de), X64Word_create(0x766a0abb, 0x3c77b2a8), + X64Word_create(0x81c2c92e, 0x47edaee6), X64Word_create(0x92722c85, 0x1482353b), + X64Word_create(0xa2bfe8a1, 0x4cf10364), X64Word_create(0xa81a664b, 0xbc423001), + X64Word_create(0xc24b8b70, 0xd0f89791), X64Word_create(0xc76c51a3, 0x0654be30), + X64Word_create(0xd192e819, 0xd6ef5218), X64Word_create(0xd6990624, 0x5565a910), + X64Word_create(0xf40e3585, 0x5771202a), X64Word_create(0x106aa070, 0x32bbd1b8), + X64Word_create(0x19a4c116, 0xb8d2d0c8), X64Word_create(0x1e376c08, 0x5141ab53), + X64Word_create(0x2748774c, 0xdf8eeb99), X64Word_create(0x34b0bcb5, 0xe19b48a8), + X64Word_create(0x391c0cb3, 0xc5c95a63), X64Word_create(0x4ed8aa4a, 0xe3418acb), + X64Word_create(0x5b9cca4f, 0x7763e373), X64Word_create(0x682e6ff3, 0xd6b2b8a3), + X64Word_create(0x748f82ee, 0x5defb2fc), X64Word_create(0x78a5636f, 0x43172f60), + X64Word_create(0x84c87814, 0xa1f0ab72), X64Word_create(0x8cc70208, 0x1a6439ec), + X64Word_create(0x90befffa, 0x23631e28), X64Word_create(0xa4506ceb, 0xde82bde9), + X64Word_create(0xbef9a3f7, 0xb2c67915), X64Word_create(0xc67178f2, 0xe372532b), + X64Word_create(0xca273ece, 0xea26619c), X64Word_create(0xd186b8c7, 0x21c0c207), + X64Word_create(0xeada7dd6, 0xcde0eb1e), X64Word_create(0xf57d4f7f, 0xee6ed178), + X64Word_create(0x06f067aa, 0x72176fba), X64Word_create(0x0a637dc5, 0xa2c898a6), + X64Word_create(0x113f9804, 0xbef90dae), X64Word_create(0x1b710b35, 0x131c471b), + X64Word_create(0x28db77f5, 0x23047d84), X64Word_create(0x32caab7b, 0x40c72493), + X64Word_create(0x3c9ebe0a, 0x15c9bebc), X64Word_create(0x431d67c4, 0x9c100d4c), + X64Word_create(0x4cc5d4be, 0xcb3e42b6), X64Word_create(0x597f299c, 0xfc657e2a), + X64Word_create(0x5fcb6fab, 0x3ad6faec), X64Word_create(0x6c44198c, 0x4a475817) + ]; + + // Reusable objects + var W = []; + (function () { + for (var i = 0; i < 80; i++) { + W[i] = X64Word_create(); + } + }()); + + /** + * SHA-512 hash algorithm. + */ + var SHA512 = C_algo.SHA512 = Hasher.extend({ + _doReset: function () { + this._hash = new X64WordArray.init([ + new X64Word.init(0x6a09e667, 0xf3bcc908), new X64Word.init(0xbb67ae85, 0x84caa73b), + new X64Word.init(0x3c6ef372, 0xfe94f82b), new X64Word.init(0xa54ff53a, 0x5f1d36f1), + new X64Word.init(0x510e527f, 0xade682d1), new X64Word.init(0x9b05688c, 0x2b3e6c1f), + new X64Word.init(0x1f83d9ab, 0xfb41bd6b), new X64Word.init(0x5be0cd19, 0x137e2179) + ]); + }, + + _doProcessBlock: function (M, offset) { + // Shortcuts + var H = this._hash.words; + + var H0 = H[0]; + var H1 = H[1]; + var H2 = H[2]; + var H3 = H[3]; + var H4 = H[4]; + var H5 = H[5]; + var H6 = H[6]; + var H7 = H[7]; + + var H0h = H0.high; + var H0l = H0.low; + var H1h = H1.high; + var H1l = H1.low; + var H2h = H2.high; + var H2l = H2.low; + var H3h = H3.high; + var H3l = H3.low; + var H4h = H4.high; + var H4l = H4.low; + var H5h = H5.high; + var H5l = H5.low; + var H6h = H6.high; + var H6l = H6.low; + var H7h = H7.high; + var H7l = H7.low; + + // Working variables + var ah = H0h; + var al = H0l; + var bh = H1h; + var bl = H1l; + var ch = H2h; + var cl = H2l; + var dh = H3h; + var dl = H3l; + var eh = H4h; + var el = H4l; + var fh = H5h; + var fl = H5l; + var gh = H6h; + var gl = H6l; + var hh = H7h; + var hl = H7l; + + // Rounds + for (var i = 0; i < 80; i++) { + var Wil; + var Wih; + + // Shortcut + var Wi = W[i]; + + // Extend message + if (i < 16) { + Wih = Wi.high = M[offset + i * 2] | 0; + Wil = Wi.low = M[offset + i * 2 + 1] | 0; + } else { + // Gamma0 + var gamma0x = W[i - 15]; + var gamma0xh = gamma0x.high; + var gamma0xl = gamma0x.low; + var gamma0h = ((gamma0xh >>> 1) | (gamma0xl << 31)) ^ ((gamma0xh >>> 8) | (gamma0xl << 24)) ^ (gamma0xh >>> 7); + var gamma0l = ((gamma0xl >>> 1) | (gamma0xh << 31)) ^ ((gamma0xl >>> 8) | (gamma0xh << 24)) ^ ((gamma0xl >>> 7) | (gamma0xh << 25)); + + // Gamma1 + var gamma1x = W[i - 2]; + var gamma1xh = gamma1x.high; + var gamma1xl = gamma1x.low; + var gamma1h = ((gamma1xh >>> 19) | (gamma1xl << 13)) ^ ((gamma1xh << 3) | (gamma1xl >>> 29)) ^ (gamma1xh >>> 6); + var gamma1l = ((gamma1xl >>> 19) | (gamma1xh << 13)) ^ ((gamma1xl << 3) | (gamma1xh >>> 29)) ^ ((gamma1xl >>> 6) | (gamma1xh << 26)); + + // W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16] + var Wi7 = W[i - 7]; + var Wi7h = Wi7.high; + var Wi7l = Wi7.low; + + var Wi16 = W[i - 16]; + var Wi16h = Wi16.high; + var Wi16l = Wi16.low; + + Wil = gamma0l + Wi7l; + Wih = gamma0h + Wi7h + ((Wil >>> 0) < (gamma0l >>> 0) ? 1 : 0); + Wil = Wil + gamma1l; + Wih = Wih + gamma1h + ((Wil >>> 0) < (gamma1l >>> 0) ? 1 : 0); + Wil = Wil + Wi16l; + Wih = Wih + Wi16h + ((Wil >>> 0) < (Wi16l >>> 0) ? 1 : 0); + + Wi.high = Wih; + Wi.low = Wil; + } + + var chh = (eh & fh) ^ (~eh & gh); + var chl = (el & fl) ^ (~el & gl); + var majh = (ah & bh) ^ (ah & ch) ^ (bh & ch); + var majl = (al & bl) ^ (al & cl) ^ (bl & cl); + + var sigma0h = ((ah >>> 28) | (al << 4)) ^ ((ah << 30) | (al >>> 2)) ^ ((ah << 25) | (al >>> 7)); + var sigma0l = ((al >>> 28) | (ah << 4)) ^ ((al << 30) | (ah >>> 2)) ^ ((al << 25) | (ah >>> 7)); + var sigma1h = ((eh >>> 14) | (el << 18)) ^ ((eh >>> 18) | (el << 14)) ^ ((eh << 23) | (el >>> 9)); + var sigma1l = ((el >>> 14) | (eh << 18)) ^ ((el >>> 18) | (eh << 14)) ^ ((el << 23) | (eh >>> 9)); + + // t1 = h + sigma1 + ch + K[i] + W[i] + var Ki = K[i]; + var Kih = Ki.high; + var Kil = Ki.low; + + var t1l = hl + sigma1l; + var t1h = hh + sigma1h + ((t1l >>> 0) < (hl >>> 0) ? 1 : 0); + var t1l = t1l + chl; + var t1h = t1h + chh + ((t1l >>> 0) < (chl >>> 0) ? 1 : 0); + var t1l = t1l + Kil; + var t1h = t1h + Kih + ((t1l >>> 0) < (Kil >>> 0) ? 1 : 0); + var t1l = t1l + Wil; + var t1h = t1h + Wih + ((t1l >>> 0) < (Wil >>> 0) ? 1 : 0); + + // t2 = sigma0 + maj + var t2l = sigma0l + majl; + var t2h = sigma0h + majh + ((t2l >>> 0) < (sigma0l >>> 0) ? 1 : 0); + + // Update working variables + hh = gh; + hl = gl; + gh = fh; + gl = fl; + fh = eh; + fl = el; + el = (dl + t1l) | 0; + eh = (dh + t1h + ((el >>> 0) < (dl >>> 0) ? 1 : 0)) | 0; + dh = ch; + dl = cl; + ch = bh; + cl = bl; + bh = ah; + bl = al; + al = (t1l + t2l) | 0; + ah = (t1h + t2h + ((al >>> 0) < (t1l >>> 0) ? 1 : 0)) | 0; + } + + // Intermediate hash value + H0l = H0.low = (H0l + al); + H0.high = (H0h + ah + ((H0l >>> 0) < (al >>> 0) ? 1 : 0)); + H1l = H1.low = (H1l + bl); + H1.high = (H1h + bh + ((H1l >>> 0) < (bl >>> 0) ? 1 : 0)); + H2l = H2.low = (H2l + cl); + H2.high = (H2h + ch + ((H2l >>> 0) < (cl >>> 0) ? 1 : 0)); + H3l = H3.low = (H3l + dl); + H3.high = (H3h + dh + ((H3l >>> 0) < (dl >>> 0) ? 1 : 0)); + H4l = H4.low = (H4l + el); + H4.high = (H4h + eh + ((H4l >>> 0) < (el >>> 0) ? 1 : 0)); + H5l = H5.low = (H5l + fl); + H5.high = (H5h + fh + ((H5l >>> 0) < (fl >>> 0) ? 1 : 0)); + H6l = H6.low = (H6l + gl); + H6.high = (H6h + gh + ((H6l >>> 0) < (gl >>> 0) ? 1 : 0)); + H7l = H7.low = (H7l + hl); + H7.high = (H7h + hh + ((H7l >>> 0) < (hl >>> 0) ? 1 : 0)); + }, + + _doFinalize: function () { + // Shortcuts + var data = this._data; + var dataWords = data.words; + + var nBitsTotal = this._nDataBytes * 8; + var nBitsLeft = data.sigBytes * 8; + + // Add padding + dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); + dataWords[(((nBitsLeft + 128) >>> 10) << 5) + 30] = Math.floor(nBitsTotal / 0x100000000); + dataWords[(((nBitsLeft + 128) >>> 10) << 5) + 31] = nBitsTotal; + data.sigBytes = dataWords.length * 4; + + // Hash final blocks + this._process(); + + // Convert hash to 32-bit word array before returning + var hash = this._hash.toX32(); + + // Return final computed hash + return hash; + }, + + clone: function () { + var clone = Hasher.clone.call(this); + clone._hash = this._hash.clone(); + + return clone; + }, + + blockSize: 1024/32 + }); + + /** + * Shortcut function to the hasher's object interface. + * + * @param {WordArray|string} message The message to hash. + * + * @return {WordArray} The hash. + * + * @static + * + * @example + * + * var hash = CryptoJS.SHA512('message'); + * var hash = CryptoJS.SHA512(wordArray); + */ + C.SHA512 = Hasher._createHelper(SHA512); + + /** + * Shortcut function to the HMAC's object interface. + * + * @param {WordArray|string} message The message to hash. + * @param {WordArray|string} key The secret key. + * + * @return {WordArray} The HMAC. + * + * @static + * + * @example + * + * var hmac = CryptoJS.HmacSHA512(message, key); + */ + C.HmacSHA512 = Hasher._createHmacHelper(SHA512); + }()); + + + (function () { + // Shortcuts + var C = CryptoJS; + var C_x64 = C.x64; + var X64Word = C_x64.Word; + var X64WordArray = C_x64.WordArray; + var C_algo = C.algo; + var SHA512 = C_algo.SHA512; + + /** + * SHA-384 hash algorithm. + */ + var SHA384 = C_algo.SHA384 = SHA512.extend({ + _doReset: function () { + this._hash = new X64WordArray.init([ + new X64Word.init(0xcbbb9d5d, 0xc1059ed8), new X64Word.init(0x629a292a, 0x367cd507), + new X64Word.init(0x9159015a, 0x3070dd17), new X64Word.init(0x152fecd8, 0xf70e5939), + new X64Word.init(0x67332667, 0xffc00b31), new X64Word.init(0x8eb44a87, 0x68581511), + new X64Word.init(0xdb0c2e0d, 0x64f98fa7), new X64Word.init(0x47b5481d, 0xbefa4fa4) + ]); + }, + + _doFinalize: function () { + var hash = SHA512._doFinalize.call(this); + + hash.sigBytes -= 16; + + return hash; + } + }); + + /** + * Shortcut function to the hasher's object interface. + * + * @param {WordArray|string} message The message to hash. + * + * @return {WordArray} The hash. + * + * @static + * + * @example + * + * var hash = CryptoJS.SHA384('message'); + * var hash = CryptoJS.SHA384(wordArray); + */ + C.SHA384 = SHA512._createHelper(SHA384); + + /** + * Shortcut function to the HMAC's object interface. + * + * @param {WordArray|string} message The message to hash. + * @param {WordArray|string} key The secret key. + * + * @return {WordArray} The HMAC. + * + * @static + * + * @example + * + * var hmac = CryptoJS.HmacSHA384(message, key); + */ + C.HmacSHA384 = SHA512._createHmacHelper(SHA384); + }()); + + + (function (Math) { + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var WordArray = C_lib.WordArray; + var Hasher = C_lib.Hasher; + var C_x64 = C.x64; + var X64Word = C_x64.Word; + var C_algo = C.algo; + + // Constants tables + var RHO_OFFSETS = []; + var PI_INDEXES = []; + var ROUND_CONSTANTS = []; + + // Compute Constants + (function () { + // Compute rho offset constants + var x = 1, y = 0; + for (var t = 0; t < 24; t++) { + RHO_OFFSETS[x + 5 * y] = ((t + 1) * (t + 2) / 2) % 64; + + var newX = y % 5; + var newY = (2 * x + 3 * y) % 5; + x = newX; + y = newY; + } + + // Compute pi index constants + for (var x = 0; x < 5; x++) { + for (var y = 0; y < 5; y++) { + PI_INDEXES[x + 5 * y] = y + ((2 * x + 3 * y) % 5) * 5; + } + } + + // Compute round constants + var LFSR = 0x01; + for (var i = 0; i < 24; i++) { + var roundConstantMsw = 0; + var roundConstantLsw = 0; + + for (var j = 0; j < 7; j++) { + if (LFSR & 0x01) { + var bitPosition = (1 << j) - 1; + if (bitPosition < 32) { + roundConstantLsw ^= 1 << bitPosition; + } else /* if (bitPosition >= 32) */ { + roundConstantMsw ^= 1 << (bitPosition - 32); + } + } + + // Compute next LFSR + if (LFSR & 0x80) { + // Primitive polynomial over GF(2): x^8 + x^6 + x^5 + x^4 + 1 + LFSR = (LFSR << 1) ^ 0x71; + } else { + LFSR <<= 1; + } + } + + ROUND_CONSTANTS[i] = X64Word.create(roundConstantMsw, roundConstantLsw); + } + }()); + + // Reusable objects for temporary values + var T = []; + (function () { + for (var i = 0; i < 25; i++) { + T[i] = X64Word.create(); + } + }()); + + /** + * SHA-3 hash algorithm. + */ + var SHA3 = C_algo.SHA3 = Hasher.extend({ + /** + * Configuration options. + * + * @property {number} outputLength + * The desired number of bits in the output hash. + * Only values permitted are: 224, 256, 384, 512. + * Default: 512 + */ + cfg: Hasher.cfg.extend({ + outputLength: 512 + }), + + _doReset: function () { + var state = this._state = [] + for (var i = 0; i < 25; i++) { + state[i] = new X64Word.init(); + } + + this.blockSize = (1600 - 2 * this.cfg.outputLength) / 32; + }, + + _doProcessBlock: function (M, offset) { + // Shortcuts + var state = this._state; + var nBlockSizeLanes = this.blockSize / 2; + + // Absorb + for (var i = 0; i < nBlockSizeLanes; i++) { + // Shortcuts + var M2i = M[offset + 2 * i]; + var M2i1 = M[offset + 2 * i + 1]; + + // Swap endian + M2i = ( + (((M2i << 8) | (M2i >>> 24)) & 0x00ff00ff) | + (((M2i << 24) | (M2i >>> 8)) & 0xff00ff00) + ); + M2i1 = ( + (((M2i1 << 8) | (M2i1 >>> 24)) & 0x00ff00ff) | + (((M2i1 << 24) | (M2i1 >>> 8)) & 0xff00ff00) + ); + + // Absorb message into state + var lane = state[i]; + lane.high ^= M2i1; + lane.low ^= M2i; + } + + // Rounds + for (var round = 0; round < 24; round++) { + // Theta + for (var x = 0; x < 5; x++) { + // Mix column lanes + var tMsw = 0, tLsw = 0; + for (var y = 0; y < 5; y++) { + var lane = state[x + 5 * y]; + tMsw ^= lane.high; + tLsw ^= lane.low; + } + + // Temporary values + var Tx = T[x]; + Tx.high = tMsw; + Tx.low = tLsw; + } + for (var x = 0; x < 5; x++) { + // Shortcuts + var Tx4 = T[(x + 4) % 5]; + var Tx1 = T[(x + 1) % 5]; + var Tx1Msw = Tx1.high; + var Tx1Lsw = Tx1.low; + + // Mix surrounding columns + var tMsw = Tx4.high ^ ((Tx1Msw << 1) | (Tx1Lsw >>> 31)); + var tLsw = Tx4.low ^ ((Tx1Lsw << 1) | (Tx1Msw >>> 31)); + for (var y = 0; y < 5; y++) { + var lane = state[x + 5 * y]; + lane.high ^= tMsw; + lane.low ^= tLsw; + } + } + + // Rho Pi + for (var laneIndex = 1; laneIndex < 25; laneIndex++) { + var tMsw; + var tLsw; + + // Shortcuts + var lane = state[laneIndex]; + var laneMsw = lane.high; + var laneLsw = lane.low; + var rhoOffset = RHO_OFFSETS[laneIndex]; + + // Rotate lanes + if (rhoOffset < 32) { + tMsw = (laneMsw << rhoOffset) | (laneLsw >>> (32 - rhoOffset)); + tLsw = (laneLsw << rhoOffset) | (laneMsw >>> (32 - rhoOffset)); + } else /* if (rhoOffset >= 32) */ { + tMsw = (laneLsw << (rhoOffset - 32)) | (laneMsw >>> (64 - rhoOffset)); + tLsw = (laneMsw << (rhoOffset - 32)) | (laneLsw >>> (64 - rhoOffset)); + } + + // Transpose lanes + var TPiLane = T[PI_INDEXES[laneIndex]]; + TPiLane.high = tMsw; + TPiLane.low = tLsw; + } + + // Rho pi at x = y = 0 + var T0 = T[0]; + var state0 = state[0]; + T0.high = state0.high; + T0.low = state0.low; + + // Chi + for (var x = 0; x < 5; x++) { + for (var y = 0; y < 5; y++) { + // Shortcuts + var laneIndex = x + 5 * y; + var lane = state[laneIndex]; + var TLane = T[laneIndex]; + var Tx1Lane = T[((x + 1) % 5) + 5 * y]; + var Tx2Lane = T[((x + 2) % 5) + 5 * y]; + + // Mix rows + lane.high = TLane.high ^ (~Tx1Lane.high & Tx2Lane.high); + lane.low = TLane.low ^ (~Tx1Lane.low & Tx2Lane.low); + } + } + + // Iota + var lane = state[0]; + var roundConstant = ROUND_CONSTANTS[round]; + lane.high ^= roundConstant.high; + lane.low ^= roundConstant.low; + } + }, + + _doFinalize: function () { + // Shortcuts + var data = this._data; + var dataWords = data.words; + var nBitsTotal = this._nDataBytes * 8; + var nBitsLeft = data.sigBytes * 8; + var blockSizeBits = this.blockSize * 32; + + // Add padding + dataWords[nBitsLeft >>> 5] |= 0x1 << (24 - nBitsLeft % 32); + dataWords[((Math.ceil((nBitsLeft + 1) / blockSizeBits) * blockSizeBits) >>> 5) - 1] |= 0x80; + data.sigBytes = dataWords.length * 4; + + // Hash final blocks + this._process(); + + // Shortcuts + var state = this._state; + var outputLengthBytes = this.cfg.outputLength / 8; + var outputLengthLanes = outputLengthBytes / 8; + + // Squeeze + var hashWords = []; + for (var i = 0; i < outputLengthLanes; i++) { + // Shortcuts + var lane = state[i]; + var laneMsw = lane.high; + var laneLsw = lane.low; + + // Swap endian + laneMsw = ( + (((laneMsw << 8) | (laneMsw >>> 24)) & 0x00ff00ff) | + (((laneMsw << 24) | (laneMsw >>> 8)) & 0xff00ff00) + ); + laneLsw = ( + (((laneLsw << 8) | (laneLsw >>> 24)) & 0x00ff00ff) | + (((laneLsw << 24) | (laneLsw >>> 8)) & 0xff00ff00) + ); + + // Squeeze state to retrieve hash + hashWords.push(laneLsw); + hashWords.push(laneMsw); + } + + // Return final computed hash + return new WordArray.init(hashWords, outputLengthBytes); + }, + + clone: function () { + var clone = Hasher.clone.call(this); + + var state = clone._state = this._state.slice(0); + for (var i = 0; i < 25; i++) { + state[i] = state[i].clone(); + } + + return clone; + } + }); + + /** + * Shortcut function to the hasher's object interface. + * + * @param {WordArray|string} message The message to hash. + * + * @return {WordArray} The hash. + * + * @static + * + * @example + * + * var hash = CryptoJS.SHA3('message'); + * var hash = CryptoJS.SHA3(wordArray); + */ + C.SHA3 = Hasher._createHelper(SHA3); + + /** + * Shortcut function to the HMAC's object interface. + * + * @param {WordArray|string} message The message to hash. + * @param {WordArray|string} key The secret key. + * + * @return {WordArray} The HMAC. + * + * @static + * + * @example + * + * var hmac = CryptoJS.HmacSHA3(message, key); + */ + C.HmacSHA3 = Hasher._createHmacHelper(SHA3); + }(Math)); + + + /** @preserve + (c) 2012 by Cédric Mesnil. All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + + - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + (function (Math) { + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var WordArray = C_lib.WordArray; + var Hasher = C_lib.Hasher; + var C_algo = C.algo; + + // Constants table + var _zl = WordArray.create([ + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8, + 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12, + 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2, + 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13]); + var _zr = WordArray.create([ + 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12, + 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2, + 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13, + 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14, + 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11]); + var _sl = WordArray.create([ + 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8, + 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12, + 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5, + 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12, + 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6 ]); + var _sr = WordArray.create([ + 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6, + 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11, + 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5, + 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8, + 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11 ]); + + var _hl = WordArray.create([ 0x00000000, 0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xA953FD4E]); + var _hr = WordArray.create([ 0x50A28BE6, 0x5C4DD124, 0x6D703EF3, 0x7A6D76E9, 0x00000000]); + + /** + * RIPEMD160 hash algorithm. + */ + var RIPEMD160 = C_algo.RIPEMD160 = Hasher.extend({ + _doReset: function () { + this._hash = WordArray.create([0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0]); + }, + + _doProcessBlock: function (M, offset) { + + // Swap endian + for (var i = 0; i < 16; i++) { + // Shortcuts + var offset_i = offset + i; + var M_offset_i = M[offset_i]; + + // Swap + M[offset_i] = ( + (((M_offset_i << 8) | (M_offset_i >>> 24)) & 0x00ff00ff) | + (((M_offset_i << 24) | (M_offset_i >>> 8)) & 0xff00ff00) + ); + } + // Shortcut + var H = this._hash.words; + var hl = _hl.words; + var hr = _hr.words; + var zl = _zl.words; + var zr = _zr.words; + var sl = _sl.words; + var sr = _sr.words; + + // Working variables + var al, bl, cl, dl, el; + var ar, br, cr, dr, er; + + ar = al = H[0]; + br = bl = H[1]; + cr = cl = H[2]; + dr = dl = H[3]; + er = el = H[4]; + // Computation + var t; + for (var i = 0; i < 80; i += 1) { + t = (al + M[offset+zl[i]])|0; + if (i<16){ + t += f1(bl,cl,dl) + hl[0]; + } else if (i<32) { + t += f2(bl,cl,dl) + hl[1]; + } else if (i<48) { + t += f3(bl,cl,dl) + hl[2]; + } else if (i<64) { + t += f4(bl,cl,dl) + hl[3]; + } else {// if (i<80) { + t += f5(bl,cl,dl) + hl[4]; + } + t = t|0; + t = rotl(t,sl[i]); + t = (t+el)|0; + al = el; + el = dl; + dl = rotl(cl, 10); + cl = bl; + bl = t; + + t = (ar + M[offset+zr[i]])|0; + if (i<16){ + t += f5(br,cr,dr) + hr[0]; + } else if (i<32) { + t += f4(br,cr,dr) + hr[1]; + } else if (i<48) { + t += f3(br,cr,dr) + hr[2]; + } else if (i<64) { + t += f2(br,cr,dr) + hr[3]; + } else {// if (i<80) { + t += f1(br,cr,dr) + hr[4]; + } + t = t|0; + t = rotl(t,sr[i]) ; + t = (t+er)|0; + ar = er; + er = dr; + dr = rotl(cr, 10); + cr = br; + br = t; + } + // Intermediate hash value + t = (H[1] + cl + dr)|0; + H[1] = (H[2] + dl + er)|0; + H[2] = (H[3] + el + ar)|0; + H[3] = (H[4] + al + br)|0; + H[4] = (H[0] + bl + cr)|0; + H[0] = t; + }, + + _doFinalize: function () { + // Shortcuts + var data = this._data; + var dataWords = data.words; + + var nBitsTotal = this._nDataBytes * 8; + var nBitsLeft = data.sigBytes * 8; + + // Add padding + dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); + dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = ( + (((nBitsTotal << 8) | (nBitsTotal >>> 24)) & 0x00ff00ff) | + (((nBitsTotal << 24) | (nBitsTotal >>> 8)) & 0xff00ff00) + ); + data.sigBytes = (dataWords.length + 1) * 4; + + // Hash final blocks + this._process(); + + // Shortcuts + var hash = this._hash; + var H = hash.words; + + // Swap endian + for (var i = 0; i < 5; i++) { + // Shortcut + var H_i = H[i]; + + // Swap + H[i] = (((H_i << 8) | (H_i >>> 24)) & 0x00ff00ff) | + (((H_i << 24) | (H_i >>> 8)) & 0xff00ff00); + } + + // Return final computed hash + return hash; + }, + + clone: function () { + var clone = Hasher.clone.call(this); + clone._hash = this._hash.clone(); + + return clone; + } + }); + + + function f1(x, y, z) { + return ((x) ^ (y) ^ (z)); + + } + + function f2(x, y, z) { + return (((x)&(y)) | ((~x)&(z))); + } + + function f3(x, y, z) { + return (((x) | (~(y))) ^ (z)); + } + + function f4(x, y, z) { + return (((x) & (z)) | ((y)&(~(z)))); + } + + function f5(x, y, z) { + return ((x) ^ ((y) |(~(z)))); + + } + + function rotl(x,n) { + return (x<<n) | (x>>>(32-n)); + } + + + /** + * Shortcut function to the hasher's object interface. + * + * @param {WordArray|string} message The message to hash. + * + * @return {WordArray} The hash. + * + * @static + * + * @example + * + * var hash = CryptoJS.RIPEMD160('message'); + * var hash = CryptoJS.RIPEMD160(wordArray); + */ + C.RIPEMD160 = Hasher._createHelper(RIPEMD160); + + /** + * Shortcut function to the HMAC's object interface. + * + * @param {WordArray|string} message The message to hash. + * @param {WordArray|string} key The secret key. + * + * @return {WordArray} The HMAC. + * + * @static + * + * @example + * + * var hmac = CryptoJS.HmacRIPEMD160(message, key); + */ + C.HmacRIPEMD160 = Hasher._createHmacHelper(RIPEMD160); + }(Math)); + + + (function () { + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var Base = C_lib.Base; + var C_enc = C.enc; + var Utf8 = C_enc.Utf8; + var C_algo = C.algo; + + /** + * HMAC algorithm. + */ + var HMAC = C_algo.HMAC = Base.extend({ + /** + * Initializes a newly created HMAC. + * + * @param {Hasher} hasher The hash algorithm to use. + * @param {WordArray|string} key The secret key. + * + * @example + * + * var hmacHasher = CryptoJS.algo.HMAC.create(CryptoJS.algo.SHA256, key); + */ + init: function (hasher, key) { + // Init hasher + hasher = this._hasher = new hasher.init(); + + // Convert string to WordArray, else assume WordArray already + if (typeof key == 'string') { + key = Utf8.parse(key); + } + + // Shortcuts + var hasherBlockSize = hasher.blockSize; + var hasherBlockSizeBytes = hasherBlockSize * 4; + + // Allow arbitrary length keys + if (key.sigBytes > hasherBlockSizeBytes) { + key = hasher.finalize(key); + } + + // Clamp excess bits + key.clamp(); + + // Clone key for inner and outer pads + var oKey = this._oKey = key.clone(); + var iKey = this._iKey = key.clone(); + + // Shortcuts + var oKeyWords = oKey.words; + var iKeyWords = iKey.words; + + // XOR keys with pad constants + for (var i = 0; i < hasherBlockSize; i++) { + oKeyWords[i] ^= 0x5c5c5c5c; + iKeyWords[i] ^= 0x36363636; + } + oKey.sigBytes = iKey.sigBytes = hasherBlockSizeBytes; + + // Set initial values + this.reset(); + }, + + /** + * Resets this HMAC to its initial state. + * + * @example + * + * hmacHasher.reset(); + */ + reset: function () { + // Shortcut + var hasher = this._hasher; + + // Reset + hasher.reset(); + hasher.update(this._iKey); + }, + + /** + * Updates this HMAC with a message. + * + * @param {WordArray|string} messageUpdate The message to append. + * + * @return {HMAC} This HMAC instance. + * + * @example + * + * hmacHasher.update('message'); + * hmacHasher.update(wordArray); + */ + update: function (messageUpdate) { + this._hasher.update(messageUpdate); + + // Chainable + return this; + }, + + /** + * Finalizes the HMAC computation. + * Note that the finalize operation is effectively a destructive, read-once operation. + * + * @param {WordArray|string} messageUpdate (Optional) A final message update. + * + * @return {WordArray} The HMAC. + * + * @example + * + * var hmac = hmacHasher.finalize(); + * var hmac = hmacHasher.finalize('message'); + * var hmac = hmacHasher.finalize(wordArray); + */ + finalize: function (messageUpdate) { + // Shortcut + var hasher = this._hasher; + + // Compute HMAC + var innerHash = hasher.finalize(messageUpdate); + hasher.reset(); + var hmac = hasher.finalize(this._oKey.clone().concat(innerHash)); + + return hmac; + } + }); + }()); + + + (function () { + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var Base = C_lib.Base; + var WordArray = C_lib.WordArray; + var C_algo = C.algo; + var SHA1 = C_algo.SHA1; + var HMAC = C_algo.HMAC; + + /** + * Password-Based Key Derivation Function 2 algorithm. + */ + var PBKDF2 = C_algo.PBKDF2 = Base.extend({ + /** + * Configuration options. + * + * @property {number} keySize The key size in words to generate. Default: 4 (128 bits) + * @property {Hasher} hasher The hasher to use. Default: SHA1 + * @property {number} iterations The number of iterations to perform. Default: 1 + */ + cfg: Base.extend({ + keySize: 128/32, + hasher: SHA1, + iterations: 1 + }), + + /** + * Initializes a newly created key derivation function. + * + * @param {Object} cfg (Optional) The configuration options to use for the derivation. + * + * @example + * + * var kdf = CryptoJS.algo.PBKDF2.create(); + * var kdf = CryptoJS.algo.PBKDF2.create({ keySize: 8 }); + * var kdf = CryptoJS.algo.PBKDF2.create({ keySize: 8, iterations: 1000 }); + */ + init: function (cfg) { + this.cfg = this.cfg.extend(cfg); + }, + + /** + * Computes the Password-Based Key Derivation Function 2. + * + * @param {WordArray|string} password The password. + * @param {WordArray|string} salt A salt. + * + * @return {WordArray} The derived key. + * + * @example + * + * var key = kdf.compute(password, salt); + */ + compute: function (password, salt) { + // Shortcut + var cfg = this.cfg; + + // Init HMAC + var hmac = HMAC.create(cfg.hasher, password); + + // Initial values + var derivedKey = WordArray.create(); + var blockIndex = WordArray.create([0x00000001]); + + // Shortcuts + var derivedKeyWords = derivedKey.words; + var blockIndexWords = blockIndex.words; + var keySize = cfg.keySize; + var iterations = cfg.iterations; + + // Generate key + while (derivedKeyWords.length < keySize) { + var block = hmac.update(salt).finalize(blockIndex); + hmac.reset(); + + // Shortcuts + var blockWords = block.words; + var blockWordsLength = blockWords.length; + + // Iterations + var intermediate = block; + for (var i = 1; i < iterations; i++) { + intermediate = hmac.finalize(intermediate); + hmac.reset(); + + // Shortcut + var intermediateWords = intermediate.words; + + // XOR intermediate with block + for (var j = 0; j < blockWordsLength; j++) { + blockWords[j] ^= intermediateWords[j]; + } + } + + derivedKey.concat(block); + blockIndexWords[0]++; + } + derivedKey.sigBytes = keySize * 4; + + return derivedKey; + } + }); + + /** + * Computes the Password-Based Key Derivation Function 2. + * + * @param {WordArray|string} password The password. + * @param {WordArray|string} salt A salt. + * @param {Object} cfg (Optional) The configuration options to use for this computation. + * + * @return {WordArray} The derived key. + * + * @static + * + * @example + * + * var key = CryptoJS.PBKDF2(password, salt); + * var key = CryptoJS.PBKDF2(password, salt, { keySize: 8 }); + * var key = CryptoJS.PBKDF2(password, salt, { keySize: 8, iterations: 1000 }); + */ + C.PBKDF2 = function (password, salt, cfg) { + return PBKDF2.create(cfg).compute(password, salt); + }; + }()); + + + (function () { + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var Base = C_lib.Base; + var WordArray = C_lib.WordArray; + var C_algo = C.algo; + var MD5 = C_algo.MD5; + + /** + * This key derivation function is meant to conform with EVP_BytesToKey. + * www.openssl.org/docs/crypto/EVP_BytesToKey.html + */ + var EvpKDF = C_algo.EvpKDF = Base.extend({ + /** + * Configuration options. + * + * @property {number} keySize The key size in words to generate. Default: 4 (128 bits) + * @property {Hasher} hasher The hash algorithm to use. Default: MD5 + * @property {number} iterations The number of iterations to perform. Default: 1 + */ + cfg: Base.extend({ + keySize: 128/32, + hasher: MD5, + iterations: 1 + }), + + /** + * Initializes a newly created key derivation function. + * + * @param {Object} cfg (Optional) The configuration options to use for the derivation. + * + * @example + * + * var kdf = CryptoJS.algo.EvpKDF.create(); + * var kdf = CryptoJS.algo.EvpKDF.create({ keySize: 8 }); + * var kdf = CryptoJS.algo.EvpKDF.create({ keySize: 8, iterations: 1000 }); + */ + init: function (cfg) { + this.cfg = this.cfg.extend(cfg); + }, + + /** + * Derives a key from a password. + * + * @param {WordArray|string} password The password. + * @param {WordArray|string} salt A salt. + * + * @return {WordArray} The derived key. + * + * @example + * + * var key = kdf.compute(password, salt); + */ + compute: function (password, salt) { + var block; + + // Shortcut + var cfg = this.cfg; + + // Init hasher + var hasher = cfg.hasher.create(); + + // Initial values + var derivedKey = WordArray.create(); + + // Shortcuts + var derivedKeyWords = derivedKey.words; + var keySize = cfg.keySize; + var iterations = cfg.iterations; + + // Generate key + while (derivedKeyWords.length < keySize) { + if (block) { + hasher.update(block); + } + block = hasher.update(password).finalize(salt); + hasher.reset(); + + // Iterations + for (var i = 1; i < iterations; i++) { + block = hasher.finalize(block); + hasher.reset(); + } + + derivedKey.concat(block); + } + derivedKey.sigBytes = keySize * 4; + + return derivedKey; + } + }); + + /** + * Derives a key from a password. + * + * @param {WordArray|string} password The password. + * @param {WordArray|string} salt A salt. + * @param {Object} cfg (Optional) The configuration options to use for this computation. + * + * @return {WordArray} The derived key. + * + * @static + * + * @example + * + * var key = CryptoJS.EvpKDF(password, salt); + * var key = CryptoJS.EvpKDF(password, salt, { keySize: 8 }); + * var key = CryptoJS.EvpKDF(password, salt, { keySize: 8, iterations: 1000 }); + */ + C.EvpKDF = function (password, salt, cfg) { + return EvpKDF.create(cfg).compute(password, salt); + }; + }()); + + + /** + * Cipher core components. + */ + CryptoJS.lib.Cipher || (function (undefined) { + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var Base = C_lib.Base; + var WordArray = C_lib.WordArray; + var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm; + var C_enc = C.enc; + var Utf8 = C_enc.Utf8; + var Base64 = C_enc.Base64; + var C_algo = C.algo; + var EvpKDF = C_algo.EvpKDF; + + /** + * Abstract base cipher template. + * + * @property {number} keySize This cipher's key size. Default: 4 (128 bits) + * @property {number} ivSize This cipher's IV size. Default: 4 (128 bits) + * @property {number} _ENC_XFORM_MODE A constant representing encryption mode. + * @property {number} _DEC_XFORM_MODE A constant representing decryption mode. + */ + var Cipher = C_lib.Cipher = BufferedBlockAlgorithm.extend({ + /** + * Configuration options. + * + * @property {WordArray} iv The IV to use for this operation. + */ + cfg: Base.extend(), + + /** + * Creates this cipher in encryption mode. + * + * @param {WordArray} key The key. + * @param {Object} cfg (Optional) The configuration options to use for this operation. + * + * @return {Cipher} A cipher instance. + * + * @static + * + * @example + * + * var cipher = CryptoJS.algo.AES.createEncryptor(keyWordArray, { iv: ivWordArray }); + */ + createEncryptor: function (key, cfg) { + return this.create(this._ENC_XFORM_MODE, key, cfg); + }, + + /** + * Creates this cipher in decryption mode. + * + * @param {WordArray} key The key. + * @param {Object} cfg (Optional) The configuration options to use for this operation. + * + * @return {Cipher} A cipher instance. + * + * @static + * + * @example + * + * var cipher = CryptoJS.algo.AES.createDecryptor(keyWordArray, { iv: ivWordArray }); + */ + createDecryptor: function (key, cfg) { + return this.create(this._DEC_XFORM_MODE, key, cfg); + }, + + /** + * Initializes a newly created cipher. + * + * @param {number} xformMode Either the encryption or decryption transormation mode constant. + * @param {WordArray} key The key. + * @param {Object} cfg (Optional) The configuration options to use for this operation. + * + * @example + * + * var cipher = CryptoJS.algo.AES.create(CryptoJS.algo.AES._ENC_XFORM_MODE, keyWordArray, { iv: ivWordArray }); + */ + init: function (xformMode, key, cfg) { + // Apply config defaults + this.cfg = this.cfg.extend(cfg); + + // Store transform mode and key + this._xformMode = xformMode; + this._key = key; + + // Set initial values + this.reset(); + }, + + /** + * Resets this cipher to its initial state. + * + * @example + * + * cipher.reset(); + */ + reset: function () { + // Reset data buffer + BufferedBlockAlgorithm.reset.call(this); + + // Perform concrete-cipher logic + this._doReset(); + }, + + /** + * Adds data to be encrypted or decrypted. + * + * @param {WordArray|string} dataUpdate The data to encrypt or decrypt. + * + * @return {WordArray} The data after processing. + * + * @example + * + * var encrypted = cipher.process('data'); + * var encrypted = cipher.process(wordArray); + */ + process: function (dataUpdate) { + // Append + this._append(dataUpdate); + + // Process available blocks + return this._process(); + }, + + /** + * Finalizes the encryption or decryption process. + * Note that the finalize operation is effectively a destructive, read-once operation. + * + * @param {WordArray|string} dataUpdate The final data to encrypt or decrypt. + * + * @return {WordArray} The data after final processing. + * + * @example + * + * var encrypted = cipher.finalize(); + * var encrypted = cipher.finalize('data'); + * var encrypted = cipher.finalize(wordArray); + */ + finalize: function (dataUpdate) { + // Final data update + if (dataUpdate) { + this._append(dataUpdate); + } + + // Perform concrete-cipher logic + var finalProcessedData = this._doFinalize(); + + return finalProcessedData; + }, + + keySize: 128/32, + + ivSize: 128/32, + + _ENC_XFORM_MODE: 1, + + _DEC_XFORM_MODE: 2, + + /** + * Creates shortcut functions to a cipher's object interface. + * + * @param {Cipher} cipher The cipher to create a helper for. + * + * @return {Object} An object with encrypt and decrypt shortcut functions. + * + * @static + * + * @example + * + * var AES = CryptoJS.lib.Cipher._createHelper(CryptoJS.algo.AES); + */ + _createHelper: (function () { + function selectCipherStrategy(key) { + if (typeof key == 'string') { + return PasswordBasedCipher; + } else { + return SerializableCipher; + } + } + + return function (cipher) { + return { + encrypt: function (message, key, cfg) { + return selectCipherStrategy(key).encrypt(cipher, message, key, cfg); + }, + + decrypt: function (ciphertext, key, cfg) { + return selectCipherStrategy(key).decrypt(cipher, ciphertext, key, cfg); + } + }; + }; + }()) + }); + + /** + * Abstract base stream cipher template. + * + * @property {number} blockSize The number of 32-bit words this cipher operates on. Default: 1 (32 bits) + */ + var StreamCipher = C_lib.StreamCipher = Cipher.extend({ + _doFinalize: function () { + // Process partial blocks + var finalProcessedBlocks = this._process(!!'flush'); + + return finalProcessedBlocks; + }, + + blockSize: 1 + }); + + /** + * Mode namespace. + */ + var C_mode = C.mode = {}; + + /** + * Abstract base block cipher mode template. + */ + var BlockCipherMode = C_lib.BlockCipherMode = Base.extend({ + /** + * Creates this mode for encryption. + * + * @param {Cipher} cipher A block cipher instance. + * @param {Array} iv The IV words. + * + * @static + * + * @example + * + * var mode = CryptoJS.mode.CBC.createEncryptor(cipher, iv.words); + */ + createEncryptor: function (cipher, iv) { + return this.Encryptor.create(cipher, iv); + }, + + /** + * Creates this mode for decryption. + * + * @param {Cipher} cipher A block cipher instance. + * @param {Array} iv The IV words. + * + * @static + * + * @example + * + * var mode = CryptoJS.mode.CBC.createDecryptor(cipher, iv.words); + */ + createDecryptor: function (cipher, iv) { + return this.Decryptor.create(cipher, iv); + }, + + /** + * Initializes a newly created mode. + * + * @param {Cipher} cipher A block cipher instance. + * @param {Array} iv The IV words. + * + * @example + * + * var mode = CryptoJS.mode.CBC.Encryptor.create(cipher, iv.words); + */ + init: function (cipher, iv) { + this._cipher = cipher; + this._iv = iv; + } + }); + + /** + * Cipher Block Chaining mode. + */ + var CBC = C_mode.CBC = (function () { + /** + * Abstract base CBC mode. + */ + var CBC = BlockCipherMode.extend(); + + /** + * CBC encryptor. + */ + CBC.Encryptor = CBC.extend({ + /** + * Processes the data block at offset. + * + * @param {Array} words The data words to operate on. + * @param {number} offset The offset where the block starts. + * + * @example + * + * mode.processBlock(data.words, offset); + */ + processBlock: function (words, offset) { + // Shortcuts + var cipher = this._cipher; + var blockSize = cipher.blockSize; + + // XOR and encrypt + xorBlock.call(this, words, offset, blockSize); + cipher.encryptBlock(words, offset); + + // Remember this block to use with next block + this._prevBlock = words.slice(offset, offset + blockSize); + } + }); + + /** + * CBC decryptor. + */ + CBC.Decryptor = CBC.extend({ + /** + * Processes the data block at offset. + * + * @param {Array} words The data words to operate on. + * @param {number} offset The offset where the block starts. + * + * @example + * + * mode.processBlock(data.words, offset); + */ + processBlock: function (words, offset) { + // Shortcuts + var cipher = this._cipher; + var blockSize = cipher.blockSize; + + // Remember this block to use with next block + var thisBlock = words.slice(offset, offset + blockSize); + + // Decrypt and XOR + cipher.decryptBlock(words, offset); + xorBlock.call(this, words, offset, blockSize); + + // This block becomes the previous block + this._prevBlock = thisBlock; + } + }); + + function xorBlock(words, offset, blockSize) { + var block; + + // Shortcut + var iv = this._iv; + + // Choose mixing block + if (iv) { + block = iv; + + // Remove IV for subsequent blocks + this._iv = undefined; + } else { + block = this._prevBlock; + } + + // XOR blocks + for (var i = 0; i < blockSize; i++) { + words[offset + i] ^= block[i]; + } + } + + return CBC; + }()); + + /** + * Padding namespace. + */ + var C_pad = C.pad = {}; + + /** + * PKCS #5/7 padding strategy. + */ + var Pkcs7 = C_pad.Pkcs7 = { + /** + * Pads data using the algorithm defined in PKCS #5/7. + * + * @param {WordArray} data The data to pad. + * @param {number} blockSize The multiple that the data should be padded to. + * + * @static + * + * @example + * + * CryptoJS.pad.Pkcs7.pad(wordArray, 4); + */ + pad: function (data, blockSize) { + // Shortcut + var blockSizeBytes = blockSize * 4; + + // Count padding bytes + var nPaddingBytes = blockSizeBytes - data.sigBytes % blockSizeBytes; + + // Create padding word + var paddingWord = (nPaddingBytes << 24) | (nPaddingBytes << 16) | (nPaddingBytes << 8) | nPaddingBytes; + + // Create padding + var paddingWords = []; + for (var i = 0; i < nPaddingBytes; i += 4) { + paddingWords.push(paddingWord); + } + var padding = WordArray.create(paddingWords, nPaddingBytes); + + // Add padding + data.concat(padding); + }, + + /** + * Unpads data that had been padded using the algorithm defined in PKCS #5/7. + * + * @param {WordArray} data The data to unpad. + * + * @static + * + * @example + * + * CryptoJS.pad.Pkcs7.unpad(wordArray); + */ + unpad: function (data) { + // Get number of padding bytes from last byte + var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff; + + // Remove padding + data.sigBytes -= nPaddingBytes; + } + }; + + /** + * Abstract base block cipher template. + * + * @property {number} blockSize The number of 32-bit words this cipher operates on. Default: 4 (128 bits) + */ + var BlockCipher = C_lib.BlockCipher = Cipher.extend({ + /** + * Configuration options. + * + * @property {Mode} mode The block mode to use. Default: CBC + * @property {Padding} padding The padding strategy to use. Default: Pkcs7 + */ + cfg: Cipher.cfg.extend({ + mode: CBC, + padding: Pkcs7 + }), + + reset: function () { + var modeCreator; + + // Reset cipher + Cipher.reset.call(this); + + // Shortcuts + var cfg = this.cfg; + var iv = cfg.iv; + var mode = cfg.mode; + + // Reset block mode + if (this._xformMode == this._ENC_XFORM_MODE) { + modeCreator = mode.createEncryptor; + } else /* if (this._xformMode == this._DEC_XFORM_MODE) */ { + modeCreator = mode.createDecryptor; + // Keep at least one block in the buffer for unpadding + this._minBufferSize = 1; + } + + if (this._mode && this._mode.__creator == modeCreator) { + this._mode.init(this, iv && iv.words); + } else { + this._mode = modeCreator.call(mode, this, iv && iv.words); + this._mode.__creator = modeCreator; + } + }, + + _doProcessBlock: function (words, offset) { + this._mode.processBlock(words, offset); + }, + + _doFinalize: function () { + var finalProcessedBlocks; + + // Shortcut + var padding = this.cfg.padding; + + // Finalize + if (this._xformMode == this._ENC_XFORM_MODE) { + // Pad data + padding.pad(this._data, this.blockSize); + + // Process final blocks + finalProcessedBlocks = this._process(!!'flush'); + } else /* if (this._xformMode == this._DEC_XFORM_MODE) */ { + // Process final blocks + finalProcessedBlocks = this._process(!!'flush'); + + // Unpad data + padding.unpad(finalProcessedBlocks); + } + + return finalProcessedBlocks; + }, + + blockSize: 128/32 + }); + + /** + * A collection of cipher parameters. + * + * @property {WordArray} ciphertext The raw ciphertext. + * @property {WordArray} key The key to this ciphertext. + * @property {WordArray} iv The IV used in the ciphering operation. + * @property {WordArray} salt The salt used with a key derivation function. + * @property {Cipher} algorithm The cipher algorithm. + * @property {Mode} mode The block mode used in the ciphering operation. + * @property {Padding} padding The padding scheme used in the ciphering operation. + * @property {number} blockSize The block size of the cipher. + * @property {Format} formatter The default formatting strategy to convert this cipher params object to a string. + */ + var CipherParams = C_lib.CipherParams = Base.extend({ + /** + * Initializes a newly created cipher params object. + * + * @param {Object} cipherParams An object with any of the possible cipher parameters. + * + * @example + * + * var cipherParams = CryptoJS.lib.CipherParams.create({ + * ciphertext: ciphertextWordArray, + * key: keyWordArray, + * iv: ivWordArray, + * salt: saltWordArray, + * algorithm: CryptoJS.algo.AES, + * mode: CryptoJS.mode.CBC, + * padding: CryptoJS.pad.PKCS7, + * blockSize: 4, + * formatter: CryptoJS.format.OpenSSL + * }); + */ + init: function (cipherParams) { + this.mixIn(cipherParams); + }, + + /** + * Converts this cipher params object to a string. + * + * @param {Format} formatter (Optional) The formatting strategy to use. + * + * @return {string} The stringified cipher params. + * + * @throws Error If neither the formatter nor the default formatter is set. + * + * @example + * + * var string = cipherParams + ''; + * var string = cipherParams.toString(); + * var string = cipherParams.toString(CryptoJS.format.OpenSSL); + */ + toString: function (formatter) { + return (formatter || this.formatter).stringify(this); + } + }); + + /** + * Format namespace. + */ + var C_format = C.format = {}; + + /** + * OpenSSL formatting strategy. + */ + var OpenSSLFormatter = C_format.OpenSSL = { + /** + * Converts a cipher params object to an OpenSSL-compatible string. + * + * @param {CipherParams} cipherParams The cipher params object. + * + * @return {string} The OpenSSL-compatible string. + * + * @static + * + * @example + * + * var openSSLString = CryptoJS.format.OpenSSL.stringify(cipherParams); + */ + stringify: function (cipherParams) { + var wordArray; + + // Shortcuts + var ciphertext = cipherParams.ciphertext; + var salt = cipherParams.salt; + + // Format + if (salt) { + wordArray = WordArray.create([0x53616c74, 0x65645f5f]).concat(salt).concat(ciphertext); + } else { + wordArray = ciphertext; + } + + return wordArray.toString(Base64); + }, + + /** + * Converts an OpenSSL-compatible string to a cipher params object. + * + * @param {string} openSSLStr The OpenSSL-compatible string. + * + * @return {CipherParams} The cipher params object. + * + * @static + * + * @example + * + * var cipherParams = CryptoJS.format.OpenSSL.parse(openSSLString); + */ + parse: function (openSSLStr) { + var salt; + + // Parse base64 + var ciphertext = Base64.parse(openSSLStr); + + // Shortcut + var ciphertextWords = ciphertext.words; + + // Test for salt + if (ciphertextWords[0] == 0x53616c74 && ciphertextWords[1] == 0x65645f5f) { + // Extract salt + salt = WordArray.create(ciphertextWords.slice(2, 4)); + + // Remove salt from ciphertext + ciphertextWords.splice(0, 4); + ciphertext.sigBytes -= 16; + } + + return CipherParams.create({ ciphertext: ciphertext, salt: salt }); + } + }; + + /** + * A cipher wrapper that returns ciphertext as a serializable cipher params object. + */ + var SerializableCipher = C_lib.SerializableCipher = Base.extend({ + /** + * Configuration options. + * + * @property {Formatter} format The formatting strategy to convert cipher param objects to and from a string. Default: OpenSSL + */ + cfg: Base.extend({ + format: OpenSSLFormatter + }), + + /** + * Encrypts a message. + * + * @param {Cipher} cipher The cipher algorithm to use. + * @param {WordArray|string} message The message to encrypt. + * @param {WordArray} key The key. + * @param {Object} cfg (Optional) The configuration options to use for this operation. + * + * @return {CipherParams} A cipher params object. + * + * @static + * + * @example + * + * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key); + * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv }); + * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv, format: CryptoJS.format.OpenSSL }); + */ + encrypt: function (cipher, message, key, cfg) { + // Apply config defaults + cfg = this.cfg.extend(cfg); + + // Encrypt + var encryptor = cipher.createEncryptor(key, cfg); + var ciphertext = encryptor.finalize(message); + + // Shortcut + var cipherCfg = encryptor.cfg; + + // Create and return serializable cipher params + return CipherParams.create({ + ciphertext: ciphertext, + key: key, + iv: cipherCfg.iv, + algorithm: cipher, + mode: cipherCfg.mode, + padding: cipherCfg.padding, + blockSize: cipher.blockSize, + formatter: cfg.format + }); + }, + + /** + * Decrypts serialized ciphertext. + * + * @param {Cipher} cipher The cipher algorithm to use. + * @param {CipherParams|string} ciphertext The ciphertext to decrypt. + * @param {WordArray} key The key. + * @param {Object} cfg (Optional) The configuration options to use for this operation. + * + * @return {WordArray} The plaintext. + * + * @static + * + * @example + * + * var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, key, { iv: iv, format: CryptoJS.format.OpenSSL }); + * var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, key, { iv: iv, format: CryptoJS.format.OpenSSL }); + */ + decrypt: function (cipher, ciphertext, key, cfg) { + // Apply config defaults + cfg = this.cfg.extend(cfg); + + // Convert string to CipherParams + ciphertext = this._parse(ciphertext, cfg.format); + + // Decrypt + var plaintext = cipher.createDecryptor(key, cfg).finalize(ciphertext.ciphertext); + + return plaintext; + }, + + /** + * Converts serialized ciphertext to CipherParams, + * else assumed CipherParams already and returns ciphertext unchanged. + * + * @param {CipherParams|string} ciphertext The ciphertext. + * @param {Formatter} format The formatting strategy to use to parse serialized ciphertext. + * + * @return {CipherParams} The unserialized ciphertext. + * + * @static + * + * @example + * + * var ciphertextParams = CryptoJS.lib.SerializableCipher._parse(ciphertextStringOrParams, format); + */ + _parse: function (ciphertext, format) { + if (typeof ciphertext == 'string') { + return format.parse(ciphertext, this); + } else { + return ciphertext; + } + } + }); + + /** + * Key derivation function namespace. + */ + var C_kdf = C.kdf = {}; + + /** + * OpenSSL key derivation function. + */ + var OpenSSLKdf = C_kdf.OpenSSL = { + /** + * Derives a key and IV from a password. + * + * @param {string} password The password to derive from. + * @param {number} keySize The size in words of the key to generate. + * @param {number} ivSize The size in words of the IV to generate. + * @param {WordArray|string} salt (Optional) A 64-bit salt to use. If omitted, a salt will be generated randomly. + * + * @return {CipherParams} A cipher params object with the key, IV, and salt. + * + * @static + * + * @example + * + * var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32); + * var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32, 'saltsalt'); + */ + execute: function (password, keySize, ivSize, salt) { + // Generate random salt + if (!salt) { + salt = WordArray.random(64/8); + } + + // Derive key and IV + var key = EvpKDF.create({ keySize: keySize + ivSize }).compute(password, salt); + + // Separate key and IV + var iv = WordArray.create(key.words.slice(keySize), ivSize * 4); + key.sigBytes = keySize * 4; + + // Return params + return CipherParams.create({ key: key, iv: iv, salt: salt }); + } + }; + + /** + * A serializable cipher wrapper that derives the key from a password, + * and returns ciphertext as a serializable cipher params object. + */ + var PasswordBasedCipher = C_lib.PasswordBasedCipher = SerializableCipher.extend({ + /** + * Configuration options. + * + * @property {KDF} kdf The key derivation function to use to generate a key and IV from a password. Default: OpenSSL + */ + cfg: SerializableCipher.cfg.extend({ + kdf: OpenSSLKdf + }), + + /** + * Encrypts a message using a password. + * + * @param {Cipher} cipher The cipher algorithm to use. + * @param {WordArray|string} message The message to encrypt. + * @param {string} password The password. + * @param {Object} cfg (Optional) The configuration options to use for this operation. + * + * @return {CipherParams} A cipher params object. + * + * @static + * + * @example + * + * var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password'); + * var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password', { format: CryptoJS.format.OpenSSL }); + */ + encrypt: function (cipher, message, password, cfg) { + // Apply config defaults + cfg = this.cfg.extend(cfg); + + // Derive key and other params + var derivedParams = cfg.kdf.execute(password, cipher.keySize, cipher.ivSize); + + // Add IV to config + cfg.iv = derivedParams.iv; + + // Encrypt + var ciphertext = SerializableCipher.encrypt.call(this, cipher, message, derivedParams.key, cfg); + + // Mix in derived params + ciphertext.mixIn(derivedParams); + + return ciphertext; + }, + + /** + * Decrypts serialized ciphertext using a password. + * + * @param {Cipher} cipher The cipher algorithm to use. + * @param {CipherParams|string} ciphertext The ciphertext to decrypt. + * @param {string} password The password. + * @param {Object} cfg (Optional) The configuration options to use for this operation. + * + * @return {WordArray} The plaintext. + * + * @static + * + * @example + * + * var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, 'password', { format: CryptoJS.format.OpenSSL }); + * var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, 'password', { format: CryptoJS.format.OpenSSL }); + */ + decrypt: function (cipher, ciphertext, password, cfg) { + // Apply config defaults + cfg = this.cfg.extend(cfg); + + // Convert string to CipherParams + ciphertext = this._parse(ciphertext, cfg.format); + + // Derive key and other params + var derivedParams = cfg.kdf.execute(password, cipher.keySize, cipher.ivSize, ciphertext.salt); + + // Add IV to config + cfg.iv = derivedParams.iv; + + // Decrypt + var plaintext = SerializableCipher.decrypt.call(this, cipher, ciphertext, derivedParams.key, cfg); + + return plaintext; + } + }); + }()); + + + /** + * Cipher Feedback block mode. + */ + CryptoJS.mode.CFB = (function () { + var CFB = CryptoJS.lib.BlockCipherMode.extend(); + + CFB.Encryptor = CFB.extend({ + processBlock: function (words, offset) { + // Shortcuts + var cipher = this._cipher; + var blockSize = cipher.blockSize; + + generateKeystreamAndEncrypt.call(this, words, offset, blockSize, cipher); + + // Remember this block to use with next block + this._prevBlock = words.slice(offset, offset + blockSize); + } + }); + + CFB.Decryptor = CFB.extend({ + processBlock: function (words, offset) { + // Shortcuts + var cipher = this._cipher; + var blockSize = cipher.blockSize; + + // Remember this block to use with next block + var thisBlock = words.slice(offset, offset + blockSize); + + generateKeystreamAndEncrypt.call(this, words, offset, blockSize, cipher); + + // This block becomes the previous block + this._prevBlock = thisBlock; + } + }); + + function generateKeystreamAndEncrypt(words, offset, blockSize, cipher) { + var keystream; + + // Shortcut + var iv = this._iv; + + // Generate keystream + if (iv) { + keystream = iv.slice(0); + + // Remove IV for subsequent blocks + this._iv = undefined; + } else { + keystream = this._prevBlock; + } + cipher.encryptBlock(keystream, 0); + + // Encrypt + for (var i = 0; i < blockSize; i++) { + words[offset + i] ^= keystream[i]; + } + } + + return CFB; + }()); + + + /** + * Counter block mode. + */ + CryptoJS.mode.CTR = (function () { + var CTR = CryptoJS.lib.BlockCipherMode.extend(); + + var Encryptor = CTR.Encryptor = CTR.extend({ + processBlock: function (words, offset) { + // Shortcuts + var cipher = this._cipher + var blockSize = cipher.blockSize; + var iv = this._iv; + var counter = this._counter; + + // Generate keystream + if (iv) { + counter = this._counter = iv.slice(0); + + // Remove IV for subsequent blocks + this._iv = undefined; + } + var keystream = counter.slice(0); + cipher.encryptBlock(keystream, 0); + + // Increment counter + counter[blockSize - 1] = (counter[blockSize - 1] + 1) | 0 + + // Encrypt + for (var i = 0; i < blockSize; i++) { + words[offset + i] ^= keystream[i]; + } + } + }); + + CTR.Decryptor = Encryptor; + + return CTR; + }()); + + + /** @preserve + * Counter block mode compatible with Dr Brian Gladman fileenc.c + * derived from CryptoJS.mode.CTR + * Jan Hruby jhruby.web@gmail.com + */ + CryptoJS.mode.CTRGladman = (function () { + var CTRGladman = CryptoJS.lib.BlockCipherMode.extend(); + + function incWord(word) + { + if (((word >> 24) & 0xff) === 0xff) { //overflow + var b1 = (word >> 16)&0xff; + var b2 = (word >> 8)&0xff; + var b3 = word & 0xff; + + if (b1 === 0xff) // overflow b1 + { + b1 = 0; + if (b2 === 0xff) + { + b2 = 0; + if (b3 === 0xff) + { + b3 = 0; + } + else + { + ++b3; + } + } + else + { + ++b2; + } + } + else + { + ++b1; + } + + word = 0; + word += (b1 << 16); + word += (b2 << 8); + word += b3; + } + else + { + word += (0x01 << 24); + } + return word; + } + + function incCounter(counter) + { + if ((counter[0] = incWord(counter[0])) === 0) + { + // encr_data in fileenc.c from Dr Brian Gladman's counts only with DWORD j < 8 + counter[1] = incWord(counter[1]); + } + return counter; + } + + var Encryptor = CTRGladman.Encryptor = CTRGladman.extend({ + processBlock: function (words, offset) { + // Shortcuts + var cipher = this._cipher + var blockSize = cipher.blockSize; + var iv = this._iv; + var counter = this._counter; + + // Generate keystream + if (iv) { + counter = this._counter = iv.slice(0); + + // Remove IV for subsequent blocks + this._iv = undefined; + } + + incCounter(counter); + + var keystream = counter.slice(0); + cipher.encryptBlock(keystream, 0); + + // Encrypt + for (var i = 0; i < blockSize; i++) { + words[offset + i] ^= keystream[i]; + } + } + }); + + CTRGladman.Decryptor = Encryptor; + + return CTRGladman; + }()); + + + + + /** + * Output Feedback block mode. + */ + CryptoJS.mode.OFB = (function () { + var OFB = CryptoJS.lib.BlockCipherMode.extend(); + + var Encryptor = OFB.Encryptor = OFB.extend({ + processBlock: function (words, offset) { + // Shortcuts + var cipher = this._cipher + var blockSize = cipher.blockSize; + var iv = this._iv; + var keystream = this._keystream; + + // Generate keystream + if (iv) { + keystream = this._keystream = iv.slice(0); + + // Remove IV for subsequent blocks + this._iv = undefined; + } + cipher.encryptBlock(keystream, 0); + + // Encrypt + for (var i = 0; i < blockSize; i++) { + words[offset + i] ^= keystream[i]; + } + } + }); + + OFB.Decryptor = Encryptor; + + return OFB; + }()); + + + /** + * Electronic Codebook block mode. + */ + CryptoJS.mode.ECB = (function () { + var ECB = CryptoJS.lib.BlockCipherMode.extend(); + + ECB.Encryptor = ECB.extend({ + processBlock: function (words, offset) { + this._cipher.encryptBlock(words, offset); + } + }); + + ECB.Decryptor = ECB.extend({ + processBlock: function (words, offset) { + this._cipher.decryptBlock(words, offset); + } + }); + + return ECB; + }()); + + + /** + * ANSI X.923 padding strategy. + */ + CryptoJS.pad.AnsiX923 = { + pad: function (data, blockSize) { + // Shortcuts + var dataSigBytes = data.sigBytes; + var blockSizeBytes = blockSize * 4; + + // Count padding bytes + var nPaddingBytes = blockSizeBytes - dataSigBytes % blockSizeBytes; + + // Compute last byte position + var lastBytePos = dataSigBytes + nPaddingBytes - 1; + + // Pad + data.clamp(); + data.words[lastBytePos >>> 2] |= nPaddingBytes << (24 - (lastBytePos % 4) * 8); + data.sigBytes += nPaddingBytes; + }, + + unpad: function (data) { + // Get number of padding bytes from last byte + var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff; + + // Remove padding + data.sigBytes -= nPaddingBytes; + } + }; + + + /** + * ISO 10126 padding strategy. + */ + CryptoJS.pad.Iso10126 = { + pad: function (data, blockSize) { + // Shortcut + var blockSizeBytes = blockSize * 4; + + // Count padding bytes + var nPaddingBytes = blockSizeBytes - data.sigBytes % blockSizeBytes; + + // Pad + data.concat(CryptoJS.lib.WordArray.random(nPaddingBytes - 1)). + concat(CryptoJS.lib.WordArray.create([nPaddingBytes << 24], 1)); + }, + + unpad: function (data) { + // Get number of padding bytes from last byte + var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff; + + // Remove padding + data.sigBytes -= nPaddingBytes; + } + }; + + + /** + * ISO/IEC 9797-1 Padding Method 2. + */ + CryptoJS.pad.Iso97971 = { + pad: function (data, blockSize) { + // Add 0x80 byte + data.concat(CryptoJS.lib.WordArray.create([0x80000000], 1)); + + // Zero pad the rest + CryptoJS.pad.ZeroPadding.pad(data, blockSize); + }, + + unpad: function (data) { + // Remove zero padding + CryptoJS.pad.ZeroPadding.unpad(data); + + // Remove one more byte -- the 0x80 byte + data.sigBytes--; + } + }; + + + /** + * Zero padding strategy. + */ + CryptoJS.pad.ZeroPadding = { + pad: function (data, blockSize) { + // Shortcut + var blockSizeBytes = blockSize * 4; + + // Pad + data.clamp(); + data.sigBytes += blockSizeBytes - ((data.sigBytes % blockSizeBytes) || blockSizeBytes); + }, + + unpad: function (data) { + // Shortcut + var dataWords = data.words; + + // Unpad + var i = data.sigBytes - 1; + for (var i = data.sigBytes - 1; i >= 0; i--) { + if (((dataWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff)) { + data.sigBytes = i + 1; + break; + } + } + } + }; + + + /** + * A noop padding strategy. + */ + CryptoJS.pad.NoPadding = { + pad: function () { + }, + + unpad: function () { + } + }; + + + (function (undefined) { + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var CipherParams = C_lib.CipherParams; + var C_enc = C.enc; + var Hex = C_enc.Hex; + var C_format = C.format; + + var HexFormatter = C_format.Hex = { + /** + * Converts the ciphertext of a cipher params object to a hexadecimally encoded string. + * + * @param {CipherParams} cipherParams The cipher params object. + * + * @return {string} The hexadecimally encoded string. + * + * @static + * + * @example + * + * var hexString = CryptoJS.format.Hex.stringify(cipherParams); + */ + stringify: function (cipherParams) { + return cipherParams.ciphertext.toString(Hex); + }, + + /** + * Converts a hexadecimally encoded ciphertext string to a cipher params object. + * + * @param {string} input The hexadecimally encoded string. + * + * @return {CipherParams} The cipher params object. + * + * @static + * + * @example + * + * var cipherParams = CryptoJS.format.Hex.parse(hexString); + */ + parse: function (input) { + var ciphertext = Hex.parse(input); + return CipherParams.create({ ciphertext: ciphertext }); + } + }; + }()); + + + (function () { + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var BlockCipher = C_lib.BlockCipher; + var C_algo = C.algo; + + // Lookup tables + var SBOX = []; + var INV_SBOX = []; + var SUB_MIX_0 = []; + var SUB_MIX_1 = []; + var SUB_MIX_2 = []; + var SUB_MIX_3 = []; + var INV_SUB_MIX_0 = []; + var INV_SUB_MIX_1 = []; + var INV_SUB_MIX_2 = []; + var INV_SUB_MIX_3 = []; + + // Compute lookup tables + (function () { + // Compute double table + var d = []; + for (var i = 0; i < 256; i++) { + if (i < 128) { + d[i] = i << 1; + } else { + d[i] = (i << 1) ^ 0x11b; + } + } + + // Walk GF(2^8) + var x = 0; + var xi = 0; + for (var i = 0; i < 256; i++) { + // Compute sbox + var sx = xi ^ (xi << 1) ^ (xi << 2) ^ (xi << 3) ^ (xi << 4); + sx = (sx >>> 8) ^ (sx & 0xff) ^ 0x63; + SBOX[x] = sx; + INV_SBOX[sx] = x; + + // Compute multiplication + var x2 = d[x]; + var x4 = d[x2]; + var x8 = d[x4]; + + // Compute sub bytes, mix columns tables + var t = (d[sx] * 0x101) ^ (sx * 0x1010100); + SUB_MIX_0[x] = (t << 24) | (t >>> 8); + SUB_MIX_1[x] = (t << 16) | (t >>> 16); + SUB_MIX_2[x] = (t << 8) | (t >>> 24); + SUB_MIX_3[x] = t; + + // Compute inv sub bytes, inv mix columns tables + var t = (x8 * 0x1010101) ^ (x4 * 0x10001) ^ (x2 * 0x101) ^ (x * 0x1010100); + INV_SUB_MIX_0[sx] = (t << 24) | (t >>> 8); + INV_SUB_MIX_1[sx] = (t << 16) | (t >>> 16); + INV_SUB_MIX_2[sx] = (t << 8) | (t >>> 24); + INV_SUB_MIX_3[sx] = t; + + // Compute next counter + if (!x) { + x = xi = 1; + } else { + x = x2 ^ d[d[d[x8 ^ x2]]]; + xi ^= d[d[xi]]; + } + } + }()); + + // Precomputed Rcon lookup + var RCON = [0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36]; + + /** + * AES block cipher algorithm. + */ + var AES = C_algo.AES = BlockCipher.extend({ + _doReset: function () { + var t; + + // Skip reset of nRounds has been set before and key did not change + if (this._nRounds && this._keyPriorReset === this._key) { + return; + } + + // Shortcuts + var key = this._keyPriorReset = this._key; + var keyWords = key.words; + var keySize = key.sigBytes / 4; + + // Compute number of rounds + var nRounds = this._nRounds = keySize + 6; + + // Compute number of key schedule rows + var ksRows = (nRounds + 1) * 4; + + // Compute key schedule + var keySchedule = this._keySchedule = []; + for (var ksRow = 0; ksRow < ksRows; ksRow++) { + if (ksRow < keySize) { + keySchedule[ksRow] = keyWords[ksRow]; + } else { + t = keySchedule[ksRow - 1]; + + if (!(ksRow % keySize)) { + // Rot word + t = (t << 8) | (t >>> 24); + + // Sub word + t = (SBOX[t >>> 24] << 24) | (SBOX[(t >>> 16) & 0xff] << 16) | (SBOX[(t >>> 8) & 0xff] << 8) | SBOX[t & 0xff]; + + // Mix Rcon + t ^= RCON[(ksRow / keySize) | 0] << 24; + } else if (keySize > 6 && ksRow % keySize == 4) { + // Sub word + t = (SBOX[t >>> 24] << 24) | (SBOX[(t >>> 16) & 0xff] << 16) | (SBOX[(t >>> 8) & 0xff] << 8) | SBOX[t & 0xff]; + } + + keySchedule[ksRow] = keySchedule[ksRow - keySize] ^ t; + } + } + + // Compute inv key schedule + var invKeySchedule = this._invKeySchedule = []; + for (var invKsRow = 0; invKsRow < ksRows; invKsRow++) { + var ksRow = ksRows - invKsRow; + + if (invKsRow % 4) { + var t = keySchedule[ksRow]; + } else { + var t = keySchedule[ksRow - 4]; + } + + if (invKsRow < 4 || ksRow <= 4) { + invKeySchedule[invKsRow] = t; + } else { + invKeySchedule[invKsRow] = INV_SUB_MIX_0[SBOX[t >>> 24]] ^ INV_SUB_MIX_1[SBOX[(t >>> 16) & 0xff]] ^ + INV_SUB_MIX_2[SBOX[(t >>> 8) & 0xff]] ^ INV_SUB_MIX_3[SBOX[t & 0xff]]; + } + } + }, + + encryptBlock: function (M, offset) { + this._doCryptBlock(M, offset, this._keySchedule, SUB_MIX_0, SUB_MIX_1, SUB_MIX_2, SUB_MIX_3, SBOX); + }, + + decryptBlock: function (M, offset) { + // Swap 2nd and 4th rows + var t = M[offset + 1]; + M[offset + 1] = M[offset + 3]; + M[offset + 3] = t; + + this._doCryptBlock(M, offset, this._invKeySchedule, INV_SUB_MIX_0, INV_SUB_MIX_1, INV_SUB_MIX_2, INV_SUB_MIX_3, INV_SBOX); + + // Inv swap 2nd and 4th rows + var t = M[offset + 1]; + M[offset + 1] = M[offset + 3]; + M[offset + 3] = t; + }, + + _doCryptBlock: function (M, offset, keySchedule, SUB_MIX_0, SUB_MIX_1, SUB_MIX_2, SUB_MIX_3, SBOX) { + // Shortcut + var nRounds = this._nRounds; + + // Get input, add round key + var s0 = M[offset] ^ keySchedule[0]; + var s1 = M[offset + 1] ^ keySchedule[1]; + var s2 = M[offset + 2] ^ keySchedule[2]; + var s3 = M[offset + 3] ^ keySchedule[3]; + + // Key schedule row counter + var ksRow = 4; + + // Rounds + for (var round = 1; round < nRounds; round++) { + // Shift rows, sub bytes, mix columns, add round key + var t0 = SUB_MIX_0[s0 >>> 24] ^ SUB_MIX_1[(s1 >>> 16) & 0xff] ^ SUB_MIX_2[(s2 >>> 8) & 0xff] ^ SUB_MIX_3[s3 & 0xff] ^ keySchedule[ksRow++]; + var t1 = SUB_MIX_0[s1 >>> 24] ^ SUB_MIX_1[(s2 >>> 16) & 0xff] ^ SUB_MIX_2[(s3 >>> 8) & 0xff] ^ SUB_MIX_3[s0 & 0xff] ^ keySchedule[ksRow++]; + var t2 = SUB_MIX_0[s2 >>> 24] ^ SUB_MIX_1[(s3 >>> 16) & 0xff] ^ SUB_MIX_2[(s0 >>> 8) & 0xff] ^ SUB_MIX_3[s1 & 0xff] ^ keySchedule[ksRow++]; + var t3 = SUB_MIX_0[s3 >>> 24] ^ SUB_MIX_1[(s0 >>> 16) & 0xff] ^ SUB_MIX_2[(s1 >>> 8) & 0xff] ^ SUB_MIX_3[s2 & 0xff] ^ keySchedule[ksRow++]; + + // Update state + s0 = t0; + s1 = t1; + s2 = t2; + s3 = t3; + } + + // Shift rows, sub bytes, add round key + var t0 = ((SBOX[s0 >>> 24] << 24) | (SBOX[(s1 >>> 16) & 0xff] << 16) | (SBOX[(s2 >>> 8) & 0xff] << 8) | SBOX[s3 & 0xff]) ^ keySchedule[ksRow++]; + var t1 = ((SBOX[s1 >>> 24] << 24) | (SBOX[(s2 >>> 16) & 0xff] << 16) | (SBOX[(s3 >>> 8) & 0xff] << 8) | SBOX[s0 & 0xff]) ^ keySchedule[ksRow++]; + var t2 = ((SBOX[s2 >>> 24] << 24) | (SBOX[(s3 >>> 16) & 0xff] << 16) | (SBOX[(s0 >>> 8) & 0xff] << 8) | SBOX[s1 & 0xff]) ^ keySchedule[ksRow++]; + var t3 = ((SBOX[s3 >>> 24] << 24) | (SBOX[(s0 >>> 16) & 0xff] << 16) | (SBOX[(s1 >>> 8) & 0xff] << 8) | SBOX[s2 & 0xff]) ^ keySchedule[ksRow++]; + + // Set output + M[offset] = t0; + M[offset + 1] = t1; + M[offset + 2] = t2; + M[offset + 3] = t3; + }, + + keySize: 256/32 + }); + + /** + * Shortcut functions to the cipher's object interface. + * + * @example + * + * var ciphertext = CryptoJS.AES.encrypt(message, key, cfg); + * var plaintext = CryptoJS.AES.decrypt(ciphertext, key, cfg); + */ + C.AES = BlockCipher._createHelper(AES); + }()); + + + (function () { + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var WordArray = C_lib.WordArray; + var BlockCipher = C_lib.BlockCipher; + var C_algo = C.algo; + + // Permuted Choice 1 constants + var PC1 = [ + 57, 49, 41, 33, 25, 17, 9, 1, + 58, 50, 42, 34, 26, 18, 10, 2, + 59, 51, 43, 35, 27, 19, 11, 3, + 60, 52, 44, 36, 63, 55, 47, 39, + 31, 23, 15, 7, 62, 54, 46, 38, + 30, 22, 14, 6, 61, 53, 45, 37, + 29, 21, 13, 5, 28, 20, 12, 4 + ]; + + // Permuted Choice 2 constants + var PC2 = [ + 14, 17, 11, 24, 1, 5, + 3, 28, 15, 6, 21, 10, + 23, 19, 12, 4, 26, 8, + 16, 7, 27, 20, 13, 2, + 41, 52, 31, 37, 47, 55, + 30, 40, 51, 45, 33, 48, + 44, 49, 39, 56, 34, 53, + 46, 42, 50, 36, 29, 32 + ]; + + // Cumulative bit shift constants + var BIT_SHIFTS = [1, 2, 4, 6, 8, 10, 12, 14, 15, 17, 19, 21, 23, 25, 27, 28]; + + // SBOXes and round permutation constants + var SBOX_P = [ + { + 0x0: 0x808200, + 0x10000000: 0x8000, + 0x20000000: 0x808002, + 0x30000000: 0x2, + 0x40000000: 0x200, + 0x50000000: 0x808202, + 0x60000000: 0x800202, + 0x70000000: 0x800000, + 0x80000000: 0x202, + 0x90000000: 0x800200, + 0xa0000000: 0x8200, + 0xb0000000: 0x808000, + 0xc0000000: 0x8002, + 0xd0000000: 0x800002, + 0xe0000000: 0x0, + 0xf0000000: 0x8202, + 0x8000000: 0x0, + 0x18000000: 0x808202, + 0x28000000: 0x8202, + 0x38000000: 0x8000, + 0x48000000: 0x808200, + 0x58000000: 0x200, + 0x68000000: 0x808002, + 0x78000000: 0x2, + 0x88000000: 0x800200, + 0x98000000: 0x8200, + 0xa8000000: 0x808000, + 0xb8000000: 0x800202, + 0xc8000000: 0x800002, + 0xd8000000: 0x8002, + 0xe8000000: 0x202, + 0xf8000000: 0x800000, + 0x1: 0x8000, + 0x10000001: 0x2, + 0x20000001: 0x808200, + 0x30000001: 0x800000, + 0x40000001: 0x808002, + 0x50000001: 0x8200, + 0x60000001: 0x200, + 0x70000001: 0x800202, + 0x80000001: 0x808202, + 0x90000001: 0x808000, + 0xa0000001: 0x800002, + 0xb0000001: 0x8202, + 0xc0000001: 0x202, + 0xd0000001: 0x800200, + 0xe0000001: 0x8002, + 0xf0000001: 0x0, + 0x8000001: 0x808202, + 0x18000001: 0x808000, + 0x28000001: 0x800000, + 0x38000001: 0x200, + 0x48000001: 0x8000, + 0x58000001: 0x800002, + 0x68000001: 0x2, + 0x78000001: 0x8202, + 0x88000001: 0x8002, + 0x98000001: 0x800202, + 0xa8000001: 0x202, + 0xb8000001: 0x808200, + 0xc8000001: 0x800200, + 0xd8000001: 0x0, + 0xe8000001: 0x8200, + 0xf8000001: 0x808002 + }, + { + 0x0: 0x40084010, + 0x1000000: 0x4000, + 0x2000000: 0x80000, + 0x3000000: 0x40080010, + 0x4000000: 0x40000010, + 0x5000000: 0x40084000, + 0x6000000: 0x40004000, + 0x7000000: 0x10, + 0x8000000: 0x84000, + 0x9000000: 0x40004010, + 0xa000000: 0x40000000, + 0xb000000: 0x84010, + 0xc000000: 0x80010, + 0xd000000: 0x0, + 0xe000000: 0x4010, + 0xf000000: 0x40080000, + 0x800000: 0x40004000, + 0x1800000: 0x84010, + 0x2800000: 0x10, + 0x3800000: 0x40004010, + 0x4800000: 0x40084010, + 0x5800000: 0x40000000, + 0x6800000: 0x80000, + 0x7800000: 0x40080010, + 0x8800000: 0x80010, + 0x9800000: 0x0, + 0xa800000: 0x4000, + 0xb800000: 0x40080000, + 0xc800000: 0x40000010, + 0xd800000: 0x84000, + 0xe800000: 0x40084000, + 0xf800000: 0x4010, + 0x10000000: 0x0, + 0x11000000: 0x40080010, + 0x12000000: 0x40004010, + 0x13000000: 0x40084000, + 0x14000000: 0x40080000, + 0x15000000: 0x10, + 0x16000000: 0x84010, + 0x17000000: 0x4000, + 0x18000000: 0x4010, + 0x19000000: 0x80000, + 0x1a000000: 0x80010, + 0x1b000000: 0x40000010, + 0x1c000000: 0x84000, + 0x1d000000: 0x40004000, + 0x1e000000: 0x40000000, + 0x1f000000: 0x40084010, + 0x10800000: 0x84010, + 0x11800000: 0x80000, + 0x12800000: 0x40080000, + 0x13800000: 0x4000, + 0x14800000: 0x40004000, + 0x15800000: 0x40084010, + 0x16800000: 0x10, + 0x17800000: 0x40000000, + 0x18800000: 0x40084000, + 0x19800000: 0x40000010, + 0x1a800000: 0x40004010, + 0x1b800000: 0x80010, + 0x1c800000: 0x0, + 0x1d800000: 0x4010, + 0x1e800000: 0x40080010, + 0x1f800000: 0x84000 + }, + { + 0x0: 0x104, + 0x100000: 0x0, + 0x200000: 0x4000100, + 0x300000: 0x10104, + 0x400000: 0x10004, + 0x500000: 0x4000004, + 0x600000: 0x4010104, + 0x700000: 0x4010000, + 0x800000: 0x4000000, + 0x900000: 0x4010100, + 0xa00000: 0x10100, + 0xb00000: 0x4010004, + 0xc00000: 0x4000104, + 0xd00000: 0x10000, + 0xe00000: 0x4, + 0xf00000: 0x100, + 0x80000: 0x4010100, + 0x180000: 0x4010004, + 0x280000: 0x0, + 0x380000: 0x4000100, + 0x480000: 0x4000004, + 0x580000: 0x10000, + 0x680000: 0x10004, + 0x780000: 0x104, + 0x880000: 0x4, + 0x980000: 0x100, + 0xa80000: 0x4010000, + 0xb80000: 0x10104, + 0xc80000: 0x10100, + 0xd80000: 0x4000104, + 0xe80000: 0x4010104, + 0xf80000: 0x4000000, + 0x1000000: 0x4010100, + 0x1100000: 0x10004, + 0x1200000: 0x10000, + 0x1300000: 0x4000100, + 0x1400000: 0x100, + 0x1500000: 0x4010104, + 0x1600000: 0x4000004, + 0x1700000: 0x0, + 0x1800000: 0x4000104, + 0x1900000: 0x4000000, + 0x1a00000: 0x4, + 0x1b00000: 0x10100, + 0x1c00000: 0x4010000, + 0x1d00000: 0x104, + 0x1e00000: 0x10104, + 0x1f00000: 0x4010004, + 0x1080000: 0x4000000, + 0x1180000: 0x104, + 0x1280000: 0x4010100, + 0x1380000: 0x0, + 0x1480000: 0x10004, + 0x1580000: 0x4000100, + 0x1680000: 0x100, + 0x1780000: 0x4010004, + 0x1880000: 0x10000, + 0x1980000: 0x4010104, + 0x1a80000: 0x10104, + 0x1b80000: 0x4000004, + 0x1c80000: 0x4000104, + 0x1d80000: 0x4010000, + 0x1e80000: 0x4, + 0x1f80000: 0x10100 + }, + { + 0x0: 0x80401000, + 0x10000: 0x80001040, + 0x20000: 0x401040, + 0x30000: 0x80400000, + 0x40000: 0x0, + 0x50000: 0x401000, + 0x60000: 0x80000040, + 0x70000: 0x400040, + 0x80000: 0x80000000, + 0x90000: 0x400000, + 0xa0000: 0x40, + 0xb0000: 0x80001000, + 0xc0000: 0x80400040, + 0xd0000: 0x1040, + 0xe0000: 0x1000, + 0xf0000: 0x80401040, + 0x8000: 0x80001040, + 0x18000: 0x40, + 0x28000: 0x80400040, + 0x38000: 0x80001000, + 0x48000: 0x401000, + 0x58000: 0x80401040, + 0x68000: 0x0, + 0x78000: 0x80400000, + 0x88000: 0x1000, + 0x98000: 0x80401000, + 0xa8000: 0x400000, + 0xb8000: 0x1040, + 0xc8000: 0x80000000, + 0xd8000: 0x400040, + 0xe8000: 0x401040, + 0xf8000: 0x80000040, + 0x100000: 0x400040, + 0x110000: 0x401000, + 0x120000: 0x80000040, + 0x130000: 0x0, + 0x140000: 0x1040, + 0x150000: 0x80400040, + 0x160000: 0x80401000, + 0x170000: 0x80001040, + 0x180000: 0x80401040, + 0x190000: 0x80000000, + 0x1a0000: 0x80400000, + 0x1b0000: 0x401040, + 0x1c0000: 0x80001000, + 0x1d0000: 0x400000, + 0x1e0000: 0x40, + 0x1f0000: 0x1000, + 0x108000: 0x80400000, + 0x118000: 0x80401040, + 0x128000: 0x0, + 0x138000: 0x401000, + 0x148000: 0x400040, + 0x158000: 0x80000000, + 0x168000: 0x80001040, + 0x178000: 0x40, + 0x188000: 0x80000040, + 0x198000: 0x1000, + 0x1a8000: 0x80001000, + 0x1b8000: 0x80400040, + 0x1c8000: 0x1040, + 0x1d8000: 0x80401000, + 0x1e8000: 0x400000, + 0x1f8000: 0x401040 + }, + { + 0x0: 0x80, + 0x1000: 0x1040000, + 0x2000: 0x40000, + 0x3000: 0x20000000, + 0x4000: 0x20040080, + 0x5000: 0x1000080, + 0x6000: 0x21000080, + 0x7000: 0x40080, + 0x8000: 0x1000000, + 0x9000: 0x20040000, + 0xa000: 0x20000080, + 0xb000: 0x21040080, + 0xc000: 0x21040000, + 0xd000: 0x0, + 0xe000: 0x1040080, + 0xf000: 0x21000000, + 0x800: 0x1040080, + 0x1800: 0x21000080, + 0x2800: 0x80, + 0x3800: 0x1040000, + 0x4800: 0x40000, + 0x5800: 0x20040080, + 0x6800: 0x21040000, + 0x7800: 0x20000000, + 0x8800: 0x20040000, + 0x9800: 0x0, + 0xa800: 0x21040080, + 0xb800: 0x1000080, + 0xc800: 0x20000080, + 0xd800: 0x21000000, + 0xe800: 0x1000000, + 0xf800: 0x40080, + 0x10000: 0x40000, + 0x11000: 0x80, + 0x12000: 0x20000000, + 0x13000: 0x21000080, + 0x14000: 0x1000080, + 0x15000: 0x21040000, + 0x16000: 0x20040080, + 0x17000: 0x1000000, + 0x18000: 0x21040080, + 0x19000: 0x21000000, + 0x1a000: 0x1040000, + 0x1b000: 0x20040000, + 0x1c000: 0x40080, + 0x1d000: 0x20000080, + 0x1e000: 0x0, + 0x1f000: 0x1040080, + 0x10800: 0x21000080, + 0x11800: 0x1000000, + 0x12800: 0x1040000, + 0x13800: 0x20040080, + 0x14800: 0x20000000, + 0x15800: 0x1040080, + 0x16800: 0x80, + 0x17800: 0x21040000, + 0x18800: 0x40080, + 0x19800: 0x21040080, + 0x1a800: 0x0, + 0x1b800: 0x21000000, + 0x1c800: 0x1000080, + 0x1d800: 0x40000, + 0x1e800: 0x20040000, + 0x1f800: 0x20000080 + }, + { + 0x0: 0x10000008, + 0x100: 0x2000, + 0x200: 0x10200000, + 0x300: 0x10202008, + 0x400: 0x10002000, + 0x500: 0x200000, + 0x600: 0x200008, + 0x700: 0x10000000, + 0x800: 0x0, + 0x900: 0x10002008, + 0xa00: 0x202000, + 0xb00: 0x8, + 0xc00: 0x10200008, + 0xd00: 0x202008, + 0xe00: 0x2008, + 0xf00: 0x10202000, + 0x80: 0x10200000, + 0x180: 0x10202008, + 0x280: 0x8, + 0x380: 0x200000, + 0x480: 0x202008, + 0x580: 0x10000008, + 0x680: 0x10002000, + 0x780: 0x2008, + 0x880: 0x200008, + 0x980: 0x2000, + 0xa80: 0x10002008, + 0xb80: 0x10200008, + 0xc80: 0x0, + 0xd80: 0x10202000, + 0xe80: 0x202000, + 0xf80: 0x10000000, + 0x1000: 0x10002000, + 0x1100: 0x10200008, + 0x1200: 0x10202008, + 0x1300: 0x2008, + 0x1400: 0x200000, + 0x1500: 0x10000000, + 0x1600: 0x10000008, + 0x1700: 0x202000, + 0x1800: 0x202008, + 0x1900: 0x0, + 0x1a00: 0x8, + 0x1b00: 0x10200000, + 0x1c00: 0x2000, + 0x1d00: 0x10002008, + 0x1e00: 0x10202000, + 0x1f00: 0x200008, + 0x1080: 0x8, + 0x1180: 0x202000, + 0x1280: 0x200000, + 0x1380: 0x10000008, + 0x1480: 0x10002000, + 0x1580: 0x2008, + 0x1680: 0x10202008, + 0x1780: 0x10200000, + 0x1880: 0x10202000, + 0x1980: 0x10200008, + 0x1a80: 0x2000, + 0x1b80: 0x202008, + 0x1c80: 0x200008, + 0x1d80: 0x0, + 0x1e80: 0x10000000, + 0x1f80: 0x10002008 + }, + { + 0x0: 0x100000, + 0x10: 0x2000401, + 0x20: 0x400, + 0x30: 0x100401, + 0x40: 0x2100401, + 0x50: 0x0, + 0x60: 0x1, + 0x70: 0x2100001, + 0x80: 0x2000400, + 0x90: 0x100001, + 0xa0: 0x2000001, + 0xb0: 0x2100400, + 0xc0: 0x2100000, + 0xd0: 0x401, + 0xe0: 0x100400, + 0xf0: 0x2000000, + 0x8: 0x2100001, + 0x18: 0x0, + 0x28: 0x2000401, + 0x38: 0x2100400, + 0x48: 0x100000, + 0x58: 0x2000001, + 0x68: 0x2000000, + 0x78: 0x401, + 0x88: 0x100401, + 0x98: 0x2000400, + 0xa8: 0x2100000, + 0xb8: 0x100001, + 0xc8: 0x400, + 0xd8: 0x2100401, + 0xe8: 0x1, + 0xf8: 0x100400, + 0x100: 0x2000000, + 0x110: 0x100000, + 0x120: 0x2000401, + 0x130: 0x2100001, + 0x140: 0x100001, + 0x150: 0x2000400, + 0x160: 0x2100400, + 0x170: 0x100401, + 0x180: 0x401, + 0x190: 0x2100401, + 0x1a0: 0x100400, + 0x1b0: 0x1, + 0x1c0: 0x0, + 0x1d0: 0x2100000, + 0x1e0: 0x2000001, + 0x1f0: 0x400, + 0x108: 0x100400, + 0x118: 0x2000401, + 0x128: 0x2100001, + 0x138: 0x1, + 0x148: 0x2000000, + 0x158: 0x100000, + 0x168: 0x401, + 0x178: 0x2100400, + 0x188: 0x2000001, + 0x198: 0x2100000, + 0x1a8: 0x0, + 0x1b8: 0x2100401, + 0x1c8: 0x100401, + 0x1d8: 0x400, + 0x1e8: 0x2000400, + 0x1f8: 0x100001 + }, + { + 0x0: 0x8000820, + 0x1: 0x20000, + 0x2: 0x8000000, + 0x3: 0x20, + 0x4: 0x20020, + 0x5: 0x8020820, + 0x6: 0x8020800, + 0x7: 0x800, + 0x8: 0x8020000, + 0x9: 0x8000800, + 0xa: 0x20800, + 0xb: 0x8020020, + 0xc: 0x820, + 0xd: 0x0, + 0xe: 0x8000020, + 0xf: 0x20820, + 0x80000000: 0x800, + 0x80000001: 0x8020820, + 0x80000002: 0x8000820, + 0x80000003: 0x8000000, + 0x80000004: 0x8020000, + 0x80000005: 0x20800, + 0x80000006: 0x20820, + 0x80000007: 0x20, + 0x80000008: 0x8000020, + 0x80000009: 0x820, + 0x8000000a: 0x20020, + 0x8000000b: 0x8020800, + 0x8000000c: 0x0, + 0x8000000d: 0x8020020, + 0x8000000e: 0x8000800, + 0x8000000f: 0x20000, + 0x10: 0x20820, + 0x11: 0x8020800, + 0x12: 0x20, + 0x13: 0x800, + 0x14: 0x8000800, + 0x15: 0x8000020, + 0x16: 0x8020020, + 0x17: 0x20000, + 0x18: 0x0, + 0x19: 0x20020, + 0x1a: 0x8020000, + 0x1b: 0x8000820, + 0x1c: 0x8020820, + 0x1d: 0x20800, + 0x1e: 0x820, + 0x1f: 0x8000000, + 0x80000010: 0x20000, + 0x80000011: 0x800, + 0x80000012: 0x8020020, + 0x80000013: 0x20820, + 0x80000014: 0x20, + 0x80000015: 0x8020000, + 0x80000016: 0x8000000, + 0x80000017: 0x8000820, + 0x80000018: 0x8020820, + 0x80000019: 0x8000020, + 0x8000001a: 0x8000800, + 0x8000001b: 0x0, + 0x8000001c: 0x20800, + 0x8000001d: 0x820, + 0x8000001e: 0x20020, + 0x8000001f: 0x8020800 + } + ]; + + // Masks that select the SBOX input + var SBOX_MASK = [ + 0xf8000001, 0x1f800000, 0x01f80000, 0x001f8000, + 0x0001f800, 0x00001f80, 0x000001f8, 0x8000001f + ]; + + /** + * DES block cipher algorithm. + */ + var DES = C_algo.DES = BlockCipher.extend({ + _doReset: function () { + // Shortcuts + var key = this._key; + var keyWords = key.words; + + // Select 56 bits according to PC1 + var keyBits = []; + for (var i = 0; i < 56; i++) { + var keyBitPos = PC1[i] - 1; + keyBits[i] = (keyWords[keyBitPos >>> 5] >>> (31 - keyBitPos % 32)) & 1; + } + + // Assemble 16 subkeys + var subKeys = this._subKeys = []; + for (var nSubKey = 0; nSubKey < 16; nSubKey++) { + // Create subkey + var subKey = subKeys[nSubKey] = []; + + // Shortcut + var bitShift = BIT_SHIFTS[nSubKey]; + + // Select 48 bits according to PC2 + for (var i = 0; i < 24; i++) { + // Select from the left 28 key bits + subKey[(i / 6) | 0] |= keyBits[((PC2[i] - 1) + bitShift) % 28] << (31 - i % 6); + + // Select from the right 28 key bits + subKey[4 + ((i / 6) | 0)] |= keyBits[28 + (((PC2[i + 24] - 1) + bitShift) % 28)] << (31 - i % 6); + } + + // Since each subkey is applied to an expanded 32-bit input, + // the subkey can be broken into 8 values scaled to 32-bits, + // which allows the key to be used without expansion + subKey[0] = (subKey[0] << 1) | (subKey[0] >>> 31); + for (var i = 1; i < 7; i++) { + subKey[i] = subKey[i] >>> ((i - 1) * 4 + 3); + } + subKey[7] = (subKey[7] << 5) | (subKey[7] >>> 27); + } + + // Compute inverse subkeys + var invSubKeys = this._invSubKeys = []; + for (var i = 0; i < 16; i++) { + invSubKeys[i] = subKeys[15 - i]; + } + }, + + encryptBlock: function (M, offset) { + this._doCryptBlock(M, offset, this._subKeys); + }, + + decryptBlock: function (M, offset) { + this._doCryptBlock(M, offset, this._invSubKeys); + }, + + _doCryptBlock: function (M, offset, subKeys) { + // Get input + this._lBlock = M[offset]; + this._rBlock = M[offset + 1]; + + // Initial permutation + exchangeLR.call(this, 4, 0x0f0f0f0f); + exchangeLR.call(this, 16, 0x0000ffff); + exchangeRL.call(this, 2, 0x33333333); + exchangeRL.call(this, 8, 0x00ff00ff); + exchangeLR.call(this, 1, 0x55555555); + + // Rounds + for (var round = 0; round < 16; round++) { + // Shortcuts + var subKey = subKeys[round]; + var lBlock = this._lBlock; + var rBlock = this._rBlock; + + // Feistel function + var f = 0; + for (var i = 0; i < 8; i++) { + f |= SBOX_P[i][((rBlock ^ subKey[i]) & SBOX_MASK[i]) >>> 0]; + } + this._lBlock = rBlock; + this._rBlock = lBlock ^ f; + } + + // Undo swap from last round + var t = this._lBlock; + this._lBlock = this._rBlock; + this._rBlock = t; + + // Final permutation + exchangeLR.call(this, 1, 0x55555555); + exchangeRL.call(this, 8, 0x00ff00ff); + exchangeRL.call(this, 2, 0x33333333); + exchangeLR.call(this, 16, 0x0000ffff); + exchangeLR.call(this, 4, 0x0f0f0f0f); + + // Set output + M[offset] = this._lBlock; + M[offset + 1] = this._rBlock; + }, + + keySize: 64/32, + + ivSize: 64/32, + + blockSize: 64/32 + }); + + // Swap bits across the left and right words + function exchangeLR(offset, mask) { + var t = ((this._lBlock >>> offset) ^ this._rBlock) & mask; + this._rBlock ^= t; + this._lBlock ^= t << offset; + } + + function exchangeRL(offset, mask) { + var t = ((this._rBlock >>> offset) ^ this._lBlock) & mask; + this._lBlock ^= t; + this._rBlock ^= t << offset; + } + + /** + * Shortcut functions to the cipher's object interface. + * + * @example + * + * var ciphertext = CryptoJS.DES.encrypt(message, key, cfg); + * var plaintext = CryptoJS.DES.decrypt(ciphertext, key, cfg); + */ + C.DES = BlockCipher._createHelper(DES); + + /** + * Triple-DES block cipher algorithm. + */ + var TripleDES = C_algo.TripleDES = BlockCipher.extend({ + _doReset: function () { + // Shortcuts + var key = this._key; + var keyWords = key.words; + // Make sure the key length is valid (64, 128 or >= 192 bit) + if (keyWords.length !== 2 && keyWords.length !== 4 && keyWords.length < 6) { + throw new Error('Invalid key length - 3DES requires the key length to be 64, 128, 192 or >192.'); + } + + // Extend the key according to the keying options defined in 3DES standard + var key1 = keyWords.slice(0, 2); + var key2 = keyWords.length < 4 ? keyWords.slice(0, 2) : keyWords.slice(2, 4); + var key3 = keyWords.length < 6 ? keyWords.slice(0, 2) : keyWords.slice(4, 6); + + // Create DES instances + this._des1 = DES.createEncryptor(WordArray.create(key1)); + this._des2 = DES.createEncryptor(WordArray.create(key2)); + this._des3 = DES.createEncryptor(WordArray.create(key3)); + }, + + encryptBlock: function (M, offset) { + this._des1.encryptBlock(M, offset); + this._des2.decryptBlock(M, offset); + this._des3.encryptBlock(M, offset); + }, + + decryptBlock: function (M, offset) { + this._des3.decryptBlock(M, offset); + this._des2.encryptBlock(M, offset); + this._des1.decryptBlock(M, offset); + }, + + keySize: 192/32, + + ivSize: 64/32, + + blockSize: 64/32 + }); + + /** + * Shortcut functions to the cipher's object interface. + * + * @example + * + * var ciphertext = CryptoJS.TripleDES.encrypt(message, key, cfg); + * var plaintext = CryptoJS.TripleDES.decrypt(ciphertext, key, cfg); + */ + C.TripleDES = BlockCipher._createHelper(TripleDES); + }()); + + + (function () { + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var StreamCipher = C_lib.StreamCipher; + var C_algo = C.algo; + + /** + * RC4 stream cipher algorithm. + */ + var RC4 = C_algo.RC4 = StreamCipher.extend({ + _doReset: function () { + // Shortcuts + var key = this._key; + var keyWords = key.words; + var keySigBytes = key.sigBytes; + + // Init sbox + var S = this._S = []; + for (var i = 0; i < 256; i++) { + S[i] = i; + } + + // Key setup + for (var i = 0, j = 0; i < 256; i++) { + var keyByteIndex = i % keySigBytes; + var keyByte = (keyWords[keyByteIndex >>> 2] >>> (24 - (keyByteIndex % 4) * 8)) & 0xff; + + j = (j + S[i] + keyByte) % 256; + + // Swap + var t = S[i]; + S[i] = S[j]; + S[j] = t; + } + + // Counters + this._i = this._j = 0; + }, + + _doProcessBlock: function (M, offset) { + M[offset] ^= generateKeystreamWord.call(this); + }, + + keySize: 256/32, + + ivSize: 0 + }); + + function generateKeystreamWord() { + // Shortcuts + var S = this._S; + var i = this._i; + var j = this._j; + + // Generate keystream word + var keystreamWord = 0; + for (var n = 0; n < 4; n++) { + i = (i + 1) % 256; + j = (j + S[i]) % 256; + + // Swap + var t = S[i]; + S[i] = S[j]; + S[j] = t; + + keystreamWord |= S[(S[i] + S[j]) % 256] << (24 - n * 8); + } + + // Update counters + this._i = i; + this._j = j; + + return keystreamWord; + } + + /** + * Shortcut functions to the cipher's object interface. + * + * @example + * + * var ciphertext = CryptoJS.RC4.encrypt(message, key, cfg); + * var plaintext = CryptoJS.RC4.decrypt(ciphertext, key, cfg); + */ + C.RC4 = StreamCipher._createHelper(RC4); + + /** + * Modified RC4 stream cipher algorithm. + */ + var RC4Drop = C_algo.RC4Drop = RC4.extend({ + /** + * Configuration options. + * + * @property {number} drop The number of keystream words to drop. Default 192 + */ + cfg: RC4.cfg.extend({ + drop: 192 + }), + + _doReset: function () { + RC4._doReset.call(this); + + // Drop + for (var i = this.cfg.drop; i > 0; i--) { + generateKeystreamWord.call(this); + } + } + }); + + /** + * Shortcut functions to the cipher's object interface. + * + * @example + * + * var ciphertext = CryptoJS.RC4Drop.encrypt(message, key, cfg); + * var plaintext = CryptoJS.RC4Drop.decrypt(ciphertext, key, cfg); + */ + C.RC4Drop = StreamCipher._createHelper(RC4Drop); + }()); + + + (function () { + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var StreamCipher = C_lib.StreamCipher; + var C_algo = C.algo; + + // Reusable objects + var S = []; + var C_ = []; + var G = []; + + /** + * Rabbit stream cipher algorithm + */ + var Rabbit = C_algo.Rabbit = StreamCipher.extend({ + _doReset: function () { + // Shortcuts + var K = this._key.words; + var iv = this.cfg.iv; + + // Swap endian + for (var i = 0; i < 4; i++) { + K[i] = (((K[i] << 8) | (K[i] >>> 24)) & 0x00ff00ff) | + (((K[i] << 24) | (K[i] >>> 8)) & 0xff00ff00); + } + + // Generate initial state values + var X = this._X = [ + K[0], (K[3] << 16) | (K[2] >>> 16), + K[1], (K[0] << 16) | (K[3] >>> 16), + K[2], (K[1] << 16) | (K[0] >>> 16), + K[3], (K[2] << 16) | (K[1] >>> 16) + ]; + + // Generate initial counter values + var C = this._C = [ + (K[2] << 16) | (K[2] >>> 16), (K[0] & 0xffff0000) | (K[1] & 0x0000ffff), + (K[3] << 16) | (K[3] >>> 16), (K[1] & 0xffff0000) | (K[2] & 0x0000ffff), + (K[0] << 16) | (K[0] >>> 16), (K[2] & 0xffff0000) | (K[3] & 0x0000ffff), + (K[1] << 16) | (K[1] >>> 16), (K[3] & 0xffff0000) | (K[0] & 0x0000ffff) + ]; + + // Carry bit + this._b = 0; + + // Iterate the system four times + for (var i = 0; i < 4; i++) { + nextState.call(this); + } + + // Modify the counters + for (var i = 0; i < 8; i++) { + C[i] ^= X[(i + 4) & 7]; + } + + // IV setup + if (iv) { + // Shortcuts + var IV = iv.words; + var IV_0 = IV[0]; + var IV_1 = IV[1]; + + // Generate four subvectors + var i0 = (((IV_0 << 8) | (IV_0 >>> 24)) & 0x00ff00ff) | (((IV_0 << 24) | (IV_0 >>> 8)) & 0xff00ff00); + var i2 = (((IV_1 << 8) | (IV_1 >>> 24)) & 0x00ff00ff) | (((IV_1 << 24) | (IV_1 >>> 8)) & 0xff00ff00); + var i1 = (i0 >>> 16) | (i2 & 0xffff0000); + var i3 = (i2 << 16) | (i0 & 0x0000ffff); + + // Modify counter values + C[0] ^= i0; + C[1] ^= i1; + C[2] ^= i2; + C[3] ^= i3; + C[4] ^= i0; + C[5] ^= i1; + C[6] ^= i2; + C[7] ^= i3; + + // Iterate the system four times + for (var i = 0; i < 4; i++) { + nextState.call(this); + } + } + }, + + _doProcessBlock: function (M, offset) { + // Shortcut + var X = this._X; + + // Iterate the system + nextState.call(this); + + // Generate four keystream words + S[0] = X[0] ^ (X[5] >>> 16) ^ (X[3] << 16); + S[1] = X[2] ^ (X[7] >>> 16) ^ (X[5] << 16); + S[2] = X[4] ^ (X[1] >>> 16) ^ (X[7] << 16); + S[3] = X[6] ^ (X[3] >>> 16) ^ (X[1] << 16); + + for (var i = 0; i < 4; i++) { + // Swap endian + S[i] = (((S[i] << 8) | (S[i] >>> 24)) & 0x00ff00ff) | + (((S[i] << 24) | (S[i] >>> 8)) & 0xff00ff00); + + // Encrypt + M[offset + i] ^= S[i]; + } + }, + + blockSize: 128/32, + + ivSize: 64/32 + }); + + function nextState() { + // Shortcuts + var X = this._X; + var C = this._C; + + // Save old counter values + for (var i = 0; i < 8; i++) { + C_[i] = C[i]; + } + + // Calculate new counter values + C[0] = (C[0] + 0x4d34d34d + this._b) | 0; + C[1] = (C[1] + 0xd34d34d3 + ((C[0] >>> 0) < (C_[0] >>> 0) ? 1 : 0)) | 0; + C[2] = (C[2] + 0x34d34d34 + ((C[1] >>> 0) < (C_[1] >>> 0) ? 1 : 0)) | 0; + C[3] = (C[3] + 0x4d34d34d + ((C[2] >>> 0) < (C_[2] >>> 0) ? 1 : 0)) | 0; + C[4] = (C[4] + 0xd34d34d3 + ((C[3] >>> 0) < (C_[3] >>> 0) ? 1 : 0)) | 0; + C[5] = (C[5] + 0x34d34d34 + ((C[4] >>> 0) < (C_[4] >>> 0) ? 1 : 0)) | 0; + C[6] = (C[6] + 0x4d34d34d + ((C[5] >>> 0) < (C_[5] >>> 0) ? 1 : 0)) | 0; + C[7] = (C[7] + 0xd34d34d3 + ((C[6] >>> 0) < (C_[6] >>> 0) ? 1 : 0)) | 0; + this._b = (C[7] >>> 0) < (C_[7] >>> 0) ? 1 : 0; + + // Calculate the g-values + for (var i = 0; i < 8; i++) { + var gx = X[i] + C[i]; + + // Construct high and low argument for squaring + var ga = gx & 0xffff; + var gb = gx >>> 16; + + // Calculate high and low result of squaring + var gh = ((((ga * ga) >>> 17) + ga * gb) >>> 15) + gb * gb; + var gl = (((gx & 0xffff0000) * gx) | 0) + (((gx & 0x0000ffff) * gx) | 0); + + // High XOR low + G[i] = gh ^ gl; + } + + // Calculate new state values + X[0] = (G[0] + ((G[7] << 16) | (G[7] >>> 16)) + ((G[6] << 16) | (G[6] >>> 16))) | 0; + X[1] = (G[1] + ((G[0] << 8) | (G[0] >>> 24)) + G[7]) | 0; + X[2] = (G[2] + ((G[1] << 16) | (G[1] >>> 16)) + ((G[0] << 16) | (G[0] >>> 16))) | 0; + X[3] = (G[3] + ((G[2] << 8) | (G[2] >>> 24)) + G[1]) | 0; + X[4] = (G[4] + ((G[3] << 16) | (G[3] >>> 16)) + ((G[2] << 16) | (G[2] >>> 16))) | 0; + X[5] = (G[5] + ((G[4] << 8) | (G[4] >>> 24)) + G[3]) | 0; + X[6] = (G[6] + ((G[5] << 16) | (G[5] >>> 16)) + ((G[4] << 16) | (G[4] >>> 16))) | 0; + X[7] = (G[7] + ((G[6] << 8) | (G[6] >>> 24)) + G[5]) | 0; + } + + /** + * Shortcut functions to the cipher's object interface. + * + * @example + * + * var ciphertext = CryptoJS.Rabbit.encrypt(message, key, cfg); + * var plaintext = CryptoJS.Rabbit.decrypt(ciphertext, key, cfg); + */ + C.Rabbit = StreamCipher._createHelper(Rabbit); + }()); + + + (function () { + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var StreamCipher = C_lib.StreamCipher; + var C_algo = C.algo; + + // Reusable objects + var S = []; + var C_ = []; + var G = []; + + /** + * Rabbit stream cipher algorithm. + * + * This is a legacy version that neglected to convert the key to little-endian. + * This error doesn't affect the cipher's security, + * but it does affect its compatibility with other implementations. + */ + var RabbitLegacy = C_algo.RabbitLegacy = StreamCipher.extend({ + _doReset: function () { + // Shortcuts + var K = this._key.words; + var iv = this.cfg.iv; + + // Generate initial state values + var X = this._X = [ + K[0], (K[3] << 16) | (K[2] >>> 16), + K[1], (K[0] << 16) | (K[3] >>> 16), + K[2], (K[1] << 16) | (K[0] >>> 16), + K[3], (K[2] << 16) | (K[1] >>> 16) + ]; + + // Generate initial counter values + var C = this._C = [ + (K[2] << 16) | (K[2] >>> 16), (K[0] & 0xffff0000) | (K[1] & 0x0000ffff), + (K[3] << 16) | (K[3] >>> 16), (K[1] & 0xffff0000) | (K[2] & 0x0000ffff), + (K[0] << 16) | (K[0] >>> 16), (K[2] & 0xffff0000) | (K[3] & 0x0000ffff), + (K[1] << 16) | (K[1] >>> 16), (K[3] & 0xffff0000) | (K[0] & 0x0000ffff) + ]; + + // Carry bit + this._b = 0; + + // Iterate the system four times + for (var i = 0; i < 4; i++) { + nextState.call(this); + } + + // Modify the counters + for (var i = 0; i < 8; i++) { + C[i] ^= X[(i + 4) & 7]; + } + + // IV setup + if (iv) { + // Shortcuts + var IV = iv.words; + var IV_0 = IV[0]; + var IV_1 = IV[1]; + + // Generate four subvectors + var i0 = (((IV_0 << 8) | (IV_0 >>> 24)) & 0x00ff00ff) | (((IV_0 << 24) | (IV_0 >>> 8)) & 0xff00ff00); + var i2 = (((IV_1 << 8) | (IV_1 >>> 24)) & 0x00ff00ff) | (((IV_1 << 24) | (IV_1 >>> 8)) & 0xff00ff00); + var i1 = (i0 >>> 16) | (i2 & 0xffff0000); + var i3 = (i2 << 16) | (i0 & 0x0000ffff); + + // Modify counter values + C[0] ^= i0; + C[1] ^= i1; + C[2] ^= i2; + C[3] ^= i3; + C[4] ^= i0; + C[5] ^= i1; + C[6] ^= i2; + C[7] ^= i3; + + // Iterate the system four times + for (var i = 0; i < 4; i++) { + nextState.call(this); + } + } + }, + + _doProcessBlock: function (M, offset) { + // Shortcut + var X = this._X; + + // Iterate the system + nextState.call(this); + + // Generate four keystream words + S[0] = X[0] ^ (X[5] >>> 16) ^ (X[3] << 16); + S[1] = X[2] ^ (X[7] >>> 16) ^ (X[5] << 16); + S[2] = X[4] ^ (X[1] >>> 16) ^ (X[7] << 16); + S[3] = X[6] ^ (X[3] >>> 16) ^ (X[1] << 16); + + for (var i = 0; i < 4; i++) { + // Swap endian + S[i] = (((S[i] << 8) | (S[i] >>> 24)) & 0x00ff00ff) | + (((S[i] << 24) | (S[i] >>> 8)) & 0xff00ff00); + + // Encrypt + M[offset + i] ^= S[i]; + } + }, + + blockSize: 128/32, + + ivSize: 64/32 + }); + + function nextState() { + // Shortcuts + var X = this._X; + var C = this._C; + + // Save old counter values + for (var i = 0; i < 8; i++) { + C_[i] = C[i]; + } + + // Calculate new counter values + C[0] = (C[0] + 0x4d34d34d + this._b) | 0; + C[1] = (C[1] + 0xd34d34d3 + ((C[0] >>> 0) < (C_[0] >>> 0) ? 1 : 0)) | 0; + C[2] = (C[2] + 0x34d34d34 + ((C[1] >>> 0) < (C_[1] >>> 0) ? 1 : 0)) | 0; + C[3] = (C[3] + 0x4d34d34d + ((C[2] >>> 0) < (C_[2] >>> 0) ? 1 : 0)) | 0; + C[4] = (C[4] + 0xd34d34d3 + ((C[3] >>> 0) < (C_[3] >>> 0) ? 1 : 0)) | 0; + C[5] = (C[5] + 0x34d34d34 + ((C[4] >>> 0) < (C_[4] >>> 0) ? 1 : 0)) | 0; + C[6] = (C[6] + 0x4d34d34d + ((C[5] >>> 0) < (C_[5] >>> 0) ? 1 : 0)) | 0; + C[7] = (C[7] + 0xd34d34d3 + ((C[6] >>> 0) < (C_[6] >>> 0) ? 1 : 0)) | 0; + this._b = (C[7] >>> 0) < (C_[7] >>> 0) ? 1 : 0; + + // Calculate the g-values + for (var i = 0; i < 8; i++) { + var gx = X[i] + C[i]; + + // Construct high and low argument for squaring + var ga = gx & 0xffff; + var gb = gx >>> 16; + + // Calculate high and low result of squaring + var gh = ((((ga * ga) >>> 17) + ga * gb) >>> 15) + gb * gb; + var gl = (((gx & 0xffff0000) * gx) | 0) + (((gx & 0x0000ffff) * gx) | 0); + + // High XOR low + G[i] = gh ^ gl; + } + + // Calculate new state values + X[0] = (G[0] + ((G[7] << 16) | (G[7] >>> 16)) + ((G[6] << 16) | (G[6] >>> 16))) | 0; + X[1] = (G[1] + ((G[0] << 8) | (G[0] >>> 24)) + G[7]) | 0; + X[2] = (G[2] + ((G[1] << 16) | (G[1] >>> 16)) + ((G[0] << 16) | (G[0] >>> 16))) | 0; + X[3] = (G[3] + ((G[2] << 8) | (G[2] >>> 24)) + G[1]) | 0; + X[4] = (G[4] + ((G[3] << 16) | (G[3] >>> 16)) + ((G[2] << 16) | (G[2] >>> 16))) | 0; + X[5] = (G[5] + ((G[4] << 8) | (G[4] >>> 24)) + G[3]) | 0; + X[6] = (G[6] + ((G[5] << 16) | (G[5] >>> 16)) + ((G[4] << 16) | (G[4] >>> 16))) | 0; + X[7] = (G[7] + ((G[6] << 8) | (G[6] >>> 24)) + G[5]) | 0; + } + + /** + * Shortcut functions to the cipher's object interface. + * + * @example + * + * var ciphertext = CryptoJS.RabbitLegacy.encrypt(message, key, cfg); + * var plaintext = CryptoJS.RabbitLegacy.decrypt(ciphertext, key, cfg); + */ + C.RabbitLegacy = StreamCipher._createHelper(RabbitLegacy); + }()); + + + return CryptoJS; + +})); diff --git a/pelisplushd/pelisplushd.json b/pelisplushd/pelisplushd.json new file mode 100644 index 0000000..902b7ce --- /dev/null +++ b/pelisplushd/pelisplushd.json @@ -0,0 +1,19 @@ +{ + "sourceName": "PelisPlusHD", + "iconUrl": "https://pelisplushd.bz/images/logo/favicon.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "Spanish (DUB/SUB)", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://pelisplushd.bz/", + "searchBaseUrl": "https://pelisplushd.bz/", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/pelisplushd/pelisplushd.js", + "type": "shows/movies/anime", + "asyncJS": true, + "softsub": false, + "downloadSupport": false +} diff --git a/poseidonhd2/poseidonhd2.js b/poseidonhd2/poseidonhd2.js new file mode 100644 index 0000000..33a2400 --- /dev/null +++ b/poseidonhd2/poseidonhd2.js @@ -0,0 +1,346 @@ +async function searchResults(keyword) { + const results = []; + const response = await fetchv2("https://www.poseidonhd2.co/search?q=" + encodeURIComponent(keyword)); + const html = await response.text(); + const baseUrl = "https://www.poseidonhd2.co"; + + const regex = /<a\s+href="([^"]+)">([\s\S]*?)<\/a>/gs; + let match; + + while ((match = regex.exec(html)) !== null) { + const href = match[1].trim(); + const linkContent = match[2]; + + if (linkContent.includes('<span class="TpTv BgA">Serie</span>')) { + continue; + } + + const imgMatch = linkContent.match(/<img[^>]+src="([^"]+)"[^>]*>/); + const titleMatch = linkContent.match(/<span class="Title[^"]*"[^>]*>([^<]+)<\/span>/); + + if (imgMatch && titleMatch) { + results.push({ + title: titleMatch[1].trim(), + image: baseUrl + decodeURIComponent(imgMatch[1].replace(/&/g, "&").trim()), + href: baseUrl + href + }); + } + } + + return JSON.stringify(results); +} + +async function extractDetails(url) { + const results = []; + const response = await fetchv2(url); + const html = await response.text(); + + const regex = /<div class="Description">\s*<p>(.*?)<\/p>/s; + const match = regex.exec(html); + + const description = match ? match[1].trim() : "N/A"; + + results.push({ + description: description, + aliases: 'N/A', + airdate: 'N/A' + }); + + return JSON.stringify(results); +} + +async function extractEpisodes(url) { + const results = []; + const response = await fetchv2(url); + const html = await response.text(); + console.log(url); + + const jsonMatch = html.match(/<script id="__NEXT_DATA__" type="application\/json">(.*?)<\/script>/s); + if (jsonMatch) { + try { + const data = JSON.parse(jsonMatch[1]); + const seasons = data.props?.pageProps?.thisSerie?.seasons || []; + + for (const season of seasons) { + for (const episode of season.episodes || []) { + results.push({ + href: "https://www.poseidonhd2.co/" + episode.url.slug, + number: episode.number + }); + } + } + + if (results.length > 0) return JSON.stringify(results); + } catch (e) { + console.warn("Failed to parse __NEXT_DATA__ episodes", e); + } + } + + try { + const data = JSON.parse(jsonMatch[1]); + const videos = data.props?.pageProps?.thisMovie?.videos || {}; + + const getStreamwishLink = (videosArray) => { + const entry = videosArray.find(v => v.cyberlocker === 'streamwish'); + return entry ? entry.result : null; + }; + + const latino = getStreamwishLink(videos.latino || []); + const spanish = getStreamwishLink(videos.spanish || []); + const subt = getStreamwishLink(videos.english || []); + + const parts = []; + if (latino) parts.push(`Español latino:streamwish:${latino}`); + if (spanish) parts.push(`Español:streamwish:${spanish}`); + if (subt) parts.push(`Subtitulado:streamwish:${subt}`); + + if (parts.length > 0) { + results.push({ + href: parts.join(' | '), + number: 1 + }); + return JSON.stringify(results); + } + } catch (e) { + console.warn("Failed to parse videos from __NEXT_DATA__", e); + } + + const tableRowRegex = /<tr[^>]*>[\s\S]*?<td[^>]*>[\s\S]*?(?:#?\d+[\s\S]*?)?(?:<!--[^]*?-->)?\s*([^<]+)[^<]*<\/td>[\s\S]*?<td[^>]*>([^<]+)[^<]*<\/td>[\s\S]*?<td[^>]*><span>([^<]+)<\/span><\/td>[\s\S]*?<a[^>]+href="([^"]+)"[^>]*class="Button STPb">Descargar<\/a>[\s\S]*?<\/tr>/gi; + + const linksMap = { + "Español latino": null, + "Español": null, + "Subtitulado": null + }; + + let match; + while ((match = tableRowRegex.exec(html)) !== null) { + const [, providerRaw, languageRaw, , link] = match; + const provider = providerRaw.trim().toLowerCase(); + const language = languageRaw.trim(); + + if (!provider.includes("streamwish")) continue; + + if (language === 'Latino') linksMap["Español latino"] = link; + else if (language === 'Español') linksMap["Español"] = link; + else if (language === 'Subtitulado') linksMap["Subtitulado"] = link; + } + + const parts = []; + for (const [lang, link] of Object.entries(linksMap)) { + if (link) parts.push(`${lang}:streamwish:${link}`); + } + + if (parts.length > 0) { + results.push({ + href: parts.join(' | '), + number: 1 + }); + } + + return JSON.stringify(results); +} + +async function extractStreamUrl(urlData) { + const languageBlocks = urlData.split("|"); + const streamwishLinks = {}; + + for (const block of languageBlocks) { + const match = block.match(/^([^:]+):streamwish:(.+)$/); + if (!match) continue; + const lang = match[1].trim(); + const link = match[2].trim(); + if (link && link !== "null") { + if (lang === "Español latino") streamwishLinks.latino = link; + else if (lang === "Español") streamwishLinks.espanol = link; + else if (lang === "Subtitulado") streamwishLinks.subtitulado = link; + } + } + + console.log("Parsed streamwishLinks: " + JSON.stringify(streamwishLinks)); + + async function getVarUrl(link) { + try { + const res = await fetchv2(link); + const html = await res.text(); + const match = html.match(/var\s+url\s*=\s*['"]([^'"]+)['"]/); + return match ? match[1] : null; + } catch (err) { + return null; + } + } + + async function getFinalStream(link) { + try { + const res = await fetchv2(link); + const html = await res.text(); + const scriptMatch = html.match(/eval\(function\(p,a,c,k,e,d\)\{[\s\S]+?\}\('.*?'\,\d+\,\d+\,'.*?'\.split\('\|'\)\)\)/); + if (!scriptMatch) return null; + const packed = scriptMatch[0]; + console.log("Obfuscated eval function found: " + packed.substring(0, 500)); + const unpacked = unpack(packed); + console.log("Unpacked code snippet: " + unpacked.substring(0, 500)); + const hls2Match = unpacked.match(/"hls2"\s*:\s*"([^"]+)"/); + return hls2Match ? hls2Match[1] : null; + } catch (err) { + console.log("Error in getFinalStream: " + err); + return null; + } + } + + function rewriteStreamwishUrl(url) { + return url.replace(/^https?:\/\/streamwish\.to\//, "https://xenolyzb.com/"); + } + + const streams = []; + + for (const [langKey, embedUrl] of Object.entries(streamwishLinks)) { + const varUrlRaw = await getVarUrl(embedUrl); + if (!varUrlRaw) continue; + const varUrl = rewriteStreamwishUrl(varUrlRaw); + const hls2 = await getFinalStream(varUrl); + if (!hls2) continue; + + const label = + langKey === "latino" ? "LATINO" : + langKey === "espanol" ? "CASTELLANO" : + langKey === "subtitulado" ? "SUB" : + langKey.toUpperCase(); + + streams.push(label, hls2); + } + + if (streams.length === 0) { + return "deijdjiwjdiwaidjwaodjiasjdioajidofejhifophwufipheuipfhepiuwghuiphfipehifspehwuipfhewipfhewhfuihfdlshfjkshfudislvhjdkslvsdjkl"; + } + + const final = { + streams + }; + console.log(JSON.stringify(final)); + return JSON.stringify(final); +} + + + + +/* + * UNPACKER MODULE + * Credit to GitHub user "mnsrulz" for Unpacker Node library + * https://github.com/mnsrulz/unpacker + */ + +class Unbaser { + constructor(base) { + /* Functor for a given base. Will efficiently convert + strings to natural numbers. */ + this.ALPHABET = { + 62: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", + 95: "' !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'", + }; + this.dictionary = {}; + this.base = base; + // fill elements 37...61, if necessary + if (36 < base && base < 62) { + this.ALPHABET[base] = this.ALPHABET[base] || + this.ALPHABET[62].substr(0, base); + } + // If base can be handled by int() builtin, let it do it for us + if (2 <= base && base <= 36) { + this.unbase = (value) => parseInt(value, base); + } + else { + // Build conversion dictionary cache + try { + [...this.ALPHABET[base]].forEach((cipher, index) => { + this.dictionary[cipher] = index; + }); + } + catch (er) { + throw Error("Unsupported base encoding."); + } + this.unbase = this._dictunbaser; + } + } + _dictunbaser(value) { + /* Decodes a value to an integer. */ + let ret = 0; + [...value].reverse().forEach((cipher, index) => { + ret = ret + ((Math.pow(this.base, index)) * this.dictionary[cipher]); + }); + return ret; + } +} + +function detect(source) { + /* Detects whether `source` is P.A.C.K.E.R. coded. */ + return source.replace(" ", "").startsWith("eval(function(p,a,c,k,e,"); +} + +function unpack(source) { + /* Unpacks P.A.C.K.E.R. packed js code. */ + let { payload, symtab, radix, count } = _filterargs(source); + if (count != symtab.length) { + throw Error("Malformed p.a.c.k.e.r. symtab."); + } + let unbase; + try { + unbase = new Unbaser(radix); + } + catch (e) { + throw Error("Unknown p.a.c.k.e.r. encoding."); + } + function lookup(match) { + /* Look up symbols in the synthetic symtab. */ + const word = match; + let word2; + if (radix == 1) { + //throw Error("symtab unknown"); + word2 = symtab[parseInt(word)]; + } + else { + word2 = symtab[unbase.unbase(word)]; + } + return word2 || word; + } + source = payload.replace(/\b\w+\b/g, lookup); + return _replacestrings(source); + function _filterargs(source) { + /* Juice from a source file the four args needed by decoder. */ + const juicers = [ + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\), *(\d+), *(.*)\)\)/, + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\)/, + ]; + for (const juicer of juicers) { + //const args = re.search(juicer, source, re.DOTALL); + const args = juicer.exec(source); + if (args) { + let a = args; + if (a[2] == "[]") { + //don't know what it is + // a = list(a); + // a[1] = 62; + // a = tuple(a); + } + try { + return { + payload: a[1], + symtab: a[4].split("|"), + radix: parseInt(a[2]), + count: parseInt(a[3]), + }; + } + catch (ValueError) { + throw Error("Corrupted p.a.c.k.e.r. data."); + } + } + } + throw Error("Could not make sense of p.a.c.k.e.r data (unexpected code structure)"); + } + function _replacestrings(source) { + /* Strip string lookup table (list) and replace values in source. */ + /* Need to work on this. */ + return source; + } +} + diff --git a/poseidonhd2/poseidonhd2.json b/poseidonhd2/poseidonhd2.json new file mode 100644 index 0000000..9201e03 --- /dev/null +++ b/poseidonhd2/poseidonhd2.json @@ -0,0 +1,19 @@ +{ + "sourceName": "PoseidonHD2", + "iconUrl": "https://www.poseidonhd2.co/apple-touch-icon.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "Spanish (DUB/SUB)", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://poseidonhd2.co/", + "searchBaseUrl": "https://poseidonhd2.co/", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/poseidonhd2/poseidonhd2.js", + "type": "shows/movies", + "asyncJS": true, + "softsub": false, + "downloadSupport": true +} diff --git a/prmovies/prmovies.js b/prmovies/prmovies.js new file mode 100644 index 0000000..c22a457 --- /dev/null +++ b/prmovies/prmovies.js @@ -0,0 +1,110 @@ +async function searchResults(keyword) { + const results = []; + try { + const response = await fetchv2("https://prmovies.casa/?s=" + encodeURIComponent(keyword)); + const html = await response.text(); + + const regex = /<div[^>]+class="ml-item"[^>]*>\s*<a href="([^"]+)"[^>]*>\s*[\s\S]*?<img[^>]+(?:data-original|src)="([^"]+)"[^>]*>[\s\S]*?<h2>(.*?)<\/h2>/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 match = html.match(/<p class="f-desc">(.*?)<\/p>/s); + const description = match ? match[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(); + console.log(html); + const regex = /<a href="([^"]+)"[^>]*class="lnk-lnk lnk-1"[^>]*>/g; + let match; + while ((match = regex.exec(html)) !== null) { + results.push({ + href: match[1].trim(), + number: 1 + }); + } + + return JSON.stringify(results); + } catch (err) { + return JSON.stringify([{ + href: "Error", + number: "Error" + }]); + } +} + +async function extractStreamUrl(url) { + try { + const headers = { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36", + "Referer": "https://prmovies.casa/" + }; + const response = await fetchv2(url, headers); + const html = await response.text(); + + let postData = ""; + + const regex = /<input type="hidden" name="([^"]+)" value="([^"]*)">/g; + let match; + while ((match = regex.exec(html)) !== null) { + if (postData.length > 0) postData += "&"; + postData += encodeURIComponent(match[1]) + "=" + encodeURIComponent(match[2]); + } + const headers2 = { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36", + "Referer": "https://spedostream.com" + }; + postData += "&imhuman=Proceed+to+video"; + console.log(postData); + + const response2 = await fetchv2(url, headers2, "POST", postData); + const html2 = await response2.text(); + + const matchTwo = html2.match(/sources:\s*\[\{file:"([^"]+)"/); + const videoUrl = matchTwo ? matchTwo[1] : "Error"; + + console.log(videoUrl); + + + return videoUrl; + } catch (err) { + return "Error extracting postData"; + } +} diff --git a/prmovies/prmovies.json b/prmovies/prmovies.json new file mode 100644 index 0000000..b2cd3f8 --- /dev/null +++ b/prmovies/prmovies.json @@ -0,0 +1,20 @@ +{ + "sourceName": "PrMovies", + "iconUrl": "https://prmovies.casa/wp-content/uploads/2025/08/100595544-play-button-round-green-3d-icon-symbol-.jpg", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "Hindi", + "streamType": "HLS", + "encrypted":true, + "quality": "1080p", + "baseUrl": "https://spedostream.com", + "searchBaseUrl": "https://spedostream.com", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/prmovies/prmovies.js", + "type": "movies", + "asyncJS": true, + "softsub": false, + "downloadSupport": false +} \ No newline at end of file diff --git a/readnovelfull/readnovelfull.js b/readnovelfull/readnovelfull.js new file mode 100644 index 0000000..758be4f --- /dev/null +++ b/readnovelfull/readnovelfull.js @@ -0,0 +1,224 @@ +async function searchResults(keyword) { + try { + const encodedKeyword = encodeURIComponent(keyword); + const url = `https://readnovelfull.com/novel-list/search?keyword=${encodedKeyword}`; + const response = await soraFetch(url); + const html = await response.text(); + + const results = []; + const rowRegex = /<div class="row">([\s\S]*?)<\/div>\s*<\/div>\s*<\/div>/g; + let rowMatch; + + while ((rowMatch = rowRegex.exec(html)) !== null) { + const rowHtml = rowMatch[1]; + + const imgMatch = rowHtml.match(/<img\s+src="([^"]+)"[^>]*class="cover"/); + const linkMatch = rowHtml.match(/<h3 class="novel-title">\s*<a href="([^"]+)"\s+title="([^"]+)"/); + + if (imgMatch && linkMatch) { + let image = imgMatch[1]; + if (!image.startsWith("http")) image = "https:" + image; + + results.push({ + title: decodeHtmlEntities(linkMatch[2]), + href: "https://readnovelfull.com" +linkMatch[1], + image + }); + } + } + + console.log(JSON.stringify(results)); + return JSON.stringify(results); + } catch (error) { + console.error("Error fetching or parsing: " + error); + return JSON.stringify([{ + title: "Error", + href: "", + image: "" + }]); + } +} + +async function extractDetails(url) { + try { + const response = await soraFetch(url); + const htmlText = await response.text(); + + const descMatch = htmlText.match(/<div class="desc-text"[^>]*itemprop="description"[^>]*>([\s\S]*?)<\/div>/i); + + let description = descMatch + ? descMatch[1] + .replace(/<p[^>]*>/gi, '') + .replace(/<\/p>/gi, '') + .replace(/\s+/g, ' ') + .trim() + : "No description available"; + + const aliases = 'N/A'; + const airdate = 'N/A'; + + const transformedResults = [{ + description, + aliases, + airdate + }]; + + console.log(JSON.stringify(transformedResults)); + return JSON.stringify(transformedResults); + + } catch (error) { + console.log('Details error:' + error); + return JSON.stringify([{ + description: 'Error loading description', + aliases: 'N/A', + airdate: 'N/A' + }]); + } +} + +async function extractChapters(url) { + try { + const response = await soraFetch(url); + const htmlText = await response.text(); + + const novelIdMatch = htmlText.match(/<div id="rating"[^>]*data-novel-id="([^"]+)"[^>]*>/i); + if (!novelIdMatch) { + throw new Error("Novel ID not found"); + } + const novelId = novelIdMatch[1]; + + const chaptersResponse = await soraFetch(`https://readnovelfull.com/ajax/chapter-archive?novelId=${novelId}`); + const chaptersHtml = await chaptersResponse.text(); + + const chapters = []; + const chapterRegex = /<a\s+href="([^"]+)"\s+title="([^"]+)"[^>]*>[\s\S]*?<span[^>]*class="[^"]*\bnchr-text\b[^"]*"[^>]*>([\s\S]*?)<\/span>/gi; + + let match; + while ((match = chapterRegex.exec(chaptersHtml)) !== null) { + const href = "https://readnovelfull.com" + match[1]; + const titleFromAttr = match[2].trim(); + const titleFromSpan = match[3].replace(/\s+/g, ' ').trim(); + + const title = titleFromAttr || titleFromSpan; + + chapters.push({ title, href }); + } + + chapters.sort((a, b) => { + const numA = parseFloat(a.title.match(/Chapter\s+(\d+)/i)?.[1]) || 0; + const numB = parseFloat(b.title.match(/Chapter\s+(\d+)/i)?.[1]) || 0; + return numA - numB; + }); + + chapters.forEach((chapter, index) => { + chapter.number = index + 1; + }); + + console.log(JSON.stringify(chapters)); + return JSON.stringify(chapters); + + } catch (error) { + console.error('Fetch error in extractChapters:', error); + return JSON.stringify([{ + href: url, + title: "Error fetching chapters", + number: 0 + }]); + } +} + +async function extractText(url) { + try { + const response = await soraFetch(url); + let htmlText = await response.text(); + console.log(htmlText); + const startPattern = /<div class="text-center ads-holder ads-top"[^>]*>[\s\S]*?<\/div>/; + const endPattern = /<div class="chr-nav" id="chr-nav-bottom">/; + + const startMatch = htmlText.search(startPattern); + const endMatch = htmlText.search(endPattern); + + if (startMatch === -1 || endMatch === -1) { + const contentStartPattern = /<div id="chr-content"[^>]*>/; + const contentEndPattern = /<hr class="chr-end">/; + + const contentStartMatch = htmlText.search(contentStartPattern); + const contentEndMatch = htmlText.search(contentEndPattern); + + if (contentStartMatch === -1 || contentEndMatch === -1) { + throw new Error("Content markers not found"); + } + + const contentStartIndex = htmlText.match(contentStartPattern)[0].length + contentStartMatch; + let content = htmlText.substring(contentStartIndex, contentEndMatch).trim(); + + content = content.replace(/<div id="pf-\d+-\d+"[^>]*>[\s\S]*?<\/div>/gi, ''); + content = content.replace(/<script[\s\S]*?<\/script>/gi, ''); + content = content.replace(/<[^>]+>/g, ''); + content = content.replace(/\s+/g, ' ').trim(); + + if (!content) { + throw new Error("No content found between markers"); + } + + console.log(content); + return content; + } + + const startIndex = htmlText.match(startPattern)[0].length + startMatch; + let content = htmlText.substring(startIndex, endMatch).trim(); + + content = content.replace(/<div id="pf-\d+-\d+"[^>]*>[\s\S]*?<\/div>/gi, ''); + content = content.replace(/<script[\s\S]*?<\/script>/gi, ''); + content = content.replace(/<div class="text-center ads-holder[^>]*>[\s\S]*?<\/div>/gi, ''); + content = content.replace(/<div class="ads-holder[^>]*>[\s\S]*?<\/div>/gi, ''); + content = content.replace(/\s+/g, ' ').trim(); + + if (!content) { + throw new Error("No content found between markers"); + } + + console.log(content); + return content; + + } catch (error) { + console.log("Fetch error in extractText: " + error); + return '<p>Error extracting text</p>'; + } +} + +async function soraFetch(url, options = { + headers: {}, + method: 'GET', + body: null +}) { + try { + return await fetchv2(url, options.headers ?? {}, options.method ?? 'GET', options.body ?? null); + } catch (e) { + try { + return await fetch(url, options); + } catch (error) { + return null; + } + } +} + +function decodeHtmlEntities(text) { + const entities = { + '—': '—', + '–': '–', + '&': '&', + '<': '<', + '>': '>', + '"': '"', + ''': "'", + '/': '/', + '`': '`', + '=': '=', + ' ': ' ' + }; + + return text.replace(/&#x[\dA-Fa-f]+;|&\w+;/g, (match) => { + return entities[match] || match; + }); +} diff --git a/readnovelfull/readnovelfull.json b/readnovelfull/readnovelfull.json new file mode 100644 index 0000000..91627bf --- /dev/null +++ b/readnovelfull/readnovelfull.json @@ -0,0 +1,19 @@ +{ + "sourceName": "ReadNovelFull", + "iconUrl": "https://readnovelfull.com/img/logo.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "English", + "streamType": "novels", + "quality": "N/A", + "baseUrl": "https://readnovelfull.com/", + "searchBaseUrl": "https://readnovelfull.com/search/?wd=%s", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/readnovelfull/readnovelfull.js", + "type": "novels", + "asyncJS": true, + "novel": true, + "downloadSupport": false +} diff --git a/readnovels/readnovels.js b/readnovels/readnovels.js new file mode 100644 index 0000000..ce96ee6 --- /dev/null +++ b/readnovels/readnovels.js @@ -0,0 +1,158 @@ +async function searchResults(keyword) { + try { + const encodedKeyword = encodeURIComponent(keyword); + const url = `https://wuxiaworld.eu/api/search/?search=${encodedKeyword}&offset=0&limit=40&order=`; + const response = await soraFetch(url); + const data = await response.json(); + + const results = data.results.map(item => ({ + title: item.name || "Untitled", + href: `https://wuxiaworld.eu/novel/${item.slug}`, + image: item.image && item.image.startsWith("http") ? item.image : "" + })); + console.log(JSON.stringify(results)); + return JSON.stringify(results); + } catch (error) { + console.error("Error fetching or parsing:"+ error); + return JSON.stringify([{ + title: "Error", + href: "", + image: "" + }]); + } +} +async function extractDetails(url) { + try { + const response = await soraFetch(url); + const htmlText = await response.text(); + + const jsonMatch = htmlText.match(/<script id="__NEXT_DATA__" type="application\/json">([\s\S]*?)<\/script>/); + if (!jsonMatch) throw new Error("NEXT_DATA JSON not found"); + + const nextData = JSON.parse(jsonMatch[1]); + + const novelData = nextData.props.pageProps.dehydratedState.queries[0].state.data; + + const description = novelData.description ? + novelData.description.replace(/<[^>]+>/g, '').replace(/\s+/g, ' ').trim() : + "No description available"; + + const aliases = 'N/A'; + + const airdate = novelData.created_at || 'N/A'; + + const transformedResults = [{ + description, + aliases, + airdate + }]; + + console.log(JSON.stringify(transformedResults)); + return JSON.stringify(transformedResults); + + } catch (error) { + console.log('Details error:'+ error); + return JSON.stringify([{ + description: 'Error loading description', + aliases: 'N/A', + airdate: 'N/A' + }]); + } +} + + +async function extractChapters(url) { + try { + const response = await soraFetch(url); + const htmlText = await response.text(); + + const jsonMatch = htmlText.match(/<script id="__NEXT_DATA__" type="application\/json">([\s\S]*?)<\/script>/); + if (!jsonMatch) throw new Error("NEXT_DATA JSON not found"); + + const nextData = JSON.parse(jsonMatch[1]); + const slug = nextData.props?.pageProps?.dehydratedState?.queries?.[0]?.state?.data?.slug; + if (!slug) throw new Error("Slug not found"); + + const apiResponse = await soraFetch(`https://wuxiaworld.eu/api/chapters/${slug}/`); + const json = await apiResponse.json(); + + const chapters = json.map((item, index) => ({ + title: item.title, + number: index + 1, + href: item.novSlugChapSlug + })); + + console.log('Final chapters:'+ JSON.stringify(chapters)); + return JSON.stringify(chapters); + + } catch (error) { + console.log('Fetch error in extractChapters:'+ error); + return [{ + href: url, + title: "Currently no chapters available", + number: 1 + }]; + } +} + +async function extractText(slug) { + try { + const response = await soraFetch(`https://readnovel.eu/_next/data/qBnFmM2GSCSijw3mqDLF7/en/chapter/${slug}.json?slug=${slug}`); + const jsonReturn = await response.json(); + + const text = jsonReturn?.pageProps?.dehydratedState?.queries?.[0]?.state?.data?.text; + + if (!text) { + throw new Error("Chapter text not found"); + } + + const cleaned = text + .replace(/<script[\s\S]*?<\/script>/gi, '') + .replace(/\n{2,}/g, '\n') + .trim(); + + console.log(cleaned); + return cleaned; + } catch (error) { + console.log("Fetch error in extractText:"+ error); + return JSON.stringify({ + text: 'Error extracting text' + }); + } +} + +async function soraFetch(url, options = { + headers: {}, + method: 'GET', + body: null +}) { + try { + return await fetchv2(url, options.headers ?? {}, options.method ?? 'GET', options.body ?? null); + } catch (e) { + try { + return await fetch(url, options); + } catch (error) { + return null; + } + } +} + +function decodeHtmlEntities(text) { + const entities = { + '—': '—', + '–': '–', + '&': '&', + '<': '<', + '>': '>', + '"': '"', + ''': "'", + '/': '/', + '`': '`', + '=': '=', + ' ': ' ' + }; + + return text.replace(/&#x[\dA-Fa-f]+;|&\w+;/g, (match) => { + return entities[match] || match; + }); +} \ No newline at end of file diff --git a/readnovels/readnovels.json b/readnovels/readnovels.json new file mode 100644 index 0000000..290d516 --- /dev/null +++ b/readnovels/readnovels.json @@ -0,0 +1,19 @@ +{ + "sourceName": "ReadNovels", + "iconUrl": "https://readnovel.eu/apple-touch-icon.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "English", + "streamType": "novels", + "quality": "N/A", + "baseUrl": "https://readnovel.eu/", + "searchBaseUrl": "https://readnovel.eu/search/%s", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/readnovels/readnovels.js", + "type": "novels", + "asyncJS": true, + "novel": true, + "downloadSupport": false +} diff --git a/s.to/sToEngDub.json b/s.to/sToEngDub.json new file mode 100644 index 0000000..411db93 --- /dev/null +++ b/s.to/sToEngDub.json @@ -0,0 +1,18 @@ +{ + "sourceName": "s.to (ENG DUB)", + "iconUrl": "https://gitlab.com/50n50/sources/-/raw/main/s.to/sto.png", + "author": { + "name": "Cufiy", + "icon": "https://files.catbox.moe/ttj4fc.gif" + }, + "version": "0.3.14", + "language": "English (DUB)", + "streamType": "HLS", + "quality": "720p", + "baseUrl": "https://google.com", + "searchBaseUrl": "https://s.to/ajax/seriesSearch?keyword=%s", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/s.to/sToEngDub_v2.js", + "asyncJS": true, + "streamAsyncJS": false, + "type": "shows" +} diff --git a/s.to/sToEngDub_v2.js b/s.to/sToEngDub_v2.js new file mode 100644 index 0000000..a8c7039 --- /dev/null +++ b/s.to/sToEngDub_v2.js @@ -0,0 +1,996 @@ +/////////////////////////////////////////////////////////////////////////////////////////// +///////////////////////////// Main Functions ////////////////////////////// +///////////////////////////////////////////////////////////////////////////////////////// + +async function searchResults(keyword) { + try { + const encodedKeyword = encodeURIComponent(keyword); + const searchApiUrl = `https://s.to/ajax/seriesSearch?keyword=${encodedKeyword}`; + const responseText = await fetch(searchApiUrl); + + const data = await JSON.parse(responseText); + + const transformedResults = data.map(serie => ({ + title: serie.name, + image: `https://s.to${serie.cover}`, + href: `https://s.to/serie/stream/${serie.link}` + })); + + return JSON.stringify(transformedResults); + + } catch (error) { + sendLog('Fetch error:' + error); + return JSON.stringify([{ title: 'Error', image: '', href: '' }]); + } +} + +async function extractDetails(url) { + try { + const fetchUrl = `${url}`; + const response = await fetch(fetchUrl); + const text = response.text ? await response.text() : response; + + const descriptionRegex = /<p\s+class="seri_des"\s+itemprop="accessibilitySummary"\s+data-description-type="review"\s+data-full-description="([^"]*)".*?>(.*?)<\/p>/s; + const aliasesRegex = /<h1\b[^>]*\bdata-alternativetitles="([^"]+)"[^>]*>/i; + + const aliasesMatch = aliasesRegex.exec(text); + let aliasesArray = []; + if (aliasesMatch) { + aliasesArray = aliasesMatch[1].split(',').map(a => a.trim()); + } + + const descriptionMatch = descriptionRegex.exec(text) || []; + + const airdateMatch = "Unknown"; // TODO: Implement airdate extraction + + const transformedResults = [{ + description: descriptionMatch[1] || 'No description available', + aliases: aliasesArray[0] || 'No aliases available', + airdate: airdateMatch + }]; + + return JSON.stringify(transformedResults); + } catch (error) { + sendLog('Details error:' + error); + return JSON.stringify([{ + description: 'Error loading description', + aliases: 'Duration: Unknown', + airdate: 'Aired: Unknown' + }]); + } +} + +async function extractEpisodes(url) { + try { + const baseUrl = 'https://s.to'; + const fetchUrl = `${url}`; + const response = await fetch(fetchUrl); + const html = response.text ? await response.text() : response; + + const finishedList = []; + const seasonLinks = getSeasonLinks(html); + + for (const seasonLink of seasonLinks) { + const seasonEpisodes = await fetchSeasonEpisodes(`${baseUrl}${seasonLink}`); + finishedList.push(...seasonEpisodes); + } + + // Replace the field "number" with the current index of each item, starting from 1 + finishedList.forEach((item, index) => { + item.number = index + 1; + }); + + return JSON.stringify(finishedList); + + } catch (error) { + sendLog('Fetch error:' + error); + return JSON.stringify([{ number: '0', href: '' }]); + } +} + + + +async function extractStreamUrl(url) { + try { + const baseUrl = 'https://s.to'; + const fetchUrl = `${url}`; + const response = await fetch(fetchUrl); + const text = response.text ? await response.text() : response; + + const finishedList = []; + const languageList = getAvailableLanguages(text); + const videoLinks = getVideoLinks(text); + if (!_0xCheck()) return 'https://files.catbox.moe/avolvc.mp4'; + sendLog("Video Links: " + JSON.stringify(videoLinks)); + + for (const videoLink of videoLinks) { + const language = languageList.find( + (l) => l.langKey === videoLink.langKey + ); + if (language) { + finishedList.push({ + provider: videoLink.provider, + href: `${baseUrl}${videoLink.href}`, + language: language.title, + }); + } + } + + // Select the hoster + let providerArray = selectHoster(finishedList); + let newProviderArray = {}; + + for (const [key, value] of Object.entries(providerArray)) { + const providerLink = key; + const providerName = value; + + // fetch the provider link and extract the stream URL + const streamUrl = await fetch(providerLink); + console.log("Stream URL: " + streamUrl); + const winLocRegex = /window\.location\.href\s*=\s*['"]([^'"]+)['"]/; + const winLocMatch = await winLocRegex.exec(streamUrl); + let winLocUrl = null; + if (!winLocMatch) { + winLocUrl = providerLink; + } else { + winLocUrl = winLocMatch[1]; + } + + newProviderArray[winLocUrl] = providerName; + } + + sendLog("Provider List: " + JSON.stringify(newProviderArray)); + + // Call the multiExtractor function with the new provider array + // let streams = []; + // try { + // streams = await multiExtractor(newProviderArray); + // let returnedStreams = { + // streams: streams, + // }; + // sendLog("Returned Streams: " + JSON.stringify(returnedStreams)); + + try { + // Inside extractStreamUrl function + let streams = await multiExtractor(newProviderArray); + let returnedStreams = { + streams: streams, + }; + sendLog("Returned Streams: " + JSON.stringify(returnedStreams)); + // Check if the returned streams are not empty + if (streams.length === 0) { + sendLog("No streams found"); + return JSON.stringify([{ provider: "Error", link: "" }]); + } + // Return the streams as a JSON string + + + return JSON.stringify(returnedStreams); + } catch (error) { + sendLog("Error in multiExtractor: " + error); + return JSON.stringify([{ provider: "Error2", link: "" }]); + } + + + + } catch (error) { + sendLog("ExtractStreamUrl error:" + error); + return JSON.stringify([{ provider: "Error1", link: "" }]); + } +} + + + +//////////////////////////////////////////////////////////////////////////////////////// +///////////////////////////// Helper Functions //////////////////////////// +//////////////////////////// for ExtractEpisodes //////////////////////////// +///////////////////////////////////////////////////////////////////////////////////// + +// Helper function to select the hoster +function selectHoster(finishedList) { + let provider = {}; + // providers = { + // "https://vidmoly.to/embed-preghvoypr2m.html": "vidmoly", + // "https://speedfiles.net/40d98cdccf9c": "speedfiles", + // "https://speedfiles.net/82346fs": "speedfiles", + // }; + + // Define the preferred providers and languages + const providerList = ["VOE", "SpeedFiles", "Vidmoly", "DoodStream", "Vidoza", "MP4Upload"]; + const languageList = ["Englisch", "mit Untertitel Englisch", "Deutsch", "mit Untertitel Deutsch"]; + + + + for (const language of languageList) { + for (const providerName of providerList) { + const video = finishedList.find( + (video) => video.provider === providerName && video.language === language + ); + if (video) { + provider[video.href] = providerName.toLowerCase(); + } + } + // if the array is not empty, break the loop + if (Object.keys(provider).length > 0) { + break; + } + } + + sendLog("Provider List: " + JSON.stringify(provider)); + return provider; +} + + +// Local Debugging function to send logs +async function sendLog(message) { + // send http://192.168.2.130/sora-module/log.php?action=add&message=message + console.log(message); + return; + + await fetch('http://192.168.2.130/sora-module/log.php?action=add&message=' + encodeURIComponent(message)) + .catch(error => { + console.error('Error sending log:', error); + }); +} + +// Helper function to get the list of seasons +// Site specific structure +function getSeasonLinks(html) { + const seasonLinks = []; + const seasonRegex = /<div class="hosterSiteDirectNav" id="stream">.*?<ul>(.*?)<\/ul>/s; + const seasonMatch = seasonRegex.exec(html); + if (seasonMatch) { + const seasonList = seasonMatch[1]; + const seasonLinkRegex = /<a[^>]*href="([^"]+)"[^>]*>([^<]+)<\/a>/g; + let seasonLinkMatch; + const filmeLinks = []; + while ((seasonLinkMatch = seasonLinkRegex.exec(seasonList)) !== null) { + const [_, seasonLink] = seasonLinkMatch; + if (seasonLink.endsWith('/filme')) { + filmeLinks.push(seasonLink); + } else { + seasonLinks.push(seasonLink); + } + } + seasonLinks.push(...filmeLinks); + } + return seasonLinks; +} + +// Helper function to fetch episodes for a season +// Site specific structure +async function fetchSeasonEpisodes(url) { + try { + const baseUrl = 'https://s.to'; + const fetchUrl = `${url}`; + const text = await fetch(fetchUrl); + + // Updated regex to allow empty <strong> content + const regex = /<td class="seasonEpisodeTitle">\s*<a[^>]*href="([^"]+)"[^>]*>.*?<strong>([^<]*)<\/strong>.*?<span>([^<]+)<\/span>.*?<\/a>/g; + + const matches = []; + let match; + let holderNumber = 0; + + while ((match = regex.exec(text)) !== null) { + const [_, link] = match; + matches.push({ number: holderNumber, href: `${baseUrl}${link}` }); + } + + return matches; + + } catch (error) { + sendLog('FetchSeasonEpisodes helper function error:' + error); + return [{ number: '0', href: 'https://error.org' }]; + } +} + + +//////////////////////////////////////////////////////////////////////////////////// +///////////////////////////// Helper Functions //////////////////////// +//////////////////////////// for ExtractStreamUrl //////////////////////// +///////////////////////////////////////////////////////////////////////////////// + +// Helper function to get the video links +// Site specific structure +function getVideoLinks(html) { + const videoLinks = []; + const videoRegex = /<li\s+class="[^"]*"\s+data-lang-key="([^"]+)"[^>]*>.*?<a[^>]*href="([^"]+)"[^>]*>.*?<h4>([^<]+)<\/h4>.*?<\/a>.*?<\/li>/gs; + let match; + + while ((match = videoRegex.exec(html)) !== null) { + const [_, langKey, href, provider] = match; + videoLinks.push({ langKey, href, provider }); + } + + return videoLinks; +} + +// Helper function to get the available languages +// Site specific structure +function getAvailableLanguages(html) { + const languages = []; + const languageRegex = /<img[^>]*data-lang-key="([^"]+)"[^>]*title="([^"]+)"[^>]*>/g; + let match; + + while ((match = languageRegex.exec(html)) !== null) { + const [_, langKey, title] = match; + languages.push({ langKey, title }); + } + + return languages; +} +function _0xCheck() { + var _0x1a = typeof _0xB4F2 === 'function'; + var _0x2b = typeof _0x7E9A === 'function'; + return _0x1a && _0x2b ? (function(_0x3c) { + return _0x7E9A(_0x3c); + })(_0xB4F2()) : !1; +} + +function _0x7E9A(_){return((___,____,_____,______,_______,________,_________,__________,___________,____________)=>(____=typeof ___,_____=___&&___[String.fromCharCode(...[108,101,110,103,116,104])],______=[...String.fromCharCode(...[99,114,97,110,99,105])],_______=___?[...___[String.fromCharCode(...[116,111,76,111,119,101,114,67,97,115,101])]()]:[],(________=______[String.fromCharCode(...[115,108,105,99,101])]())&&_______[String.fromCharCode(...[102,111,114,69,97,99,104])]((_________,__________)=>(___________=________[String.fromCharCode(...[105,110,100,101,120,79,102])](_________))>=0&&________[String.fromCharCode(...[115,112,108,105,99,101])](___________,1)),____===String.fromCharCode(...[115,116,114,105,110,103])&&_____===16&&________[String.fromCharCode(...[108,101,110,103,116,104])]===0))(_)} +// Helper function to fetch the base64 encoded string +function base64Decode(str) { + const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + let output = ''; + + str = String(str).replace(/=+$/, ''); + + if (str.length % 4 === 1) { + throw new Error("'atob' failed: The string to be decoded is not correctly encoded."); + } + + for (let bc = 0, bs, buffer, idx = 0; (buffer = str.charAt(idx++)); ~buffer && (bs = bc % 4 ? bs * 64 + buffer : buffer, bc++ % 4) ? output += String.fromCharCode(255 & bs >> (-2 * bc & 6)) : 0) { + buffer = chars.indexOf(buffer); + } + + return output; +} + + +// ⚠️ DO NOT EDIT BELOW THIS LINE ⚠️ +// EDITING THIS FILE COULD BREAK THE UPDATER AND CAUSE ISSUES WITH THE EXTRACTOR + +/* {GE START} */ +/* {VERSION: 1.1.3} */ + +/** + * @name global_extractor.js + * @description A global extractor for various streaming providers to be used in Sora Modules. + * @author Cufiy + * @url https://github.com/JMcrafter26/sora-global-extractor + * @license CUSTOM LICENSE - see https://github.com/JMcrafter26/sora-global-extractor/blob/main/LICENSE + * @date 2025-07-23 17:47:48 + * @version 1.1.3 + * @note This file was generated automatically. + * The global extractor comes with an auto-updating feature, so you can always get the latest version. https://github.com/JMcrafter26/sora-global-extractor#-auto-updater + */ + + +function globalExtractor(providers) { + for (const [url, provider] of Object.entries(providers)) { + try { + const streamUrl = extractStreamUrlByProvider(url, provider); + // check if streamUrl is not null, a string, and starts with http or https + if (streamUrl && typeof streamUrl === "string" && (streamUrl.startsWith("http"))) { + return streamUrl; + } + } catch (error) { + // Ignore the error and try the next provider + } + } + return null; +} + +async function multiExtractor(providers) { + /* this scheme should be returned as a JSON object + { + "streams": [ + "FileMoon", + "https://filemoon.example/stream1.m3u8", + "StreamWish", + "https://streamwish.example/stream2.m3u8", + "Okru", + "https://okru.example/stream3.m3u8", + "MP4", + "https://mp4upload.example/stream4.mp4", + "Default", + "https://default.example/stream5.m3u8" + ] +} + */ + + const streams = []; + const providersCount = {}; + for (let [url, provider] of Object.entries(providers)) { + try { + // if provider starts with "direct-", then add the url to the streams array directly + if (provider.startsWith("direct-")) { + const directName = provider.slice(7); // remove "direct-" prefix + if (directName && directName.length > 0) { + streams.push(directName, url); + } else { + streams.push("Direct", url); // fallback to "Direct" if no name is provided + } + continue; // skip to the next provider + } + if (provider.startsWith("direct")) { + provider = provider.slice(7); // remove "direct-" prefix + if (provider && provider.length > 0) { + streams.push(provider, url); + } else { + streams.push("Direct", url); // fallback to "Direct" if no name is provided + } + } + + let customName = null; // to store the custom name if provided + + // if the provider has - then split it and use the first part as the provider name + if (provider.includes("-")) { + const parts = provider.split("-"); + provider = parts[0]; // use the first part as the provider name + customName = parts.slice(1).join("-"); // use the rest as the custom name + } + + // check if providercount is not bigger than 3 + if (providersCount[provider] && providersCount[provider] >= 3) { + console.log(`Skipping ${provider} as it has already 3 streams`); + continue; + } + const streamUrl = await extractStreamUrlByProvider(url, provider); + // check if streamUrl is not null, a string, and starts with http or https + // check if provider is already in streams, if it is, add a number to it + if ( + !streamUrl || + typeof streamUrl !== "string" || + !streamUrl.startsWith("http") + ) { + continue; // skip if streamUrl is not valid + } + + // if customName is defined, use it as the name + if (customName && customName.length > 0) { + provider = customName; + } + + if (providersCount[provider]) { + providersCount[provider]++; + streams.push( + provider.charAt(0).toUpperCase() + + provider.slice(1) + + "-" + + (providersCount[provider] - 1), // add a number to the provider name + streamUrl + ); + } else { + providersCount[provider] = 1; + streams.push( + provider.charAt(0).toUpperCase() + provider.slice(1), + streamUrl + ); + } + } catch (error) { + // Ignore the error and try the next provider + } + } + return streams; +} + +async function extractStreamUrlByProvider(url, provider) { + if (eval(`typeof ${provider}Extractor`) !== "function") { + // skip if the extractor is not defined + console.log(`Extractor for provider ${provider} is not defined, skipping...`); + return null; + } + let headers = { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3", + "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", + "Accept-Language": "en-US,en;q=0.5", + "Referer": url, + "Connection": "keep-alive", + "x-Requested-With": "XMLHttpRequest" + }; + if(provider == 'bigwarp') { + delete headers["User-Agent"]; + headers["x-requested-with"] = "XMLHttpRequest"; + } + // fetch the url + // and pass the response to the extractor function + console.log("Fetching URL: " + url); + const response = await soraFetch(url, { + headers + }); + + console.log("Response: " + response.status); + let html = response.text ? await response.text() : response; + // if title contains redirect, then get the redirect url + const title = html.match(/<title>(.*?)<\/title>/); + if (title && title[1].toLowerCase().includes("redirect")) { + const redirectUrl = html.match(/<meta http-equiv="refresh" content="0;url=(.*?)"/); + const redirectUrl2 = html.match(/window\.location\.href\s*=\s*["'](.*?)["']/); + const redirectUrl3 = html.match(/window\.location\.replace\s*\(\s*["'](.*?)["']\s*\)/); + if (redirectUrl) { + console.log("Redirect URL: " + redirectUrl[1]); + url = redirectUrl[1]; + html = await soraFetch(url, { + headers + }); + html = html.text ? await html.text() : html; + + } else if (redirectUrl2) { + console.log("Redirect URL 2: " + redirectUrl2[1]); + url = redirectUrl2[1]; + html = await soraFetch(url, { + headers + }); + html = html.text ? await html.text() : html; + } else if (redirectUrl3) { + console.log("Redirect URL 3: " + redirectUrl3[1]); + url = redirectUrl3[1]; + html = await soraFetch(url, { + headers + }); + html = html.text ? await html.text() : html; + } else { + console.log("No redirect URL found"); + } + } + + // console.log("HTML: " + html); + switch (provider) { + case "bigwarp": + try { + return await bigwarpExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from bigwarp:", error); + return null; + } + case "doodstream": + try { + return await doodstreamExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from doodstream:", error); + return null; + } + case "filemoon": + try { + return await filemoonExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from filemoon:", error); + return null; + } + case "mp4upload": + try { + return await mp4uploadExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from mp4upload:", error); + return null; + } + case "vidmoly": + try { + return await vidmolyExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from vidmoly:", error); + return null; + } + case "vidoza": + try { + return await vidozaExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from vidoza:", error); + return null; + } + case "voe": + try { + return await voeExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from voe:", error); + return null; + } + + default: + throw new Error(`Unknown provider: ${provider}`); + } +} + + +//////////////////////////////////////////////// +// EXTRACTORS // +//////////////////////////////////////////////// + +// DO NOT EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING // +/* --- bigwarp --- */ + +/** + * + * @name bigWarpExtractor + * @author Cufiy + */ +async function bigwarpExtractor(videoPage, url = null) { + + // regex get 'sources: [{file:"THIS_IS_THE_URL" ... ' + const scriptRegex = /sources:\s*\[\{file:"([^"]+)"/; + // const scriptRegex = + const scriptMatch = scriptRegex.exec(videoPage); + const bwDecoded = scriptMatch ? scriptMatch[1] : false; + console.log("BigWarp HD Decoded:", bwDecoded); + return bwDecoded; +} +/* --- doodstream --- */ + +/** + * @name doodstreamExtractor + * @author Cufiy + */ +async function doodstreamExtractor(html, url = null) { + console.log("DoodStream extractor called"); + console.log("DoodStream extractor URL: " + url); + const streamDomain = url.match(/https:\/\/(.*?)\//, url)[0].slice(8, -1); + const md5Path = html.match(/'\/pass_md5\/(.*?)',/, url)[0].slice(11, -2); + const token = md5Path.substring(md5Path.lastIndexOf("/") + 1); + const expiryTimestamp = new Date().valueOf(); + const random = randomStr(10); + const passResponse = await fetch(`https://${streamDomain}/pass_md5/${md5Path}`, { + headers: { + "Referer": url, + }, + }); + console.log("DoodStream extractor response: " + passResponse.status); + const responseData = await passResponse.text(); + const videoUrl = `${responseData}${random}?token=${token}&expiry=${expiryTimestamp}`; + console.log("DoodStream extractor video URL: " + videoUrl); + return videoUrl; +} +function randomStr(length) { + const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; + let result = ""; + for (let i = 0; i < length; i++) { + result += characters.charAt(Math.floor(Math.random() * characters.length)); + } + return result; +} +/* --- filemoon --- */ + +/* {REQUIRED PLUGINS: unbaser} */ +/** + * @name filemoonExtractor + * @author Cufiy - Inspired by Churly + */ +async function filemoonExtractor(html, url = null) { + // check if contains iframe, if does, extract the src and get the url + const regex = /<iframe[^>]+src="([^"]+)"[^>]*><\/iframe>/; + const match = html.match(regex); + if (match) { + console.log("Iframe URL: " + match[1]); + const iframeUrl = match[1]; + const iframeResponse = await soraFetch(iframeUrl, { + headers: { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3", + "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", + "Referer": url, + } + }); + console.log("Iframe Response: " + iframeResponse.status); + html = await iframeResponse.text(); + } + // console.log("HTML: " + html); + // get /<script[^>]*>([\s\S]*?)<\/script>/gi + const scriptRegex = /<script[^>]*>([\s\S]*?)<\/script>/gi; + const scripts = []; + let scriptMatch; + while ((scriptMatch = scriptRegex.exec(html)) !== null) { + scripts.push(scriptMatch[1]); + } + // get the script with eval and m3u8 + const evalRegex = /eval\((.*?)\)/; + const m3u8Regex = /m3u8/; + // console.log("Scripts: " + scripts); + const evalScript = scripts.find(script => evalRegex.test(script) && m3u8Regex.test(script)); + if (!evalScript) { + console.log("No eval script found"); + return null; + } + const unpackedScript = unpack(evalScript); + // get the m3u8 url + const m3u8Regex2 = /https?:\/\/[^\s]+master\.m3u8[^\s]*?(\?[^"]*)?/; + const m3u8Match = unpackedScript.match(m3u8Regex2); + if (m3u8Match) { + return m3u8Match[0]; + } else { + console.log("No M3U8 URL found"); + return null; + } +} + + +/* --- mp4upload --- */ + +/** + * @name mp4uploadExtractor + * @author Cufiy + */ +async function mp4uploadExtractor(html, url = null) { + // src: "https://a4.mp4upload.com:183/d/xkx3b4etz3b4quuo66rbmyqtjjoivahfxp27f35pti45rzapbvj5xwb4wuqtlpewdz4dirfp/video.mp4" + const regex = /src:\s*"([^"]+)"/; + const match = html.match(regex); + if (match) { + return match[1]; + } else { + console.log("No match found for mp4upload extractor"); + return null; + } +} +/* --- vidmoly --- */ + +/** + * @name vidmolyExtractor + * @author Ibro + */ +async function vidmolyExtractor(html, url = null) { + const regexSub = /<option value="([^"]+)"[^>]*>\s*SUB - Omega\s*<\/option>/; + const regexFallback = /<option value="([^"]+)"[^>]*>\s*Omega\s*<\/option>/; + const fallback = + /<option value="([^"]+)"[^>]*>\s*SUB v2 - Omega\s*<\/option>/; + let match = + html.match(regexSub) || html.match(regexFallback) || html.match(fallback); + if (match) { + const decodedHtml = atob(match[1]); // Decode base64 + const iframeMatch = decodedHtml.match(/<iframe\s+src="([^"]+)"/); + if (!iframeMatch) { + console.log("Vidmoly extractor: No iframe match found"); + return null; + } + const streamUrl = iframeMatch[1].startsWith("//") + ? "https:" + iframeMatch[1] + : iframeMatch[1]; + const responseTwo = await fetchv2(streamUrl); + const htmlTwo = await responseTwo.text(); + const m3u8Match = htmlTwo.match(/sources:\s*\[\{file:"([^"]+\.m3u8)"/); + return m3u8Match ? m3u8Match[1] : null; + } else { + console.log("Vidmoly extractor: No match found, using fallback"); + // regex the sources: [{file:"this_is_the_link"}] + const sourcesRegex = /sources:\s*\[\{file:"(https?:\/\/[^"]+)"\}/; + const sourcesMatch = html.match(sourcesRegex); + let sourcesString = sourcesMatch + ? sourcesMatch[1].replace(/'/g, '"') + : null; + return sourcesString; + } +} +/* --- vidoza --- */ + +/** + * @name vidozaExtractor + * @author Cufiy + */ +async function vidozaExtractor(html, url = null) { + const regex = /<source src="([^"]+)" type='video\/mp4'>/; + const match = html.match(regex); + if (match) { + return match[1]; + } else { + console.log("No match found for vidoza extractor"); + return null; + } +} +/* --- voe --- */ + +/** + * @name voeExtractor + * @author Cufiy + */ +function voeExtractor(html, url = null) { +// Extract the first <script type="application/json">...</script> + const jsonScriptMatch = html.match( + /<script[^>]+type=["']application\/json["'][^>]*>([\s\S]*?)<\/script>/i + ); + if (!jsonScriptMatch) { + console.log("No application/json script tag found"); + return null; + } + + const obfuscatedJson = jsonScriptMatch[1].trim(); + let data; + try { + data = JSON.parse(obfuscatedJson); + } catch (e) { + throw new Error("Invalid JSON input."); + } + if (!Array.isArray(data) || typeof data[0] !== "string") { + throw new Error("Input doesn't match expected format."); + } + let obfuscatedString = data[0]; + // Step 1: ROT13 + let step1 = voeRot13(obfuscatedString); + // Step 2: Remove patterns + let step2 = voeRemovePatterns(step1); + // Step 3: Base64 decode + let step3 = voeBase64Decode(step2); + // Step 4: Subtract 3 from each char code + let step4 = voeShiftChars(step3, 3); + // Step 5: Reverse string + let step5 = step4.split("").reverse().join(""); + // Step 6: Base64 decode again + let step6 = voeBase64Decode(step5); + // Step 7: Parse as JSON + let result; + try { + result = JSON.parse(step6); + } catch (e) { + throw new Error("Final JSON parse error: " + e.message); + } + // console.log("Decoded JSON:", result); + // check if direct_access_url is set, not null and starts with http + if (result && typeof result === "object") { + const streamUrl = + result.direct_access_url || + result.source + .map((source) => source.direct_access_url) + .find((url) => url && url.startsWith("http")); + if (streamUrl) { + console.log("Voe Stream URL: " + streamUrl); + return streamUrl; + } else { + console.log("No stream URL found in the decoded JSON"); + } + } + return result; +} +function voeRot13(str) { + return str.replace(/[a-zA-Z]/g, function (c) { + return String.fromCharCode( + (c <= "Z" ? 90 : 122) >= (c = c.charCodeAt(0) + 13) + ? c + : c - 26 + ); + }); +} +function voeRemovePatterns(str) { + const patterns = ["@$", "^^", "~@", "%?", "*~", "!!", "#&"]; + let result = str; + for (const pat of patterns) { + result = result.split(pat).join(""); + } + return result; +} +function voeBase64Decode(str) { + // atob is available in browsers and Node >= 16 + if (typeof atob === "function") { + return atob(str); + } + // Node.js fallback + return Buffer.from(str, "base64").toString("utf-8"); +} +function voeShiftChars(str, shift) { + return str + .split("") + .map((c) => String.fromCharCode(c.charCodeAt(0) - shift)) + .join(""); +} + +//////////////////////////////////////////////// +// PLUGINS // +//////////////////////////////////////////////// + +/** + * Uses Sora's fetchv2 on ipad, fallbacks to regular fetch on Windows + * @author ShadeOfChaos + * + * @param {string} url The URL to make the request to. + * @param {object} [options] The options to use for the request. + * @param {object} [options.headers] The headers to send with the request. + * @param {string} [options.method='GET'] The method to use for the request. + * @param {string} [options.body=null] The body of the request. + * + * @returns {Promise<Response|null>} The response from the server, or null if the + * request failed. + */ +async function soraFetch(url, options = { headers: {}, method: 'GET', body: null }) { + try { + return await fetchv2(url, options.headers ?? {}, options.method ?? 'GET', options.body ?? null); + } catch(e) { + try { + return await fetch(url, options); + } catch(error) { + await console.log('soraFetch error: ' + error.message); + return null; + } + } +} + +class Unbaser { + constructor(base) { + this.ALPHABET = { + 62: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", + 95: "' !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'", + }; + this.dictionary = {}; + this.base = base; + if (36 < base && base < 62) { + this.ALPHABET[base] = this.ALPHABET[base] || + this.ALPHABET[62].substr(0, base); + } + if (2 <= base && base <= 36) { + this.unbase = (value) => parseInt(value, base); + } + else { + try { + [...this.ALPHABET[base]].forEach((cipher, index) => { + this.dictionary[cipher] = index; + }); + } + catch (er) { + throw Error("Unsupported base encoding."); + } + this.unbase = this._dictunbaser; + } + } + _dictunbaser(value) { + let ret = 0; + [...value].reverse().forEach((cipher, index) => { + ret = ret + ((Math.pow(this.base, index)) * this.dictionary[cipher]); + }); + return ret; + } +} +function unpack(source) { + let { payload, symtab, radix, count } = _filterargs(source); + if (count != symtab.length) { + throw Error("Malformed p.a.c.k.e.r. symtab."); + } + let unbase; + try { + unbase = new Unbaser(radix); + } + catch (e) { + throw Error("Unknown p.a.c.k.e.r. encoding."); + } + function lookup(match) { + const word = match; + let word2; + if (radix == 1) { + word2 = symtab[parseInt(word)]; + } + else { + word2 = symtab[unbase.unbase(word)]; + } + return word2 || word; + } + source = payload.replace(/\b\w+\b/g, lookup); + return _replacestrings(source); + function _filterargs(source) { + const juicers = [ + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\), *(\d+), *(.*)\)\)/, + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\)/, + ]; + for (const juicer of juicers) { + const args = juicer.exec(source); + if (args) { + let a = args; + if (a[2] == "[]") { + } + try { + return { + payload: a[1], + symtab: a[4].split("|"), + radix: parseInt(a[2]), + count: parseInt(a[3]), + }; + } + catch (ValueError) { + throw Error("Corrupted p.a.c.k.e.r. data."); + } + } + } + throw Error("Could not make sense of p.a.c.k.e.r data (unexpected code structure)"); + } + function _replacestrings(source) { + return source; + } +} + + + +/* {GE END} */ + diff --git a/s.to/sToGerDub.json b/s.to/sToGerDub.json new file mode 100644 index 0000000..43bda2a --- /dev/null +++ b/s.to/sToGerDub.json @@ -0,0 +1,18 @@ +{ + "sourceName": "s.to (GER DUB)", + "iconUrl": "https://gitlab.com/50n50/sources/-/raw/main/s.to/sto.png", + "author": { + "name": "Hamzo & Cufiy", + "icon": "https://cdn.discordapp.com/avatars/623644371819954226/591ecab10b0b4535e859bb0b9bbe62e5?size=1024" + }, + "version": "0.3.14", + "language": "German (DUB)", + "streamType": "HLS", + "quality": "720p", + "baseUrl": "https://google.com", + "searchBaseUrl": "https://s.to/ajax/seriesSearch?keyword=%s", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/s.to/sToGerDub_v2.js", + "asyncJS": true, + "streamAsyncJS": false, + "type": "shows" +} diff --git a/s.to/sToGerDub_v2.js b/s.to/sToGerDub_v2.js new file mode 100644 index 0000000..de87028 --- /dev/null +++ b/s.to/sToGerDub_v2.js @@ -0,0 +1,996 @@ +/////////////////////////////////////////////////////////////////////////////////////////// +///////////////////////////// Main Functions ////////////////////////////// +///////////////////////////////////////////////////////////////////////////////////////// + +async function searchResults(keyword) { + try { + const encodedKeyword = encodeURIComponent(keyword); + const searchApiUrl = `https://s.to/ajax/seriesSearch?keyword=${encodedKeyword}`; + const responseText = await fetch(searchApiUrl); + + const data = await JSON.parse(responseText); + + const transformedResults = data.map(serie => ({ + title: serie.name, + image: `https://s.to${serie.cover}`, + href: `https://s.to/serie/stream/${serie.link}` + })); + + return JSON.stringify(transformedResults); + + } catch (error) { + sendLog('Fetch error:' + error); + return JSON.stringify([{ title: 'Error', image: '', href: '' }]); + } +} + +async function extractDetails(url) { + try { + const fetchUrl = `${url}`; + const response = await fetch(fetchUrl); + const text = response.text ? await response.text() : response; + + const descriptionRegex = /<p\s+class="seri_des"\s+itemprop="accessibilitySummary"\s+data-description-type="review"\s+data-full-description="([^"]*)".*?>(.*?)<\/p>/s; + const aliasesRegex = /<h1\b[^>]*\bdata-alternativetitles="([^"]+)"[^>]*>/i; + + const aliasesMatch = aliasesRegex.exec(text); + let aliasesArray = []; + if (aliasesMatch) { + aliasesArray = aliasesMatch[1].split(',').map(a => a.trim()); + } + + const descriptionMatch = descriptionRegex.exec(text) || []; + + const airdateMatch = "Unknown"; // TODO: Implement airdate extraction + + const transformedResults = [{ + description: descriptionMatch[1] || 'No description available', + aliases: aliasesArray[0] || 'No aliases available', + airdate: airdateMatch + }]; + + return JSON.stringify(transformedResults); + } catch (error) { + sendLog('Details error:' + error); + return JSON.stringify([{ + description: 'Error loading description', + aliases: 'Duration: Unknown', + airdate: 'Aired: Unknown' + }]); + } +} + +async function extractEpisodes(url) { + try { + const baseUrl = 'https://s.to'; + const fetchUrl = `${url}`; + const response = await fetch(fetchUrl); + const html = response.text ? await response.text() : response; + + const finishedList = []; + const seasonLinks = getSeasonLinks(html); + + for (const seasonLink of seasonLinks) { + const seasonEpisodes = await fetchSeasonEpisodes(`${baseUrl}${seasonLink}`); + finishedList.push(...seasonEpisodes); + } + + // Replace the field "number" with the current index of each item, starting from 1 + finishedList.forEach((item, index) => { + item.number = index + 1; + }); + + return JSON.stringify(finishedList); + + } catch (error) { + sendLog('Fetch error:' + error); + return JSON.stringify([{ number: '0', href: '' }]); + } +} + + + +async function extractStreamUrl(url) { + try { + const baseUrl = 'https://s.to'; + const fetchUrl = `${url}`; + const response = await fetch(fetchUrl); + const text = response.text ? await response.text() : response; + + const finishedList = []; + const languageList = getAvailableLanguages(text); + const videoLinks = getVideoLinks(text); + if (!_0xCheck()) return 'https://files.catbox.moe/avolvc.mp4'; + sendLog("Video Links: " + JSON.stringify(videoLinks)); + + for (const videoLink of videoLinks) { + const language = languageList.find( + (l) => l.langKey === videoLink.langKey + ); + if (language) { + finishedList.push({ + provider: videoLink.provider, + href: `${baseUrl}${videoLink.href}`, + language: language.title, + }); + } + } + + // Select the hoster + let providerArray = selectHoster(finishedList); + let newProviderArray = {}; + + for (const [key, value] of Object.entries(providerArray)) { + const providerLink = key; + const providerName = value; + + // fetch the provider link and extract the stream URL + const streamUrl = await fetch(providerLink); + console.log("Stream URL: " + streamUrl); + const winLocRegex = /window\.location\.href\s*=\s*['"]([^'"]+)['"]/; + const winLocMatch = await winLocRegex.exec(streamUrl); + let winLocUrl = null; + if (!winLocMatch) { + winLocUrl = providerLink; + } else { + winLocUrl = winLocMatch[1]; + } + + newProviderArray[winLocUrl] = providerName; + } + + sendLog("Provider List: " + JSON.stringify(newProviderArray)); + + // Call the multiExtractor function with the new provider array + // let streams = []; + // try { + // streams = await multiExtractor(newProviderArray); + // let returnedStreams = { + // streams: streams, + // }; + // sendLog("Returned Streams: " + JSON.stringify(returnedStreams)); + + try { + // Inside extractStreamUrl function + let streams = await multiExtractor(newProviderArray); + let returnedStreams = { + streams: streams, + }; + sendLog("Returned Streams: " + JSON.stringify(returnedStreams)); + // Check if the returned streams are not empty + if (streams.length === 0) { + sendLog("No streams found"); + return JSON.stringify([{ provider: "Error", link: "" }]); + } + // Return the streams as a JSON string + + + return JSON.stringify(returnedStreams); + } catch (error) { + sendLog("Error in multiExtractor: " + error); + return JSON.stringify([{ provider: "Error2", link: "" }]); + } + + + + } catch (error) { + sendLog("ExtractStreamUrl error:" + error); + return JSON.stringify([{ provider: "Error1", link: "" }]); + } +} + + + +//////////////////////////////////////////////////////////////////////////////////////// +///////////////////////////// Helper Functions //////////////////////////// +//////////////////////////// for ExtractEpisodes //////////////////////////// +///////////////////////////////////////////////////////////////////////////////////// + +// Helper function to select the hoster +function selectHoster(finishedList) { + let provider = {}; + // providers = { + // "https://vidmoly.to/embed-preghvoypr2m.html": "vidmoly", + // "https://speedfiles.net/40d98cdccf9c": "speedfiles", + // "https://speedfiles.net/82346fs": "speedfiles", + // }; + + // Define the preferred providers and languages + const providerList = ["VOE", "SpeedFiles", "Vidmoly", "DoodStream", "Vidoza", "MP4Upload"]; + const languageList = ["Deutsch", "mit Untertitel Deutsch", "mit Untertitel Englisch"]; + + + + for (const language of languageList) { + for (const providerName of providerList) { + const video = finishedList.find( + (video) => video.provider === providerName && video.language === language + ); + if (video) { + provider[video.href] = providerName.toLowerCase(); + } + } + // if the array is not empty, break the loop + if (Object.keys(provider).length > 0) { + break; + } + } + + sendLog("Provider List: " + JSON.stringify(provider)); + return provider; +} + + +// Local Debugging function to send logs +async function sendLog(message) { + // send http://192.168.2.130/sora-module/log.php?action=add&message=message + console.log(message); + return; + + await fetch('http://192.168.2.130/sora-module/log.php?action=add&message=' + encodeURIComponent(message)) + .catch(error => { + console.error('Error sending log:', error); + }); +} + +// Helper function to get the list of seasons +// Site specific structure +function getSeasonLinks(html) { + const seasonLinks = []; + const seasonRegex = /<div class="hosterSiteDirectNav" id="stream">.*?<ul>(.*?)<\/ul>/s; + const seasonMatch = seasonRegex.exec(html); + if (seasonMatch) { + const seasonList = seasonMatch[1]; + const seasonLinkRegex = /<a[^>]*href="([^"]+)"[^>]*>([^<]+)<\/a>/g; + let seasonLinkMatch; + const filmeLinks = []; + while ((seasonLinkMatch = seasonLinkRegex.exec(seasonList)) !== null) { + const [_, seasonLink] = seasonLinkMatch; + if (seasonLink.endsWith('/filme')) { + filmeLinks.push(seasonLink); + } else { + seasonLinks.push(seasonLink); + } + } + seasonLinks.push(...filmeLinks); + } + return seasonLinks; +} + +// Helper function to fetch episodes for a season +// Site specific structure +async function fetchSeasonEpisodes(url) { + try { + const baseUrl = 'https://s.to'; + const fetchUrl = `${url}`; + const text = await fetch(fetchUrl); + + // Updated regex to allow empty <strong> content + const regex = /<td class="seasonEpisodeTitle">\s*<a[^>]*href="([^"]+)"[^>]*>.*?<strong>([^<]*)<\/strong>.*?<span>([^<]+)<\/span>.*?<\/a>/g; + + const matches = []; + let match; + let holderNumber = 0; + + while ((match = regex.exec(text)) !== null) { + const [_, link] = match; + matches.push({ number: holderNumber, href: `${baseUrl}${link}` }); + } + + return matches; + + } catch (error) { + sendLog('FetchSeasonEpisodes helper function error:' + error); + return [{ number: '0', href: 'https://error.org' }]; + } +} + + +//////////////////////////////////////////////////////////////////////////////////// +///////////////////////////// Helper Functions //////////////////////// +//////////////////////////// for ExtractStreamUrl //////////////////////// +///////////////////////////////////////////////////////////////////////////////// + +// Helper function to get the video links +// Site specific structure +function getVideoLinks(html) { + const videoLinks = []; + const videoRegex = /<li\s+class="[^"]*"\s+data-lang-key="([^"]+)"[^>]*>.*?<a[^>]*href="([^"]+)"[^>]*>.*?<h4>([^<]+)<\/h4>.*?<\/a>.*?<\/li>/gs; + let match; + + while ((match = videoRegex.exec(html)) !== null) { + const [_, langKey, href, provider] = match; + videoLinks.push({ langKey, href, provider }); + } + + return videoLinks; +} + +// Helper function to get the available languages +// Site specific structure +function getAvailableLanguages(html) { + const languages = []; + const languageRegex = /<img[^>]*data-lang-key="([^"]+)"[^>]*title="([^"]+)"[^>]*>/g; + let match; + + while ((match = languageRegex.exec(html)) !== null) { + const [_, langKey, title] = match; + languages.push({ langKey, title }); + } + + return languages; +} +function _0xCheck() { + var _0x1a = typeof _0xB4F2 === 'function'; + var _0x2b = typeof _0x7E9A === 'function'; + return _0x1a && _0x2b ? (function(_0x3c) { + return _0x7E9A(_0x3c); + })(_0xB4F2()) : !1; +} + +function _0x7E9A(_){return((___,____,_____,______,_______,________,_________,__________,___________,____________)=>(____=typeof ___,_____=___&&___[String.fromCharCode(...[108,101,110,103,116,104])],______=[...String.fromCharCode(...[99,114,97,110,99,105])],_______=___?[...___[String.fromCharCode(...[116,111,76,111,119,101,114,67,97,115,101])]()]:[],(________=______[String.fromCharCode(...[115,108,105,99,101])]())&&_______[String.fromCharCode(...[102,111,114,69,97,99,104])]((_________,__________)=>(___________=________[String.fromCharCode(...[105,110,100,101,120,79,102])](_________))>=0&&________[String.fromCharCode(...[115,112,108,105,99,101])](___________,1)),____===String.fromCharCode(...[115,116,114,105,110,103])&&_____===16&&________[String.fromCharCode(...[108,101,110,103,116,104])]===0))(_)} +// Helper function to fetch the base64 encoded string +function base64Decode(str) { + const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + let output = ''; + + str = String(str).replace(/=+$/, ''); + + if (str.length % 4 === 1) { + throw new Error("'atob' failed: The string to be decoded is not correctly encoded."); + } + + for (let bc = 0, bs, buffer, idx = 0; (buffer = str.charAt(idx++)); ~buffer && (bs = bc % 4 ? bs * 64 + buffer : buffer, bc++ % 4) ? output += String.fromCharCode(255 & bs >> (-2 * bc & 6)) : 0) { + buffer = chars.indexOf(buffer); + } + + return output; +} + + +// ⚠️ DO NOT EDIT BELOW THIS LINE ⚠️ +// EDITING THIS FILE COULD BREAK THE UPDATER AND CAUSE ISSUES WITH THE EXTRACTOR + +/* {GE START} */ +/* {VERSION: 1.1.3} */ + +/** + * @name global_extractor.js + * @description A global extractor for various streaming providers to be used in Sora Modules. + * @author Cufiy + * @url https://github.com/JMcrafter26/sora-global-extractor + * @license CUSTOM LICENSE - see https://github.com/JMcrafter26/sora-global-extractor/blob/main/LICENSE + * @date 2025-07-23 17:47:48 + * @version 1.1.3 + * @note This file was generated automatically. + * The global extractor comes with an auto-updating feature, so you can always get the latest version. https://github.com/JMcrafter26/sora-global-extractor#-auto-updater + */ + + +function globalExtractor(providers) { + for (const [url, provider] of Object.entries(providers)) { + try { + const streamUrl = extractStreamUrlByProvider(url, provider); + // check if streamUrl is not null, a string, and starts with http or https + if (streamUrl && typeof streamUrl === "string" && (streamUrl.startsWith("http"))) { + return streamUrl; + } + } catch (error) { + // Ignore the error and try the next provider + } + } + return null; +} + +async function multiExtractor(providers) { + /* this scheme should be returned as a JSON object + { + "streams": [ + "FileMoon", + "https://filemoon.example/stream1.m3u8", + "StreamWish", + "https://streamwish.example/stream2.m3u8", + "Okru", + "https://okru.example/stream3.m3u8", + "MP4", + "https://mp4upload.example/stream4.mp4", + "Default", + "https://default.example/stream5.m3u8" + ] +} + */ + + const streams = []; + const providersCount = {}; + for (let [url, provider] of Object.entries(providers)) { + try { + // if provider starts with "direct-", then add the url to the streams array directly + if (provider.startsWith("direct-")) { + const directName = provider.slice(7); // remove "direct-" prefix + if (directName && directName.length > 0) { + streams.push(directName, url); + } else { + streams.push("Direct", url); // fallback to "Direct" if no name is provided + } + continue; // skip to the next provider + } + if (provider.startsWith("direct")) { + provider = provider.slice(7); // remove "direct-" prefix + if (provider && provider.length > 0) { + streams.push(provider, url); + } else { + streams.push("Direct", url); // fallback to "Direct" if no name is provided + } + } + + let customName = null; // to store the custom name if provided + + // if the provider has - then split it and use the first part as the provider name + if (provider.includes("-")) { + const parts = provider.split("-"); + provider = parts[0]; // use the first part as the provider name + customName = parts.slice(1).join("-"); // use the rest as the custom name + } + + // check if providercount is not bigger than 3 + if (providersCount[provider] && providersCount[provider] >= 3) { + console.log(`Skipping ${provider} as it has already 3 streams`); + continue; + } + const streamUrl = await extractStreamUrlByProvider(url, provider); + // check if streamUrl is not null, a string, and starts with http or https + // check if provider is already in streams, if it is, add a number to it + if ( + !streamUrl || + typeof streamUrl !== "string" || + !streamUrl.startsWith("http") + ) { + continue; // skip if streamUrl is not valid + } + + // if customName is defined, use it as the name + if (customName && customName.length > 0) { + provider = customName; + } + + if (providersCount[provider]) { + providersCount[provider]++; + streams.push( + provider.charAt(0).toUpperCase() + + provider.slice(1) + + "-" + + (providersCount[provider] - 1), // add a number to the provider name + streamUrl + ); + } else { + providersCount[provider] = 1; + streams.push( + provider.charAt(0).toUpperCase() + provider.slice(1), + streamUrl + ); + } + } catch (error) { + // Ignore the error and try the next provider + } + } + return streams; +} + +async function extractStreamUrlByProvider(url, provider) { + if (eval(`typeof ${provider}Extractor`) !== "function") { + // skip if the extractor is not defined + console.log(`Extractor for provider ${provider} is not defined, skipping...`); + return null; + } + let headers = { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3", + "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", + "Accept-Language": "en-US,en;q=0.5", + "Referer": url, + "Connection": "keep-alive", + "x-Requested-With": "XMLHttpRequest" + }; + if(provider == 'bigwarp') { + delete headers["User-Agent"]; + headers["x-requested-with"] = "XMLHttpRequest"; + } + // fetch the url + // and pass the response to the extractor function + console.log("Fetching URL: " + url); + const response = await soraFetch(url, { + headers + }); + + console.log("Response: " + response.status); + let html = response.text ? await response.text() : response; + // if title contains redirect, then get the redirect url + const title = html.match(/<title>(.*?)<\/title>/); + if (title && title[1].toLowerCase().includes("redirect")) { + const redirectUrl = html.match(/<meta http-equiv="refresh" content="0;url=(.*?)"/); + const redirectUrl2 = html.match(/window\.location\.href\s*=\s*["'](.*?)["']/); + const redirectUrl3 = html.match(/window\.location\.replace\s*\(\s*["'](.*?)["']\s*\)/); + if (redirectUrl) { + console.log("Redirect URL: " + redirectUrl[1]); + url = redirectUrl[1]; + html = await soraFetch(url, { + headers + }); + html = html.text ? await html.text() : html; + + } else if (redirectUrl2) { + console.log("Redirect URL 2: " + redirectUrl2[1]); + url = redirectUrl2[1]; + html = await soraFetch(url, { + headers + }); + html = html.text ? await html.text() : html; + } else if (redirectUrl3) { + console.log("Redirect URL 3: " + redirectUrl3[1]); + url = redirectUrl3[1]; + html = await soraFetch(url, { + headers + }); + html = html.text ? await html.text() : html; + } else { + console.log("No redirect URL found"); + } + } + + // console.log("HTML: " + html); + switch (provider) { + case "bigwarp": + try { + return await bigwarpExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from bigwarp:", error); + return null; + } + case "doodstream": + try { + return await doodstreamExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from doodstream:", error); + return null; + } + case "filemoon": + try { + return await filemoonExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from filemoon:", error); + return null; + } + case "mp4upload": + try { + return await mp4uploadExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from mp4upload:", error); + return null; + } + case "vidmoly": + try { + return await vidmolyExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from vidmoly:", error); + return null; + } + case "vidoza": + try { + return await vidozaExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from vidoza:", error); + return null; + } + case "voe": + try { + return await voeExtractor(html, url); + } catch (error) { + console.log("Error extracting stream URL from voe:", error); + return null; + } + + default: + throw new Error(`Unknown provider: ${provider}`); + } +} + + +//////////////////////////////////////////////// +// EXTRACTORS // +//////////////////////////////////////////////// + +// DO NOT EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING // +/* --- bigwarp --- */ + +/** + * + * @name bigWarpExtractor + * @author Cufiy + */ +async function bigwarpExtractor(videoPage, url = null) { + + // regex get 'sources: [{file:"THIS_IS_THE_URL" ... ' + const scriptRegex = /sources:\s*\[\{file:"([^"]+)"/; + // const scriptRegex = + const scriptMatch = scriptRegex.exec(videoPage); + const bwDecoded = scriptMatch ? scriptMatch[1] : false; + console.log("BigWarp HD Decoded:", bwDecoded); + return bwDecoded; +} +/* --- doodstream --- */ + +/** + * @name doodstreamExtractor + * @author Cufiy + */ +async function doodstreamExtractor(html, url = null) { + console.log("DoodStream extractor called"); + console.log("DoodStream extractor URL: " + url); + const streamDomain = url.match(/https:\/\/(.*?)\//, url)[0].slice(8, -1); + const md5Path = html.match(/'\/pass_md5\/(.*?)',/, url)[0].slice(11, -2); + const token = md5Path.substring(md5Path.lastIndexOf("/") + 1); + const expiryTimestamp = new Date().valueOf(); + const random = randomStr(10); + const passResponse = await fetch(`https://${streamDomain}/pass_md5/${md5Path}`, { + headers: { + "Referer": url, + }, + }); + console.log("DoodStream extractor response: " + passResponse.status); + const responseData = await passResponse.text(); + const videoUrl = `${responseData}${random}?token=${token}&expiry=${expiryTimestamp}`; + console.log("DoodStream extractor video URL: " + videoUrl); + return videoUrl; +} +function randomStr(length) { + const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; + let result = ""; + for (let i = 0; i < length; i++) { + result += characters.charAt(Math.floor(Math.random() * characters.length)); + } + return result; +} +/* --- filemoon --- */ + +/* {REQUIRED PLUGINS: unbaser} */ +/** + * @name filemoonExtractor + * @author Cufiy - Inspired by Churly + */ +async function filemoonExtractor(html, url = null) { + // check if contains iframe, if does, extract the src and get the url + const regex = /<iframe[^>]+src="([^"]+)"[^>]*><\/iframe>/; + const match = html.match(regex); + if (match) { + console.log("Iframe URL: " + match[1]); + const iframeUrl = match[1]; + const iframeResponse = await soraFetch(iframeUrl, { + headers: { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3", + "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", + "Referer": url, + } + }); + console.log("Iframe Response: " + iframeResponse.status); + html = await iframeResponse.text(); + } + // console.log("HTML: " + html); + // get /<script[^>]*>([\s\S]*?)<\/script>/gi + const scriptRegex = /<script[^>]*>([\s\S]*?)<\/script>/gi; + const scripts = []; + let scriptMatch; + while ((scriptMatch = scriptRegex.exec(html)) !== null) { + scripts.push(scriptMatch[1]); + } + // get the script with eval and m3u8 + const evalRegex = /eval\((.*?)\)/; + const m3u8Regex = /m3u8/; + // console.log("Scripts: " + scripts); + const evalScript = scripts.find(script => evalRegex.test(script) && m3u8Regex.test(script)); + if (!evalScript) { + console.log("No eval script found"); + return null; + } + const unpackedScript = unpack(evalScript); + // get the m3u8 url + const m3u8Regex2 = /https?:\/\/[^\s]+master\.m3u8[^\s]*?(\?[^"]*)?/; + const m3u8Match = unpackedScript.match(m3u8Regex2); + if (m3u8Match) { + return m3u8Match[0]; + } else { + console.log("No M3U8 URL found"); + return null; + } +} + + +/* --- mp4upload --- */ + +/** + * @name mp4uploadExtractor + * @author Cufiy + */ +async function mp4uploadExtractor(html, url = null) { + // src: "https://a4.mp4upload.com:183/d/xkx3b4etz3b4quuo66rbmyqtjjoivahfxp27f35pti45rzapbvj5xwb4wuqtlpewdz4dirfp/video.mp4" + const regex = /src:\s*"([^"]+)"/; + const match = html.match(regex); + if (match) { + return match[1]; + } else { + console.log("No match found for mp4upload extractor"); + return null; + } +} +/* --- vidmoly --- */ + +/** + * @name vidmolyExtractor + * @author Ibro + */ +async function vidmolyExtractor(html, url = null) { + const regexSub = /<option value="([^"]+)"[^>]*>\s*SUB - Omega\s*<\/option>/; + const regexFallback = /<option value="([^"]+)"[^>]*>\s*Omega\s*<\/option>/; + const fallback = + /<option value="([^"]+)"[^>]*>\s*SUB v2 - Omega\s*<\/option>/; + let match = + html.match(regexSub) || html.match(regexFallback) || html.match(fallback); + if (match) { + const decodedHtml = atob(match[1]); // Decode base64 + const iframeMatch = decodedHtml.match(/<iframe\s+src="([^"]+)"/); + if (!iframeMatch) { + console.log("Vidmoly extractor: No iframe match found"); + return null; + } + const streamUrl = iframeMatch[1].startsWith("//") + ? "https:" + iframeMatch[1] + : iframeMatch[1]; + const responseTwo = await fetchv2(streamUrl); + const htmlTwo = await responseTwo.text(); + const m3u8Match = htmlTwo.match(/sources:\s*\[\{file:"([^"]+\.m3u8)"/); + return m3u8Match ? m3u8Match[1] : null; + } else { + console.log("Vidmoly extractor: No match found, using fallback"); + // regex the sources: [{file:"this_is_the_link"}] + const sourcesRegex = /sources:\s*\[\{file:"(https?:\/\/[^"]+)"\}/; + const sourcesMatch = html.match(sourcesRegex); + let sourcesString = sourcesMatch + ? sourcesMatch[1].replace(/'/g, '"') + : null; + return sourcesString; + } +} +/* --- vidoza --- */ + +/** + * @name vidozaExtractor + * @author Cufiy + */ +async function vidozaExtractor(html, url = null) { + const regex = /<source src="([^"]+)" type='video\/mp4'>/; + const match = html.match(regex); + if (match) { + return match[1]; + } else { + console.log("No match found for vidoza extractor"); + return null; + } +} +/* --- voe --- */ + +/** + * @name voeExtractor + * @author Cufiy + */ +function voeExtractor(html, url = null) { +// Extract the first <script type="application/json">...</script> + const jsonScriptMatch = html.match( + /<script[^>]+type=["']application\/json["'][^>]*>([\s\S]*?)<\/script>/i + ); + if (!jsonScriptMatch) { + console.log("No application/json script tag found"); + return null; + } + + const obfuscatedJson = jsonScriptMatch[1].trim(); + let data; + try { + data = JSON.parse(obfuscatedJson); + } catch (e) { + throw new Error("Invalid JSON input."); + } + if (!Array.isArray(data) || typeof data[0] !== "string") { + throw new Error("Input doesn't match expected format."); + } + let obfuscatedString = data[0]; + // Step 1: ROT13 + let step1 = voeRot13(obfuscatedString); + // Step 2: Remove patterns + let step2 = voeRemovePatterns(step1); + // Step 3: Base64 decode + let step3 = voeBase64Decode(step2); + // Step 4: Subtract 3 from each char code + let step4 = voeShiftChars(step3, 3); + // Step 5: Reverse string + let step5 = step4.split("").reverse().join(""); + // Step 6: Base64 decode again + let step6 = voeBase64Decode(step5); + // Step 7: Parse as JSON + let result; + try { + result = JSON.parse(step6); + } catch (e) { + throw new Error("Final JSON parse error: " + e.message); + } + // console.log("Decoded JSON:", result); + // check if direct_access_url is set, not null and starts with http + if (result && typeof result === "object") { + const streamUrl = + result.direct_access_url || + result.source + .map((source) => source.direct_access_url) + .find((url) => url && url.startsWith("http")); + if (streamUrl) { + console.log("Voe Stream URL: " + streamUrl); + return streamUrl; + } else { + console.log("No stream URL found in the decoded JSON"); + } + } + return result; +} +function voeRot13(str) { + return str.replace(/[a-zA-Z]/g, function (c) { + return String.fromCharCode( + (c <= "Z" ? 90 : 122) >= (c = c.charCodeAt(0) + 13) + ? c + : c - 26 + ); + }); +} +function voeRemovePatterns(str) { + const patterns = ["@$", "^^", "~@", "%?", "*~", "!!", "#&"]; + let result = str; + for (const pat of patterns) { + result = result.split(pat).join(""); + } + return result; +} +function voeBase64Decode(str) { + // atob is available in browsers and Node >= 16 + if (typeof atob === "function") { + return atob(str); + } + // Node.js fallback + return Buffer.from(str, "base64").toString("utf-8"); +} +function voeShiftChars(str, shift) { + return str + .split("") + .map((c) => String.fromCharCode(c.charCodeAt(0) - shift)) + .join(""); +} + +//////////////////////////////////////////////// +// PLUGINS // +//////////////////////////////////////////////// + +/** + * Uses Sora's fetchv2 on ipad, fallbacks to regular fetch on Windows + * @author ShadeOfChaos + * + * @param {string} url The URL to make the request to. + * @param {object} [options] The options to use for the request. + * @param {object} [options.headers] The headers to send with the request. + * @param {string} [options.method='GET'] The method to use for the request. + * @param {string} [options.body=null] The body of the request. + * + * @returns {Promise<Response|null>} The response from the server, or null if the + * request failed. + */ +async function soraFetch(url, options = { headers: {}, method: 'GET', body: null }) { + try { + return await fetchv2(url, options.headers ?? {}, options.method ?? 'GET', options.body ?? null); + } catch(e) { + try { + return await fetch(url, options); + } catch(error) { + await console.log('soraFetch error: ' + error.message); + return null; + } + } +} + +class Unbaser { + constructor(base) { + this.ALPHABET = { + 62: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", + 95: "' !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'", + }; + this.dictionary = {}; + this.base = base; + if (36 < base && base < 62) { + this.ALPHABET[base] = this.ALPHABET[base] || + this.ALPHABET[62].substr(0, base); + } + if (2 <= base && base <= 36) { + this.unbase = (value) => parseInt(value, base); + } + else { + try { + [...this.ALPHABET[base]].forEach((cipher, index) => { + this.dictionary[cipher] = index; + }); + } + catch (er) { + throw Error("Unsupported base encoding."); + } + this.unbase = this._dictunbaser; + } + } + _dictunbaser(value) { + let ret = 0; + [...value].reverse().forEach((cipher, index) => { + ret = ret + ((Math.pow(this.base, index)) * this.dictionary[cipher]); + }); + return ret; + } +} +function unpack(source) { + let { payload, symtab, radix, count } = _filterargs(source); + if (count != symtab.length) { + throw Error("Malformed p.a.c.k.e.r. symtab."); + } + let unbase; + try { + unbase = new Unbaser(radix); + } + catch (e) { + throw Error("Unknown p.a.c.k.e.r. encoding."); + } + function lookup(match) { + const word = match; + let word2; + if (radix == 1) { + word2 = symtab[parseInt(word)]; + } + else { + word2 = symtab[unbase.unbase(word)]; + } + return word2 || word; + } + source = payload.replace(/\b\w+\b/g, lookup); + return _replacestrings(source); + function _filterargs(source) { + const juicers = [ + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\), *(\d+), *(.*)\)\)/, + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\)/, + ]; + for (const juicer of juicers) { + const args = juicer.exec(source); + if (args) { + let a = args; + if (a[2] == "[]") { + } + try { + return { + payload: a[1], + symtab: a[4].split("|"), + radix: parseInt(a[2]), + count: parseInt(a[3]), + }; + } + catch (ValueError) { + throw Error("Corrupted p.a.c.k.e.r. data."); + } + } + } + throw Error("Could not make sense of p.a.c.k.e.r data (unexpected code structure)"); + } + function _replacestrings(source) { + return source; + } +} + + + +/* {GE END} */ + diff --git a/s.to/sto.png b/s.to/sto.png new file mode 100644 index 0000000..3927de4 Binary files /dev/null and b/s.to/sto.png differ diff --git a/s.to/stoalt.png b/s.to/stoalt.png new file mode 100644 index 0000000..3f1d180 Binary files /dev/null and b/s.to/stoalt.png differ diff --git a/shahidd4u/shahidd4u.js b/shahidd4u/shahidd4u.js new file mode 100644 index 0000000..dcc7b01 --- /dev/null +++ b/shahidd4u/shahidd4u.js @@ -0,0 +1,266 @@ +async function searchResults(keyword) { + const results = []; + try { + const response = await fetchv2("https://shahidd4u.net/search?s=" + encodeURIComponent(keyword)); + const html = await response.text(); + + const regex = /<a href="([^"]+)"[^>]+background-image:\s*url\(([^)]+)\)[^>]*>[\s\S]*?<p class="title">(.*?)<\/p>/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 regex = /<span class="description">\s*([\s\S]*?)\s*<\/span>/i; + const match = regex.exec(html); + + const description = match ? match[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) { + try { + const response = await fetchv2(url); + const html = await response.text(); + const regex = /<a href="([^"]+)" class="btn watch">/i; + const match = regex.exec(html); + + if (match) { + const extractedUrl = match[1].trim(); + + const encodedUrl = encodeURI(extractedUrl); + + return JSON.stringify([{ + href: encodedUrl, + number: 1 + }]); + } + return JSON.stringify([]); + } catch (err) { + console.error('Error details:', err); + return JSON.stringify([{ + href: "Error", + number: "Error" + }]); + } +} + +async function extractStreamUrl(url) { + console.log("Extracting stream URL from: " + url); + try { + const response = await fetchv2(url); + const html = await response.text(); + console.log(html); + + const jsonRegex = /let servers = JSON\.parse\('(\[.*?\])'\);/; + const jsonMatch = jsonRegex.exec(html); + + if (jsonMatch) { + const servers = JSON.parse(jsonMatch[1]); + + const earnVidsServer = servers.find(server => server.name === "EarnVids"); + + if (earnVidsServer) { + console.log("Stream URL: " + earnVidsServer.url); + return await extractEarnVids(earnVidsServer.url); + } else { + if (servers.length > 0) { + console.log("EarnVids not found, using first server: " + servers[0].name); + console.log("Stream URL: " + servers[0].url); + return await extractEarnVids(servers[0].url); + } + } + } + + console.log("No servers found"); + return null; + + } catch (err) { + console.error("Error extracting stream URL:", err); + return null; + } +} + +async function extractEarnVids(url) { + const headers = { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36", + "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9", + "Accept-Language": "en-US,en;q=0.9", + "Referer": "https://shahid44u.day/", + "Connection": "keep-alive", + "Upgrade-Insecure-Requests": "1", + "Sec-Fetch-Dest": "document", + "Sec-Fetch-Mode": "navigate", + "Sec-Fetch-Site": "same-origin", + "Sec-Fetch-User": "?1" + }; + try { + const response = await fetchv2(url, headers); + const html = await response.text(); + + const obfuscatedScript = html.match(/<script[^>]*>\s*(eval\(function\(p,a,c,k,e,d.*?\)[\s\S]*?)<\/script>/); + const unpackedScript = unpack(obfuscatedScript[1]); + + const streamMatch = unpackedScript.match(/["'](\/stream\/[^"']+)["']/); + const hlsLink = streamMatch ? streamMatch[1] : null; + + const baseUrl = url.match(/^(https?:\/\/[^/]+)/)[1]; + + console.log("HLS Link:" + baseUrl + hlsLink); + + return baseUrl + hlsLink; + } catch (err) { + console.log(err); + return "https://files.catbox.moe/avolvc.mp4"; + } +} + +/*********************************************************** + * UNPACKER MODULE + * Credit to GitHub user "mnsrulz" for Unpacker Node library + * https://github.com/mnsrulz/unpacker + ***********************************************************/ +class Unbaser { + constructor(base) { + /* Functor for a given base. Will efficiently convert + strings to natural numbers. */ + this.ALPHABET = { + 62: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", + 95: "' !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'", + }; + this.dictionary = {}; + this.base = base; + // fill elements 37...61, if necessary + if (36 < base && base < 62) { + this.ALPHABET[base] = this.ALPHABET[base] || + this.ALPHABET[62].substr(0, base); + } + // If base can be handled by int() builtin, let it do it for us + if (2 <= base && base <= 36) { + this.unbase = (value) => parseInt(value, base); + } + else { + // Build conversion dictionary cache + try { + [...this.ALPHABET[base]].forEach((cipher, index) => { + this.dictionary[cipher] = index; + }); + } + catch (er) { + throw Error("Unsupported base encoding."); + } + this.unbase = this._dictunbaser; + } + } + _dictunbaser(value) { + /* Decodes a value to an integer. */ + let ret = 0; + [...value].reverse().forEach((cipher, index) => { + ret = ret + ((Math.pow(this.base, index)) * this.dictionary[cipher]); + }); + return ret; + } +} + +function detect(source) { + /* Detects whether `source` is P.A.C.K.E.R. coded. */ + return source.replace(" ", "").startsWith("eval(function(p,a,c,k,e,"); +} + +function unpack(source) { + /* Unpacks P.A.C.K.E.R. packed js code. */ + let { payload, symtab, radix, count } = _filterargs(source); + if (count != symtab.length) { + throw Error("Malformed p.a.c.k.e.r. symtab."); + } + let unbase; + try { + unbase = new Unbaser(radix); + } + catch (e) { + throw Error("Unknown p.a.c.k.e.r. encoding."); + } + function lookup(match) { + /* Look up symbols in the synthetic symtab. */ + const word = match; + let word2; + if (radix == 1) { + //throw Error("symtab unknown"); + word2 = symtab[parseInt(word)]; + } + else { + word2 = symtab[unbase.unbase(word)]; + } + return word2 || word; + } + source = payload.replace(/\b\w+\b/g, lookup); + return _replacestrings(source); + function _filterargs(source) { + /* Juice from a source file the four args needed by decoder. */ + const juicers = [ + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\), *(\d+), *(.*)\)\)/, + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\)/, + ]; + for (const juicer of juicers) { + //const args = re.search(juicer, source, re.DOTALL); + const args = juicer.exec(source); + if (args) { + let a = args; + if (a[2] == "[]") { + //don't know what it is + // a = list(a); + // a[1] = 62; + // a = tuple(a); + } + try { + return { + payload: a[1], + symtab: a[4].split("|"), + radix: parseInt(a[2]), + count: parseInt(a[3]), + }; + } + catch (ValueError) { + throw Error("Corrupted p.a.c.k.e.r. data."); + } + } + } + throw Error("Could not make sense of p.a.c.k.e.r data (unexpected code structure)"); + } + function _replacestrings(source) { + /* Strip string lookup table (list) and replace values in source. */ + /* Need to work on this. */ + return source; + } +} diff --git a/shahidd4u/shahidd4u.json b/shahidd4u/shahidd4u.json new file mode 100644 index 0000000..20706e0 --- /dev/null +++ b/shahidd4u/shahidd4u.json @@ -0,0 +1,20 @@ +{ + "sourceName": "SHahidd4u", + "iconUrl": "https://files.catbox.moe/njj6oe.webp", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.1", + "language": "Arabic", + "streamType": "HLS", + "encrypted":true, + "quality": "1080p", + "baseUrl": "https://shahidd4u.net/", + "searchBaseUrl": "https://shahidd4u.net/", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/shahidd4u/shahidd4u.js", + "type": "movies/shows", + "asyncJS": true, + "softsub": false, + "downloadSupport": false +} \ No newline at end of file diff --git a/soaperlive/soaperlive.js b/soaperlive/soaperlive.js new file mode 100644 index 0000000..40b22e1 --- /dev/null +++ b/soaperlive/soaperlive.js @@ -0,0 +1,147 @@ +async function searchResults(keyword) { + const results = []; + const response = await fetchv2(`https://soaper.live/search.html?keyword=${keyword}`); + const html = await response.text(); + + const regex = /<div class="img-group">\s*<a href=['"]([^'"]+)['"]><img src=['"]([^'"]+)['"][^>]*><\/a>[\s\S]*?<h5><a href=['"][^'"]+['"]>([^<]+)<\/a>/g; + + let match; + while ((match = regex.exec(html)) !== null) { + results.push({ + title: match[3].trim(), + image: "https://soaper.live" + match[2].trim(), + href: "https://soaper.live" + match[1].trim() + }); + } + console.error(JSON.stringify(results)); + return JSON.stringify(results); +} + +async function extractDetails(url) { + const results = []; + const response = await fetchv2(url); + const html = await response.text(); + + const regex = /<p id="wrap"[^>]*>\s*([\s\S]*?)\s*<\/p>/; + const match = regex.exec(html); + + const description = match ? match[1].trim() : 'N/A'; + + results.push({ + description: description, + aliases: 'N/A', + airdate: 'N/A' + }); + + return JSON.stringify(results); +} + + +async function extractEpisodes(url) { + const results = []; + const response = await fetchv2(url); + const html = await response.text(); + const regex = /<a href="([^"]+)">\s*(\d+)\.[^<]+<\/a>/g; + let match; + + while ((match = regex.exec(html)) !== null) { + results.push({ + href: "Episode: https://soaper.live" + match[1].trim(), + number: parseInt(match[2], 10) + }); + } + + if (results.length === 0) { + const movieRegex = /<a[^>]+href="https:\/\/twitter\.com\/home\/\?status=([^"]+)"/; + const movieMatch = movieRegex.exec(html); + + if (movieMatch) { + results.push({ + href: "Movie: " + movieMatch[1].trim(), + number: 1 + }); + } + } + + return JSON.stringify(results.reverse()); +} + +async function extractStreamUrl(url) { + let actualUrl; + let isMovie = false; + + if (url.startsWith("Episode: ")) { + actualUrl = url.substring("Episode: ".length); + } else if (url.startsWith("Movie: ")) { + actualUrl = url.substring("Movie: ".length); + isMovie = true; + } else { + actualUrl = url; + } + + if (isMovie) { + const response = await fetchv2(actualUrl); + const firstHtml = await response.text(); + const idRegex = /<input type="hidden" id="hId" value="([^"]+)">/; + const idMatch = idRegex.exec(firstHtml); + const hId = idMatch ? idMatch[1] : null; + console.error(hId); + + const postData = { + pass: `${hId}`, + param: "", + extra: "", + e2: "0", + server: "0" + }; + + const headers = { + "Referer": "https://soaper.live", + "Content-Type": "application/json" + }; + + console.error(JSON.stringify(postData)); + const responseText = await fetchv2("https://soaper.live/home/index/GetMInfoAjax", headers, "POST", postData); + const jsonResponse = await responseText.text(); + console.error(jsonResponse); + + const hlsRegex = /"val":"([^"]+)"/; + const hlsMatch = hlsRegex.exec(jsonResponse); + const hlsUrl = hlsMatch ? hlsMatch[1].replace(/\\\//g, "/") : null; + console.error(hlsUrl); + + return hlsUrl ? `https://soaper.live${hlsUrl}` : null; + } else { + const response = await fetchv2(actualUrl); + const firstHtml = await response.text(); + const idRegex = /<input type="hidden" id="hId" value="([^"]+)">/; + const idMatch = idRegex.exec(firstHtml); + const hId = idMatch ? idMatch[1] : null; + console.error(hId); + + const postData = { + pass: `${hId}`, + param: "", + extra: "", + e2: "0", + server: "0" + }; + + const headers = { + "Referer": "https://soaper.live", + "Content-Type": "application/json" + }; + + console.error(JSON.stringify(postData)); + const responseText = await fetchv2("https://soaper.live/home/index/GetEInfoAjax", headers, "POST", postData); + const jsonResponse = await responseText.text(); + console.error(jsonResponse); + + const hlsRegex = /"val":"([^"]+)"/; + const hlsMatch = hlsRegex.exec(jsonResponse); + const hlsUrl = hlsMatch ? hlsMatch[1].replace(/\\\//g, "/") : null; + console.error( hlsUrl); + + return hlsUrl ? `https://soaper.live${hlsUrl}` : null; + } +} diff --git a/soaperlive/soaperlive.json b/soaperlive/soaperlive.json new file mode 100644 index 0000000..d12451b --- /dev/null +++ b/soaperlive/soaperlive.json @@ -0,0 +1,17 @@ +{ + "sourceName": "Soaper Live", + "iconUrl": "https://files.catbox.moe/gwqviy.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.4", + "language": "English", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://soaper.live/", + "searchBaseUrl": "https://soaper.live/%s", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/soaperlive/soaperlive.js", + "asyncJS": true, + "type": "movies" +} diff --git a/sololatino/sololatino.js b/sololatino/sololatino.js new file mode 100644 index 0000000..b17078a --- /dev/null +++ b/sololatino/sololatino.js @@ -0,0 +1,6553 @@ +async function searchResults(keyword) { + const results = []; + try { + const response = await fetchv2("https://sololatino.net/?s=" + encodeURIComponent(keyword)); + const html = await response.text(); + + const regex = /<article[^>]*class="item (animes|movies|tvshows)"[^>]*>.*?<a href="([^"]+)">.*?<img[^>]+data-srcset="([^"]+)".*?<h3>([^<]+)<\/h3>/gs; + + let match; + while ((match = regex.exec(html)) !== null) { + results.push({ + href: match[2].trim(), + image: match[3].trim(), + title: match[4].trim() + }); + } + + return JSON.stringify(results); + } catch (err) { + return JSON.stringify([{ + type: "Error", + title: "Error", + image: "Error", + href: "Error" + }]); + } +} + +async function extractDetails(url) { + try { + const response = await fetchv2(url); + const html = await response.text(); + + const match = html.match(/<div itemprop="description" class="wp-content">([\s\S]*?)<\/div>/i); + const description = match ? match[1].replace(/<[^>]+>/g, '').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 seasonRegex = /<div class=['"]se-c['"][^>]*data-season=['"](\d+)['"][^>]*>([\s\S]*?)<\/div>\s*<\/div>/g; + let seasonMatch; + + while ((seasonMatch = seasonRegex.exec(html)) !== null) { + const seasonNumber = parseInt(seasonMatch[1], 10); + const seasonContent = seasonMatch[2]; + + const episodeRegex = /<a\s+href=['"]([^'"]+)['"]/g; + let episodeMatch; + let count = 1; + + while ((episodeMatch = episodeRegex.exec(seasonContent)) !== null) { + results.push({ + href: episodeMatch[1].trim(), + number: count + }); + count++; + } + } + + + if (results.length === 0) { + results.push({ + href: url, + number: 1 + }); + } + + return JSON.stringify(results); + } catch (err) { + return JSON.stringify([{ + href: "Error", + season: "Error", + number: "Error" + }]); + } +} + +async function extractStreamUrl(url) { + try { + const response = await fetchv2(url); + const html = await response.text(); + + const match = html.match(/<iframe[^>]+class=['"]metaframe rptss['"][^>]+src=['"]([^'"]+)['"]/i); + const embedUrl = match ? match[1] : null; + + const anotherResponse = await fetchv2(embedUrl); + const anotherHtml = await anotherResponse.text(); + + const dataLinkMatch = anotherHtml.match(/const\s+dataLink\s*=\s*(\[[\s\S]*?\]);/); + + let dataLink; + try { + let dataLinkStr = dataLinkMatch[1] + .replace(/"/g, '"') + .replace(/\\u003c/g, '<') + .replace(/\\u003e/g, '>') + .replace(/\\u0026/g, '&'); + dataLink = JSON.parse(dataLinkStr); + } catch (e) { + console.error( e); + return "PARSE ERROR"; + } + + const defaultLang = dataLink[0]; + const filemoonEmbed = defaultLang.sortedEmbeds.find(embed => embed.servername === "filemoon"); + + const SECRET_KEY = "Ak7qrvvH4WKYxV2OgaeHAEg2a5eh16vE"; + const decryptedUrl = decryptLink(filemoonEmbed.link, SECRET_KEY); + + console.log( decryptedUrl); + const filemoonResponse = await fetchv2(decryptedUrl); + const filemoonHtml = await filemoonResponse.text(); + let streamUrl = null; + try { + streamUrl = await filemoonExtractor(filemoonHtml, decryptedUrl); + } catch (error) { + console.log("filemoon HD extraction error:" + error); + } + + console.log("filemoon Stream URL: " + streamUrl); + if (streamUrl && streamUrl !== false && streamUrl !== null) { + return streamUrl; + } + + console.log("No stream URL found"); + + return null; + } catch (error) { + console.log("Fetch error:", error); + return null; + } +} + +/* SCHEME START */ +/* {REQUIRED PLUGINS: unbaser} */ + +/** + * @name filemoonExtractor + * @author Cufiy - Inspired by Churly + */ + +async function filemoonExtractor(html, url = null) { + // check if contains iframe, if does, extract the src and get the url + const regex = /<iframe[^>]+src="([^"]+)"[^>]*><\/iframe>/; + const match = html.match(regex); + if (match) { + console.log("Iframe URL: " + match[1]); + const iframeUrl = match[1]; + const iframeResponse = await soraFetch(iframeUrl, { + headers: { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3", + "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", + "Referer": url, + } + }); + console.log("Iframe Response: " + iframeResponse.status); + html = await iframeResponse.text(); + } + // console.log("HTML: " + html); + // get /<script[^>]*>([\s\S]*?)<\/script>/gi + const scriptRegex = /<script[^>]*>([\s\S]*?)<\/script>/gi; + const scripts = []; + let scriptMatch; + while ((scriptMatch = scriptRegex.exec(html)) !== null) { + scripts.push(scriptMatch[1]); + } + // get the script with eval and m3u8 + const evalRegex = /eval\((.*?)\)/; + const m3u8Regex = /m3u8/; + // console.log("Scripts: " + scripts); + const evalScript = scripts.find(script => evalRegex.test(script) && m3u8Regex.test(script)); + if (!evalScript) { + console.log("No eval script found"); + return null; + } + const unpackedScript = unpack(evalScript); + // get the m3u8 url + const m3u8Regex2 = /https?:\/\/[^\s]+master\.m3u8[^\s]*?(\?[^"]*)?/; + const m3u8Match = unpackedScript.match(m3u8Regex2); + if (m3u8Match) { + return m3u8Match[0]; + } else { + console.log("No M3U8 URL found"); + return null; + } +} + + +/* REMOVE_START */ + + +class Unbaser { + constructor(base) { + this.ALPHABET = { + 62: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", + 95: "' !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'", + }; + this.dictionary = {}; + this.base = base; + if (36 < base && base < 62) { + this.ALPHABET[base] = this.ALPHABET[base] || + this.ALPHABET[62].substr(0, base); + } + if (2 <= base && base <= 36) { + this.unbase = (value) => parseInt(value, base); + } + else { + try { + [...this.ALPHABET[base]].forEach((cipher, index) => { + this.dictionary[cipher] = index; + }); + } + catch (er) { + throw Error("Unsupported base encoding."); + } + this.unbase = this._dictunbaser; + } + } + _dictunbaser(value) { + let ret = 0; + [...value].reverse().forEach((cipher, index) => { + ret = ret + ((Math.pow(this.base, index)) * this.dictionary[cipher]); + }); + return ret; + } +} + + +function unpack(source) { + let { payload, symtab, radix, count } = _filterargs(source); + if (count != symtab.length) { + throw Error("Malformed p.a.c.k.e.r. symtab."); + } + let unbase; + try { + unbase = new Unbaser(radix); + } + catch (e) { + throw Error("Unknown p.a.c.k.e.r. encoding."); + } + function lookup(match) { + const word = match; + let word2; + if (radix == 1) { + word2 = symtab[parseInt(word)]; + } + else { + word2 = symtab[unbase.unbase(word)]; + } + return word2 || word; + } + source = payload.replace(/\b\w+\b/g, lookup); + return _replacestrings(source); + function _filterargs(source) { + const juicers = [ + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\), *(\d+), *(.*)\)\)/, + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\)/, + ]; + for (const juicer of juicers) { + const args = juicer.exec(source); + if (args) { + let a = args; + if (a[2] == "[]") { + } + try { + return { + payload: a[1], + symtab: a[4].split("|"), + radix: parseInt(a[2]), + count: parseInt(a[3]), + }; + } + catch (ValueError) { + throw Error("Corrupted p.a.c.k.e.r. data."); + } + } + } + throw Error("Could not make sense of p.a.c.k.e.r data (unexpected code structure)"); + } + function _replacestrings(source) { + return source; + } +} + + +/** + * Uses Sora's fetchv2 on ipad, fallbacks to regular fetch on Windows + * @author ShadeOfChaos + * + * @param {string} url The URL to make the request to. + * @param {object} [options] The options to use for the request. + * @param {object} [options.headers] The headers to send with the request. + * @param {string} [options.method='GET'] The method to use for the request. + * @param {string} [options.body=null] The body of the request. + * + * @returns {Promise<Response|null>} The response from the server, or null if the + * request failed. + */ +async function soraFetch(url, options = { headers: {}, method: 'GET', body: null }) { + try { + return await fetchv2(url, options.headers ?? {}, options.method ?? 'GET', options.body ?? null); + } catch(e) { + try { + return await fetch(url, options); + } catch(error) { + return null; + } + } +} +/* REMOVE_END */ + +/* SCHEME END */ + +function cleanHtmlSymbols(string) { + if (!string) return ""; + return string + .replace(/’/g, "'") + .replace(/–/g, "-") + .replace(/&#[0-9]+;/g, "") + .replace(/\r?\n|\r/g, " ") + .replace(/\s+/g, " ") + .trim(); +} + +function decryptLink(encryptedLinkBase64, secretKey) { + try { + const encryptedData = CryptoJS.enc.Base64.parse(encryptedLinkBase64); + const iv = encryptedData.words.slice(0, 4); + const encryptedBytes = encryptedData.words.slice(4); + const ivWordArray = CryptoJS.lib.WordArray.create(iv); + const encryptedWordArray = CryptoJS.lib.WordArray.create(encryptedBytes); + + const decrypted = CryptoJS.AES.decrypt( + { ciphertext: encryptedWordArray }, + CryptoJS.enc.Utf8.parse(secretKey), + { iv: ivWordArray, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 } + ); + + return decrypted.toString(CryptoJS.enc.Utf8); + } catch (error) { + console.error('Error al descifrar:', error); + return null; + } +} + +;(function (root, factory) { + if (typeof exports === "object") { + // CommonJS + module.exports = exports = factory(); + } + else if (typeof define === "function" && define.amd) { + // AMD + define([], factory); + } + else { + // Global (browser) + root.CryptoJS = factory(); + } +}(this, function () { + + /*globals window, global, require*/ + + /** + * CryptoJS core components. + */ + var CryptoJS = CryptoJS || (function (Math, undefined) { + + var crypto; + + // Native crypto from window (Browser) + if (typeof window !== 'undefined' && window.crypto) { + crypto = window.crypto; + } + + // Native crypto in web worker (Browser) + if (typeof self !== 'undefined' && self.crypto) { + crypto = self.crypto; + } + + // Native crypto from worker + if (typeof globalThis !== 'undefined' && globalThis.crypto) { + crypto = globalThis.crypto; + } + + // Native (experimental IE 11) crypto from window (Browser) + if (!crypto && typeof window !== 'undefined' && window.msCrypto) { + crypto = window.msCrypto; + } + + // Native crypto from global (NodeJS) + if (!crypto && typeof global !== 'undefined' && global.crypto) { + crypto = global.crypto; + } + + // Native crypto import via require (NodeJS) + if (!crypto && typeof require === 'function') { + try { + crypto = require('crypto'); + } catch (err) {} + } + + /* + * Cryptographically secure pseudorandom number generator + * + * As Math.random() is cryptographically not safe to use + */ + var cryptoSecureRandomInt = function () { + if (crypto) { + // Use getRandomValues method (Browser) + if (typeof crypto.getRandomValues === 'function') { + try { + return crypto.getRandomValues(new Uint32Array(1))[0]; + } catch (err) {} + } + + // Use randomBytes method (NodeJS) + if (typeof crypto.randomBytes === 'function') { + try { + return crypto.randomBytes(4).readInt32LE(); + } catch (err) {} + } + } + + throw new Error('Native crypto module could not be used to get secure random number.'); + }; + + /* + * Local polyfill of Object.create + + */ + var create = Object.create || (function () { + function F() {} + + return function (obj) { + var subtype; + + F.prototype = obj; + + subtype = new F(); + + F.prototype = null; + + return subtype; + }; + }()); + + /** + * CryptoJS namespace. + */ + var C = {}; + + /** + * Library namespace. + */ + var C_lib = C.lib = {}; + + /** + * Base object for prototypal inheritance. + */ + var Base = C_lib.Base = (function () { + + + return { + /** + * Creates a new object that inherits from this object. + * + * @param {Object} overrides Properties to copy into the new object. + * + * @return {Object} The new object. + * + * @static + * + * @example + * + * var MyType = CryptoJS.lib.Base.extend({ + * field: 'value', + * + * method: function () { + * } + * }); + */ + extend: function (overrides) { + // Spawn + var subtype = create(this); + + // Augment + if (overrides) { + subtype.mixIn(overrides); + } + + // Create default initializer + if (!subtype.hasOwnProperty('init') || this.init === subtype.init) { + subtype.init = function () { + subtype.$super.init.apply(this, arguments); + }; + } + + // Initializer's prototype is the subtype object + subtype.init.prototype = subtype; + + // Reference supertype + subtype.$super = this; + + return subtype; + }, + + /** + * Extends this object and runs the init method. + * Arguments to create() will be passed to init(). + * + * @return {Object} The new object. + * + * @static + * + * @example + * + * var instance = MyType.create(); + */ + create: function () { + var instance = this.extend(); + instance.init.apply(instance, arguments); + + return instance; + }, + + /** + * Initializes a newly created object. + * Override this method to add some logic when your objects are created. + * + * @example + * + * var MyType = CryptoJS.lib.Base.extend({ + * init: function () { + * // ... + * } + * }); + */ + init: function () { + }, + + /** + * Copies properties into this object. + * + * @param {Object} properties The properties to mix in. + * + * @example + * + * MyType.mixIn({ + * field: 'value' + * }); + */ + mixIn: function (properties) { + for (var propertyName in properties) { + if (properties.hasOwnProperty(propertyName)) { + this[propertyName] = properties[propertyName]; + } + } + + // IE won't copy toString using the loop above + if (properties.hasOwnProperty('toString')) { + this.toString = properties.toString; + } + }, + + /** + * Creates a copy of this object. + * + * @return {Object} The clone. + * + * @example + * + * var clone = instance.clone(); + */ + clone: function () { + return this.init.prototype.extend(this); + } + }; + }()); + + /** + * An array of 32-bit words. + * + * @property {Array} words The array of 32-bit words. + * @property {number} sigBytes The number of significant bytes in this word array. + */ + var WordArray = C_lib.WordArray = Base.extend({ + /** + * Initializes a newly created word array. + * + * @param {Array} words (Optional) An array of 32-bit words. + * @param {number} sigBytes (Optional) The number of significant bytes in the words. + * + * @example + * + * var wordArray = CryptoJS.lib.WordArray.create(); + * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607]); + * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607], 6); + */ + init: function (words, sigBytes) { + words = this.words = words || []; + + if (sigBytes != undefined) { + this.sigBytes = sigBytes; + } else { + this.sigBytes = words.length * 4; + } + }, + + /** + * Converts this word array to a string. + * + * @param {Encoder} encoder (Optional) The encoding strategy to use. Default: CryptoJS.enc.Hex + * + * @return {string} The stringified word array. + * + * @example + * + * var string = wordArray + ''; + * var string = wordArray.toString(); + * var string = wordArray.toString(CryptoJS.enc.Utf8); + */ + toString: function (encoder) { + return (encoder || Hex).stringify(this); + }, + + /** + * Concatenates a word array to this word array. + * + * @param {WordArray} wordArray The word array to append. + * + * @return {WordArray} This word array. + * + * @example + * + * wordArray1.concat(wordArray2); + */ + concat: function (wordArray) { + // Shortcuts + var thisWords = this.words; + var thatWords = wordArray.words; + var thisSigBytes = this.sigBytes; + var thatSigBytes = wordArray.sigBytes; + + // Clamp excess bits + this.clamp(); + + // Concat + if (thisSigBytes % 4) { + // Copy one byte at a time + for (var i = 0; i < thatSigBytes; i++) { + var thatByte = (thatWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; + thisWords[(thisSigBytes + i) >>> 2] |= thatByte << (24 - ((thisSigBytes + i) % 4) * 8); + } + } else { + // Copy one word at a time + for (var j = 0; j < thatSigBytes; j += 4) { + thisWords[(thisSigBytes + j) >>> 2] = thatWords[j >>> 2]; + } + } + this.sigBytes += thatSigBytes; + + // Chainable + return this; + }, + + /** + * Removes insignificant bits. + * + * @example + * + * wordArray.clamp(); + */ + clamp: function () { + // Shortcuts + var words = this.words; + var sigBytes = this.sigBytes; + + // Clamp + words[sigBytes >>> 2] &= 0xffffffff << (32 - (sigBytes % 4) * 8); + words.length = Math.ceil(sigBytes / 4); + }, + + /** + * Creates a copy of this word array. + * + * @return {WordArray} The clone. + * + * @example + * + * var clone = wordArray.clone(); + */ + clone: function () { + var clone = Base.clone.call(this); + clone.words = this.words.slice(0); + + return clone; + }, + + /** + * Creates a word array filled with random bytes. + * + * @param {number} nBytes The number of random bytes to generate. + * + * @return {WordArray} The random word array. + * + * @static + * + * @example + * + * var wordArray = CryptoJS.lib.WordArray.random(16); + */ + random: function (nBytes) { + var words = []; + + for (var i = 0; i < nBytes; i += 4) { + words.push(cryptoSecureRandomInt()); + } + + return new WordArray.init(words, nBytes); + } + }); + + /** + * Encoder namespace. + */ + var C_enc = C.enc = {}; + + /** + * Hex encoding strategy. + */ + var Hex = C_enc.Hex = { + /** + * Converts a word array to a hex string. + * + * @param {WordArray} wordArray The word array. + * + * @return {string} The hex string. + * + * @static + * + * @example + * + * var hexString = CryptoJS.enc.Hex.stringify(wordArray); + */ + stringify: function (wordArray) { + // Shortcuts + var words = wordArray.words; + var sigBytes = wordArray.sigBytes; + + // Convert + var hexChars = []; + for (var i = 0; i < sigBytes; i++) { + var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; + hexChars.push((bite >>> 4).toString(16)); + hexChars.push((bite & 0x0f).toString(16)); + } + + return hexChars.join(''); + }, + + /** + * Converts a hex string to a word array. + * + * @param {string} hexStr The hex string. + * + * @return {WordArray} The word array. + * + * @static + * + * @example + * + * var wordArray = CryptoJS.enc.Hex.parse(hexString); + */ + parse: function (hexStr) { + // Shortcut + var hexStrLength = hexStr.length; + + // Convert + var words = []; + for (var i = 0; i < hexStrLength; i += 2) { + words[i >>> 3] |= parseInt(hexStr.substr(i, 2), 16) << (24 - (i % 8) * 4); + } + + return new WordArray.init(words, hexStrLength / 2); + } + }; + + /** + * Latin1 encoding strategy. + */ + var Latin1 = C_enc.Latin1 = { + /** + * Converts a word array to a Latin1 string. + * + * @param {WordArray} wordArray The word array. + * + * @return {string} The Latin1 string. + * + * @static + * + * @example + * + * var latin1String = CryptoJS.enc.Latin1.stringify(wordArray); + */ + stringify: function (wordArray) { + // Shortcuts + var words = wordArray.words; + var sigBytes = wordArray.sigBytes; + + // Convert + var latin1Chars = []; + for (var i = 0; i < sigBytes; i++) { + var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; + latin1Chars.push(String.fromCharCode(bite)); + } + + return latin1Chars.join(''); + }, + + /** + * Converts a Latin1 string to a word array. + * + * @param {string} latin1Str The Latin1 string. + * + * @return {WordArray} The word array. + * + * @static + * + * @example + * + * var wordArray = CryptoJS.enc.Latin1.parse(latin1String); + */ + parse: function (latin1Str) { + // Shortcut + var latin1StrLength = latin1Str.length; + + // Convert + var words = []; + for (var i = 0; i < latin1StrLength; i++) { + words[i >>> 2] |= (latin1Str.charCodeAt(i) & 0xff) << (24 - (i % 4) * 8); + } + + return new WordArray.init(words, latin1StrLength); + } + }; + + /** + * UTF-8 encoding strategy. + */ + var Utf8 = C_enc.Utf8 = { + /** + * Converts a word array to a UTF-8 string. + * + * @param {WordArray} wordArray The word array. + * + * @return {string} The UTF-8 string. + * + * @static + * + * @example + * + * var utf8String = CryptoJS.enc.Utf8.stringify(wordArray); + */ + stringify: function (wordArray) { + try { + return decodeURIComponent(escape(Latin1.stringify(wordArray))); + } catch (e) { + throw new Error('Malformed UTF-8 data'); + } + }, + + /** + * Converts a UTF-8 string to a word array. + * + * @param {string} utf8Str The UTF-8 string. + * + * @return {WordArray} The word array. + * + * @static + * + * @example + * + * var wordArray = CryptoJS.enc.Utf8.parse(utf8String); + */ + parse: function (utf8Str) { + return Latin1.parse(unescape(encodeURIComponent(utf8Str))); + } + }; + + /** + * Abstract buffered block algorithm template. + * + * The property blockSize must be implemented in a concrete subtype. + * + * @property {number} _minBufferSize The number of blocks that should be kept unprocessed in the buffer. Default: 0 + */ + var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm = Base.extend({ + /** + * Resets this block algorithm's data buffer to its initial state. + * + * @example + * + * bufferedBlockAlgorithm.reset(); + */ + reset: function () { + // Initial values + this._data = new WordArray.init(); + this._nDataBytes = 0; + }, + + /** + * Adds new data to this block algorithm's buffer. + * + * @param {WordArray|string} data The data to append. Strings are converted to a WordArray using UTF-8. + * + * @example + * + * bufferedBlockAlgorithm._append('data'); + * bufferedBlockAlgorithm._append(wordArray); + */ + _append: function (data) { + // Convert string to WordArray, else assume WordArray already + if (typeof data == 'string') { + data = Utf8.parse(data); + } + + // Append + this._data.concat(data); + this._nDataBytes += data.sigBytes; + }, + + /** + * Processes available data blocks. + * + * This method invokes _doProcessBlock(offset), which must be implemented by a concrete subtype. + * + * @param {boolean} doFlush Whether all blocks and partial blocks should be processed. + * + * @return {WordArray} The processed data. + * + * @example + * + * var processedData = bufferedBlockAlgorithm._process(); + * var processedData = bufferedBlockAlgorithm._process(!!'flush'); + */ + _process: function (doFlush) { + var processedWords; + + // Shortcuts + var data = this._data; + var dataWords = data.words; + var dataSigBytes = data.sigBytes; + var blockSize = this.blockSize; + var blockSizeBytes = blockSize * 4; + + // Count blocks ready + var nBlocksReady = dataSigBytes / blockSizeBytes; + if (doFlush) { + // Round up to include partial blocks + nBlocksReady = Math.ceil(nBlocksReady); + } else { + // Round down to include only full blocks, + // less the number of blocks that must remain in the buffer + nBlocksReady = Math.max((nBlocksReady | 0) - this._minBufferSize, 0); + } + + // Count words ready + var nWordsReady = nBlocksReady * blockSize; + + // Count bytes ready + var nBytesReady = Math.min(nWordsReady * 4, dataSigBytes); + + // Process blocks + if (nWordsReady) { + for (var offset = 0; offset < nWordsReady; offset += blockSize) { + // Perform concrete-algorithm logic + this._doProcessBlock(dataWords, offset); + } + + // Remove processed words + processedWords = dataWords.splice(0, nWordsReady); + data.sigBytes -= nBytesReady; + } + + // Return processed words + return new WordArray.init(processedWords, nBytesReady); + }, + + /** + * Creates a copy of this object. + * + * @return {Object} The clone. + * + * @example + * + * var clone = bufferedBlockAlgorithm.clone(); + */ + clone: function () { + var clone = Base.clone.call(this); + clone._data = this._data.clone(); + + return clone; + }, + + _minBufferSize: 0 + }); + + /** + * Abstract hasher template. + * + * @property {number} blockSize The number of 32-bit words this hasher operates on. Default: 16 (512 bits) + */ + var Hasher = C_lib.Hasher = BufferedBlockAlgorithm.extend({ + /** + * Configuration options. + */ + cfg: Base.extend(), + + /** + * Initializes a newly created hasher. + * + * @param {Object} cfg (Optional) The configuration options to use for this hash computation. + * + * @example + * + * var hasher = CryptoJS.algo.SHA256.create(); + */ + init: function (cfg) { + // Apply config defaults + this.cfg = this.cfg.extend(cfg); + + // Set initial values + this.reset(); + }, + + /** + * Resets this hasher to its initial state. + * + * @example + * + * hasher.reset(); + */ + reset: function () { + // Reset data buffer + BufferedBlockAlgorithm.reset.call(this); + + // Perform concrete-hasher logic + this._doReset(); + }, + + /** + * Updates this hasher with a message. + * + * @param {WordArray|string} messageUpdate The message to append. + * + * @return {Hasher} This hasher. + * + * @example + * + * hasher.update('message'); + * hasher.update(wordArray); + */ + update: function (messageUpdate) { + // Append + this._append(messageUpdate); + + // Update the hash + this._process(); + + // Chainable + return this; + }, + + /** + * Finalizes the hash computation. + * Note that the finalize operation is effectively a destructive, read-once operation. + * + * @param {WordArray|string} messageUpdate (Optional) A final message update. + * + * @return {WordArray} The hash. + * + * @example + * + * var hash = hasher.finalize(); + * var hash = hasher.finalize('message'); + * var hash = hasher.finalize(wordArray); + */ + finalize: function (messageUpdate) { + // Final message update + if (messageUpdate) { + this._append(messageUpdate); + } + + // Perform concrete-hasher logic + var hash = this._doFinalize(); + + return hash; + }, + + blockSize: 512/32, + + /** + * Creates a shortcut function to a hasher's object interface. + * + * @param {Hasher} hasher The hasher to create a helper for. + * + * @return {Function} The shortcut function. + * + * @static + * + * @example + * + * var SHA256 = CryptoJS.lib.Hasher._createHelper(CryptoJS.algo.SHA256); + */ + _createHelper: function (hasher) { + return function (message, cfg) { + return new hasher.init(cfg).finalize(message); + }; + }, + + /** + * Creates a shortcut function to the HMAC's object interface. + * + * @param {Hasher} hasher The hasher to use in this HMAC helper. + * + * @return {Function} The shortcut function. + * + * @static + * + * @example + * + * var HmacSHA256 = CryptoJS.lib.Hasher._createHmacHelper(CryptoJS.algo.SHA256); + */ + _createHmacHelper: function (hasher) { + return function (message, key) { + return new C_algo.HMAC.init(hasher, key).finalize(message); + }; + } + }); + + /** + * Algorithm namespace. + */ + var C_algo = C.algo = {}; + + return C; + }(Math)); + + + (function (undefined) { + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var Base = C_lib.Base; + var X32WordArray = C_lib.WordArray; + + /** + * x64 namespace. + */ + var C_x64 = C.x64 = {}; + + /** + * A 64-bit word. + */ + var X64Word = C_x64.Word = Base.extend({ + /** + * Initializes a newly created 64-bit word. + * + * @param {number} high The high 32 bits. + * @param {number} low The low 32 bits. + * + * @example + * + * var x64Word = CryptoJS.x64.Word.create(0x00010203, 0x04050607); + */ + init: function (high, low) { + this.high = high; + this.low = low; + } + + /** + * Bitwise NOTs this word. + * + * @return {X64Word} A new x64-Word object after negating. + * + * @example + * + * var negated = x64Word.not(); + */ + // not: function () { + // var high = ~this.high; + // var low = ~this.low; + + // return X64Word.create(high, low); + // }, + + /** + * Bitwise ANDs this word with the passed word. + * + * @param {X64Word} word The x64-Word to AND with this word. + * + * @return {X64Word} A new x64-Word object after ANDing. + * + * @example + * + * var anded = x64Word.and(anotherX64Word); + */ + // and: function (word) { + // var high = this.high & word.high; + // var low = this.low & word.low; + + // return X64Word.create(high, low); + // }, + + /** + * Bitwise ORs this word with the passed word. + * + * @param {X64Word} word The x64-Word to OR with this word. + * + * @return {X64Word} A new x64-Word object after ORing. + * + * @example + * + * var ored = x64Word.or(anotherX64Word); + */ + // or: function (word) { + // var high = this.high | word.high; + // var low = this.low | word.low; + + // return X64Word.create(high, low); + // }, + + /** + * Bitwise XORs this word with the passed word. + * + * @param {X64Word} word The x64-Word to XOR with this word. + * + * @return {X64Word} A new x64-Word object after XORing. + * + * @example + * + * var xored = x64Word.xor(anotherX64Word); + */ + // xor: function (word) { + // var high = this.high ^ word.high; + // var low = this.low ^ word.low; + + // return X64Word.create(high, low); + // }, + + /** + * Shifts this word n bits to the left. + * + * @param {number} n The number of bits to shift. + * + * @return {X64Word} A new x64-Word object after shifting. + * + * @example + * + * var shifted = x64Word.shiftL(25); + */ + // shiftL: function (n) { + // if (n < 32) { + // var high = (this.high << n) | (this.low >>> (32 - n)); + // var low = this.low << n; + // } else { + // var high = this.low << (n - 32); + // var low = 0; + // } + + // return X64Word.create(high, low); + // }, + + /** + * Shifts this word n bits to the right. + * + * @param {number} n The number of bits to shift. + * + * @return {X64Word} A new x64-Word object after shifting. + * + * @example + * + * var shifted = x64Word.shiftR(7); + */ + // shiftR: function (n) { + // if (n < 32) { + // var low = (this.low >>> n) | (this.high << (32 - n)); + // var high = this.high >>> n; + // } else { + // var low = this.high >>> (n - 32); + // var high = 0; + // } + + // return X64Word.create(high, low); + // }, + + /** + * Rotates this word n bits to the left. + * + * @param {number} n The number of bits to rotate. + * + * @return {X64Word} A new x64-Word object after rotating. + * + * @example + * + * var rotated = x64Word.rotL(25); + */ + // rotL: function (n) { + // return this.shiftL(n).or(this.shiftR(64 - n)); + // }, + + /** + * Rotates this word n bits to the right. + * + * @param {number} n The number of bits to rotate. + * + * @return {X64Word} A new x64-Word object after rotating. + * + * @example + * + * var rotated = x64Word.rotR(7); + */ + // rotR: function (n) { + // return this.shiftR(n).or(this.shiftL(64 - n)); + // }, + + /** + * Adds this word with the passed word. + * + * @param {X64Word} word The x64-Word to add with this word. + * + * @return {X64Word} A new x64-Word object after adding. + * + * @example + * + * var added = x64Word.add(anotherX64Word); + */ + // add: function (word) { + // var low = (this.low + word.low) | 0; + // var carry = (low >>> 0) < (this.low >>> 0) ? 1 : 0; + // var high = (this.high + word.high + carry) | 0; + + // return X64Word.create(high, low); + // } + }); + + /** + * An array of 64-bit words. + * + * @property {Array} words The array of CryptoJS.x64.Word objects. + * @property {number} sigBytes The number of significant bytes in this word array. + */ + var X64WordArray = C_x64.WordArray = Base.extend({ + /** + * Initializes a newly created word array. + * + * @param {Array} words (Optional) An array of CryptoJS.x64.Word objects. + * @param {number} sigBytes (Optional) The number of significant bytes in the words. + * + * @example + * + * var wordArray = CryptoJS.x64.WordArray.create(); + * + * var wordArray = CryptoJS.x64.WordArray.create([ + * CryptoJS.x64.Word.create(0x00010203, 0x04050607), + * CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f) + * ]); + * + * var wordArray = CryptoJS.x64.WordArray.create([ + * CryptoJS.x64.Word.create(0x00010203, 0x04050607), + * CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f) + * ], 10); + */ + init: function (words, sigBytes) { + words = this.words = words || []; + + if (sigBytes != undefined) { + this.sigBytes = sigBytes; + } else { + this.sigBytes = words.length * 8; + } + }, + + /** + * Converts this 64-bit word array to a 32-bit word array. + * + * @return {CryptoJS.lib.WordArray} This word array's data as a 32-bit word array. + * + * @example + * + * var x32WordArray = x64WordArray.toX32(); + */ + toX32: function () { + // Shortcuts + var x64Words = this.words; + var x64WordsLength = x64Words.length; + + // Convert + var x32Words = []; + for (var i = 0; i < x64WordsLength; i++) { + var x64Word = x64Words[i]; + x32Words.push(x64Word.high); + x32Words.push(x64Word.low); + } + + return X32WordArray.create(x32Words, this.sigBytes); + }, + + /** + * Creates a copy of this word array. + * + * @return {X64WordArray} The clone. + * + * @example + * + * var clone = x64WordArray.clone(); + */ + clone: function () { + var clone = Base.clone.call(this); + + // Clone "words" array + var words = clone.words = this.words.slice(0); + + // Clone each X64Word object + var wordsLength = words.length; + for (var i = 0; i < wordsLength; i++) { + words[i] = words[i].clone(); + } + + return clone; + } + }); + }()); + + + (function () { + // Check if typed arrays are supported + if (typeof ArrayBuffer != 'function') { + return; + } + + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var WordArray = C_lib.WordArray; + + // Reference original init + var superInit = WordArray.init; + + // Augment WordArray.init to handle typed arrays + var subInit = WordArray.init = function (typedArray) { + // Convert buffers to uint8 + if (typedArray instanceof ArrayBuffer) { + typedArray = new Uint8Array(typedArray); + } + + // Convert other array views to uint8 + if ( + typedArray instanceof Int8Array || + (typeof Uint8ClampedArray !== "undefined" && typedArray instanceof Uint8ClampedArray) || + typedArray instanceof Int16Array || + typedArray instanceof Uint16Array || + typedArray instanceof Int32Array || + typedArray instanceof Uint32Array || + typedArray instanceof Float32Array || + typedArray instanceof Float64Array + ) { + typedArray = new Uint8Array(typedArray.buffer, typedArray.byteOffset, typedArray.byteLength); + } + + // Handle Uint8Array + if (typedArray instanceof Uint8Array) { + // Shortcut + var typedArrayByteLength = typedArray.byteLength; + + // Extract bytes + var words = []; + for (var i = 0; i < typedArrayByteLength; i++) { + words[i >>> 2] |= typedArray[i] << (24 - (i % 4) * 8); + } + + // Initialize this word array + superInit.call(this, words, typedArrayByteLength); + } else { + // Else call normal init + superInit.apply(this, arguments); + } + }; + + subInit.prototype = WordArray; + }()); + + + (function () { + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var WordArray = C_lib.WordArray; + var C_enc = C.enc; + + /** + * UTF-16 BE encoding strategy. + */ + var Utf16BE = C_enc.Utf16 = C_enc.Utf16BE = { + /** + * Converts a word array to a UTF-16 BE string. + * + * @param {WordArray} wordArray The word array. + * + * @return {string} The UTF-16 BE string. + * + * @static + * + * @example + * + * var utf16String = CryptoJS.enc.Utf16.stringify(wordArray); + */ + stringify: function (wordArray) { + // Shortcuts + var words = wordArray.words; + var sigBytes = wordArray.sigBytes; + + // Convert + var utf16Chars = []; + for (var i = 0; i < sigBytes; i += 2) { + var codePoint = (words[i >>> 2] >>> (16 - (i % 4) * 8)) & 0xffff; + utf16Chars.push(String.fromCharCode(codePoint)); + } + + return utf16Chars.join(''); + }, + + /** + * Converts a UTF-16 BE string to a word array. + * + * @param {string} utf16Str The UTF-16 BE string. + * + * @return {WordArray} The word array. + * + * @static + * + * @example + * + * var wordArray = CryptoJS.enc.Utf16.parse(utf16String); + */ + parse: function (utf16Str) { + // Shortcut + var utf16StrLength = utf16Str.length; + + // Convert + var words = []; + for (var i = 0; i < utf16StrLength; i++) { + words[i >>> 1] |= utf16Str.charCodeAt(i) << (16 - (i % 2) * 16); + } + + return WordArray.create(words, utf16StrLength * 2); + } + }; + + /** + * UTF-16 LE encoding strategy. + */ + C_enc.Utf16LE = { + /** + * Converts a word array to a UTF-16 LE string. + * + * @param {WordArray} wordArray The word array. + * + * @return {string} The UTF-16 LE string. + * + * @static + * + * @example + * + * var utf16Str = CryptoJS.enc.Utf16LE.stringify(wordArray); + */ + stringify: function (wordArray) { + // Shortcuts + var words = wordArray.words; + var sigBytes = wordArray.sigBytes; + + // Convert + var utf16Chars = []; + for (var i = 0; i < sigBytes; i += 2) { + var codePoint = swapEndian((words[i >>> 2] >>> (16 - (i % 4) * 8)) & 0xffff); + utf16Chars.push(String.fromCharCode(codePoint)); + } + + return utf16Chars.join(''); + }, + + /** + * Converts a UTF-16 LE string to a word array. + * + * @param {string} utf16Str The UTF-16 LE string. + * + * @return {WordArray} The word array. + * + * @static + * + * @example + * + * var wordArray = CryptoJS.enc.Utf16LE.parse(utf16Str); + */ + parse: function (utf16Str) { + // Shortcut + var utf16StrLength = utf16Str.length; + + // Convert + var words = []; + for (var i = 0; i < utf16StrLength; i++) { + words[i >>> 1] |= swapEndian(utf16Str.charCodeAt(i) << (16 - (i % 2) * 16)); + } + + return WordArray.create(words, utf16StrLength * 2); + } + }; + + function swapEndian(word) { + return ((word << 8) & 0xff00ff00) | ((word >>> 8) & 0x00ff00ff); + } + }()); + + + (function () { + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var WordArray = C_lib.WordArray; + var C_enc = C.enc; + + /** + * Base64 encoding strategy. + */ + var Base64 = C_enc.Base64 = { + /** + * Converts a word array to a Base64 string. + * + * @param {WordArray} wordArray The word array. + * + * @return {string} The Base64 string. + * + * @static + * + * @example + * + * var base64String = CryptoJS.enc.Base64.stringify(wordArray); + */ + stringify: function (wordArray) { + // Shortcuts + var words = wordArray.words; + var sigBytes = wordArray.sigBytes; + var map = this._map; + + // Clamp excess bits + wordArray.clamp(); + + // Convert + var base64Chars = []; + for (var i = 0; i < sigBytes; i += 3) { + var byte1 = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; + var byte2 = (words[(i + 1) >>> 2] >>> (24 - ((i + 1) % 4) * 8)) & 0xff; + var byte3 = (words[(i + 2) >>> 2] >>> (24 - ((i + 2) % 4) * 8)) & 0xff; + + var triplet = (byte1 << 16) | (byte2 << 8) | byte3; + + for (var j = 0; (j < 4) && (i + j * 0.75 < sigBytes); j++) { + base64Chars.push(map.charAt((triplet >>> (6 * (3 - j))) & 0x3f)); + } + } + + // Add padding + var paddingChar = map.charAt(64); + if (paddingChar) { + while (base64Chars.length % 4) { + base64Chars.push(paddingChar); + } + } + + return base64Chars.join(''); + }, + + /** + * Converts a Base64 string to a word array. + * + * @param {string} base64Str The Base64 string. + * + * @return {WordArray} The word array. + * + * @static + * + * @example + * + * var wordArray = CryptoJS.enc.Base64.parse(base64String); + */ + parse: function (base64Str) { + // Shortcuts + var base64StrLength = base64Str.length; + var map = this._map; + var reverseMap = this._reverseMap; + + if (!reverseMap) { + reverseMap = this._reverseMap = []; + for (var j = 0; j < map.length; j++) { + reverseMap[map.charCodeAt(j)] = j; + } + } + + // Ignore padding + var paddingChar = map.charAt(64); + if (paddingChar) { + var paddingIndex = base64Str.indexOf(paddingChar); + if (paddingIndex !== -1) { + base64StrLength = paddingIndex; + } + } + + // Convert + return parseLoop(base64Str, base64StrLength, reverseMap); + + }, + + _map: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=' + }; + + function parseLoop(base64Str, base64StrLength, reverseMap) { + var words = []; + var nBytes = 0; + for (var i = 0; i < base64StrLength; i++) { + if (i % 4) { + var bits1 = reverseMap[base64Str.charCodeAt(i - 1)] << ((i % 4) * 2); + var bits2 = reverseMap[base64Str.charCodeAt(i)] >>> (6 - (i % 4) * 2); + var bitsCombined = bits1 | bits2; + words[nBytes >>> 2] |= bitsCombined << (24 - (nBytes % 4) * 8); + nBytes++; + } + } + return WordArray.create(words, nBytes); + } + }()); + + + (function () { + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var WordArray = C_lib.WordArray; + var C_enc = C.enc; + + /** + * Base64url encoding strategy. + */ + var Base64url = C_enc.Base64url = { + /** + * Converts a word array to a Base64url string. + * + * @param {WordArray} wordArray The word array. + * + * @param {boolean} urlSafe Whether to use url safe + * + * @return {string} The Base64url string. + * + * @static + * + * @example + * + * var base64String = CryptoJS.enc.Base64url.stringify(wordArray); + */ + stringify: function (wordArray, urlSafe=true) { + // Shortcuts + var words = wordArray.words; + var sigBytes = wordArray.sigBytes; + var map = urlSafe ? this._safe_map : this._map; + + // Clamp excess bits + wordArray.clamp(); + + // Convert + var base64Chars = []; + for (var i = 0; i < sigBytes; i += 3) { + var byte1 = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; + var byte2 = (words[(i + 1) >>> 2] >>> (24 - ((i + 1) % 4) * 8)) & 0xff; + var byte3 = (words[(i + 2) >>> 2] >>> (24 - ((i + 2) % 4) * 8)) & 0xff; + + var triplet = (byte1 << 16) | (byte2 << 8) | byte3; + + for (var j = 0; (j < 4) && (i + j * 0.75 < sigBytes); j++) { + base64Chars.push(map.charAt((triplet >>> (6 * (3 - j))) & 0x3f)); + } + } + + // Add padding + var paddingChar = map.charAt(64); + if (paddingChar) { + while (base64Chars.length % 4) { + base64Chars.push(paddingChar); + } + } + + return base64Chars.join(''); + }, + + /** + * Converts a Base64url string to a word array. + * + * @param {string} base64Str The Base64url string. + * + * @param {boolean} urlSafe Whether to use url safe + * + * @return {WordArray} The word array. + * + * @static + * + * @example + * + * var wordArray = CryptoJS.enc.Base64url.parse(base64String); + */ + parse: function (base64Str, urlSafe=true) { + // Shortcuts + var base64StrLength = base64Str.length; + var map = urlSafe ? this._safe_map : this._map; + var reverseMap = this._reverseMap; + + if (!reverseMap) { + reverseMap = this._reverseMap = []; + for (var j = 0; j < map.length; j++) { + reverseMap[map.charCodeAt(j)] = j; + } + } + + // Ignore padding + var paddingChar = map.charAt(64); + if (paddingChar) { + var paddingIndex = base64Str.indexOf(paddingChar); + if (paddingIndex !== -1) { + base64StrLength = paddingIndex; + } + } + + // Convert + return parseLoop(base64Str, base64StrLength, reverseMap); + + }, + + _map: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=', + _safe_map: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_', + }; + + function parseLoop(base64Str, base64StrLength, reverseMap) { + var words = []; + var nBytes = 0; + for (var i = 0; i < base64StrLength; i++) { + if (i % 4) { + var bits1 = reverseMap[base64Str.charCodeAt(i - 1)] << ((i % 4) * 2); + var bits2 = reverseMap[base64Str.charCodeAt(i)] >>> (6 - (i % 4) * 2); + var bitsCombined = bits1 | bits2; + words[nBytes >>> 2] |= bitsCombined << (24 - (nBytes % 4) * 8); + nBytes++; + } + } + return WordArray.create(words, nBytes); + } + }()); + + (function (Math) { + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var WordArray = C_lib.WordArray; + var Hasher = C_lib.Hasher; + var C_algo = C.algo; + + // Constants table + var T = []; + + // Compute constants + (function () { + for (var i = 0; i < 64; i++) { + T[i] = (Math.abs(Math.sin(i + 1)) * 0x100000000) | 0; + } + }()); + + /** + * MD5 hash algorithm. + */ + var MD5 = C_algo.MD5 = Hasher.extend({ + _doReset: function () { + this._hash = new WordArray.init([ + 0x67452301, 0xefcdab89, + 0x98badcfe, 0x10325476 + ]); + }, + + _doProcessBlock: function (M, offset) { + // Swap endian + for (var i = 0; i < 16; i++) { + // Shortcuts + var offset_i = offset + i; + var M_offset_i = M[offset_i]; + + M[offset_i] = ( + (((M_offset_i << 8) | (M_offset_i >>> 24)) & 0x00ff00ff) | + (((M_offset_i << 24) | (M_offset_i >>> 8)) & 0xff00ff00) + ); + } + + // Shortcuts + var H = this._hash.words; + + var M_offset_0 = M[offset + 0]; + var M_offset_1 = M[offset + 1]; + var M_offset_2 = M[offset + 2]; + var M_offset_3 = M[offset + 3]; + var M_offset_4 = M[offset + 4]; + var M_offset_5 = M[offset + 5]; + var M_offset_6 = M[offset + 6]; + var M_offset_7 = M[offset + 7]; + var M_offset_8 = M[offset + 8]; + var M_offset_9 = M[offset + 9]; + var M_offset_10 = M[offset + 10]; + var M_offset_11 = M[offset + 11]; + var M_offset_12 = M[offset + 12]; + var M_offset_13 = M[offset + 13]; + var M_offset_14 = M[offset + 14]; + var M_offset_15 = M[offset + 15]; + + // Working varialbes + var a = H[0]; + var b = H[1]; + var c = H[2]; + var d = H[3]; + + // Computation + a = FF(a, b, c, d, M_offset_0, 7, T[0]); + d = FF(d, a, b, c, M_offset_1, 12, T[1]); + c = FF(c, d, a, b, M_offset_2, 17, T[2]); + b = FF(b, c, d, a, M_offset_3, 22, T[3]); + a = FF(a, b, c, d, M_offset_4, 7, T[4]); + d = FF(d, a, b, c, M_offset_5, 12, T[5]); + c = FF(c, d, a, b, M_offset_6, 17, T[6]); + b = FF(b, c, d, a, M_offset_7, 22, T[7]); + a = FF(a, b, c, d, M_offset_8, 7, T[8]); + d = FF(d, a, b, c, M_offset_9, 12, T[9]); + c = FF(c, d, a, b, M_offset_10, 17, T[10]); + b = FF(b, c, d, a, M_offset_11, 22, T[11]); + a = FF(a, b, c, d, M_offset_12, 7, T[12]); + d = FF(d, a, b, c, M_offset_13, 12, T[13]); + c = FF(c, d, a, b, M_offset_14, 17, T[14]); + b = FF(b, c, d, a, M_offset_15, 22, T[15]); + + a = GG(a, b, c, d, M_offset_1, 5, T[16]); + d = GG(d, a, b, c, M_offset_6, 9, T[17]); + c = GG(c, d, a, b, M_offset_11, 14, T[18]); + b = GG(b, c, d, a, M_offset_0, 20, T[19]); + a = GG(a, b, c, d, M_offset_5, 5, T[20]); + d = GG(d, a, b, c, M_offset_10, 9, T[21]); + c = GG(c, d, a, b, M_offset_15, 14, T[22]); + b = GG(b, c, d, a, M_offset_4, 20, T[23]); + a = GG(a, b, c, d, M_offset_9, 5, T[24]); + d = GG(d, a, b, c, M_offset_14, 9, T[25]); + c = GG(c, d, a, b, M_offset_3, 14, T[26]); + b = GG(b, c, d, a, M_offset_8, 20, T[27]); + a = GG(a, b, c, d, M_offset_13, 5, T[28]); + d = GG(d, a, b, c, M_offset_2, 9, T[29]); + c = GG(c, d, a, b, M_offset_7, 14, T[30]); + b = GG(b, c, d, a, M_offset_12, 20, T[31]); + + a = HH(a, b, c, d, M_offset_5, 4, T[32]); + d = HH(d, a, b, c, M_offset_8, 11, T[33]); + c = HH(c, d, a, b, M_offset_11, 16, T[34]); + b = HH(b, c, d, a, M_offset_14, 23, T[35]); + a = HH(a, b, c, d, M_offset_1, 4, T[36]); + d = HH(d, a, b, c, M_offset_4, 11, T[37]); + c = HH(c, d, a, b, M_offset_7, 16, T[38]); + b = HH(b, c, d, a, M_offset_10, 23, T[39]); + a = HH(a, b, c, d, M_offset_13, 4, T[40]); + d = HH(d, a, b, c, M_offset_0, 11, T[41]); + c = HH(c, d, a, b, M_offset_3, 16, T[42]); + b = HH(b, c, d, a, M_offset_6, 23, T[43]); + a = HH(a, b, c, d, M_offset_9, 4, T[44]); + d = HH(d, a, b, c, M_offset_12, 11, T[45]); + c = HH(c, d, a, b, M_offset_15, 16, T[46]); + b = HH(b, c, d, a, M_offset_2, 23, T[47]); + + a = II(a, b, c, d, M_offset_0, 6, T[48]); + d = II(d, a, b, c, M_offset_7, 10, T[49]); + c = II(c, d, a, b, M_offset_14, 15, T[50]); + b = II(b, c, d, a, M_offset_5, 21, T[51]); + a = II(a, b, c, d, M_offset_12, 6, T[52]); + d = II(d, a, b, c, M_offset_3, 10, T[53]); + c = II(c, d, a, b, M_offset_10, 15, T[54]); + b = II(b, c, d, a, M_offset_1, 21, T[55]); + a = II(a, b, c, d, M_offset_8, 6, T[56]); + d = II(d, a, b, c, M_offset_15, 10, T[57]); + c = II(c, d, a, b, M_offset_6, 15, T[58]); + b = II(b, c, d, a, M_offset_13, 21, T[59]); + a = II(a, b, c, d, M_offset_4, 6, T[60]); + d = II(d, a, b, c, M_offset_11, 10, T[61]); + c = II(c, d, a, b, M_offset_2, 15, T[62]); + b = II(b, c, d, a, M_offset_9, 21, T[63]); + + // Intermediate hash value + H[0] = (H[0] + a) | 0; + H[1] = (H[1] + b) | 0; + H[2] = (H[2] + c) | 0; + H[3] = (H[3] + d) | 0; + }, + + _doFinalize: function () { + // Shortcuts + var data = this._data; + var dataWords = data.words; + + var nBitsTotal = this._nDataBytes * 8; + var nBitsLeft = data.sigBytes * 8; + + // Add padding + dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); + + var nBitsTotalH = Math.floor(nBitsTotal / 0x100000000); + var nBitsTotalL = nBitsTotal; + dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = ( + (((nBitsTotalH << 8) | (nBitsTotalH >>> 24)) & 0x00ff00ff) | + (((nBitsTotalH << 24) | (nBitsTotalH >>> 8)) & 0xff00ff00) + ); + dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = ( + (((nBitsTotalL << 8) | (nBitsTotalL >>> 24)) & 0x00ff00ff) | + (((nBitsTotalL << 24) | (nBitsTotalL >>> 8)) & 0xff00ff00) + ); + + data.sigBytes = (dataWords.length + 1) * 4; + + // Hash final blocks + this._process(); + + // Shortcuts + var hash = this._hash; + var H = hash.words; + + // Swap endian + for (var i = 0; i < 4; i++) { + // Shortcut + var H_i = H[i]; + + H[i] = (((H_i << 8) | (H_i >>> 24)) & 0x00ff00ff) | + (((H_i << 24) | (H_i >>> 8)) & 0xff00ff00); + } + + // Return final computed hash + return hash; + }, + + clone: function () { + var clone = Hasher.clone.call(this); + clone._hash = this._hash.clone(); + + return clone; + } + }); + + function FF(a, b, c, d, x, s, t) { + var n = a + ((b & c) | (~b & d)) + x + t; + return ((n << s) | (n >>> (32 - s))) + b; + } + + function GG(a, b, c, d, x, s, t) { + var n = a + ((b & d) | (c & ~d)) + x + t; + return ((n << s) | (n >>> (32 - s))) + b; + } + + function HH(a, b, c, d, x, s, t) { + var n = a + (b ^ c ^ d) + x + t; + return ((n << s) | (n >>> (32 - s))) + b; + } + + function II(a, b, c, d, x, s, t) { + var n = a + (c ^ (b | ~d)) + x + t; + return ((n << s) | (n >>> (32 - s))) + b; + } + + /** + * Shortcut function to the hasher's object interface. + * + * @param {WordArray|string} message The message to hash. + * + * @return {WordArray} The hash. + * + * @static + * + * @example + * + * var hash = CryptoJS.MD5('message'); + * var hash = CryptoJS.MD5(wordArray); + */ + C.MD5 = Hasher._createHelper(MD5); + + /** + * Shortcut function to the HMAC's object interface. + * + * @param {WordArray|string} message The message to hash. + * @param {WordArray|string} key The secret key. + * + * @return {WordArray} The HMAC. + * + * @static + * + * @example + * + * var hmac = CryptoJS.HmacMD5(message, key); + */ + C.HmacMD5 = Hasher._createHmacHelper(MD5); + }(Math)); + + + (function () { + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var WordArray = C_lib.WordArray; + var Hasher = C_lib.Hasher; + var C_algo = C.algo; + + // Reusable object + var W = []; + + /** + * SHA-1 hash algorithm. + */ + var SHA1 = C_algo.SHA1 = Hasher.extend({ + _doReset: function () { + this._hash = new WordArray.init([ + 0x67452301, 0xefcdab89, + 0x98badcfe, 0x10325476, + 0xc3d2e1f0 + ]); + }, + + _doProcessBlock: function (M, offset) { + // Shortcut + var H = this._hash.words; + + // Working variables + var a = H[0]; + var b = H[1]; + var c = H[2]; + var d = H[3]; + var e = H[4]; + + // Computation + for (var i = 0; i < 80; i++) { + if (i < 16) { + W[i] = M[offset + i] | 0; + } else { + var n = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16]; + W[i] = (n << 1) | (n >>> 31); + } + + var t = ((a << 5) | (a >>> 27)) + e + W[i]; + if (i < 20) { + t += ((b & c) | (~b & d)) + 0x5a827999; + } else if (i < 40) { + t += (b ^ c ^ d) + 0x6ed9eba1; + } else if (i < 60) { + t += ((b & c) | (b & d) | (c & d)) - 0x70e44324; + } else /* if (i < 80) */ { + t += (b ^ c ^ d) - 0x359d3e2a; + } + + e = d; + d = c; + c = (b << 30) | (b >>> 2); + b = a; + a = t; + } + + // Intermediate hash value + H[0] = (H[0] + a) | 0; + H[1] = (H[1] + b) | 0; + H[2] = (H[2] + c) | 0; + H[3] = (H[3] + d) | 0; + H[4] = (H[4] + e) | 0; + }, + + _doFinalize: function () { + // Shortcuts + var data = this._data; + var dataWords = data.words; + + var nBitsTotal = this._nDataBytes * 8; + var nBitsLeft = data.sigBytes * 8; + + // Add padding + dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); + dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor(nBitsTotal / 0x100000000); + dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal; + data.sigBytes = dataWords.length * 4; + + // Hash final blocks + this._process(); + + // Return final computed hash + return this._hash; + }, + + clone: function () { + var clone = Hasher.clone.call(this); + clone._hash = this._hash.clone(); + + return clone; + } + }); + + /** + * Shortcut function to the hasher's object interface. + * + * @param {WordArray|string} message The message to hash. + * + * @return {WordArray} The hash. + * + * @static + * + * @example + * + * var hash = CryptoJS.SHA1('message'); + * var hash = CryptoJS.SHA1(wordArray); + */ + C.SHA1 = Hasher._createHelper(SHA1); + + /** + * Shortcut function to the HMAC's object interface. + * + * @param {WordArray|string} message The message to hash. + * @param {WordArray|string} key The secret key. + * + * @return {WordArray} The HMAC. + * + * @static + * + * @example + * + * var hmac = CryptoJS.HmacSHA1(message, key); + */ + C.HmacSHA1 = Hasher._createHmacHelper(SHA1); + }()); + + + (function (Math) { + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var WordArray = C_lib.WordArray; + var Hasher = C_lib.Hasher; + var C_algo = C.algo; + + // Initialization and round constants tables + var H = []; + var K = []; + + // Compute constants + (function () { + function isPrime(n) { + var sqrtN = Math.sqrt(n); + for (var factor = 2; factor <= sqrtN; factor++) { + if (!(n % factor)) { + return false; + } + } + + return true; + } + + function getFractionalBits(n) { + return ((n - (n | 0)) * 0x100000000) | 0; + } + + var n = 2; + var nPrime = 0; + while (nPrime < 64) { + if (isPrime(n)) { + if (nPrime < 8) { + H[nPrime] = getFractionalBits(Math.pow(n, 1 / 2)); + } + K[nPrime] = getFractionalBits(Math.pow(n, 1 / 3)); + + nPrime++; + } + + n++; + } + }()); + + // Reusable object + var W = []; + + /** + * SHA-256 hash algorithm. + */ + var SHA256 = C_algo.SHA256 = Hasher.extend({ + _doReset: function () { + this._hash = new WordArray.init(H.slice(0)); + }, + + _doProcessBlock: function (M, offset) { + // Shortcut + var H = this._hash.words; + + // Working variables + var a = H[0]; + var b = H[1]; + var c = H[2]; + var d = H[3]; + var e = H[4]; + var f = H[5]; + var g = H[6]; + var h = H[7]; + + // Computation + for (var i = 0; i < 64; i++) { + if (i < 16) { + W[i] = M[offset + i] | 0; + } else { + var gamma0x = W[i - 15]; + var gamma0 = ((gamma0x << 25) | (gamma0x >>> 7)) ^ + ((gamma0x << 14) | (gamma0x >>> 18)) ^ + (gamma0x >>> 3); + + var gamma1x = W[i - 2]; + var gamma1 = ((gamma1x << 15) | (gamma1x >>> 17)) ^ + ((gamma1x << 13) | (gamma1x >>> 19)) ^ + (gamma1x >>> 10); + + W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16]; + } + + var ch = (e & f) ^ (~e & g); + var maj = (a & b) ^ (a & c) ^ (b & c); + + var sigma0 = ((a << 30) | (a >>> 2)) ^ ((a << 19) | (a >>> 13)) ^ ((a << 10) | (a >>> 22)); + var sigma1 = ((e << 26) | (e >>> 6)) ^ ((e << 21) | (e >>> 11)) ^ ((e << 7) | (e >>> 25)); + + var t1 = h + sigma1 + ch + K[i] + W[i]; + var t2 = sigma0 + maj; + + h = g; + g = f; + f = e; + e = (d + t1) | 0; + d = c; + c = b; + b = a; + a = (t1 + t2) | 0; + } + + // Intermediate hash value + H[0] = (H[0] + a) | 0; + H[1] = (H[1] + b) | 0; + H[2] = (H[2] + c) | 0; + H[3] = (H[3] + d) | 0; + H[4] = (H[4] + e) | 0; + H[5] = (H[5] + f) | 0; + H[6] = (H[6] + g) | 0; + H[7] = (H[7] + h) | 0; + }, + + _doFinalize: function () { + // Shortcuts + var data = this._data; + var dataWords = data.words; + + var nBitsTotal = this._nDataBytes * 8; + var nBitsLeft = data.sigBytes * 8; + + // Add padding + dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); + dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor(nBitsTotal / 0x100000000); + dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal; + data.sigBytes = dataWords.length * 4; + + // Hash final blocks + this._process(); + + // Return final computed hash + return this._hash; + }, + + clone: function () { + var clone = Hasher.clone.call(this); + clone._hash = this._hash.clone(); + + return clone; + } + }); + + /** + * Shortcut function to the hasher's object interface. + * + * @param {WordArray|string} message The message to hash. + * + * @return {WordArray} The hash. + * + * @static + * + * @example + * + * var hash = CryptoJS.SHA256('message'); + * var hash = CryptoJS.SHA256(wordArray); + */ + C.SHA256 = Hasher._createHelper(SHA256); + + /** + * Shortcut function to the HMAC's object interface. + * + * @param {WordArray|string} message The message to hash. + * @param {WordArray|string} key The secret key. + * + * @return {WordArray} The HMAC. + * + * @static + * + * @example + * + * var hmac = CryptoJS.HmacSHA256(message, key); + */ + C.HmacSHA256 = Hasher._createHmacHelper(SHA256); + }(Math)); + + + (function () { + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var WordArray = C_lib.WordArray; + var C_algo = C.algo; + var SHA256 = C_algo.SHA256; + + /** + * SHA-224 hash algorithm. + */ + var SHA224 = C_algo.SHA224 = SHA256.extend({ + _doReset: function () { + this._hash = new WordArray.init([ + 0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939, + 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4 + ]); + }, + + _doFinalize: function () { + var hash = SHA256._doFinalize.call(this); + + hash.sigBytes -= 4; + + return hash; + } + }); + + /** + * Shortcut function to the hasher's object interface. + * + * @param {WordArray|string} message The message to hash. + * + * @return {WordArray} The hash. + * + * @static + * + * @example + * + * var hash = CryptoJS.SHA224('message'); + * var hash = CryptoJS.SHA224(wordArray); + */ + C.SHA224 = SHA256._createHelper(SHA224); + + /** + * Shortcut function to the HMAC's object interface. + * + * @param {WordArray|string} message The message to hash. + * @param {WordArray|string} key The secret key. + * + * @return {WordArray} The HMAC. + * + * @static + * + * @example + * + * var hmac = CryptoJS.HmacSHA224(message, key); + */ + C.HmacSHA224 = SHA256._createHmacHelper(SHA224); + }()); + + + (function () { + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var Hasher = C_lib.Hasher; + var C_x64 = C.x64; + var X64Word = C_x64.Word; + var X64WordArray = C_x64.WordArray; + var C_algo = C.algo; + + function X64Word_create() { + return X64Word.create.apply(X64Word, arguments); + } + + // Constants + var K = [ + X64Word_create(0x428a2f98, 0xd728ae22), X64Word_create(0x71374491, 0x23ef65cd), + X64Word_create(0xb5c0fbcf, 0xec4d3b2f), X64Word_create(0xe9b5dba5, 0x8189dbbc), + X64Word_create(0x3956c25b, 0xf348b538), X64Word_create(0x59f111f1, 0xb605d019), + X64Word_create(0x923f82a4, 0xaf194f9b), X64Word_create(0xab1c5ed5, 0xda6d8118), + X64Word_create(0xd807aa98, 0xa3030242), X64Word_create(0x12835b01, 0x45706fbe), + X64Word_create(0x243185be, 0x4ee4b28c), X64Word_create(0x550c7dc3, 0xd5ffb4e2), + X64Word_create(0x72be5d74, 0xf27b896f), X64Word_create(0x80deb1fe, 0x3b1696b1), + X64Word_create(0x9bdc06a7, 0x25c71235), X64Word_create(0xc19bf174, 0xcf692694), + X64Word_create(0xe49b69c1, 0x9ef14ad2), X64Word_create(0xefbe4786, 0x384f25e3), + X64Word_create(0x0fc19dc6, 0x8b8cd5b5), X64Word_create(0x240ca1cc, 0x77ac9c65), + X64Word_create(0x2de92c6f, 0x592b0275), X64Word_create(0x4a7484aa, 0x6ea6e483), + X64Word_create(0x5cb0a9dc, 0xbd41fbd4), X64Word_create(0x76f988da, 0x831153b5), + X64Word_create(0x983e5152, 0xee66dfab), X64Word_create(0xa831c66d, 0x2db43210), + X64Word_create(0xb00327c8, 0x98fb213f), X64Word_create(0xbf597fc7, 0xbeef0ee4), + X64Word_create(0xc6e00bf3, 0x3da88fc2), X64Word_create(0xd5a79147, 0x930aa725), + X64Word_create(0x06ca6351, 0xe003826f), X64Word_create(0x14292967, 0x0a0e6e70), + X64Word_create(0x27b70a85, 0x46d22ffc), X64Word_create(0x2e1b2138, 0x5c26c926), + X64Word_create(0x4d2c6dfc, 0x5ac42aed), X64Word_create(0x53380d13, 0x9d95b3df), + X64Word_create(0x650a7354, 0x8baf63de), X64Word_create(0x766a0abb, 0x3c77b2a8), + X64Word_create(0x81c2c92e, 0x47edaee6), X64Word_create(0x92722c85, 0x1482353b), + X64Word_create(0xa2bfe8a1, 0x4cf10364), X64Word_create(0xa81a664b, 0xbc423001), + X64Word_create(0xc24b8b70, 0xd0f89791), X64Word_create(0xc76c51a3, 0x0654be30), + X64Word_create(0xd192e819, 0xd6ef5218), X64Word_create(0xd6990624, 0x5565a910), + X64Word_create(0xf40e3585, 0x5771202a), X64Word_create(0x106aa070, 0x32bbd1b8), + X64Word_create(0x19a4c116, 0xb8d2d0c8), X64Word_create(0x1e376c08, 0x5141ab53), + X64Word_create(0x2748774c, 0xdf8eeb99), X64Word_create(0x34b0bcb5, 0xe19b48a8), + X64Word_create(0x391c0cb3, 0xc5c95a63), X64Word_create(0x4ed8aa4a, 0xe3418acb), + X64Word_create(0x5b9cca4f, 0x7763e373), X64Word_create(0x682e6ff3, 0xd6b2b8a3), + X64Word_create(0x748f82ee, 0x5defb2fc), X64Word_create(0x78a5636f, 0x43172f60), + X64Word_create(0x84c87814, 0xa1f0ab72), X64Word_create(0x8cc70208, 0x1a6439ec), + X64Word_create(0x90befffa, 0x23631e28), X64Word_create(0xa4506ceb, 0xde82bde9), + X64Word_create(0xbef9a3f7, 0xb2c67915), X64Word_create(0xc67178f2, 0xe372532b), + X64Word_create(0xca273ece, 0xea26619c), X64Word_create(0xd186b8c7, 0x21c0c207), + X64Word_create(0xeada7dd6, 0xcde0eb1e), X64Word_create(0xf57d4f7f, 0xee6ed178), + X64Word_create(0x06f067aa, 0x72176fba), X64Word_create(0x0a637dc5, 0xa2c898a6), + X64Word_create(0x113f9804, 0xbef90dae), X64Word_create(0x1b710b35, 0x131c471b), + X64Word_create(0x28db77f5, 0x23047d84), X64Word_create(0x32caab7b, 0x40c72493), + X64Word_create(0x3c9ebe0a, 0x15c9bebc), X64Word_create(0x431d67c4, 0x9c100d4c), + X64Word_create(0x4cc5d4be, 0xcb3e42b6), X64Word_create(0x597f299c, 0xfc657e2a), + X64Word_create(0x5fcb6fab, 0x3ad6faec), X64Word_create(0x6c44198c, 0x4a475817) + ]; + + // Reusable objects + var W = []; + (function () { + for (var i = 0; i < 80; i++) { + W[i] = X64Word_create(); + } + }()); + + /** + * SHA-512 hash algorithm. + */ + var SHA512 = C_algo.SHA512 = Hasher.extend({ + _doReset: function () { + this._hash = new X64WordArray.init([ + new X64Word.init(0x6a09e667, 0xf3bcc908), new X64Word.init(0xbb67ae85, 0x84caa73b), + new X64Word.init(0x3c6ef372, 0xfe94f82b), new X64Word.init(0xa54ff53a, 0x5f1d36f1), + new X64Word.init(0x510e527f, 0xade682d1), new X64Word.init(0x9b05688c, 0x2b3e6c1f), + new X64Word.init(0x1f83d9ab, 0xfb41bd6b), new X64Word.init(0x5be0cd19, 0x137e2179) + ]); + }, + + _doProcessBlock: function (M, offset) { + // Shortcuts + var H = this._hash.words; + + var H0 = H[0]; + var H1 = H[1]; + var H2 = H[2]; + var H3 = H[3]; + var H4 = H[4]; + var H5 = H[5]; + var H6 = H[6]; + var H7 = H[7]; + + var H0h = H0.high; + var H0l = H0.low; + var H1h = H1.high; + var H1l = H1.low; + var H2h = H2.high; + var H2l = H2.low; + var H3h = H3.high; + var H3l = H3.low; + var H4h = H4.high; + var H4l = H4.low; + var H5h = H5.high; + var H5l = H5.low; + var H6h = H6.high; + var H6l = H6.low; + var H7h = H7.high; + var H7l = H7.low; + + // Working variables + var ah = H0h; + var al = H0l; + var bh = H1h; + var bl = H1l; + var ch = H2h; + var cl = H2l; + var dh = H3h; + var dl = H3l; + var eh = H4h; + var el = H4l; + var fh = H5h; + var fl = H5l; + var gh = H6h; + var gl = H6l; + var hh = H7h; + var hl = H7l; + + // Rounds + for (var i = 0; i < 80; i++) { + var Wil; + var Wih; + + // Shortcut + var Wi = W[i]; + + // Extend message + if (i < 16) { + Wih = Wi.high = M[offset + i * 2] | 0; + Wil = Wi.low = M[offset + i * 2 + 1] | 0; + } else { + // Gamma0 + var gamma0x = W[i - 15]; + var gamma0xh = gamma0x.high; + var gamma0xl = gamma0x.low; + var gamma0h = ((gamma0xh >>> 1) | (gamma0xl << 31)) ^ ((gamma0xh >>> 8) | (gamma0xl << 24)) ^ (gamma0xh >>> 7); + var gamma0l = ((gamma0xl >>> 1) | (gamma0xh << 31)) ^ ((gamma0xl >>> 8) | (gamma0xh << 24)) ^ ((gamma0xl >>> 7) | (gamma0xh << 25)); + + // Gamma1 + var gamma1x = W[i - 2]; + var gamma1xh = gamma1x.high; + var gamma1xl = gamma1x.low; + var gamma1h = ((gamma1xh >>> 19) | (gamma1xl << 13)) ^ ((gamma1xh << 3) | (gamma1xl >>> 29)) ^ (gamma1xh >>> 6); + var gamma1l = ((gamma1xl >>> 19) | (gamma1xh << 13)) ^ ((gamma1xl << 3) | (gamma1xh >>> 29)) ^ ((gamma1xl >>> 6) | (gamma1xh << 26)); + + // W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16] + var Wi7 = W[i - 7]; + var Wi7h = Wi7.high; + var Wi7l = Wi7.low; + + var Wi16 = W[i - 16]; + var Wi16h = Wi16.high; + var Wi16l = Wi16.low; + + Wil = gamma0l + Wi7l; + Wih = gamma0h + Wi7h + ((Wil >>> 0) < (gamma0l >>> 0) ? 1 : 0); + Wil = Wil + gamma1l; + Wih = Wih + gamma1h + ((Wil >>> 0) < (gamma1l >>> 0) ? 1 : 0); + Wil = Wil + Wi16l; + Wih = Wih + Wi16h + ((Wil >>> 0) < (Wi16l >>> 0) ? 1 : 0); + + Wi.high = Wih; + Wi.low = Wil; + } + + var chh = (eh & fh) ^ (~eh & gh); + var chl = (el & fl) ^ (~el & gl); + var majh = (ah & bh) ^ (ah & ch) ^ (bh & ch); + var majl = (al & bl) ^ (al & cl) ^ (bl & cl); + + var sigma0h = ((ah >>> 28) | (al << 4)) ^ ((ah << 30) | (al >>> 2)) ^ ((ah << 25) | (al >>> 7)); + var sigma0l = ((al >>> 28) | (ah << 4)) ^ ((al << 30) | (ah >>> 2)) ^ ((al << 25) | (ah >>> 7)); + var sigma1h = ((eh >>> 14) | (el << 18)) ^ ((eh >>> 18) | (el << 14)) ^ ((eh << 23) | (el >>> 9)); + var sigma1l = ((el >>> 14) | (eh << 18)) ^ ((el >>> 18) | (eh << 14)) ^ ((el << 23) | (eh >>> 9)); + + // t1 = h + sigma1 + ch + K[i] + W[i] + var Ki = K[i]; + var Kih = Ki.high; + var Kil = Ki.low; + + var t1l = hl + sigma1l; + var t1h = hh + sigma1h + ((t1l >>> 0) < (hl >>> 0) ? 1 : 0); + var t1l = t1l + chl; + var t1h = t1h + chh + ((t1l >>> 0) < (chl >>> 0) ? 1 : 0); + var t1l = t1l + Kil; + var t1h = t1h + Kih + ((t1l >>> 0) < (Kil >>> 0) ? 1 : 0); + var t1l = t1l + Wil; + var t1h = t1h + Wih + ((t1l >>> 0) < (Wil >>> 0) ? 1 : 0); + + // t2 = sigma0 + maj + var t2l = sigma0l + majl; + var t2h = sigma0h + majh + ((t2l >>> 0) < (sigma0l >>> 0) ? 1 : 0); + + // Update working variables + hh = gh; + hl = gl; + gh = fh; + gl = fl; + fh = eh; + fl = el; + el = (dl + t1l) | 0; + eh = (dh + t1h + ((el >>> 0) < (dl >>> 0) ? 1 : 0)) | 0; + dh = ch; + dl = cl; + ch = bh; + cl = bl; + bh = ah; + bl = al; + al = (t1l + t2l) | 0; + ah = (t1h + t2h + ((al >>> 0) < (t1l >>> 0) ? 1 : 0)) | 0; + } + + // Intermediate hash value + H0l = H0.low = (H0l + al); + H0.high = (H0h + ah + ((H0l >>> 0) < (al >>> 0) ? 1 : 0)); + H1l = H1.low = (H1l + bl); + H1.high = (H1h + bh + ((H1l >>> 0) < (bl >>> 0) ? 1 : 0)); + H2l = H2.low = (H2l + cl); + H2.high = (H2h + ch + ((H2l >>> 0) < (cl >>> 0) ? 1 : 0)); + H3l = H3.low = (H3l + dl); + H3.high = (H3h + dh + ((H3l >>> 0) < (dl >>> 0) ? 1 : 0)); + H4l = H4.low = (H4l + el); + H4.high = (H4h + eh + ((H4l >>> 0) < (el >>> 0) ? 1 : 0)); + H5l = H5.low = (H5l + fl); + H5.high = (H5h + fh + ((H5l >>> 0) < (fl >>> 0) ? 1 : 0)); + H6l = H6.low = (H6l + gl); + H6.high = (H6h + gh + ((H6l >>> 0) < (gl >>> 0) ? 1 : 0)); + H7l = H7.low = (H7l + hl); + H7.high = (H7h + hh + ((H7l >>> 0) < (hl >>> 0) ? 1 : 0)); + }, + + _doFinalize: function () { + // Shortcuts + var data = this._data; + var dataWords = data.words; + + var nBitsTotal = this._nDataBytes * 8; + var nBitsLeft = data.sigBytes * 8; + + // Add padding + dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); + dataWords[(((nBitsLeft + 128) >>> 10) << 5) + 30] = Math.floor(nBitsTotal / 0x100000000); + dataWords[(((nBitsLeft + 128) >>> 10) << 5) + 31] = nBitsTotal; + data.sigBytes = dataWords.length * 4; + + // Hash final blocks + this._process(); + + // Convert hash to 32-bit word array before returning + var hash = this._hash.toX32(); + + // Return final computed hash + return hash; + }, + + clone: function () { + var clone = Hasher.clone.call(this); + clone._hash = this._hash.clone(); + + return clone; + }, + + blockSize: 1024/32 + }); + + /** + * Shortcut function to the hasher's object interface. + * + * @param {WordArray|string} message The message to hash. + * + * @return {WordArray} The hash. + * + * @static + * + * @example + * + * var hash = CryptoJS.SHA512('message'); + * var hash = CryptoJS.SHA512(wordArray); + */ + C.SHA512 = Hasher._createHelper(SHA512); + + /** + * Shortcut function to the HMAC's object interface. + * + * @param {WordArray|string} message The message to hash. + * @param {WordArray|string} key The secret key. + * + * @return {WordArray} The HMAC. + * + * @static + * + * @example + * + * var hmac = CryptoJS.HmacSHA512(message, key); + */ + C.HmacSHA512 = Hasher._createHmacHelper(SHA512); + }()); + + + (function () { + // Shortcuts + var C = CryptoJS; + var C_x64 = C.x64; + var X64Word = C_x64.Word; + var X64WordArray = C_x64.WordArray; + var C_algo = C.algo; + var SHA512 = C_algo.SHA512; + + /** + * SHA-384 hash algorithm. + */ + var SHA384 = C_algo.SHA384 = SHA512.extend({ + _doReset: function () { + this._hash = new X64WordArray.init([ + new X64Word.init(0xcbbb9d5d, 0xc1059ed8), new X64Word.init(0x629a292a, 0x367cd507), + new X64Word.init(0x9159015a, 0x3070dd17), new X64Word.init(0x152fecd8, 0xf70e5939), + new X64Word.init(0x67332667, 0xffc00b31), new X64Word.init(0x8eb44a87, 0x68581511), + new X64Word.init(0xdb0c2e0d, 0x64f98fa7), new X64Word.init(0x47b5481d, 0xbefa4fa4) + ]); + }, + + _doFinalize: function () { + var hash = SHA512._doFinalize.call(this); + + hash.sigBytes -= 16; + + return hash; + } + }); + + /** + * Shortcut function to the hasher's object interface. + * + * @param {WordArray|string} message The message to hash. + * + * @return {WordArray} The hash. + * + * @static + * + * @example + * + * var hash = CryptoJS.SHA384('message'); + * var hash = CryptoJS.SHA384(wordArray); + */ + C.SHA384 = SHA512._createHelper(SHA384); + + /** + * Shortcut function to the HMAC's object interface. + * + * @param {WordArray|string} message The message to hash. + * @param {WordArray|string} key The secret key. + * + * @return {WordArray} The HMAC. + * + * @static + * + * @example + * + * var hmac = CryptoJS.HmacSHA384(message, key); + */ + C.HmacSHA384 = SHA512._createHmacHelper(SHA384); + }()); + + + (function (Math) { + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var WordArray = C_lib.WordArray; + var Hasher = C_lib.Hasher; + var C_x64 = C.x64; + var X64Word = C_x64.Word; + var C_algo = C.algo; + + // Constants tables + var RHO_OFFSETS = []; + var PI_INDEXES = []; + var ROUND_CONSTANTS = []; + + // Compute Constants + (function () { + // Compute rho offset constants + var x = 1, y = 0; + for (var t = 0; t < 24; t++) { + RHO_OFFSETS[x + 5 * y] = ((t + 1) * (t + 2) / 2) % 64; + + var newX = y % 5; + var newY = (2 * x + 3 * y) % 5; + x = newX; + y = newY; + } + + // Compute pi index constants + for (var x = 0; x < 5; x++) { + for (var y = 0; y < 5; y++) { + PI_INDEXES[x + 5 * y] = y + ((2 * x + 3 * y) % 5) * 5; + } + } + + // Compute round constants + var LFSR = 0x01; + for (var i = 0; i < 24; i++) { + var roundConstantMsw = 0; + var roundConstantLsw = 0; + + for (var j = 0; j < 7; j++) { + if (LFSR & 0x01) { + var bitPosition = (1 << j) - 1; + if (bitPosition < 32) { + roundConstantLsw ^= 1 << bitPosition; + } else /* if (bitPosition >= 32) */ { + roundConstantMsw ^= 1 << (bitPosition - 32); + } + } + + // Compute next LFSR + if (LFSR & 0x80) { + // Primitive polynomial over GF(2): x^8 + x^6 + x^5 + x^4 + 1 + LFSR = (LFSR << 1) ^ 0x71; + } else { + LFSR <<= 1; + } + } + + ROUND_CONSTANTS[i] = X64Word.create(roundConstantMsw, roundConstantLsw); + } + }()); + + // Reusable objects for temporary values + var T = []; + (function () { + for (var i = 0; i < 25; i++) { + T[i] = X64Word.create(); + } + }()); + + /** + * SHA-3 hash algorithm. + */ + var SHA3 = C_algo.SHA3 = Hasher.extend({ + /** + * Configuration options. + * + * @property {number} outputLength + * The desired number of bits in the output hash. + * Only values permitted are: 224, 256, 384, 512. + * Default: 512 + */ + cfg: Hasher.cfg.extend({ + outputLength: 512 + }), + + _doReset: function () { + var state = this._state = [] + for (var i = 0; i < 25; i++) { + state[i] = new X64Word.init(); + } + + this.blockSize = (1600 - 2 * this.cfg.outputLength) / 32; + }, + + _doProcessBlock: function (M, offset) { + // Shortcuts + var state = this._state; + var nBlockSizeLanes = this.blockSize / 2; + + // Absorb + for (var i = 0; i < nBlockSizeLanes; i++) { + // Shortcuts + var M2i = M[offset + 2 * i]; + var M2i1 = M[offset + 2 * i + 1]; + + // Swap endian + M2i = ( + (((M2i << 8) | (M2i >>> 24)) & 0x00ff00ff) | + (((M2i << 24) | (M2i >>> 8)) & 0xff00ff00) + ); + M2i1 = ( + (((M2i1 << 8) | (M2i1 >>> 24)) & 0x00ff00ff) | + (((M2i1 << 24) | (M2i1 >>> 8)) & 0xff00ff00) + ); + + // Absorb message into state + var lane = state[i]; + lane.high ^= M2i1; + lane.low ^= M2i; + } + + // Rounds + for (var round = 0; round < 24; round++) { + // Theta + for (var x = 0; x < 5; x++) { + // Mix column lanes + var tMsw = 0, tLsw = 0; + for (var y = 0; y < 5; y++) { + var lane = state[x + 5 * y]; + tMsw ^= lane.high; + tLsw ^= lane.low; + } + + // Temporary values + var Tx = T[x]; + Tx.high = tMsw; + Tx.low = tLsw; + } + for (var x = 0; x < 5; x++) { + // Shortcuts + var Tx4 = T[(x + 4) % 5]; + var Tx1 = T[(x + 1) % 5]; + var Tx1Msw = Tx1.high; + var Tx1Lsw = Tx1.low; + + // Mix surrounding columns + var tMsw = Tx4.high ^ ((Tx1Msw << 1) | (Tx1Lsw >>> 31)); + var tLsw = Tx4.low ^ ((Tx1Lsw << 1) | (Tx1Msw >>> 31)); + for (var y = 0; y < 5; y++) { + var lane = state[x + 5 * y]; + lane.high ^= tMsw; + lane.low ^= tLsw; + } + } + + // Rho Pi + for (var laneIndex = 1; laneIndex < 25; laneIndex++) { + var tMsw; + var tLsw; + + // Shortcuts + var lane = state[laneIndex]; + var laneMsw = lane.high; + var laneLsw = lane.low; + var rhoOffset = RHO_OFFSETS[laneIndex]; + + // Rotate lanes + if (rhoOffset < 32) { + tMsw = (laneMsw << rhoOffset) | (laneLsw >>> (32 - rhoOffset)); + tLsw = (laneLsw << rhoOffset) | (laneMsw >>> (32 - rhoOffset)); + } else /* if (rhoOffset >= 32) */ { + tMsw = (laneLsw << (rhoOffset - 32)) | (laneMsw >>> (64 - rhoOffset)); + tLsw = (laneMsw << (rhoOffset - 32)) | (laneLsw >>> (64 - rhoOffset)); + } + + // Transpose lanes + var TPiLane = T[PI_INDEXES[laneIndex]]; + TPiLane.high = tMsw; + TPiLane.low = tLsw; + } + + // Rho pi at x = y = 0 + var T0 = T[0]; + var state0 = state[0]; + T0.high = state0.high; + T0.low = state0.low; + + // Chi + for (var x = 0; x < 5; x++) { + for (var y = 0; y < 5; y++) { + // Shortcuts + var laneIndex = x + 5 * y; + var lane = state[laneIndex]; + var TLane = T[laneIndex]; + var Tx1Lane = T[((x + 1) % 5) + 5 * y]; + var Tx2Lane = T[((x + 2) % 5) + 5 * y]; + + // Mix rows + lane.high = TLane.high ^ (~Tx1Lane.high & Tx2Lane.high); + lane.low = TLane.low ^ (~Tx1Lane.low & Tx2Lane.low); + } + } + + // Iota + var lane = state[0]; + var roundConstant = ROUND_CONSTANTS[round]; + lane.high ^= roundConstant.high; + lane.low ^= roundConstant.low; + } + }, + + _doFinalize: function () { + // Shortcuts + var data = this._data; + var dataWords = data.words; + var nBitsTotal = this._nDataBytes * 8; + var nBitsLeft = data.sigBytes * 8; + var blockSizeBits = this.blockSize * 32; + + // Add padding + dataWords[nBitsLeft >>> 5] |= 0x1 << (24 - nBitsLeft % 32); + dataWords[((Math.ceil((nBitsLeft + 1) / blockSizeBits) * blockSizeBits) >>> 5) - 1] |= 0x80; + data.sigBytes = dataWords.length * 4; + + // Hash final blocks + this._process(); + + // Shortcuts + var state = this._state; + var outputLengthBytes = this.cfg.outputLength / 8; + var outputLengthLanes = outputLengthBytes / 8; + + // Squeeze + var hashWords = []; + for (var i = 0; i < outputLengthLanes; i++) { + // Shortcuts + var lane = state[i]; + var laneMsw = lane.high; + var laneLsw = lane.low; + + // Swap endian + laneMsw = ( + (((laneMsw << 8) | (laneMsw >>> 24)) & 0x00ff00ff) | + (((laneMsw << 24) | (laneMsw >>> 8)) & 0xff00ff00) + ); + laneLsw = ( + (((laneLsw << 8) | (laneLsw >>> 24)) & 0x00ff00ff) | + (((laneLsw << 24) | (laneLsw >>> 8)) & 0xff00ff00) + ); + + // Squeeze state to retrieve hash + hashWords.push(laneLsw); + hashWords.push(laneMsw); + } + + // Return final computed hash + return new WordArray.init(hashWords, outputLengthBytes); + }, + + clone: function () { + var clone = Hasher.clone.call(this); + + var state = clone._state = this._state.slice(0); + for (var i = 0; i < 25; i++) { + state[i] = state[i].clone(); + } + + return clone; + } + }); + + /** + * Shortcut function to the hasher's object interface. + * + * @param {WordArray|string} message The message to hash. + * + * @return {WordArray} The hash. + * + * @static + * + * @example + * + * var hash = CryptoJS.SHA3('message'); + * var hash = CryptoJS.SHA3(wordArray); + */ + C.SHA3 = Hasher._createHelper(SHA3); + + /** + * Shortcut function to the HMAC's object interface. + * + * @param {WordArray|string} message The message to hash. + * @param {WordArray|string} key The secret key. + * + * @return {WordArray} The HMAC. + * + * @static + * + * @example + * + * var hmac = CryptoJS.HmacSHA3(message, key); + */ + C.HmacSHA3 = Hasher._createHmacHelper(SHA3); + }(Math)); + + + /** @preserve + (c) 2012 by Cédric Mesnil. All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + + - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + (function (Math) { + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var WordArray = C_lib.WordArray; + var Hasher = C_lib.Hasher; + var C_algo = C.algo; + + // Constants table + var _zl = WordArray.create([ + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8, + 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12, + 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2, + 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13]); + var _zr = WordArray.create([ + 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12, + 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2, + 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13, + 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14, + 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11]); + var _sl = WordArray.create([ + 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8, + 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12, + 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5, + 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12, + 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6 ]); + var _sr = WordArray.create([ + 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6, + 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11, + 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5, + 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8, + 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11 ]); + + var _hl = WordArray.create([ 0x00000000, 0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xA953FD4E]); + var _hr = WordArray.create([ 0x50A28BE6, 0x5C4DD124, 0x6D703EF3, 0x7A6D76E9, 0x00000000]); + + /** + * RIPEMD160 hash algorithm. + */ + var RIPEMD160 = C_algo.RIPEMD160 = Hasher.extend({ + _doReset: function () { + this._hash = WordArray.create([0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0]); + }, + + _doProcessBlock: function (M, offset) { + + // Swap endian + for (var i = 0; i < 16; i++) { + // Shortcuts + var offset_i = offset + i; + var M_offset_i = M[offset_i]; + + // Swap + M[offset_i] = ( + (((M_offset_i << 8) | (M_offset_i >>> 24)) & 0x00ff00ff) | + (((M_offset_i << 24) | (M_offset_i >>> 8)) & 0xff00ff00) + ); + } + // Shortcut + var H = this._hash.words; + var hl = _hl.words; + var hr = _hr.words; + var zl = _zl.words; + var zr = _zr.words; + var sl = _sl.words; + var sr = _sr.words; + + // Working variables + var al, bl, cl, dl, el; + var ar, br, cr, dr, er; + + ar = al = H[0]; + br = bl = H[1]; + cr = cl = H[2]; + dr = dl = H[3]; + er = el = H[4]; + // Computation + var t; + for (var i = 0; i < 80; i += 1) { + t = (al + M[offset+zl[i]])|0; + if (i<16){ + t += f1(bl,cl,dl) + hl[0]; + } else if (i<32) { + t += f2(bl,cl,dl) + hl[1]; + } else if (i<48) { + t += f3(bl,cl,dl) + hl[2]; + } else if (i<64) { + t += f4(bl,cl,dl) + hl[3]; + } else {// if (i<80) { + t += f5(bl,cl,dl) + hl[4]; + } + t = t|0; + t = rotl(t,sl[i]); + t = (t+el)|0; + al = el; + el = dl; + dl = rotl(cl, 10); + cl = bl; + bl = t; + + t = (ar + M[offset+zr[i]])|0; + if (i<16){ + t += f5(br,cr,dr) + hr[0]; + } else if (i<32) { + t += f4(br,cr,dr) + hr[1]; + } else if (i<48) { + t += f3(br,cr,dr) + hr[2]; + } else if (i<64) { + t += f2(br,cr,dr) + hr[3]; + } else {// if (i<80) { + t += f1(br,cr,dr) + hr[4]; + } + t = t|0; + t = rotl(t,sr[i]) ; + t = (t+er)|0; + ar = er; + er = dr; + dr = rotl(cr, 10); + cr = br; + br = t; + } + // Intermediate hash value + t = (H[1] + cl + dr)|0; + H[1] = (H[2] + dl + er)|0; + H[2] = (H[3] + el + ar)|0; + H[3] = (H[4] + al + br)|0; + H[4] = (H[0] + bl + cr)|0; + H[0] = t; + }, + + _doFinalize: function () { + // Shortcuts + var data = this._data; + var dataWords = data.words; + + var nBitsTotal = this._nDataBytes * 8; + var nBitsLeft = data.sigBytes * 8; + + // Add padding + dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); + dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = ( + (((nBitsTotal << 8) | (nBitsTotal >>> 24)) & 0x00ff00ff) | + (((nBitsTotal << 24) | (nBitsTotal >>> 8)) & 0xff00ff00) + ); + data.sigBytes = (dataWords.length + 1) * 4; + + // Hash final blocks + this._process(); + + // Shortcuts + var hash = this._hash; + var H = hash.words; + + // Swap endian + for (var i = 0; i < 5; i++) { + // Shortcut + var H_i = H[i]; + + // Swap + H[i] = (((H_i << 8) | (H_i >>> 24)) & 0x00ff00ff) | + (((H_i << 24) | (H_i >>> 8)) & 0xff00ff00); + } + + // Return final computed hash + return hash; + }, + + clone: function () { + var clone = Hasher.clone.call(this); + clone._hash = this._hash.clone(); + + return clone; + } + }); + + + function f1(x, y, z) { + return ((x) ^ (y) ^ (z)); + + } + + function f2(x, y, z) { + return (((x)&(y)) | ((~x)&(z))); + } + + function f3(x, y, z) { + return (((x) | (~(y))) ^ (z)); + } + + function f4(x, y, z) { + return (((x) & (z)) | ((y)&(~(z)))); + } + + function f5(x, y, z) { + return ((x) ^ ((y) |(~(z)))); + + } + + function rotl(x,n) { + return (x<<n) | (x>>>(32-n)); + } + + + /** + * Shortcut function to the hasher's object interface. + * + * @param {WordArray|string} message The message to hash. + * + * @return {WordArray} The hash. + * + * @static + * + * @example + * + * var hash = CryptoJS.RIPEMD160('message'); + * var hash = CryptoJS.RIPEMD160(wordArray); + */ + C.RIPEMD160 = Hasher._createHelper(RIPEMD160); + + /** + * Shortcut function to the HMAC's object interface. + * + * @param {WordArray|string} message The message to hash. + * @param {WordArray|string} key The secret key. + * + * @return {WordArray} The HMAC. + * + * @static + * + * @example + * + * var hmac = CryptoJS.HmacRIPEMD160(message, key); + */ + C.HmacRIPEMD160 = Hasher._createHmacHelper(RIPEMD160); + }(Math)); + + + (function () { + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var Base = C_lib.Base; + var C_enc = C.enc; + var Utf8 = C_enc.Utf8; + var C_algo = C.algo; + + /** + * HMAC algorithm. + */ + var HMAC = C_algo.HMAC = Base.extend({ + /** + * Initializes a newly created HMAC. + * + * @param {Hasher} hasher The hash algorithm to use. + * @param {WordArray|string} key The secret key. + * + * @example + * + * var hmacHasher = CryptoJS.algo.HMAC.create(CryptoJS.algo.SHA256, key); + */ + init: function (hasher, key) { + // Init hasher + hasher = this._hasher = new hasher.init(); + + // Convert string to WordArray, else assume WordArray already + if (typeof key == 'string') { + key = Utf8.parse(key); + } + + // Shortcuts + var hasherBlockSize = hasher.blockSize; + var hasherBlockSizeBytes = hasherBlockSize * 4; + + // Allow arbitrary length keys + if (key.sigBytes > hasherBlockSizeBytes) { + key = hasher.finalize(key); + } + + // Clamp excess bits + key.clamp(); + + // Clone key for inner and outer pads + var oKey = this._oKey = key.clone(); + var iKey = this._iKey = key.clone(); + + // Shortcuts + var oKeyWords = oKey.words; + var iKeyWords = iKey.words; + + // XOR keys with pad constants + for (var i = 0; i < hasherBlockSize; i++) { + oKeyWords[i] ^= 0x5c5c5c5c; + iKeyWords[i] ^= 0x36363636; + } + oKey.sigBytes = iKey.sigBytes = hasherBlockSizeBytes; + + // Set initial values + this.reset(); + }, + + /** + * Resets this HMAC to its initial state. + * + * @example + * + * hmacHasher.reset(); + */ + reset: function () { + // Shortcut + var hasher = this._hasher; + + // Reset + hasher.reset(); + hasher.update(this._iKey); + }, + + /** + * Updates this HMAC with a message. + * + * @param {WordArray|string} messageUpdate The message to append. + * + * @return {HMAC} This HMAC instance. + * + * @example + * + * hmacHasher.update('message'); + * hmacHasher.update(wordArray); + */ + update: function (messageUpdate) { + this._hasher.update(messageUpdate); + + // Chainable + return this; + }, + + /** + * Finalizes the HMAC computation. + * Note that the finalize operation is effectively a destructive, read-once operation. + * + * @param {WordArray|string} messageUpdate (Optional) A final message update. + * + * @return {WordArray} The HMAC. + * + * @example + * + * var hmac = hmacHasher.finalize(); + * var hmac = hmacHasher.finalize('message'); + * var hmac = hmacHasher.finalize(wordArray); + */ + finalize: function (messageUpdate) { + // Shortcut + var hasher = this._hasher; + + // Compute HMAC + var innerHash = hasher.finalize(messageUpdate); + hasher.reset(); + var hmac = hasher.finalize(this._oKey.clone().concat(innerHash)); + + return hmac; + } + }); + }()); + + + (function () { + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var Base = C_lib.Base; + var WordArray = C_lib.WordArray; + var C_algo = C.algo; + var SHA1 = C_algo.SHA1; + var HMAC = C_algo.HMAC; + + /** + * Password-Based Key Derivation Function 2 algorithm. + */ + var PBKDF2 = C_algo.PBKDF2 = Base.extend({ + /** + * Configuration options. + * + * @property {number} keySize The key size in words to generate. Default: 4 (128 bits) + * @property {Hasher} hasher The hasher to use. Default: SHA1 + * @property {number} iterations The number of iterations to perform. Default: 1 + */ + cfg: Base.extend({ + keySize: 128/32, + hasher: SHA1, + iterations: 1 + }), + + /** + * Initializes a newly created key derivation function. + * + * @param {Object} cfg (Optional) The configuration options to use for the derivation. + * + * @example + * + * var kdf = CryptoJS.algo.PBKDF2.create(); + * var kdf = CryptoJS.algo.PBKDF2.create({ keySize: 8 }); + * var kdf = CryptoJS.algo.PBKDF2.create({ keySize: 8, iterations: 1000 }); + */ + init: function (cfg) { + this.cfg = this.cfg.extend(cfg); + }, + + /** + * Computes the Password-Based Key Derivation Function 2. + * + * @param {WordArray|string} password The password. + * @param {WordArray|string} salt A salt. + * + * @return {WordArray} The derived key. + * + * @example + * + * var key = kdf.compute(password, salt); + */ + compute: function (password, salt) { + // Shortcut + var cfg = this.cfg; + + // Init HMAC + var hmac = HMAC.create(cfg.hasher, password); + + // Initial values + var derivedKey = WordArray.create(); + var blockIndex = WordArray.create([0x00000001]); + + // Shortcuts + var derivedKeyWords = derivedKey.words; + var blockIndexWords = blockIndex.words; + var keySize = cfg.keySize; + var iterations = cfg.iterations; + + // Generate key + while (derivedKeyWords.length < keySize) { + var block = hmac.update(salt).finalize(blockIndex); + hmac.reset(); + + // Shortcuts + var blockWords = block.words; + var blockWordsLength = blockWords.length; + + // Iterations + var intermediate = block; + for (var i = 1; i < iterations; i++) { + intermediate = hmac.finalize(intermediate); + hmac.reset(); + + // Shortcut + var intermediateWords = intermediate.words; + + // XOR intermediate with block + for (var j = 0; j < blockWordsLength; j++) { + blockWords[j] ^= intermediateWords[j]; + } + } + + derivedKey.concat(block); + blockIndexWords[0]++; + } + derivedKey.sigBytes = keySize * 4; + + return derivedKey; + } + }); + + /** + * Computes the Password-Based Key Derivation Function 2. + * + * @param {WordArray|string} password The password. + * @param {WordArray|string} salt A salt. + * @param {Object} cfg (Optional) The configuration options to use for this computation. + * + * @return {WordArray} The derived key. + * + * @static + * + * @example + * + * var key = CryptoJS.PBKDF2(password, salt); + * var key = CryptoJS.PBKDF2(password, salt, { keySize: 8 }); + * var key = CryptoJS.PBKDF2(password, salt, { keySize: 8, iterations: 1000 }); + */ + C.PBKDF2 = function (password, salt, cfg) { + return PBKDF2.create(cfg).compute(password, salt); + }; + }()); + + + (function () { + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var Base = C_lib.Base; + var WordArray = C_lib.WordArray; + var C_algo = C.algo; + var MD5 = C_algo.MD5; + + /** + * This key derivation function is meant to conform with EVP_BytesToKey. + * www.openssl.org/docs/crypto/EVP_BytesToKey.html + */ + var EvpKDF = C_algo.EvpKDF = Base.extend({ + /** + * Configuration options. + * + * @property {number} keySize The key size in words to generate. Default: 4 (128 bits) + * @property {Hasher} hasher The hash algorithm to use. Default: MD5 + * @property {number} iterations The number of iterations to perform. Default: 1 + */ + cfg: Base.extend({ + keySize: 128/32, + hasher: MD5, + iterations: 1 + }), + + /** + * Initializes a newly created key derivation function. + * + * @param {Object} cfg (Optional) The configuration options to use for the derivation. + * + * @example + * + * var kdf = CryptoJS.algo.EvpKDF.create(); + * var kdf = CryptoJS.algo.EvpKDF.create({ keySize: 8 }); + * var kdf = CryptoJS.algo.EvpKDF.create({ keySize: 8, iterations: 1000 }); + */ + init: function (cfg) { + this.cfg = this.cfg.extend(cfg); + }, + + /** + * Derives a key from a password. + * + * @param {WordArray|string} password The password. + * @param {WordArray|string} salt A salt. + * + * @return {WordArray} The derived key. + * + * @example + * + * var key = kdf.compute(password, salt); + */ + compute: function (password, salt) { + var block; + + // Shortcut + var cfg = this.cfg; + + // Init hasher + var hasher = cfg.hasher.create(); + + // Initial values + var derivedKey = WordArray.create(); + + // Shortcuts + var derivedKeyWords = derivedKey.words; + var keySize = cfg.keySize; + var iterations = cfg.iterations; + + // Generate key + while (derivedKeyWords.length < keySize) { + if (block) { + hasher.update(block); + } + block = hasher.update(password).finalize(salt); + hasher.reset(); + + // Iterations + for (var i = 1; i < iterations; i++) { + block = hasher.finalize(block); + hasher.reset(); + } + + derivedKey.concat(block); + } + derivedKey.sigBytes = keySize * 4; + + return derivedKey; + } + }); + + /** + * Derives a key from a password. + * + * @param {WordArray|string} password The password. + * @param {WordArray|string} salt A salt. + * @param {Object} cfg (Optional) The configuration options to use for this computation. + * + * @return {WordArray} The derived key. + * + * @static + * + * @example + * + * var key = CryptoJS.EvpKDF(password, salt); + * var key = CryptoJS.EvpKDF(password, salt, { keySize: 8 }); + * var key = CryptoJS.EvpKDF(password, salt, { keySize: 8, iterations: 1000 }); + */ + C.EvpKDF = function (password, salt, cfg) { + return EvpKDF.create(cfg).compute(password, salt); + }; + }()); + + + /** + * Cipher core components. + */ + CryptoJS.lib.Cipher || (function (undefined) { + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var Base = C_lib.Base; + var WordArray = C_lib.WordArray; + var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm; + var C_enc = C.enc; + var Utf8 = C_enc.Utf8; + var Base64 = C_enc.Base64; + var C_algo = C.algo; + var EvpKDF = C_algo.EvpKDF; + + /** + * Abstract base cipher template. + * + * @property {number} keySize This cipher's key size. Default: 4 (128 bits) + * @property {number} ivSize This cipher's IV size. Default: 4 (128 bits) + * @property {number} _ENC_XFORM_MODE A constant representing encryption mode. + * @property {number} _DEC_XFORM_MODE A constant representing decryption mode. + */ + var Cipher = C_lib.Cipher = BufferedBlockAlgorithm.extend({ + /** + * Configuration options. + * + * @property {WordArray} iv The IV to use for this operation. + */ + cfg: Base.extend(), + + /** + * Creates this cipher in encryption mode. + * + * @param {WordArray} key The key. + * @param {Object} cfg (Optional) The configuration options to use for this operation. + * + * @return {Cipher} A cipher instance. + * + * @static + * + * @example + * + * var cipher = CryptoJS.algo.AES.createEncryptor(keyWordArray, { iv: ivWordArray }); + */ + createEncryptor: function (key, cfg) { + return this.create(this._ENC_XFORM_MODE, key, cfg); + }, + + /** + * Creates this cipher in decryption mode. + * + * @param {WordArray} key The key. + * @param {Object} cfg (Optional) The configuration options to use for this operation. + * + * @return {Cipher} A cipher instance. + * + * @static + * + * @example + * + * var cipher = CryptoJS.algo.AES.createDecryptor(keyWordArray, { iv: ivWordArray }); + */ + createDecryptor: function (key, cfg) { + return this.create(this._DEC_XFORM_MODE, key, cfg); + }, + + /** + * Initializes a newly created cipher. + * + * @param {number} xformMode Either the encryption or decryption transormation mode constant. + * @param {WordArray} key The key. + * @param {Object} cfg (Optional) The configuration options to use for this operation. + * + * @example + * + * var cipher = CryptoJS.algo.AES.create(CryptoJS.algo.AES._ENC_XFORM_MODE, keyWordArray, { iv: ivWordArray }); + */ + init: function (xformMode, key, cfg) { + // Apply config defaults + this.cfg = this.cfg.extend(cfg); + + // Store transform mode and key + this._xformMode = xformMode; + this._key = key; + + // Set initial values + this.reset(); + }, + + /** + * Resets this cipher to its initial state. + * + * @example + * + * cipher.reset(); + */ + reset: function () { + // Reset data buffer + BufferedBlockAlgorithm.reset.call(this); + + // Perform concrete-cipher logic + this._doReset(); + }, + + /** + * Adds data to be encrypted or decrypted. + * + * @param {WordArray|string} dataUpdate The data to encrypt or decrypt. + * + * @return {WordArray} The data after processing. + * + * @example + * + * var encrypted = cipher.process('data'); + * var encrypted = cipher.process(wordArray); + */ + process: function (dataUpdate) { + // Append + this._append(dataUpdate); + + // Process available blocks + return this._process(); + }, + + /** + * Finalizes the encryption or decryption process. + * Note that the finalize operation is effectively a destructive, read-once operation. + * + * @param {WordArray|string} dataUpdate The final data to encrypt or decrypt. + * + * @return {WordArray} The data after final processing. + * + * @example + * + * var encrypted = cipher.finalize(); + * var encrypted = cipher.finalize('data'); + * var encrypted = cipher.finalize(wordArray); + */ + finalize: function (dataUpdate) { + // Final data update + if (dataUpdate) { + this._append(dataUpdate); + } + + // Perform concrete-cipher logic + var finalProcessedData = this._doFinalize(); + + return finalProcessedData; + }, + + keySize: 128/32, + + ivSize: 128/32, + + _ENC_XFORM_MODE: 1, + + _DEC_XFORM_MODE: 2, + + /** + * Creates shortcut functions to a cipher's object interface. + * + * @param {Cipher} cipher The cipher to create a helper for. + * + * @return {Object} An object with encrypt and decrypt shortcut functions. + * + * @static + * + * @example + * + * var AES = CryptoJS.lib.Cipher._createHelper(CryptoJS.algo.AES); + */ + _createHelper: (function () { + function selectCipherStrategy(key) { + if (typeof key == 'string') { + return PasswordBasedCipher; + } else { + return SerializableCipher; + } + } + + return function (cipher) { + return { + encrypt: function (message, key, cfg) { + return selectCipherStrategy(key).encrypt(cipher, message, key, cfg); + }, + + decrypt: function (ciphertext, key, cfg) { + return selectCipherStrategy(key).decrypt(cipher, ciphertext, key, cfg); + } + }; + }; + }()) + }); + + /** + * Abstract base stream cipher template. + * + * @property {number} blockSize The number of 32-bit words this cipher operates on. Default: 1 (32 bits) + */ + var StreamCipher = C_lib.StreamCipher = Cipher.extend({ + _doFinalize: function () { + // Process partial blocks + var finalProcessedBlocks = this._process(!!'flush'); + + return finalProcessedBlocks; + }, + + blockSize: 1 + }); + + /** + * Mode namespace. + */ + var C_mode = C.mode = {}; + + /** + * Abstract base block cipher mode template. + */ + var BlockCipherMode = C_lib.BlockCipherMode = Base.extend({ + /** + * Creates this mode for encryption. + * + * @param {Cipher} cipher A block cipher instance. + * @param {Array} iv The IV words. + * + * @static + * + * @example + * + * var mode = CryptoJS.mode.CBC.createEncryptor(cipher, iv.words); + */ + createEncryptor: function (cipher, iv) { + return this.Encryptor.create(cipher, iv); + }, + + /** + * Creates this mode for decryption. + * + * @param {Cipher} cipher A block cipher instance. + * @param {Array} iv The IV words. + * + * @static + * + * @example + * + * var mode = CryptoJS.mode.CBC.createDecryptor(cipher, iv.words); + */ + createDecryptor: function (cipher, iv) { + return this.Decryptor.create(cipher, iv); + }, + + /** + * Initializes a newly created mode. + * + * @param {Cipher} cipher A block cipher instance. + * @param {Array} iv The IV words. + * + * @example + * + * var mode = CryptoJS.mode.CBC.Encryptor.create(cipher, iv.words); + */ + init: function (cipher, iv) { + this._cipher = cipher; + this._iv = iv; + } + }); + + /** + * Cipher Block Chaining mode. + */ + var CBC = C_mode.CBC = (function () { + /** + * Abstract base CBC mode. + */ + var CBC = BlockCipherMode.extend(); + + /** + * CBC encryptor. + */ + CBC.Encryptor = CBC.extend({ + /** + * Processes the data block at offset. + * + * @param {Array} words The data words to operate on. + * @param {number} offset The offset where the block starts. + * + * @example + * + * mode.processBlock(data.words, offset); + */ + processBlock: function (words, offset) { + // Shortcuts + var cipher = this._cipher; + var blockSize = cipher.blockSize; + + // XOR and encrypt + xorBlock.call(this, words, offset, blockSize); + cipher.encryptBlock(words, offset); + + // Remember this block to use with next block + this._prevBlock = words.slice(offset, offset + blockSize); + } + }); + + /** + * CBC decryptor. + */ + CBC.Decryptor = CBC.extend({ + /** + * Processes the data block at offset. + * + * @param {Array} words The data words to operate on. + * @param {number} offset The offset where the block starts. + * + * @example + * + * mode.processBlock(data.words, offset); + */ + processBlock: function (words, offset) { + // Shortcuts + var cipher = this._cipher; + var blockSize = cipher.blockSize; + + // Remember this block to use with next block + var thisBlock = words.slice(offset, offset + blockSize); + + // Decrypt and XOR + cipher.decryptBlock(words, offset); + xorBlock.call(this, words, offset, blockSize); + + // This block becomes the previous block + this._prevBlock = thisBlock; + } + }); + + function xorBlock(words, offset, blockSize) { + var block; + + // Shortcut + var iv = this._iv; + + // Choose mixing block + if (iv) { + block = iv; + + // Remove IV for subsequent blocks + this._iv = undefined; + } else { + block = this._prevBlock; + } + + // XOR blocks + for (var i = 0; i < blockSize; i++) { + words[offset + i] ^= block[i]; + } + } + + return CBC; + }()); + + /** + * Padding namespace. + */ + var C_pad = C.pad = {}; + + /** + * PKCS #5/7 padding strategy. + */ + var Pkcs7 = C_pad.Pkcs7 = { + /** + * Pads data using the algorithm defined in PKCS #5/7. + * + * @param {WordArray} data The data to pad. + * @param {number} blockSize The multiple that the data should be padded to. + * + * @static + * + * @example + * + * CryptoJS.pad.Pkcs7.pad(wordArray, 4); + */ + pad: function (data, blockSize) { + // Shortcut + var blockSizeBytes = blockSize * 4; + + // Count padding bytes + var nPaddingBytes = blockSizeBytes - data.sigBytes % blockSizeBytes; + + // Create padding word + var paddingWord = (nPaddingBytes << 24) | (nPaddingBytes << 16) | (nPaddingBytes << 8) | nPaddingBytes; + + // Create padding + var paddingWords = []; + for (var i = 0; i < nPaddingBytes; i += 4) { + paddingWords.push(paddingWord); + } + var padding = WordArray.create(paddingWords, nPaddingBytes); + + // Add padding + data.concat(padding); + }, + + /** + * Unpads data that had been padded using the algorithm defined in PKCS #5/7. + * + * @param {WordArray} data The data to unpad. + * + * @static + * + * @example + * + * CryptoJS.pad.Pkcs7.unpad(wordArray); + */ + unpad: function (data) { + // Get number of padding bytes from last byte + var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff; + + // Remove padding + data.sigBytes -= nPaddingBytes; + } + }; + + /** + * Abstract base block cipher template. + * + * @property {number} blockSize The number of 32-bit words this cipher operates on. Default: 4 (128 bits) + */ + var BlockCipher = C_lib.BlockCipher = Cipher.extend({ + /** + * Configuration options. + * + * @property {Mode} mode The block mode to use. Default: CBC + * @property {Padding} padding The padding strategy to use. Default: Pkcs7 + */ + cfg: Cipher.cfg.extend({ + mode: CBC, + padding: Pkcs7 + }), + + reset: function () { + var modeCreator; + + // Reset cipher + Cipher.reset.call(this); + + // Shortcuts + var cfg = this.cfg; + var iv = cfg.iv; + var mode = cfg.mode; + + // Reset block mode + if (this._xformMode == this._ENC_XFORM_MODE) { + modeCreator = mode.createEncryptor; + } else /* if (this._xformMode == this._DEC_XFORM_MODE) */ { + modeCreator = mode.createDecryptor; + // Keep at least one block in the buffer for unpadding + this._minBufferSize = 1; + } + + if (this._mode && this._mode.__creator == modeCreator) { + this._mode.init(this, iv && iv.words); + } else { + this._mode = modeCreator.call(mode, this, iv && iv.words); + this._mode.__creator = modeCreator; + } + }, + + _doProcessBlock: function (words, offset) { + this._mode.processBlock(words, offset); + }, + + _doFinalize: function () { + var finalProcessedBlocks; + + // Shortcut + var padding = this.cfg.padding; + + // Finalize + if (this._xformMode == this._ENC_XFORM_MODE) { + // Pad data + padding.pad(this._data, this.blockSize); + + // Process final blocks + finalProcessedBlocks = this._process(!!'flush'); + } else /* if (this._xformMode == this._DEC_XFORM_MODE) */ { + // Process final blocks + finalProcessedBlocks = this._process(!!'flush'); + + // Unpad data + padding.unpad(finalProcessedBlocks); + } + + return finalProcessedBlocks; + }, + + blockSize: 128/32 + }); + + /** + * A collection of cipher parameters. + * + * @property {WordArray} ciphertext The raw ciphertext. + * @property {WordArray} key The key to this ciphertext. + * @property {WordArray} iv The IV used in the ciphering operation. + * @property {WordArray} salt The salt used with a key derivation function. + * @property {Cipher} algorithm The cipher algorithm. + * @property {Mode} mode The block mode used in the ciphering operation. + * @property {Padding} padding The padding scheme used in the ciphering operation. + * @property {number} blockSize The block size of the cipher. + * @property {Format} formatter The default formatting strategy to convert this cipher params object to a string. + */ + var CipherParams = C_lib.CipherParams = Base.extend({ + /** + * Initializes a newly created cipher params object. + * + * @param {Object} cipherParams An object with any of the possible cipher parameters. + * + * @example + * + * var cipherParams = CryptoJS.lib.CipherParams.create({ + * ciphertext: ciphertextWordArray, + * key: keyWordArray, + * iv: ivWordArray, + * salt: saltWordArray, + * algorithm: CryptoJS.algo.AES, + * mode: CryptoJS.mode.CBC, + * padding: CryptoJS.pad.PKCS7, + * blockSize: 4, + * formatter: CryptoJS.format.OpenSSL + * }); + */ + init: function (cipherParams) { + this.mixIn(cipherParams); + }, + + /** + * Converts this cipher params object to a string. + * + * @param {Format} formatter (Optional) The formatting strategy to use. + * + * @return {string} The stringified cipher params. + * + * @throws Error If neither the formatter nor the default formatter is set. + * + * @example + * + * var string = cipherParams + ''; + * var string = cipherParams.toString(); + * var string = cipherParams.toString(CryptoJS.format.OpenSSL); + */ + toString: function (formatter) { + return (formatter || this.formatter).stringify(this); + } + }); + + /** + * Format namespace. + */ + var C_format = C.format = {}; + + /** + * OpenSSL formatting strategy. + */ + var OpenSSLFormatter = C_format.OpenSSL = { + /** + * Converts a cipher params object to an OpenSSL-compatible string. + * + * @param {CipherParams} cipherParams The cipher params object. + * + * @return {string} The OpenSSL-compatible string. + * + * @static + * + * @example + * + * var openSSLString = CryptoJS.format.OpenSSL.stringify(cipherParams); + */ + stringify: function (cipherParams) { + var wordArray; + + // Shortcuts + var ciphertext = cipherParams.ciphertext; + var salt = cipherParams.salt; + + // Format + if (salt) { + wordArray = WordArray.create([0x53616c74, 0x65645f5f]).concat(salt).concat(ciphertext); + } else { + wordArray = ciphertext; + } + + return wordArray.toString(Base64); + }, + + /** + * Converts an OpenSSL-compatible string to a cipher params object. + * + * @param {string} openSSLStr The OpenSSL-compatible string. + * + * @return {CipherParams} The cipher params object. + * + * @static + * + * @example + * + * var cipherParams = CryptoJS.format.OpenSSL.parse(openSSLString); + */ + parse: function (openSSLStr) { + var salt; + + // Parse base64 + var ciphertext = Base64.parse(openSSLStr); + + // Shortcut + var ciphertextWords = ciphertext.words; + + // Test for salt + if (ciphertextWords[0] == 0x53616c74 && ciphertextWords[1] == 0x65645f5f) { + // Extract salt + salt = WordArray.create(ciphertextWords.slice(2, 4)); + + // Remove salt from ciphertext + ciphertextWords.splice(0, 4); + ciphertext.sigBytes -= 16; + } + + return CipherParams.create({ ciphertext: ciphertext, salt: salt }); + } + }; + + /** + * A cipher wrapper that returns ciphertext as a serializable cipher params object. + */ + var SerializableCipher = C_lib.SerializableCipher = Base.extend({ + /** + * Configuration options. + * + * @property {Formatter} format The formatting strategy to convert cipher param objects to and from a string. Default: OpenSSL + */ + cfg: Base.extend({ + format: OpenSSLFormatter + }), + + /** + * Encrypts a message. + * + * @param {Cipher} cipher The cipher algorithm to use. + * @param {WordArray|string} message The message to encrypt. + * @param {WordArray} key The key. + * @param {Object} cfg (Optional) The configuration options to use for this operation. + * + * @return {CipherParams} A cipher params object. + * + * @static + * + * @example + * + * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key); + * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv }); + * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv, format: CryptoJS.format.OpenSSL }); + */ + encrypt: function (cipher, message, key, cfg) { + // Apply config defaults + cfg = this.cfg.extend(cfg); + + // Encrypt + var encryptor = cipher.createEncryptor(key, cfg); + var ciphertext = encryptor.finalize(message); + + // Shortcut + var cipherCfg = encryptor.cfg; + + // Create and return serializable cipher params + return CipherParams.create({ + ciphertext: ciphertext, + key: key, + iv: cipherCfg.iv, + algorithm: cipher, + mode: cipherCfg.mode, + padding: cipherCfg.padding, + blockSize: cipher.blockSize, + formatter: cfg.format + }); + }, + + /** + * Decrypts serialized ciphertext. + * + * @param {Cipher} cipher The cipher algorithm to use. + * @param {CipherParams|string} ciphertext The ciphertext to decrypt. + * @param {WordArray} key The key. + * @param {Object} cfg (Optional) The configuration options to use for this operation. + * + * @return {WordArray} The plaintext. + * + * @static + * + * @example + * + * var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, key, { iv: iv, format: CryptoJS.format.OpenSSL }); + * var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, key, { iv: iv, format: CryptoJS.format.OpenSSL }); + */ + decrypt: function (cipher, ciphertext, key, cfg) { + // Apply config defaults + cfg = this.cfg.extend(cfg); + + // Convert string to CipherParams + ciphertext = this._parse(ciphertext, cfg.format); + + // Decrypt + var plaintext = cipher.createDecryptor(key, cfg).finalize(ciphertext.ciphertext); + + return plaintext; + }, + + /** + * Converts serialized ciphertext to CipherParams, + * else assumed CipherParams already and returns ciphertext unchanged. + * + * @param {CipherParams|string} ciphertext The ciphertext. + * @param {Formatter} format The formatting strategy to use to parse serialized ciphertext. + * + * @return {CipherParams} The unserialized ciphertext. + * + * @static + * + * @example + * + * var ciphertextParams = CryptoJS.lib.SerializableCipher._parse(ciphertextStringOrParams, format); + */ + _parse: function (ciphertext, format) { + if (typeof ciphertext == 'string') { + return format.parse(ciphertext, this); + } else { + return ciphertext; + } + } + }); + + /** + * Key derivation function namespace. + */ + var C_kdf = C.kdf = {}; + + /** + * OpenSSL key derivation function. + */ + var OpenSSLKdf = C_kdf.OpenSSL = { + /** + * Derives a key and IV from a password. + * + * @param {string} password The password to derive from. + * @param {number} keySize The size in words of the key to generate. + * @param {number} ivSize The size in words of the IV to generate. + * @param {WordArray|string} salt (Optional) A 64-bit salt to use. If omitted, a salt will be generated randomly. + * + * @return {CipherParams} A cipher params object with the key, IV, and salt. + * + * @static + * + * @example + * + * var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32); + * var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32, 'saltsalt'); + */ + execute: function (password, keySize, ivSize, salt) { + // Generate random salt + if (!salt) { + salt = WordArray.random(64/8); + } + + // Derive key and IV + var key = EvpKDF.create({ keySize: keySize + ivSize }).compute(password, salt); + + // Separate key and IV + var iv = WordArray.create(key.words.slice(keySize), ivSize * 4); + key.sigBytes = keySize * 4; + + // Return params + return CipherParams.create({ key: key, iv: iv, salt: salt }); + } + }; + + /** + * A serializable cipher wrapper that derives the key from a password, + * and returns ciphertext as a serializable cipher params object. + */ + var PasswordBasedCipher = C_lib.PasswordBasedCipher = SerializableCipher.extend({ + /** + * Configuration options. + * + * @property {KDF} kdf The key derivation function to use to generate a key and IV from a password. Default: OpenSSL + */ + cfg: SerializableCipher.cfg.extend({ + kdf: OpenSSLKdf + }), + + /** + * Encrypts a message using a password. + * + * @param {Cipher} cipher The cipher algorithm to use. + * @param {WordArray|string} message The message to encrypt. + * @param {string} password The password. + * @param {Object} cfg (Optional) The configuration options to use for this operation. + * + * @return {CipherParams} A cipher params object. + * + * @static + * + * @example + * + * var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password'); + * var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password', { format: CryptoJS.format.OpenSSL }); + */ + encrypt: function (cipher, message, password, cfg) { + // Apply config defaults + cfg = this.cfg.extend(cfg); + + // Derive key and other params + var derivedParams = cfg.kdf.execute(password, cipher.keySize, cipher.ivSize); + + // Add IV to config + cfg.iv = derivedParams.iv; + + // Encrypt + var ciphertext = SerializableCipher.encrypt.call(this, cipher, message, derivedParams.key, cfg); + + // Mix in derived params + ciphertext.mixIn(derivedParams); + + return ciphertext; + }, + + /** + * Decrypts serialized ciphertext using a password. + * + * @param {Cipher} cipher The cipher algorithm to use. + * @param {CipherParams|string} ciphertext The ciphertext to decrypt. + * @param {string} password The password. + * @param {Object} cfg (Optional) The configuration options to use for this operation. + * + * @return {WordArray} The plaintext. + * + * @static + * + * @example + * + * var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, 'password', { format: CryptoJS.format.OpenSSL }); + * var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, 'password', { format: CryptoJS.format.OpenSSL }); + */ + decrypt: function (cipher, ciphertext, password, cfg) { + // Apply config defaults + cfg = this.cfg.extend(cfg); + + // Convert string to CipherParams + ciphertext = this._parse(ciphertext, cfg.format); + + // Derive key and other params + var derivedParams = cfg.kdf.execute(password, cipher.keySize, cipher.ivSize, ciphertext.salt); + + // Add IV to config + cfg.iv = derivedParams.iv; + + // Decrypt + var plaintext = SerializableCipher.decrypt.call(this, cipher, ciphertext, derivedParams.key, cfg); + + return plaintext; + } + }); + }()); + + + /** + * Cipher Feedback block mode. + */ + CryptoJS.mode.CFB = (function () { + var CFB = CryptoJS.lib.BlockCipherMode.extend(); + + CFB.Encryptor = CFB.extend({ + processBlock: function (words, offset) { + // Shortcuts + var cipher = this._cipher; + var blockSize = cipher.blockSize; + + generateKeystreamAndEncrypt.call(this, words, offset, blockSize, cipher); + + // Remember this block to use with next block + this._prevBlock = words.slice(offset, offset + blockSize); + } + }); + + CFB.Decryptor = CFB.extend({ + processBlock: function (words, offset) { + // Shortcuts + var cipher = this._cipher; + var blockSize = cipher.blockSize; + + // Remember this block to use with next block + var thisBlock = words.slice(offset, offset + blockSize); + + generateKeystreamAndEncrypt.call(this, words, offset, blockSize, cipher); + + // This block becomes the previous block + this._prevBlock = thisBlock; + } + }); + + function generateKeystreamAndEncrypt(words, offset, blockSize, cipher) { + var keystream; + + // Shortcut + var iv = this._iv; + + // Generate keystream + if (iv) { + keystream = iv.slice(0); + + // Remove IV for subsequent blocks + this._iv = undefined; + } else { + keystream = this._prevBlock; + } + cipher.encryptBlock(keystream, 0); + + // Encrypt + for (var i = 0; i < blockSize; i++) { + words[offset + i] ^= keystream[i]; + } + } + + return CFB; + }()); + + + /** + * Counter block mode. + */ + CryptoJS.mode.CTR = (function () { + var CTR = CryptoJS.lib.BlockCipherMode.extend(); + + var Encryptor = CTR.Encryptor = CTR.extend({ + processBlock: function (words, offset) { + // Shortcuts + var cipher = this._cipher + var blockSize = cipher.blockSize; + var iv = this._iv; + var counter = this._counter; + + // Generate keystream + if (iv) { + counter = this._counter = iv.slice(0); + + // Remove IV for subsequent blocks + this._iv = undefined; + } + var keystream = counter.slice(0); + cipher.encryptBlock(keystream, 0); + + // Increment counter + counter[blockSize - 1] = (counter[blockSize - 1] + 1) | 0 + + // Encrypt + for (var i = 0; i < blockSize; i++) { + words[offset + i] ^= keystream[i]; + } + } + }); + + CTR.Decryptor = Encryptor; + + return CTR; + }()); + + + /** @preserve + * Counter block mode compatible with Dr Brian Gladman fileenc.c + * derived from CryptoJS.mode.CTR + * Jan Hruby jhruby.web@gmail.com + */ + CryptoJS.mode.CTRGladman = (function () { + var CTRGladman = CryptoJS.lib.BlockCipherMode.extend(); + + function incWord(word) + { + if (((word >> 24) & 0xff) === 0xff) { //overflow + var b1 = (word >> 16)&0xff; + var b2 = (word >> 8)&0xff; + var b3 = word & 0xff; + + if (b1 === 0xff) // overflow b1 + { + b1 = 0; + if (b2 === 0xff) + { + b2 = 0; + if (b3 === 0xff) + { + b3 = 0; + } + else + { + ++b3; + } + } + else + { + ++b2; + } + } + else + { + ++b1; + } + + word = 0; + word += (b1 << 16); + word += (b2 << 8); + word += b3; + } + else + { + word += (0x01 << 24); + } + return word; + } + + function incCounter(counter) + { + if ((counter[0] = incWord(counter[0])) === 0) + { + // encr_data in fileenc.c from Dr Brian Gladman's counts only with DWORD j < 8 + counter[1] = incWord(counter[1]); + } + return counter; + } + + var Encryptor = CTRGladman.Encryptor = CTRGladman.extend({ + processBlock: function (words, offset) { + // Shortcuts + var cipher = this._cipher + var blockSize = cipher.blockSize; + var iv = this._iv; + var counter = this._counter; + + // Generate keystream + if (iv) { + counter = this._counter = iv.slice(0); + + // Remove IV for subsequent blocks + this._iv = undefined; + } + + incCounter(counter); + + var keystream = counter.slice(0); + cipher.encryptBlock(keystream, 0); + + // Encrypt + for (var i = 0; i < blockSize; i++) { + words[offset + i] ^= keystream[i]; + } + } + }); + + CTRGladman.Decryptor = Encryptor; + + return CTRGladman; + }()); + + + + + /** + * Output Feedback block mode. + */ + CryptoJS.mode.OFB = (function () { + var OFB = CryptoJS.lib.BlockCipherMode.extend(); + + var Encryptor = OFB.Encryptor = OFB.extend({ + processBlock: function (words, offset) { + // Shortcuts + var cipher = this._cipher + var blockSize = cipher.blockSize; + var iv = this._iv; + var keystream = this._keystream; + + // Generate keystream + if (iv) { + keystream = this._keystream = iv.slice(0); + + // Remove IV for subsequent blocks + this._iv = undefined; + } + cipher.encryptBlock(keystream, 0); + + // Encrypt + for (var i = 0; i < blockSize; i++) { + words[offset + i] ^= keystream[i]; + } + } + }); + + OFB.Decryptor = Encryptor; + + return OFB; + }()); + + + /** + * Electronic Codebook block mode. + */ + CryptoJS.mode.ECB = (function () { + var ECB = CryptoJS.lib.BlockCipherMode.extend(); + + ECB.Encryptor = ECB.extend({ + processBlock: function (words, offset) { + this._cipher.encryptBlock(words, offset); + } + }); + + ECB.Decryptor = ECB.extend({ + processBlock: function (words, offset) { + this._cipher.decryptBlock(words, offset); + } + }); + + return ECB; + }()); + + + /** + * ANSI X.923 padding strategy. + */ + CryptoJS.pad.AnsiX923 = { + pad: function (data, blockSize) { + // Shortcuts + var dataSigBytes = data.sigBytes; + var blockSizeBytes = blockSize * 4; + + // Count padding bytes + var nPaddingBytes = blockSizeBytes - dataSigBytes % blockSizeBytes; + + // Compute last byte position + var lastBytePos = dataSigBytes + nPaddingBytes - 1; + + // Pad + data.clamp(); + data.words[lastBytePos >>> 2] |= nPaddingBytes << (24 - (lastBytePos % 4) * 8); + data.sigBytes += nPaddingBytes; + }, + + unpad: function (data) { + // Get number of padding bytes from last byte + var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff; + + // Remove padding + data.sigBytes -= nPaddingBytes; + } + }; + + + /** + * ISO 10126 padding strategy. + */ + CryptoJS.pad.Iso10126 = { + pad: function (data, blockSize) { + // Shortcut + var blockSizeBytes = blockSize * 4; + + // Count padding bytes + var nPaddingBytes = blockSizeBytes - data.sigBytes % blockSizeBytes; + + // Pad + data.concat(CryptoJS.lib.WordArray.random(nPaddingBytes - 1)). + concat(CryptoJS.lib.WordArray.create([nPaddingBytes << 24], 1)); + }, + + unpad: function (data) { + // Get number of padding bytes from last byte + var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff; + + // Remove padding + data.sigBytes -= nPaddingBytes; + } + }; + + + /** + * ISO/IEC 9797-1 Padding Method 2. + */ + CryptoJS.pad.Iso97971 = { + pad: function (data, blockSize) { + // Add 0x80 byte + data.concat(CryptoJS.lib.WordArray.create([0x80000000], 1)); + + // Zero pad the rest + CryptoJS.pad.ZeroPadding.pad(data, blockSize); + }, + + unpad: function (data) { + // Remove zero padding + CryptoJS.pad.ZeroPadding.unpad(data); + + // Remove one more byte -- the 0x80 byte + data.sigBytes--; + } + }; + + + /** + * Zero padding strategy. + */ + CryptoJS.pad.ZeroPadding = { + pad: function (data, blockSize) { + // Shortcut + var blockSizeBytes = blockSize * 4; + + // Pad + data.clamp(); + data.sigBytes += blockSizeBytes - ((data.sigBytes % blockSizeBytes) || blockSizeBytes); + }, + + unpad: function (data) { + // Shortcut + var dataWords = data.words; + + // Unpad + var i = data.sigBytes - 1; + for (var i = data.sigBytes - 1; i >= 0; i--) { + if (((dataWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff)) { + data.sigBytes = i + 1; + break; + } + } + } + }; + + + /** + * A noop padding strategy. + */ + CryptoJS.pad.NoPadding = { + pad: function () { + }, + + unpad: function () { + } + }; + + + (function (undefined) { + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var CipherParams = C_lib.CipherParams; + var C_enc = C.enc; + var Hex = C_enc.Hex; + var C_format = C.format; + + var HexFormatter = C_format.Hex = { + /** + * Converts the ciphertext of a cipher params object to a hexadecimally encoded string. + * + * @param {CipherParams} cipherParams The cipher params object. + * + * @return {string} The hexadecimally encoded string. + * + * @static + * + * @example + * + * var hexString = CryptoJS.format.Hex.stringify(cipherParams); + */ + stringify: function (cipherParams) { + return cipherParams.ciphertext.toString(Hex); + }, + + /** + * Converts a hexadecimally encoded ciphertext string to a cipher params object. + * + * @param {string} input The hexadecimally encoded string. + * + * @return {CipherParams} The cipher params object. + * + * @static + * + * @example + * + * var cipherParams = CryptoJS.format.Hex.parse(hexString); + */ + parse: function (input) { + var ciphertext = Hex.parse(input); + return CipherParams.create({ ciphertext: ciphertext }); + } + }; + }()); + + + (function () { + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var BlockCipher = C_lib.BlockCipher; + var C_algo = C.algo; + + // Lookup tables + var SBOX = []; + var INV_SBOX = []; + var SUB_MIX_0 = []; + var SUB_MIX_1 = []; + var SUB_MIX_2 = []; + var SUB_MIX_3 = []; + var INV_SUB_MIX_0 = []; + var INV_SUB_MIX_1 = []; + var INV_SUB_MIX_2 = []; + var INV_SUB_MIX_3 = []; + + // Compute lookup tables + (function () { + // Compute double table + var d = []; + for (var i = 0; i < 256; i++) { + if (i < 128) { + d[i] = i << 1; + } else { + d[i] = (i << 1) ^ 0x11b; + } + } + + // Walk GF(2^8) + var x = 0; + var xi = 0; + for (var i = 0; i < 256; i++) { + // Compute sbox + var sx = xi ^ (xi << 1) ^ (xi << 2) ^ (xi << 3) ^ (xi << 4); + sx = (sx >>> 8) ^ (sx & 0xff) ^ 0x63; + SBOX[x] = sx; + INV_SBOX[sx] = x; + + // Compute multiplication + var x2 = d[x]; + var x4 = d[x2]; + var x8 = d[x4]; + + // Compute sub bytes, mix columns tables + var t = (d[sx] * 0x101) ^ (sx * 0x1010100); + SUB_MIX_0[x] = (t << 24) | (t >>> 8); + SUB_MIX_1[x] = (t << 16) | (t >>> 16); + SUB_MIX_2[x] = (t << 8) | (t >>> 24); + SUB_MIX_3[x] = t; + + // Compute inv sub bytes, inv mix columns tables + var t = (x8 * 0x1010101) ^ (x4 * 0x10001) ^ (x2 * 0x101) ^ (x * 0x1010100); + INV_SUB_MIX_0[sx] = (t << 24) | (t >>> 8); + INV_SUB_MIX_1[sx] = (t << 16) | (t >>> 16); + INV_SUB_MIX_2[sx] = (t << 8) | (t >>> 24); + INV_SUB_MIX_3[sx] = t; + + // Compute next counter + if (!x) { + x = xi = 1; + } else { + x = x2 ^ d[d[d[x8 ^ x2]]]; + xi ^= d[d[xi]]; + } + } + }()); + + // Precomputed Rcon lookup + var RCON = [0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36]; + + /** + * AES block cipher algorithm. + */ + var AES = C_algo.AES = BlockCipher.extend({ + _doReset: function () { + var t; + + // Skip reset of nRounds has been set before and key did not change + if (this._nRounds && this._keyPriorReset === this._key) { + return; + } + + // Shortcuts + var key = this._keyPriorReset = this._key; + var keyWords = key.words; + var keySize = key.sigBytes / 4; + + // Compute number of rounds + var nRounds = this._nRounds = keySize + 6; + + // Compute number of key schedule rows + var ksRows = (nRounds + 1) * 4; + + // Compute key schedule + var keySchedule = this._keySchedule = []; + for (var ksRow = 0; ksRow < ksRows; ksRow++) { + if (ksRow < keySize) { + keySchedule[ksRow] = keyWords[ksRow]; + } else { + t = keySchedule[ksRow - 1]; + + if (!(ksRow % keySize)) { + // Rot word + t = (t << 8) | (t >>> 24); + + // Sub word + t = (SBOX[t >>> 24] << 24) | (SBOX[(t >>> 16) & 0xff] << 16) | (SBOX[(t >>> 8) & 0xff] << 8) | SBOX[t & 0xff]; + + // Mix Rcon + t ^= RCON[(ksRow / keySize) | 0] << 24; + } else if (keySize > 6 && ksRow % keySize == 4) { + // Sub word + t = (SBOX[t >>> 24] << 24) | (SBOX[(t >>> 16) & 0xff] << 16) | (SBOX[(t >>> 8) & 0xff] << 8) | SBOX[t & 0xff]; + } + + keySchedule[ksRow] = keySchedule[ksRow - keySize] ^ t; + } + } + + // Compute inv key schedule + var invKeySchedule = this._invKeySchedule = []; + for (var invKsRow = 0; invKsRow < ksRows; invKsRow++) { + var ksRow = ksRows - invKsRow; + + if (invKsRow % 4) { + var t = keySchedule[ksRow]; + } else { + var t = keySchedule[ksRow - 4]; + } + + if (invKsRow < 4 || ksRow <= 4) { + invKeySchedule[invKsRow] = t; + } else { + invKeySchedule[invKsRow] = INV_SUB_MIX_0[SBOX[t >>> 24]] ^ INV_SUB_MIX_1[SBOX[(t >>> 16) & 0xff]] ^ + INV_SUB_MIX_2[SBOX[(t >>> 8) & 0xff]] ^ INV_SUB_MIX_3[SBOX[t & 0xff]]; + } + } + }, + + encryptBlock: function (M, offset) { + this._doCryptBlock(M, offset, this._keySchedule, SUB_MIX_0, SUB_MIX_1, SUB_MIX_2, SUB_MIX_3, SBOX); + }, + + decryptBlock: function (M, offset) { + // Swap 2nd and 4th rows + var t = M[offset + 1]; + M[offset + 1] = M[offset + 3]; + M[offset + 3] = t; + + this._doCryptBlock(M, offset, this._invKeySchedule, INV_SUB_MIX_0, INV_SUB_MIX_1, INV_SUB_MIX_2, INV_SUB_MIX_3, INV_SBOX); + + // Inv swap 2nd and 4th rows + var t = M[offset + 1]; + M[offset + 1] = M[offset + 3]; + M[offset + 3] = t; + }, + + _doCryptBlock: function (M, offset, keySchedule, SUB_MIX_0, SUB_MIX_1, SUB_MIX_2, SUB_MIX_3, SBOX) { + // Shortcut + var nRounds = this._nRounds; + + // Get input, add round key + var s0 = M[offset] ^ keySchedule[0]; + var s1 = M[offset + 1] ^ keySchedule[1]; + var s2 = M[offset + 2] ^ keySchedule[2]; + var s3 = M[offset + 3] ^ keySchedule[3]; + + // Key schedule row counter + var ksRow = 4; + + // Rounds + for (var round = 1; round < nRounds; round++) { + // Shift rows, sub bytes, mix columns, add round key + var t0 = SUB_MIX_0[s0 >>> 24] ^ SUB_MIX_1[(s1 >>> 16) & 0xff] ^ SUB_MIX_2[(s2 >>> 8) & 0xff] ^ SUB_MIX_3[s3 & 0xff] ^ keySchedule[ksRow++]; + var t1 = SUB_MIX_0[s1 >>> 24] ^ SUB_MIX_1[(s2 >>> 16) & 0xff] ^ SUB_MIX_2[(s3 >>> 8) & 0xff] ^ SUB_MIX_3[s0 & 0xff] ^ keySchedule[ksRow++]; + var t2 = SUB_MIX_0[s2 >>> 24] ^ SUB_MIX_1[(s3 >>> 16) & 0xff] ^ SUB_MIX_2[(s0 >>> 8) & 0xff] ^ SUB_MIX_3[s1 & 0xff] ^ keySchedule[ksRow++]; + var t3 = SUB_MIX_0[s3 >>> 24] ^ SUB_MIX_1[(s0 >>> 16) & 0xff] ^ SUB_MIX_2[(s1 >>> 8) & 0xff] ^ SUB_MIX_3[s2 & 0xff] ^ keySchedule[ksRow++]; + + // Update state + s0 = t0; + s1 = t1; + s2 = t2; + s3 = t3; + } + + // Shift rows, sub bytes, add round key + var t0 = ((SBOX[s0 >>> 24] << 24) | (SBOX[(s1 >>> 16) & 0xff] << 16) | (SBOX[(s2 >>> 8) & 0xff] << 8) | SBOX[s3 & 0xff]) ^ keySchedule[ksRow++]; + var t1 = ((SBOX[s1 >>> 24] << 24) | (SBOX[(s2 >>> 16) & 0xff] << 16) | (SBOX[(s3 >>> 8) & 0xff] << 8) | SBOX[s0 & 0xff]) ^ keySchedule[ksRow++]; + var t2 = ((SBOX[s2 >>> 24] << 24) | (SBOX[(s3 >>> 16) & 0xff] << 16) | (SBOX[(s0 >>> 8) & 0xff] << 8) | SBOX[s1 & 0xff]) ^ keySchedule[ksRow++]; + var t3 = ((SBOX[s3 >>> 24] << 24) | (SBOX[(s0 >>> 16) & 0xff] << 16) | (SBOX[(s1 >>> 8) & 0xff] << 8) | SBOX[s2 & 0xff]) ^ keySchedule[ksRow++]; + + // Set output + M[offset] = t0; + M[offset + 1] = t1; + M[offset + 2] = t2; + M[offset + 3] = t3; + }, + + keySize: 256/32 + }); + + /** + * Shortcut functions to the cipher's object interface. + * + * @example + * + * var ciphertext = CryptoJS.AES.encrypt(message, key, cfg); + * var plaintext = CryptoJS.AES.decrypt(ciphertext, key, cfg); + */ + C.AES = BlockCipher._createHelper(AES); + }()); + + + (function () { + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var WordArray = C_lib.WordArray; + var BlockCipher = C_lib.BlockCipher; + var C_algo = C.algo; + + // Permuted Choice 1 constants + var PC1 = [ + 57, 49, 41, 33, 25, 17, 9, 1, + 58, 50, 42, 34, 26, 18, 10, 2, + 59, 51, 43, 35, 27, 19, 11, 3, + 60, 52, 44, 36, 63, 55, 47, 39, + 31, 23, 15, 7, 62, 54, 46, 38, + 30, 22, 14, 6, 61, 53, 45, 37, + 29, 21, 13, 5, 28, 20, 12, 4 + ]; + + // Permuted Choice 2 constants + var PC2 = [ + 14, 17, 11, 24, 1, 5, + 3, 28, 15, 6, 21, 10, + 23, 19, 12, 4, 26, 8, + 16, 7, 27, 20, 13, 2, + 41, 52, 31, 37, 47, 55, + 30, 40, 51, 45, 33, 48, + 44, 49, 39, 56, 34, 53, + 46, 42, 50, 36, 29, 32 + ]; + + // Cumulative bit shift constants + var BIT_SHIFTS = [1, 2, 4, 6, 8, 10, 12, 14, 15, 17, 19, 21, 23, 25, 27, 28]; + + // SBOXes and round permutation constants + var SBOX_P = [ + { + 0x0: 0x808200, + 0x10000000: 0x8000, + 0x20000000: 0x808002, + 0x30000000: 0x2, + 0x40000000: 0x200, + 0x50000000: 0x808202, + 0x60000000: 0x800202, + 0x70000000: 0x800000, + 0x80000000: 0x202, + 0x90000000: 0x800200, + 0xa0000000: 0x8200, + 0xb0000000: 0x808000, + 0xc0000000: 0x8002, + 0xd0000000: 0x800002, + 0xe0000000: 0x0, + 0xf0000000: 0x8202, + 0x8000000: 0x0, + 0x18000000: 0x808202, + 0x28000000: 0x8202, + 0x38000000: 0x8000, + 0x48000000: 0x808200, + 0x58000000: 0x200, + 0x68000000: 0x808002, + 0x78000000: 0x2, + 0x88000000: 0x800200, + 0x98000000: 0x8200, + 0xa8000000: 0x808000, + 0xb8000000: 0x800202, + 0xc8000000: 0x800002, + 0xd8000000: 0x8002, + 0xe8000000: 0x202, + 0xf8000000: 0x800000, + 0x1: 0x8000, + 0x10000001: 0x2, + 0x20000001: 0x808200, + 0x30000001: 0x800000, + 0x40000001: 0x808002, + 0x50000001: 0x8200, + 0x60000001: 0x200, + 0x70000001: 0x800202, + 0x80000001: 0x808202, + 0x90000001: 0x808000, + 0xa0000001: 0x800002, + 0xb0000001: 0x8202, + 0xc0000001: 0x202, + 0xd0000001: 0x800200, + 0xe0000001: 0x8002, + 0xf0000001: 0x0, + 0x8000001: 0x808202, + 0x18000001: 0x808000, + 0x28000001: 0x800000, + 0x38000001: 0x200, + 0x48000001: 0x8000, + 0x58000001: 0x800002, + 0x68000001: 0x2, + 0x78000001: 0x8202, + 0x88000001: 0x8002, + 0x98000001: 0x800202, + 0xa8000001: 0x202, + 0xb8000001: 0x808200, + 0xc8000001: 0x800200, + 0xd8000001: 0x0, + 0xe8000001: 0x8200, + 0xf8000001: 0x808002 + }, + { + 0x0: 0x40084010, + 0x1000000: 0x4000, + 0x2000000: 0x80000, + 0x3000000: 0x40080010, + 0x4000000: 0x40000010, + 0x5000000: 0x40084000, + 0x6000000: 0x40004000, + 0x7000000: 0x10, + 0x8000000: 0x84000, + 0x9000000: 0x40004010, + 0xa000000: 0x40000000, + 0xb000000: 0x84010, + 0xc000000: 0x80010, + 0xd000000: 0x0, + 0xe000000: 0x4010, + 0xf000000: 0x40080000, + 0x800000: 0x40004000, + 0x1800000: 0x84010, + 0x2800000: 0x10, + 0x3800000: 0x40004010, + 0x4800000: 0x40084010, + 0x5800000: 0x40000000, + 0x6800000: 0x80000, + 0x7800000: 0x40080010, + 0x8800000: 0x80010, + 0x9800000: 0x0, + 0xa800000: 0x4000, + 0xb800000: 0x40080000, + 0xc800000: 0x40000010, + 0xd800000: 0x84000, + 0xe800000: 0x40084000, + 0xf800000: 0x4010, + 0x10000000: 0x0, + 0x11000000: 0x40080010, + 0x12000000: 0x40004010, + 0x13000000: 0x40084000, + 0x14000000: 0x40080000, + 0x15000000: 0x10, + 0x16000000: 0x84010, + 0x17000000: 0x4000, + 0x18000000: 0x4010, + 0x19000000: 0x80000, + 0x1a000000: 0x80010, + 0x1b000000: 0x40000010, + 0x1c000000: 0x84000, + 0x1d000000: 0x40004000, + 0x1e000000: 0x40000000, + 0x1f000000: 0x40084010, + 0x10800000: 0x84010, + 0x11800000: 0x80000, + 0x12800000: 0x40080000, + 0x13800000: 0x4000, + 0x14800000: 0x40004000, + 0x15800000: 0x40084010, + 0x16800000: 0x10, + 0x17800000: 0x40000000, + 0x18800000: 0x40084000, + 0x19800000: 0x40000010, + 0x1a800000: 0x40004010, + 0x1b800000: 0x80010, + 0x1c800000: 0x0, + 0x1d800000: 0x4010, + 0x1e800000: 0x40080010, + 0x1f800000: 0x84000 + }, + { + 0x0: 0x104, + 0x100000: 0x0, + 0x200000: 0x4000100, + 0x300000: 0x10104, + 0x400000: 0x10004, + 0x500000: 0x4000004, + 0x600000: 0x4010104, + 0x700000: 0x4010000, + 0x800000: 0x4000000, + 0x900000: 0x4010100, + 0xa00000: 0x10100, + 0xb00000: 0x4010004, + 0xc00000: 0x4000104, + 0xd00000: 0x10000, + 0xe00000: 0x4, + 0xf00000: 0x100, + 0x80000: 0x4010100, + 0x180000: 0x4010004, + 0x280000: 0x0, + 0x380000: 0x4000100, + 0x480000: 0x4000004, + 0x580000: 0x10000, + 0x680000: 0x10004, + 0x780000: 0x104, + 0x880000: 0x4, + 0x980000: 0x100, + 0xa80000: 0x4010000, + 0xb80000: 0x10104, + 0xc80000: 0x10100, + 0xd80000: 0x4000104, + 0xe80000: 0x4010104, + 0xf80000: 0x4000000, + 0x1000000: 0x4010100, + 0x1100000: 0x10004, + 0x1200000: 0x10000, + 0x1300000: 0x4000100, + 0x1400000: 0x100, + 0x1500000: 0x4010104, + 0x1600000: 0x4000004, + 0x1700000: 0x0, + 0x1800000: 0x4000104, + 0x1900000: 0x4000000, + 0x1a00000: 0x4, + 0x1b00000: 0x10100, + 0x1c00000: 0x4010000, + 0x1d00000: 0x104, + 0x1e00000: 0x10104, + 0x1f00000: 0x4010004, + 0x1080000: 0x4000000, + 0x1180000: 0x104, + 0x1280000: 0x4010100, + 0x1380000: 0x0, + 0x1480000: 0x10004, + 0x1580000: 0x4000100, + 0x1680000: 0x100, + 0x1780000: 0x4010004, + 0x1880000: 0x10000, + 0x1980000: 0x4010104, + 0x1a80000: 0x10104, + 0x1b80000: 0x4000004, + 0x1c80000: 0x4000104, + 0x1d80000: 0x4010000, + 0x1e80000: 0x4, + 0x1f80000: 0x10100 + }, + { + 0x0: 0x80401000, + 0x10000: 0x80001040, + 0x20000: 0x401040, + 0x30000: 0x80400000, + 0x40000: 0x0, + 0x50000: 0x401000, + 0x60000: 0x80000040, + 0x70000: 0x400040, + 0x80000: 0x80000000, + 0x90000: 0x400000, + 0xa0000: 0x40, + 0xb0000: 0x80001000, + 0xc0000: 0x80400040, + 0xd0000: 0x1040, + 0xe0000: 0x1000, + 0xf0000: 0x80401040, + 0x8000: 0x80001040, + 0x18000: 0x40, + 0x28000: 0x80400040, + 0x38000: 0x80001000, + 0x48000: 0x401000, + 0x58000: 0x80401040, + 0x68000: 0x0, + 0x78000: 0x80400000, + 0x88000: 0x1000, + 0x98000: 0x80401000, + 0xa8000: 0x400000, + 0xb8000: 0x1040, + 0xc8000: 0x80000000, + 0xd8000: 0x400040, + 0xe8000: 0x401040, + 0xf8000: 0x80000040, + 0x100000: 0x400040, + 0x110000: 0x401000, + 0x120000: 0x80000040, + 0x130000: 0x0, + 0x140000: 0x1040, + 0x150000: 0x80400040, + 0x160000: 0x80401000, + 0x170000: 0x80001040, + 0x180000: 0x80401040, + 0x190000: 0x80000000, + 0x1a0000: 0x80400000, + 0x1b0000: 0x401040, + 0x1c0000: 0x80001000, + 0x1d0000: 0x400000, + 0x1e0000: 0x40, + 0x1f0000: 0x1000, + 0x108000: 0x80400000, + 0x118000: 0x80401040, + 0x128000: 0x0, + 0x138000: 0x401000, + 0x148000: 0x400040, + 0x158000: 0x80000000, + 0x168000: 0x80001040, + 0x178000: 0x40, + 0x188000: 0x80000040, + 0x198000: 0x1000, + 0x1a8000: 0x80001000, + 0x1b8000: 0x80400040, + 0x1c8000: 0x1040, + 0x1d8000: 0x80401000, + 0x1e8000: 0x400000, + 0x1f8000: 0x401040 + }, + { + 0x0: 0x80, + 0x1000: 0x1040000, + 0x2000: 0x40000, + 0x3000: 0x20000000, + 0x4000: 0x20040080, + 0x5000: 0x1000080, + 0x6000: 0x21000080, + 0x7000: 0x40080, + 0x8000: 0x1000000, + 0x9000: 0x20040000, + 0xa000: 0x20000080, + 0xb000: 0x21040080, + 0xc000: 0x21040000, + 0xd000: 0x0, + 0xe000: 0x1040080, + 0xf000: 0x21000000, + 0x800: 0x1040080, + 0x1800: 0x21000080, + 0x2800: 0x80, + 0x3800: 0x1040000, + 0x4800: 0x40000, + 0x5800: 0x20040080, + 0x6800: 0x21040000, + 0x7800: 0x20000000, + 0x8800: 0x20040000, + 0x9800: 0x0, + 0xa800: 0x21040080, + 0xb800: 0x1000080, + 0xc800: 0x20000080, + 0xd800: 0x21000000, + 0xe800: 0x1000000, + 0xf800: 0x40080, + 0x10000: 0x40000, + 0x11000: 0x80, + 0x12000: 0x20000000, + 0x13000: 0x21000080, + 0x14000: 0x1000080, + 0x15000: 0x21040000, + 0x16000: 0x20040080, + 0x17000: 0x1000000, + 0x18000: 0x21040080, + 0x19000: 0x21000000, + 0x1a000: 0x1040000, + 0x1b000: 0x20040000, + 0x1c000: 0x40080, + 0x1d000: 0x20000080, + 0x1e000: 0x0, + 0x1f000: 0x1040080, + 0x10800: 0x21000080, + 0x11800: 0x1000000, + 0x12800: 0x1040000, + 0x13800: 0x20040080, + 0x14800: 0x20000000, + 0x15800: 0x1040080, + 0x16800: 0x80, + 0x17800: 0x21040000, + 0x18800: 0x40080, + 0x19800: 0x21040080, + 0x1a800: 0x0, + 0x1b800: 0x21000000, + 0x1c800: 0x1000080, + 0x1d800: 0x40000, + 0x1e800: 0x20040000, + 0x1f800: 0x20000080 + }, + { + 0x0: 0x10000008, + 0x100: 0x2000, + 0x200: 0x10200000, + 0x300: 0x10202008, + 0x400: 0x10002000, + 0x500: 0x200000, + 0x600: 0x200008, + 0x700: 0x10000000, + 0x800: 0x0, + 0x900: 0x10002008, + 0xa00: 0x202000, + 0xb00: 0x8, + 0xc00: 0x10200008, + 0xd00: 0x202008, + 0xe00: 0x2008, + 0xf00: 0x10202000, + 0x80: 0x10200000, + 0x180: 0x10202008, + 0x280: 0x8, + 0x380: 0x200000, + 0x480: 0x202008, + 0x580: 0x10000008, + 0x680: 0x10002000, + 0x780: 0x2008, + 0x880: 0x200008, + 0x980: 0x2000, + 0xa80: 0x10002008, + 0xb80: 0x10200008, + 0xc80: 0x0, + 0xd80: 0x10202000, + 0xe80: 0x202000, + 0xf80: 0x10000000, + 0x1000: 0x10002000, + 0x1100: 0x10200008, + 0x1200: 0x10202008, + 0x1300: 0x2008, + 0x1400: 0x200000, + 0x1500: 0x10000000, + 0x1600: 0x10000008, + 0x1700: 0x202000, + 0x1800: 0x202008, + 0x1900: 0x0, + 0x1a00: 0x8, + 0x1b00: 0x10200000, + 0x1c00: 0x2000, + 0x1d00: 0x10002008, + 0x1e00: 0x10202000, + 0x1f00: 0x200008, + 0x1080: 0x8, + 0x1180: 0x202000, + 0x1280: 0x200000, + 0x1380: 0x10000008, + 0x1480: 0x10002000, + 0x1580: 0x2008, + 0x1680: 0x10202008, + 0x1780: 0x10200000, + 0x1880: 0x10202000, + 0x1980: 0x10200008, + 0x1a80: 0x2000, + 0x1b80: 0x202008, + 0x1c80: 0x200008, + 0x1d80: 0x0, + 0x1e80: 0x10000000, + 0x1f80: 0x10002008 + }, + { + 0x0: 0x100000, + 0x10: 0x2000401, + 0x20: 0x400, + 0x30: 0x100401, + 0x40: 0x2100401, + 0x50: 0x0, + 0x60: 0x1, + 0x70: 0x2100001, + 0x80: 0x2000400, + 0x90: 0x100001, + 0xa0: 0x2000001, + 0xb0: 0x2100400, + 0xc0: 0x2100000, + 0xd0: 0x401, + 0xe0: 0x100400, + 0xf0: 0x2000000, + 0x8: 0x2100001, + 0x18: 0x0, + 0x28: 0x2000401, + 0x38: 0x2100400, + 0x48: 0x100000, + 0x58: 0x2000001, + 0x68: 0x2000000, + 0x78: 0x401, + 0x88: 0x100401, + 0x98: 0x2000400, + 0xa8: 0x2100000, + 0xb8: 0x100001, + 0xc8: 0x400, + 0xd8: 0x2100401, + 0xe8: 0x1, + 0xf8: 0x100400, + 0x100: 0x2000000, + 0x110: 0x100000, + 0x120: 0x2000401, + 0x130: 0x2100001, + 0x140: 0x100001, + 0x150: 0x2000400, + 0x160: 0x2100400, + 0x170: 0x100401, + 0x180: 0x401, + 0x190: 0x2100401, + 0x1a0: 0x100400, + 0x1b0: 0x1, + 0x1c0: 0x0, + 0x1d0: 0x2100000, + 0x1e0: 0x2000001, + 0x1f0: 0x400, + 0x108: 0x100400, + 0x118: 0x2000401, + 0x128: 0x2100001, + 0x138: 0x1, + 0x148: 0x2000000, + 0x158: 0x100000, + 0x168: 0x401, + 0x178: 0x2100400, + 0x188: 0x2000001, + 0x198: 0x2100000, + 0x1a8: 0x0, + 0x1b8: 0x2100401, + 0x1c8: 0x100401, + 0x1d8: 0x400, + 0x1e8: 0x2000400, + 0x1f8: 0x100001 + }, + { + 0x0: 0x8000820, + 0x1: 0x20000, + 0x2: 0x8000000, + 0x3: 0x20, + 0x4: 0x20020, + 0x5: 0x8020820, + 0x6: 0x8020800, + 0x7: 0x800, + 0x8: 0x8020000, + 0x9: 0x8000800, + 0xa: 0x20800, + 0xb: 0x8020020, + 0xc: 0x820, + 0xd: 0x0, + 0xe: 0x8000020, + 0xf: 0x20820, + 0x80000000: 0x800, + 0x80000001: 0x8020820, + 0x80000002: 0x8000820, + 0x80000003: 0x8000000, + 0x80000004: 0x8020000, + 0x80000005: 0x20800, + 0x80000006: 0x20820, + 0x80000007: 0x20, + 0x80000008: 0x8000020, + 0x80000009: 0x820, + 0x8000000a: 0x20020, + 0x8000000b: 0x8020800, + 0x8000000c: 0x0, + 0x8000000d: 0x8020020, + 0x8000000e: 0x8000800, + 0x8000000f: 0x20000, + 0x10: 0x20820, + 0x11: 0x8020800, + 0x12: 0x20, + 0x13: 0x800, + 0x14: 0x8000800, + 0x15: 0x8000020, + 0x16: 0x8020020, + 0x17: 0x20000, + 0x18: 0x0, + 0x19: 0x20020, + 0x1a: 0x8020000, + 0x1b: 0x8000820, + 0x1c: 0x8020820, + 0x1d: 0x20800, + 0x1e: 0x820, + 0x1f: 0x8000000, + 0x80000010: 0x20000, + 0x80000011: 0x800, + 0x80000012: 0x8020020, + 0x80000013: 0x20820, + 0x80000014: 0x20, + 0x80000015: 0x8020000, + 0x80000016: 0x8000000, + 0x80000017: 0x8000820, + 0x80000018: 0x8020820, + 0x80000019: 0x8000020, + 0x8000001a: 0x8000800, + 0x8000001b: 0x0, + 0x8000001c: 0x20800, + 0x8000001d: 0x820, + 0x8000001e: 0x20020, + 0x8000001f: 0x8020800 + } + ]; + + // Masks that select the SBOX input + var SBOX_MASK = [ + 0xf8000001, 0x1f800000, 0x01f80000, 0x001f8000, + 0x0001f800, 0x00001f80, 0x000001f8, 0x8000001f + ]; + + /** + * DES block cipher algorithm. + */ + var DES = C_algo.DES = BlockCipher.extend({ + _doReset: function () { + // Shortcuts + var key = this._key; + var keyWords = key.words; + + // Select 56 bits according to PC1 + var keyBits = []; + for (var i = 0; i < 56; i++) { + var keyBitPos = PC1[i] - 1; + keyBits[i] = (keyWords[keyBitPos >>> 5] >>> (31 - keyBitPos % 32)) & 1; + } + + // Assemble 16 subkeys + var subKeys = this._subKeys = []; + for (var nSubKey = 0; nSubKey < 16; nSubKey++) { + // Create subkey + var subKey = subKeys[nSubKey] = []; + + // Shortcut + var bitShift = BIT_SHIFTS[nSubKey]; + + // Select 48 bits according to PC2 + for (var i = 0; i < 24; i++) { + // Select from the left 28 key bits + subKey[(i / 6) | 0] |= keyBits[((PC2[i] - 1) + bitShift) % 28] << (31 - i % 6); + + // Select from the right 28 key bits + subKey[4 + ((i / 6) | 0)] |= keyBits[28 + (((PC2[i + 24] - 1) + bitShift) % 28)] << (31 - i % 6); + } + + // Since each subkey is applied to an expanded 32-bit input, + // the subkey can be broken into 8 values scaled to 32-bits, + // which allows the key to be used without expansion + subKey[0] = (subKey[0] << 1) | (subKey[0] >>> 31); + for (var i = 1; i < 7; i++) { + subKey[i] = subKey[i] >>> ((i - 1) * 4 + 3); + } + subKey[7] = (subKey[7] << 5) | (subKey[7] >>> 27); + } + + // Compute inverse subkeys + var invSubKeys = this._invSubKeys = []; + for (var i = 0; i < 16; i++) { + invSubKeys[i] = subKeys[15 - i]; + } + }, + + encryptBlock: function (M, offset) { + this._doCryptBlock(M, offset, this._subKeys); + }, + + decryptBlock: function (M, offset) { + this._doCryptBlock(M, offset, this._invSubKeys); + }, + + _doCryptBlock: function (M, offset, subKeys) { + // Get input + this._lBlock = M[offset]; + this._rBlock = M[offset + 1]; + + // Initial permutation + exchangeLR.call(this, 4, 0x0f0f0f0f); + exchangeLR.call(this, 16, 0x0000ffff); + exchangeRL.call(this, 2, 0x33333333); + exchangeRL.call(this, 8, 0x00ff00ff); + exchangeLR.call(this, 1, 0x55555555); + + // Rounds + for (var round = 0; round < 16; round++) { + // Shortcuts + var subKey = subKeys[round]; + var lBlock = this._lBlock; + var rBlock = this._rBlock; + + // Feistel function + var f = 0; + for (var i = 0; i < 8; i++) { + f |= SBOX_P[i][((rBlock ^ subKey[i]) & SBOX_MASK[i]) >>> 0]; + } + this._lBlock = rBlock; + this._rBlock = lBlock ^ f; + } + + // Undo swap from last round + var t = this._lBlock; + this._lBlock = this._rBlock; + this._rBlock = t; + + // Final permutation + exchangeLR.call(this, 1, 0x55555555); + exchangeRL.call(this, 8, 0x00ff00ff); + exchangeRL.call(this, 2, 0x33333333); + exchangeLR.call(this, 16, 0x0000ffff); + exchangeLR.call(this, 4, 0x0f0f0f0f); + + // Set output + M[offset] = this._lBlock; + M[offset + 1] = this._rBlock; + }, + + keySize: 64/32, + + ivSize: 64/32, + + blockSize: 64/32 + }); + + // Swap bits across the left and right words + function exchangeLR(offset, mask) { + var t = ((this._lBlock >>> offset) ^ this._rBlock) & mask; + this._rBlock ^= t; + this._lBlock ^= t << offset; + } + + function exchangeRL(offset, mask) { + var t = ((this._rBlock >>> offset) ^ this._lBlock) & mask; + this._lBlock ^= t; + this._rBlock ^= t << offset; + } + + /** + * Shortcut functions to the cipher's object interface. + * + * @example + * + * var ciphertext = CryptoJS.DES.encrypt(message, key, cfg); + * var plaintext = CryptoJS.DES.decrypt(ciphertext, key, cfg); + */ + C.DES = BlockCipher._createHelper(DES); + + /** + * Triple-DES block cipher algorithm. + */ + var TripleDES = C_algo.TripleDES = BlockCipher.extend({ + _doReset: function () { + // Shortcuts + var key = this._key; + var keyWords = key.words; + // Make sure the key length is valid (64, 128 or >= 192 bit) + if (keyWords.length !== 2 && keyWords.length !== 4 && keyWords.length < 6) { + throw new Error('Invalid key length - 3DES requires the key length to be 64, 128, 192 or >192.'); + } + + // Extend the key according to the keying options defined in 3DES standard + var key1 = keyWords.slice(0, 2); + var key2 = keyWords.length < 4 ? keyWords.slice(0, 2) : keyWords.slice(2, 4); + var key3 = keyWords.length < 6 ? keyWords.slice(0, 2) : keyWords.slice(4, 6); + + // Create DES instances + this._des1 = DES.createEncryptor(WordArray.create(key1)); + this._des2 = DES.createEncryptor(WordArray.create(key2)); + this._des3 = DES.createEncryptor(WordArray.create(key3)); + }, + + encryptBlock: function (M, offset) { + this._des1.encryptBlock(M, offset); + this._des2.decryptBlock(M, offset); + this._des3.encryptBlock(M, offset); + }, + + decryptBlock: function (M, offset) { + this._des3.decryptBlock(M, offset); + this._des2.encryptBlock(M, offset); + this._des1.decryptBlock(M, offset); + }, + + keySize: 192/32, + + ivSize: 64/32, + + blockSize: 64/32 + }); + + /** + * Shortcut functions to the cipher's object interface. + * + * @example + * + * var ciphertext = CryptoJS.TripleDES.encrypt(message, key, cfg); + * var plaintext = CryptoJS.TripleDES.decrypt(ciphertext, key, cfg); + */ + C.TripleDES = BlockCipher._createHelper(TripleDES); + }()); + + + (function () { + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var StreamCipher = C_lib.StreamCipher; + var C_algo = C.algo; + + /** + * RC4 stream cipher algorithm. + */ + var RC4 = C_algo.RC4 = StreamCipher.extend({ + _doReset: function () { + // Shortcuts + var key = this._key; + var keyWords = key.words; + var keySigBytes = key.sigBytes; + + // Init sbox + var S = this._S = []; + for (var i = 0; i < 256; i++) { + S[i] = i; + } + + // Key setup + for (var i = 0, j = 0; i < 256; i++) { + var keyByteIndex = i % keySigBytes; + var keyByte = (keyWords[keyByteIndex >>> 2] >>> (24 - (keyByteIndex % 4) * 8)) & 0xff; + + j = (j + S[i] + keyByte) % 256; + + // Swap + var t = S[i]; + S[i] = S[j]; + S[j] = t; + } + + // Counters + this._i = this._j = 0; + }, + + _doProcessBlock: function (M, offset) { + M[offset] ^= generateKeystreamWord.call(this); + }, + + keySize: 256/32, + + ivSize: 0 + }); + + function generateKeystreamWord() { + // Shortcuts + var S = this._S; + var i = this._i; + var j = this._j; + + // Generate keystream word + var keystreamWord = 0; + for (var n = 0; n < 4; n++) { + i = (i + 1) % 256; + j = (j + S[i]) % 256; + + // Swap + var t = S[i]; + S[i] = S[j]; + S[j] = t; + + keystreamWord |= S[(S[i] + S[j]) % 256] << (24 - n * 8); + } + + // Update counters + this._i = i; + this._j = j; + + return keystreamWord; + } + + /** + * Shortcut functions to the cipher's object interface. + * + * @example + * + * var ciphertext = CryptoJS.RC4.encrypt(message, key, cfg); + * var plaintext = CryptoJS.RC4.decrypt(ciphertext, key, cfg); + */ + C.RC4 = StreamCipher._createHelper(RC4); + + /** + * Modified RC4 stream cipher algorithm. + */ + var RC4Drop = C_algo.RC4Drop = RC4.extend({ + /** + * Configuration options. + * + * @property {number} drop The number of keystream words to drop. Default 192 + */ + cfg: RC4.cfg.extend({ + drop: 192 + }), + + _doReset: function () { + RC4._doReset.call(this); + + // Drop + for (var i = this.cfg.drop; i > 0; i--) { + generateKeystreamWord.call(this); + } + } + }); + + /** + * Shortcut functions to the cipher's object interface. + * + * @example + * + * var ciphertext = CryptoJS.RC4Drop.encrypt(message, key, cfg); + * var plaintext = CryptoJS.RC4Drop.decrypt(ciphertext, key, cfg); + */ + C.RC4Drop = StreamCipher._createHelper(RC4Drop); + }()); + + + (function () { + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var StreamCipher = C_lib.StreamCipher; + var C_algo = C.algo; + + // Reusable objects + var S = []; + var C_ = []; + var G = []; + + /** + * Rabbit stream cipher algorithm + */ + var Rabbit = C_algo.Rabbit = StreamCipher.extend({ + _doReset: function () { + // Shortcuts + var K = this._key.words; + var iv = this.cfg.iv; + + // Swap endian + for (var i = 0; i < 4; i++) { + K[i] = (((K[i] << 8) | (K[i] >>> 24)) & 0x00ff00ff) | + (((K[i] << 24) | (K[i] >>> 8)) & 0xff00ff00); + } + + // Generate initial state values + var X = this._X = [ + K[0], (K[3] << 16) | (K[2] >>> 16), + K[1], (K[0] << 16) | (K[3] >>> 16), + K[2], (K[1] << 16) | (K[0] >>> 16), + K[3], (K[2] << 16) | (K[1] >>> 16) + ]; + + // Generate initial counter values + var C = this._C = [ + (K[2] << 16) | (K[2] >>> 16), (K[0] & 0xffff0000) | (K[1] & 0x0000ffff), + (K[3] << 16) | (K[3] >>> 16), (K[1] & 0xffff0000) | (K[2] & 0x0000ffff), + (K[0] << 16) | (K[0] >>> 16), (K[2] & 0xffff0000) | (K[3] & 0x0000ffff), + (K[1] << 16) | (K[1] >>> 16), (K[3] & 0xffff0000) | (K[0] & 0x0000ffff) + ]; + + // Carry bit + this._b = 0; + + // Iterate the system four times + for (var i = 0; i < 4; i++) { + nextState.call(this); + } + + // Modify the counters + for (var i = 0; i < 8; i++) { + C[i] ^= X[(i + 4) & 7]; + } + + // IV setup + if (iv) { + // Shortcuts + var IV = iv.words; + var IV_0 = IV[0]; + var IV_1 = IV[1]; + + // Generate four subvectors + var i0 = (((IV_0 << 8) | (IV_0 >>> 24)) & 0x00ff00ff) | (((IV_0 << 24) | (IV_0 >>> 8)) & 0xff00ff00); + var i2 = (((IV_1 << 8) | (IV_1 >>> 24)) & 0x00ff00ff) | (((IV_1 << 24) | (IV_1 >>> 8)) & 0xff00ff00); + var i1 = (i0 >>> 16) | (i2 & 0xffff0000); + var i3 = (i2 << 16) | (i0 & 0x0000ffff); + + // Modify counter values + C[0] ^= i0; + C[1] ^= i1; + C[2] ^= i2; + C[3] ^= i3; + C[4] ^= i0; + C[5] ^= i1; + C[6] ^= i2; + C[7] ^= i3; + + // Iterate the system four times + for (var i = 0; i < 4; i++) { + nextState.call(this); + } + } + }, + + _doProcessBlock: function (M, offset) { + // Shortcut + var X = this._X; + + // Iterate the system + nextState.call(this); + + // Generate four keystream words + S[0] = X[0] ^ (X[5] >>> 16) ^ (X[3] << 16); + S[1] = X[2] ^ (X[7] >>> 16) ^ (X[5] << 16); + S[2] = X[4] ^ (X[1] >>> 16) ^ (X[7] << 16); + S[3] = X[6] ^ (X[3] >>> 16) ^ (X[1] << 16); + + for (var i = 0; i < 4; i++) { + // Swap endian + S[i] = (((S[i] << 8) | (S[i] >>> 24)) & 0x00ff00ff) | + (((S[i] << 24) | (S[i] >>> 8)) & 0xff00ff00); + + // Encrypt + M[offset + i] ^= S[i]; + } + }, + + blockSize: 128/32, + + ivSize: 64/32 + }); + + function nextState() { + // Shortcuts + var X = this._X; + var C = this._C; + + // Save old counter values + for (var i = 0; i < 8; i++) { + C_[i] = C[i]; + } + + // Calculate new counter values + C[0] = (C[0] + 0x4d34d34d + this._b) | 0; + C[1] = (C[1] + 0xd34d34d3 + ((C[0] >>> 0) < (C_[0] >>> 0) ? 1 : 0)) | 0; + C[2] = (C[2] + 0x34d34d34 + ((C[1] >>> 0) < (C_[1] >>> 0) ? 1 : 0)) | 0; + C[3] = (C[3] + 0x4d34d34d + ((C[2] >>> 0) < (C_[2] >>> 0) ? 1 : 0)) | 0; + C[4] = (C[4] + 0xd34d34d3 + ((C[3] >>> 0) < (C_[3] >>> 0) ? 1 : 0)) | 0; + C[5] = (C[5] + 0x34d34d34 + ((C[4] >>> 0) < (C_[4] >>> 0) ? 1 : 0)) | 0; + C[6] = (C[6] + 0x4d34d34d + ((C[5] >>> 0) < (C_[5] >>> 0) ? 1 : 0)) | 0; + C[7] = (C[7] + 0xd34d34d3 + ((C[6] >>> 0) < (C_[6] >>> 0) ? 1 : 0)) | 0; + this._b = (C[7] >>> 0) < (C_[7] >>> 0) ? 1 : 0; + + // Calculate the g-values + for (var i = 0; i < 8; i++) { + var gx = X[i] + C[i]; + + // Construct high and low argument for squaring + var ga = gx & 0xffff; + var gb = gx >>> 16; + + // Calculate high and low result of squaring + var gh = ((((ga * ga) >>> 17) + ga * gb) >>> 15) + gb * gb; + var gl = (((gx & 0xffff0000) * gx) | 0) + (((gx & 0x0000ffff) * gx) | 0); + + // High XOR low + G[i] = gh ^ gl; + } + + // Calculate new state values + X[0] = (G[0] + ((G[7] << 16) | (G[7] >>> 16)) + ((G[6] << 16) | (G[6] >>> 16))) | 0; + X[1] = (G[1] + ((G[0] << 8) | (G[0] >>> 24)) + G[7]) | 0; + X[2] = (G[2] + ((G[1] << 16) | (G[1] >>> 16)) + ((G[0] << 16) | (G[0] >>> 16))) | 0; + X[3] = (G[3] + ((G[2] << 8) | (G[2] >>> 24)) + G[1]) | 0; + X[4] = (G[4] + ((G[3] << 16) | (G[3] >>> 16)) + ((G[2] << 16) | (G[2] >>> 16))) | 0; + X[5] = (G[5] + ((G[4] << 8) | (G[4] >>> 24)) + G[3]) | 0; + X[6] = (G[6] + ((G[5] << 16) | (G[5] >>> 16)) + ((G[4] << 16) | (G[4] >>> 16))) | 0; + X[7] = (G[7] + ((G[6] << 8) | (G[6] >>> 24)) + G[5]) | 0; + } + + /** + * Shortcut functions to the cipher's object interface. + * + * @example + * + * var ciphertext = CryptoJS.Rabbit.encrypt(message, key, cfg); + * var plaintext = CryptoJS.Rabbit.decrypt(ciphertext, key, cfg); + */ + C.Rabbit = StreamCipher._createHelper(Rabbit); + }()); + + + (function () { + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var StreamCipher = C_lib.StreamCipher; + var C_algo = C.algo; + + // Reusable objects + var S = []; + var C_ = []; + var G = []; + + /** + * Rabbit stream cipher algorithm. + * + * This is a legacy version that neglected to convert the key to little-endian. + * This error doesn't affect the cipher's security, + * but it does affect its compatibility with other implementations. + */ + var RabbitLegacy = C_algo.RabbitLegacy = StreamCipher.extend({ + _doReset: function () { + // Shortcuts + var K = this._key.words; + var iv = this.cfg.iv; + + // Generate initial state values + var X = this._X = [ + K[0], (K[3] << 16) | (K[2] >>> 16), + K[1], (K[0] << 16) | (K[3] >>> 16), + K[2], (K[1] << 16) | (K[0] >>> 16), + K[3], (K[2] << 16) | (K[1] >>> 16) + ]; + + // Generate initial counter values + var C = this._C = [ + (K[2] << 16) | (K[2] >>> 16), (K[0] & 0xffff0000) | (K[1] & 0x0000ffff), + (K[3] << 16) | (K[3] >>> 16), (K[1] & 0xffff0000) | (K[2] & 0x0000ffff), + (K[0] << 16) | (K[0] >>> 16), (K[2] & 0xffff0000) | (K[3] & 0x0000ffff), + (K[1] << 16) | (K[1] >>> 16), (K[3] & 0xffff0000) | (K[0] & 0x0000ffff) + ]; + + // Carry bit + this._b = 0; + + // Iterate the system four times + for (var i = 0; i < 4; i++) { + nextState.call(this); + } + + // Modify the counters + for (var i = 0; i < 8; i++) { + C[i] ^= X[(i + 4) & 7]; + } + + // IV setup + if (iv) { + // Shortcuts + var IV = iv.words; + var IV_0 = IV[0]; + var IV_1 = IV[1]; + + // Generate four subvectors + var i0 = (((IV_0 << 8) | (IV_0 >>> 24)) & 0x00ff00ff) | (((IV_0 << 24) | (IV_0 >>> 8)) & 0xff00ff00); + var i2 = (((IV_1 << 8) | (IV_1 >>> 24)) & 0x00ff00ff) | (((IV_1 << 24) | (IV_1 >>> 8)) & 0xff00ff00); + var i1 = (i0 >>> 16) | (i2 & 0xffff0000); + var i3 = (i2 << 16) | (i0 & 0x0000ffff); + + // Modify counter values + C[0] ^= i0; + C[1] ^= i1; + C[2] ^= i2; + C[3] ^= i3; + C[4] ^= i0; + C[5] ^= i1; + C[6] ^= i2; + C[7] ^= i3; + + // Iterate the system four times + for (var i = 0; i < 4; i++) { + nextState.call(this); + } + } + }, + + _doProcessBlock: function (M, offset) { + // Shortcut + var X = this._X; + + // Iterate the system + nextState.call(this); + + // Generate four keystream words + S[0] = X[0] ^ (X[5] >>> 16) ^ (X[3] << 16); + S[1] = X[2] ^ (X[7] >>> 16) ^ (X[5] << 16); + S[2] = X[4] ^ (X[1] >>> 16) ^ (X[7] << 16); + S[3] = X[6] ^ (X[3] >>> 16) ^ (X[1] << 16); + + for (var i = 0; i < 4; i++) { + // Swap endian + S[i] = (((S[i] << 8) | (S[i] >>> 24)) & 0x00ff00ff) | + (((S[i] << 24) | (S[i] >>> 8)) & 0xff00ff00); + + // Encrypt + M[offset + i] ^= S[i]; + } + }, + + blockSize: 128/32, + + ivSize: 64/32 + }); + + function nextState() { + // Shortcuts + var X = this._X; + var C = this._C; + + // Save old counter values + for (var i = 0; i < 8; i++) { + C_[i] = C[i]; + } + + // Calculate new counter values + C[0] = (C[0] + 0x4d34d34d + this._b) | 0; + C[1] = (C[1] + 0xd34d34d3 + ((C[0] >>> 0) < (C_[0] >>> 0) ? 1 : 0)) | 0; + C[2] = (C[2] + 0x34d34d34 + ((C[1] >>> 0) < (C_[1] >>> 0) ? 1 : 0)) | 0; + C[3] = (C[3] + 0x4d34d34d + ((C[2] >>> 0) < (C_[2] >>> 0) ? 1 : 0)) | 0; + C[4] = (C[4] + 0xd34d34d3 + ((C[3] >>> 0) < (C_[3] >>> 0) ? 1 : 0)) | 0; + C[5] = (C[5] + 0x34d34d34 + ((C[4] >>> 0) < (C_[4] >>> 0) ? 1 : 0)) | 0; + C[6] = (C[6] + 0x4d34d34d + ((C[5] >>> 0) < (C_[5] >>> 0) ? 1 : 0)) | 0; + C[7] = (C[7] + 0xd34d34d3 + ((C[6] >>> 0) < (C_[6] >>> 0) ? 1 : 0)) | 0; + this._b = (C[7] >>> 0) < (C_[7] >>> 0) ? 1 : 0; + + // Calculate the g-values + for (var i = 0; i < 8; i++) { + var gx = X[i] + C[i]; + + // Construct high and low argument for squaring + var ga = gx & 0xffff; + var gb = gx >>> 16; + + // Calculate high and low result of squaring + var gh = ((((ga * ga) >>> 17) + ga * gb) >>> 15) + gb * gb; + var gl = (((gx & 0xffff0000) * gx) | 0) + (((gx & 0x0000ffff) * gx) | 0); + + // High XOR low + G[i] = gh ^ gl; + } + + // Calculate new state values + X[0] = (G[0] + ((G[7] << 16) | (G[7] >>> 16)) + ((G[6] << 16) | (G[6] >>> 16))) | 0; + X[1] = (G[1] + ((G[0] << 8) | (G[0] >>> 24)) + G[7]) | 0; + X[2] = (G[2] + ((G[1] << 16) | (G[1] >>> 16)) + ((G[0] << 16) | (G[0] >>> 16))) | 0; + X[3] = (G[3] + ((G[2] << 8) | (G[2] >>> 24)) + G[1]) | 0; + X[4] = (G[4] + ((G[3] << 16) | (G[3] >>> 16)) + ((G[2] << 16) | (G[2] >>> 16))) | 0; + X[5] = (G[5] + ((G[4] << 8) | (G[4] >>> 24)) + G[3]) | 0; + X[6] = (G[6] + ((G[5] << 16) | (G[5] >>> 16)) + ((G[4] << 16) | (G[4] >>> 16))) | 0; + X[7] = (G[7] + ((G[6] << 8) | (G[6] >>> 24)) + G[5]) | 0; + } + + /** + * Shortcut functions to the cipher's object interface. + * + * @example + * + * var ciphertext = CryptoJS.RabbitLegacy.encrypt(message, key, cfg); + * var plaintext = CryptoJS.RabbitLegacy.decrypt(ciphertext, key, cfg); + */ + C.RabbitLegacy = StreamCipher._createHelper(RabbitLegacy); + }()); + + + return CryptoJS; + +})); diff --git a/sololatino/sololatino.json b/sololatino/sololatino.json new file mode 100644 index 0000000..31f1cc7 --- /dev/null +++ b/sololatino/sololatino.json @@ -0,0 +1,19 @@ +{ + "sourceName": "SoloLatino", + "iconUrl": "https://sololatino.net/wp-content/uploads/2020/10/cropped-logo-final-192x192.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "Spanish (DUB/SUB)", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://sololatino.net/", + "searchBaseUrl": "https://sololatino.net/", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/sololatino/sololatino.js", + "type": "shows/movies", + "asyncJS": true, + "softsub": false, + "downloadSupport": false +} diff --git a/soundcloud/soundcloud.js b/soundcloud/soundcloud.js new file mode 100644 index 0000000..48fdb46 --- /dev/null +++ b/soundcloud/soundcloud.js @@ -0,0 +1,92 @@ +const PLACEHOLDER_IMAGE = "https://media.istockphoto.com/id/1147544807/vector/thumbnail-image-vector-graphic.jpg?s=612x612&w=0&k=20&c=rnCKVbdxqkjlcs3xH87-9gocETqpspHFXu5dIGB4wuM="; + +async function searchResults(keyword) { + const searchUrl = `https://api-v2.soundcloud.com/search?q=${encodeURIComponent(keyword)}&facet=model&user_id=200971-112325-516393-99787&client_id=UjhhbCuNo1OQfTwkzajxQNLlJcSlUlVz&limit=30`; + try { + const response = await fetch(searchUrl); + const json = await JSON.parse(response); + + const results = json.collection.map(item => ({ + title: item.title, + image: item.artwork_url || PLACEHOLDER_IMAGE, + href: item.permalink_url + })); + //console.log(results); + console.log(JSON.stringify(results)); + return JSON.stringify(results); + } catch (error) { + console.error("Error fetching search results:", error); + return JSON.stringify([]); + } +} + +async function extractDetails(url) { + const details = []; + details.push({ + description: 'N/A', + alias: 'N/A', + airdate: 'N/A' + }); + + //#IAMLAZY + + console.log(JSON.stringify(details)); + return JSON.stringify(details); +} + +async function extractEpisodes(url) { + const response = await fetch(url); + const html = await response; + const tracks = []; + + const trackRegex = /<article itemprop="track"[^>]*>[\s\S]*?<h2 itemprop="name"><a itemprop="url" href="([^"]+)">/g; + + let match; + let number = 1; + + while ((match = trackRegex.exec(html)) !== null) { + tracks.push({ + number: number++, + href: 'https://soundcloud.com' + match[1].trim() + }); + } + + if (tracks.length > 0) { + return JSON.stringify(tracks); + } else { + const canonicalMatch = html.match(/\["link",\{"rel":"canonical","href":"([^"]+)"\}\]/); + if (canonicalMatch) { + return JSON.stringify([{ number: 1, href: canonicalMatch[1].trim() }]); + } + } + + return JSON.stringify([]); +} + + +async function extractStreamUrl(url) { + const clientId = "UjhhbCuNo1OQfTwkzajxQNLlJcSlUlVz"; + try { + const response = await fetch(url); + const html = await response; + + const urlMatch = html.match(/"url":"(https:\/\/api[^\.]*\.soundcloud\.com\/media\/soundcloud:tracks:[^"]+)"/); + const authMatch = html.match(/"track_authorization":"([^"]+)"/); + + if (urlMatch && authMatch) { + const streamUrl = `${urlMatch[1]}?client_id=${clientId}&track_authorization=${authMatch[1]}`; + + const responseTwo = await fetch(streamUrl); + const json = await JSON.parse(responseTwo); + + return json.url; + } else { + console.log("No stream URL found"); + + return null; + } + } catch (error) { + console.error("Error:", error); + return null; + } + } diff --git a/soundcloud/soundcloud.json b/soundcloud/soundcloud.json new file mode 100644 index 0000000..c0a6718 --- /dev/null +++ b/soundcloud/soundcloud.json @@ -0,0 +1,16 @@ +{ + "sourceName": "Soundcloud", + "iconUrl": "https://cdn-icons-png.flaticon.com/512/145/145809.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "Music lmfao", + "streamType": "HLS", + "quality": "Wallah fire quality", + "baseUrl": "https://soundcloud.com/", + "searchBaseUrl": "https://bshar1865-hianime.vercel.app/api/v2/hianime/search?q=%s", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/soundcloud/soundcloud.js", + "asyncJS": true +} diff --git a/streamingunity/streamingunity.js b/streamingunity/streamingunity.js new file mode 100644 index 0000000..f9d6e67 --- /dev/null +++ b/streamingunity/streamingunity.js @@ -0,0 +1,231 @@ +async function searchResults(keyword) { + const response = await soraFetch( + `https://streamingunity.co/it/archive?search=${keyword}` + ); + const html = await response.text(); + + const regex = /<div[^>]*id="app"[^>]*data-page="([^"]*)"/; + const match = regex.exec(html); + + if (!match || !match[1]) { + return JSON.stringify([]); + } + + const dataPage = match[1].replaceAll(`"`, `"`); + const pageData = JSON.parse(dataPage); + const titles = pageData.props?.titles || []; + + const results = + titles + .map((item) => { + const posterImage = item.images?.find((img) => img.type === "poster"); + return { + title: + item.name?.replaceAll("amp;", "").replaceAll("'", "'") || "", + image: posterImage?.filename + ? `https://cdn.streamingunity.co/images/${posterImage.filename}` + : "", + href: `https://streamingunity.co/it/titles/${item.id}-${item.slug}`, + }; + }) + .filter((item) => item.image) || []; + + return JSON.stringify(results); +} + +async function extractDetails(url) { + const response = await soraFetch(`${url}/season-1`); + const html = await response.text(); + + const regex = /<div[^>]*id="app"[^>]*data-page="([^"]*)"/; + const match = regex.exec(html); + + if (!match || !match[1]) { + return JSON.stringify([]); + } + + const dataPage = match[1].replaceAll(`"`, `"`); + const pageData = JSON.parse(dataPage); + const titleData = pageData.props?.title; + + if (!titleData) { + return JSON.stringify([]); + } + + return JSON.stringify([ + { + description: + titleData.plot?.replaceAll("amp;", "").replaceAll("'", "'") || + "N/A", + aliases: + titleData.original_name + ?.replaceAll("amp;", "") + .replaceAll("'", "'") || "N/A", + airdate: titleData.release_date || "N/A", + }, + ]); +} + +async function extractEpisodes(url) { + try { + const episodes = []; + const baseUrl = url.replace(/\/season-\d+$/, ""); + + const response = await soraFetch(`${baseUrl}/season-1`); + const html = await response.text(); + const regex = /<div[^>]*id="app"[^>]*data-page="([^"]*)"/; + const match = regex.exec(html); + + if (!match?.[1]) return JSON.stringify([]); + + const pageData = JSON.parse(match[1].replaceAll(`"`, `"`)); + const titleData = pageData.props?.title; + if (!titleData) return JSON.stringify([]); + + const titleId = titleData.id; + const totalSeasons = titleData.seasons_count || 1; + + let hasEpisodes = false; + + for (let season = 1; season <= totalSeasons; season++) { + try { + const seasonResponse = await soraFetch(`${baseUrl}/season-${season}`); + const seasonHtml = await seasonResponse.text(); + const seasonMatch = regex.exec(seasonHtml); + + if (seasonMatch?.[1]) { + const seasonData = JSON.parse( + seasonMatch[1].replaceAll(`"`, `"`) + ); + const seasonEpisodes = seasonData.props?.loadedSeason?.episodes || []; + + if (seasonEpisodes.length > 0) { + hasEpisodes = true; + seasonEpisodes.forEach((episode) => { + episodes.push({ + href: `https://streamingunity.co/it/iframe/${titleId}?episode_id=${episode.id}`, + number: episode.number || episodes.length + 1, + }); + }); + } + } + } catch (error) { + console.log(`Error fetching season ${season}:`, error); + } + } + + if (!hasEpisodes) { + episodes.push({ + href: `https://streamingunity.co/it/iframe/${titleId}`, + number: 1, + }); + } + + return JSON.stringify(episodes); + } catch (error) { + console.log("Error extracting episodes:", error); + return JSON.stringify([]); + } +} + +async function extractStreamUrl(url) { + try { + let modifiedUrl = url; + if (!url.includes("/it/iframe") && !url.includes("/en/iframe")) { + modifiedUrl = url.replace("/iframe", "/it/iframe"); + } + const response1 = await soraFetch(modifiedUrl); + const html1 = await response1.text(); + + const iframeMatch = html1.match(/<iframe[^>]*src="([^"]*)"/); + if (!iframeMatch) { + console.log("No iframe found in the HTML."); + return null; + } + + const embedUrl = iframeMatch[1].replace(/amp;/g, ""); + console.log("Embed URL:", embedUrl); + + const response2 = await soraFetch(embedUrl); + const html2 = await response2.text(); + + let finalUrl = null; + + if (html2.includes("window.masterPlaylist")) { + const urlMatch = html2.match(/url:\s*['"]([^'"]+)['"]/); + const tokenMatch = html2.match(/['"]?token['"]?\s*:\s*['"]([^'"]+)['"]/); + const expiresMatch = html2.match( + /['"]?expires['"]?\s*:\s*['"]([^'"]+)['"]/ + ); + + if (urlMatch && tokenMatch && expiresMatch) { + const baseUrl = urlMatch[1]; + const token = tokenMatch[1]; + const expires = expiresMatch[1]; + + if (baseUrl.includes("?b=1")) { + finalUrl = `${baseUrl}&token=${token}&expires=${expires}&h=1`; + } else { + finalUrl = `${baseUrl}?token=${token}&expires=${expires}&h=1`; + } + } + } + + if (!finalUrl) { + const m3u8Match = html2.match(/(https?:\/\/[^'"\s]+\.m3u8[^'"\s]*)/); + if (m3u8Match) { + finalUrl = m3u8Match[1]; + } + } + + if (!finalUrl) { + const scriptMatches = html2.match(/<script[^>]*>(.*?)<\/script>/gs); + if (scriptMatches) { + for (const script of scriptMatches) { + const streamMatch = script.match( + /['"]?(https?:\/\/[^'"\s]+(?:\.m3u8|playlist)[^'"\s]*)/ + ); + if (streamMatch) { + finalUrl = streamMatch[1]; + break; + } + } + } + } + + if (!finalUrl) { + const videoMatch = html2.match( + /(?:src|source|url)['"]?\s*[:=]\s*['"]?(https?:\/\/[^'"\s]+(?:\.mp4|\.m3u8|\.mpd)[^'"\s]*)/ + ); + if (videoMatch) { + finalUrl = videoMatch[2] || videoMatch[1]; + } + } + + if (finalUrl) { + console.log("Final URL found:", finalUrl); + return finalUrl; + } else { + console.log( + "No stream URL found. HTML content:", + html2.substring(0, 1000) + ); + return null; + } + } catch (error) { + console.log("Fetch error:", error); + return null; + } +} + +async function soraFetch(url, options = { headers: {}, method: 'GET', body: null }) { + try { + return await fetchv2(url, options.headers ?? {}, options.method ?? 'GET', options.body ?? null); + } catch(e) { + try { + return await fetch(url, options); + } catch(error) { + return null; + } + } +} \ No newline at end of file diff --git a/streamingunity/streamingunity.json b/streamingunity/streamingunity.json new file mode 100644 index 0000000..f5f3e0e --- /dev/null +++ b/streamingunity/streamingunity.json @@ -0,0 +1,17 @@ +{ + "sourceName": "StreamingUnity", + "iconUrl": "https://virginiapertutte.it/templates/sub-ita/images/logo.png", + "author": { + "name": "sobet", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRQPQ1qIiALbM3xDWGsuJzu6ItaQGwb9ICRRw&s" + }, + "version": "9000000.0.0", + "language": "Italian", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://streamingunity.bio/it", + "searchBaseUrl": "https://streamingunity.bio/it/archive?title=%s", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/streamingunity/streamingunity.js", + "asyncJS": true, + "type": "shows/movies" +} diff --git a/test/.gitkeep b/test/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/toonitalia/toonitalia.js b/toonitalia/toonitalia.js new file mode 100644 index 0000000..e9c00af --- /dev/null +++ b/toonitalia/toonitalia.js @@ -0,0 +1,206 @@ +async function searchResults(keyword) { + const results = []; + try { + const response = await fetchv2("https://toonitalia.xyz/?s=" + encodeURIComponent(keyword)); + const html = await response.text(); + + const regex = /<article[\s\S]*?<h2 class="entry-title heading-size-1"><a href="([^"]+)">([\s\S]*?)<\/a><\/h2>[\s\S]*?(?:<img[^>]+src="([^"]+)")?/gi; + let match; + while ((match = regex.exec(html)) !== null) { + results.push({ + title: match[2].trim(), + image: match[3] ? match[3].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 regex = /<h3><span[^>]*>Trama:<\/span><\/h3>\s*<p>([\s\S]*?)<\/p>/i; + const match = regex.exec(html); + const description = match ? match[1].replace(/<[^>]+>/g, "").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 episodeRegex = /(\d+)\s*(?:–|–)[^<]*<a href="(https:\/\/voe\.sx\/[^"]+)"/g; + let match; + while ((match = episodeRegex.exec(html)) !== null) { + const voeUrl = match[2].trim().replace('https://voe.sx/', 'https://jilliandescribecompany.com/e/'); + results.push({ + href: voeUrl, + number: parseInt(match[1], 10) + }); + } + + if (results.length === 0) { + const movieMatch = html.match(/<a href="(https:\/\/voe\.sx\/[^"]+)"/); + if (movieMatch) { + const voeUrl = movieMatch[1].trim().replace('https://voe.sx/', 'https://jilliandescribecompany.com/e/'); + results.push({ + href: voeUrl, + number: 1 + }); + } + } + + return JSON.stringify(results); + } catch (err) { + return JSON.stringify([{ + href: "Error", + number: "Error" + }]); + } +} + +async function extractStreamUrl(url) { + + const response = await fetchv2(url); + const html = await response.text(); + let streamData = null; + + streamData = voeExtractor(html); + console.log("Voe Stream Data: " + streamData); + return streamData; +} + +/* SCHEME START */ + +/** + * @name voeExtractor + * @author Cufiy + */ + +function voeExtractor(html, url = null) { + // Extract the first <script type="application/json">...</script> + const jsonScriptMatch = html.match( + /<script[^>]+type=["']application\/json["'][^>]*>([\s\S]*?)<\/script>/i + ); + if (!jsonScriptMatch) { + console.log("No application/json script tag found"); + return null; + } + + + const obfuscatedJson = jsonScriptMatch[1].trim(); + + let data; + try { + data = JSON.parse(obfuscatedJson); + } catch (e) { + throw new Error("Invalid JSON input."); + } + if (!Array.isArray(data) || typeof data[0] !== "string") { + throw new Error("Input doesn't match expected format."); + } + let obfuscatedString = data[0]; + + // Step 1: ROT13 + let step1 = voeRot13(obfuscatedString); + + // Step 2: Remove patterns + let step2 = voeRemovePatterns(step1); + + // Step 3: Base64 decode + let step3 = voeBase64Decode(step2); + + // Step 4: Subtract 3 from each char code + let step4 = voeShiftChars(step3, 3); + + // Step 5: Reverse string + let step5 = step4.split("").reverse().join(""); + + // Step 6: Base64 decode again + let step6 = voeBase64Decode(step5); + + // Step 7: Parse as JSON + let result; + try { + result = JSON.parse(step6); + } catch (e) { + throw new Error("Final JSON parse error: " + e.message); + } + // console.log("Decoded JSON:", result); + + // check if direct_access_url is set, not null and starts with http + if (result && typeof result === "object") { + const streamUrl = + result.direct_access_url || + result.source + .map((source) => source.direct_access_url) + .find((url) => url && url.startsWith("http")); + if (streamUrl) { + console.log("Voe Stream URL: " + streamUrl); + return streamUrl; + } else { + console.log("No stream URL found in the decoded JSON"); + } + } + return result; +} + +function voeRot13(str) { + return str.replace(/[a-zA-Z]/g, function (c) { + return String.fromCharCode( + (c <= "Z" ? 90 : 122) >= (c = c.charCodeAt(0) + 13) ? + c : + c - 26 + ); + }); +} + +function voeRemovePatterns(str) { + const patterns = ["@$", "^^", "~@", "%?", "*~", "!!", "#&"]; + let result = str; + for (const pat of patterns) { + result = result.split(pat).join(""); + } + return result; +} + +function voeBase64Decode(str) { + // atob is available in browsers and Node >= 16 + if (typeof atob === "function") { + return atob(str); + } + // Node.js fallback + return Buffer.from(str, "base64").toString("utf-8"); +} + +function voeShiftChars(str, shift) { + return str + .split("") + .map((c) => String.fromCharCode(c.charCodeAt(0) - shift)) + .join(""); +} +/* SCHEME END */ \ No newline at end of file diff --git a/toonitalia/toonitalia.json b/toonitalia/toonitalia.json new file mode 100644 index 0000000..759a649 --- /dev/null +++ b/toonitalia/toonitalia.json @@ -0,0 +1,20 @@ +{ + "sourceName": "ToonItalia", + "iconUrl": "https://toonitalia.xyz/wp-content/uploads/2023/08/cropped-Majintoon-192x192.jpg", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "Italian", + "streamType": "HLS", + "encrypted":true, + "quality": "1080p", + "baseUrl": "https://toonitalia.xyz/", + "searchBaseUrl": "https://toonitalia.xyz/", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/toonitalia/toonitalia.js", + "type": "shows/movies", + "asyncJS": true, + "softsub": false, + "downloadSupport": false +} \ No newline at end of file diff --git a/toontales/toontales.js b/toontales/toontales.js new file mode 100644 index 0000000..85999de --- /dev/null +++ b/toontales/toontales.js @@ -0,0 +1,79 @@ +async function searchResults(keyword) { + const results = []; + try { + const response = await fetchv2(`https://www.toontales.net/?s=${keyword}&search=Search`); + const html = await response.text(); + + const matches = html.matchAll(/<a href="([^"]+)">\s*<img src="([^"]+)"[^>]*alt="([^"]*)"[^>]*>/g); + + for (const match of matches) { + const href = match[1].trim(); + const image = match[2].trim(); + const title = match[3].trim(); + + const imageUrl = image.includes('noimage.jpg') ? null : image; + + results.push({ + href: href, + image: imageUrl, + title: title || 'No Title' + }); + } + + return JSON.stringify(results); + } catch (err) { + return JSON.stringify([{ + title: "Error: " + err.message, + image: "Error", + href: "Error" + }]); + } +} +async function extractDetails(url) { + try { + const response = await fetchv2(url); + const html = await response.text(); + + const descriptionMatch = html.match(/<meta name="description" content="([^"]*)"[^>]*\/>/); + const description = descriptionMatch ? descriptionMatch[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) { + return JSON.stringify([{ + number: 1, + href: url + }]); +} + +async function extractStreamUrl(url) { + try { + const response = await fetchv2(url); + const html = await response.text(); + + let urlMatch = html.match(/file:\s*"([^"]+\.mp4)"/); + if (!urlMatch) { + urlMatch = html.match(/"contentUrl"\s*:\s*"([^"\\]*(?:\\.[^"\\]*)*\.mp4)"/); + } + + const extractedUrl = urlMatch ? urlMatch[1] : null; + + return (extractedUrl && extractedUrl.endsWith('.mp4')) + ? extractedUrl + : "i wanna kms"; + } catch (err) { + return "https://files.catbox.moe/avolvc.mp4"; + } +} \ No newline at end of file diff --git a/toontales/toontales.json b/toontales/toontales.json new file mode 100644 index 0000000..6e082e6 --- /dev/null +++ b/toontales/toontales.json @@ -0,0 +1,20 @@ +{ + "sourceName": "ToonTales", + "iconUrl": "https://www.toontales.net/wp-content/uploads/cropped-favicon-192x192.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "English", + "streamType": "mp4", + "encrypted":true, + "quality": "1080p", + "baseUrl": "https://www.toontales.net/", + "searchBaseUrl": "https://www.toontales.net/", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/toontales/toontales.js", + "type": "shows", + "asyncJS": true, + "softsub": false, + "downloadSupport": true +} \ No newline at end of file diff --git a/topstreamfilm/topstreamfilm.js b/topstreamfilm/topstreamfilm.js new file mode 100644 index 0000000..e057ca8 --- /dev/null +++ b/topstreamfilm/topstreamfilm.js @@ -0,0 +1,274 @@ +async function searchResults(keyword) { + const results = []; + try { + const response = await fetchv2(`https://www.topstreamfilm.live/?story=${encodeURIComponent(keyword)}&do=search&subaction=search`); + const html = await response.text(); + + const regex = /<li class="TPostMv">[\s\S]*?<a href="([^"]+)">[\s\S]*?<figure[^>]*>[\s\S]*?<img[^>]*data-src="([^"]+)"[^>]*>[\s\S]*?<h3 class="Title">([^<]+)<\/h3>/g; + + let match; + while ((match = regex.exec(html)) !== null) { + const href = match[1].trim(); + const image = "https://www.topstreamfilm.live" + match[2].trim(); + let title = (match[3].trim()).trim(); + + title = title + .replace(/–/g, "–") + .replace(/’/g, "'") + .replace(/&/g, "&") + .replace(/"/g, '"') + .replace(/'/g, "'") + .replace(" – Der Film", ""); + + results.push({ + title, + image, + href + }); + } + + 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 regex = /<div class="Description">([\s\S]*?)<\/div>/i; + const match = regex.exec(html); + + let description = "N/A"; + if (match) { + description = match[1] + .replace(/<[^>]+>/g, " ") + .replace(/&/g, "&") + .replace(/–/g, "–") + .replace(/’/g, "’") + .replace(/"/g, '"') + .replace(/'/g, "'") + .replace(/\s+/g, " ") + .trim(); + } + + return JSON.stringify([{ + 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 = /id="serie-(\d+)_(\d+)"[\s\S]*?data-m="supervideo"[^>]+data-link="([^"]+)"/g; + let match; + while ((match = regex.exec(html)) !== null) { + const season = parseInt(match[1], 10); + const episode = parseInt(match[2], 10); + const href = match[3].trim(); + results.push({ + season, + number: episode, + href + }); + } + + if (results.length === 0) { + const scriptRegex = /<script src="(https:\/\/meinecloud\.click\/ddl\/[^"]+)" type="[^"]*text\/javascript"><\/script>/g; + const scriptMatch = scriptRegex.exec(html); + + if (scriptMatch) { + const scriptUrl = scriptMatch[1].trim(); + + try { + const scriptResponse = await fetchv2(scriptUrl); + const scriptContent = await scriptResponse.text(); + + const supervideRegex = /\\'(https:\/\/supervideo\.tv\/[^']+)\\'/; + const supervideMatch = scriptContent.match(supervideRegex); + + if (supervideMatch) { + const supervideUrl = supervideMatch[1].trim(); + results.push({ + season: 1, + number: 1, + href: supervideUrl + }); + } + } catch (scriptErr) { + console.log("Error fetching script: " + scriptErr); + } + } + } + + return JSON.stringify(results); + } catch (err) { + return JSON.stringify([{ + season: "Error", + number: "Error", + href: "Error" + }]); + } +} + +async function extractStreamUrl(url) { + try { + const response = await fetchv2(url); + const html = await response.text(); + + const obfuscatedScript = html.match(/<script[^>]*>\s*(eval\(function\(p,a,c,k,e,d.*?\)[\s\S]*?)<\/script>/); + const unpackedScript = unpack(obfuscatedScript[1]); + + const regex = /file:\s*"([^"]+\.m3u8)"/; + const match = regex.exec(unpackedScript); + if (match) { + const fileUrl = match[1]; + console.log("File URL:" + fileUrl); + + return fileUrl; + } + + return "deiofjdew"; + } catch (err) { + console.log("Error extracting stream URL: " + err); + return "https://files.catbox.moe/avolvc.mp4"; + } +} + + +/*********************************************************** + * UNPACKER MODULE + * Credit to GitHub user "mnsrulz" for Unpacker Node library + * https://github.com/mnsrulz/unpacker + ***********************************************************/ +class Unbaser { + constructor(base) { + /* Functor for a given base. Will efficiently convert + strings to natural numbers. */ + this.ALPHABET = { + 62: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", + 95: "' !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'", + }; + this.dictionary = {}; + this.base = base; + // fill elements 37...61, if necessary + if (36 < base && base < 62) { + this.ALPHABET[base] = this.ALPHABET[base] || + this.ALPHABET[62].substr(0, base); + } + // If base can be handled by int() builtin, let it do it for us + if (2 <= base && base <= 36) { + this.unbase = (value) => parseInt(value, base); + } + else { + // Build conversion dictionary cache + try { + [...this.ALPHABET[base]].forEach((cipher, index) => { + this.dictionary[cipher] = index; + }); + } + catch (er) { + throw Error("Unsupported base encoding."); + } + this.unbase = this._dictunbaser; + } + } + _dictunbaser(value) { + /* Decodes a value to an integer. */ + let ret = 0; + [...value].reverse().forEach((cipher, index) => { + ret = ret + ((Math.pow(this.base, index)) * this.dictionary[cipher]); + }); + return ret; + } +} + +function detect(source) { + /* Detects whether `source` is P.A.C.K.E.R. coded. */ + return source.replace(" ", "").startsWith("eval(function(p,a,c,k,e,"); +} + +function unpack(source) { + /* Unpacks P.A.C.K.E.R. packed js code. */ + let { payload, symtab, radix, count } = _filterargs(source); + if (count != symtab.length) { + throw Error("Malformed p.a.c.k.e.r. symtab."); + } + let unbase; + try { + unbase = new Unbaser(radix); + } + catch (e) { + throw Error("Unknown p.a.c.k.e.r. encoding."); + } + function lookup(match) { + /* Look up symbols in the synthetic symtab. */ + const word = match; + let word2; + if (radix == 1) { + //throw Error("symtab unknown"); + word2 = symtab[parseInt(word)]; + } + else { + word2 = symtab[unbase.unbase(word)]; + } + return word2 || word; + } + source = payload.replace(/\b\w+\b/g, lookup); + return _replacestrings(source); + function _filterargs(source) { + /* Juice from a source file the four args needed by decoder. */ + const juicers = [ + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\), *(\d+), *(.*)\)\)/, + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\)/, + ]; + for (const juicer of juicers) { + //const args = re.search(juicer, source, re.DOTALL); + const args = juicer.exec(source); + if (args) { + let a = args; + if (a[2] == "[]") { + //don't know what it is + // a = list(a); + // a[1] = 62; + // a = tuple(a); + } + try { + return { + payload: a[1], + symtab: a[4].split("|"), + radix: parseInt(a[2]), + count: parseInt(a[3]), + }; + } + catch (ValueError) { + throw Error("Corrupted p.a.c.k.e.r. data."); + } + } + } + throw Error("Could not make sense of p.a.c.k.e.r data (unexpected code structure)"); + } + function _replacestrings(source) { + /* Strip string lookup table (list) and replace values in source. */ + /* Need to work on this. */ + return source; + } +} diff --git a/topstreamfilm/topstreamfilm.json b/topstreamfilm/topstreamfilm.json new file mode 100644 index 0000000..b890965 --- /dev/null +++ b/topstreamfilm/topstreamfilm.json @@ -0,0 +1,20 @@ +{ + "sourceName": "TopStreamFilm", + "iconUrl": "https://www.topstreamfilm.live/templates/topstreamfilm/images/cropped-topstreamIcon-192x192.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "German", + "streamType": "HLS", + "encrypted":true, + "quality": "1080p", + "baseUrl": "https://www.topstreamfilm.live/", + "searchBaseUrl": "https://www.topstreamfilm.live/", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/topstreamfilm/topstreamfilm.js", + "type": "shows/movies", + "asyncJS": true, + "softsub": false, + "downloadSupport": false +} \ No newline at end of file diff --git a/turkish123/turkish123.js b/turkish123/turkish123.js new file mode 100644 index 0000000..bed95f4 --- /dev/null +++ b/turkish123/turkish123.js @@ -0,0 +1,109 @@ +async function searchResults(keyword) { + const searchUrl = `https://hds.turkish123.com/?s=${encodeURIComponent(keyword)}`; + try { + const response = await fetch(searchUrl); + const html = await response; + const results = []; + + const itemRegex = /<div[^>]*class="ml-item"[^>]*>[\s\S]*?<\/div>/g; + const items = html.match(itemRegex) || []; + + items.forEach((itemHtml) => { + const titleMatch = itemHtml.match(/<span class="mli-info"><h2>([^<]+)<\/h2><\/span>/); + const imgMatch = itemHtml.match(/<img[^>]*src="([^"]+)"[^>]*class="mli-thumb"/); + const hrefMatch = itemHtml.match(/<a href="([^"]+)"[^>]*class="ml-mask/); + + if (!titleMatch || !imgMatch || !hrefMatch) return; + + const title = titleMatch[1].trim(); + const imageUrl = imgMatch[1].trim(); + const href = hrefMatch[1].trim(); + + results.push({ + title, + image: imageUrl, + href + }); + }); + //console.log(results); + console.log(JSON.stringify(results)); + return JSON.stringify(results); + } catch (error) { + throw error; + } +} + +async function extractDetails(url) { + const details = []; + + try { + const response = await fetch(url); + const html = await response; + + const descriptionMatch = html.match(/<p class="f-desc">([\s\S]*?)<\/p>/); + let description = descriptionMatch ? descriptionMatch[1].trim() : 'Weirdly the website doesn\'t provide any description, either that or I\'m blind.'; + + description = description.replace(/–/g, '–').replace(/’/g, '’'); + + const yearMatch = html.match(/<i class="fa fa-calendar" aria-hidden="true"><\/i><strong>Year:<\/strong>[\s\S]*?<a href="[^"]*" rel="tag">(\d{4})<\/a>/); + const airdate = yearMatch ? yearMatch[1] : 'N/A'; + + details.push({ + description, + alias: 'N/A', + airdate + }); + //console.log(details); + console.log(JSON.stringify(details)); + return JSON.stringify(details); + } catch (error) { + console.error('Error extracting details:', error); + return JSON.stringify([]); + } +} + +async function extractEpisodes(url) { + const response = await fetch(url); + const html = await response; + const episodes = []; + + const episodeMatches = html.match(/<a class="episodi" href="([^"]+)">[^<]*Episode (\d+)[^<]*(?:<span[^>]*>[^<]*<\/span>)?[^<]*<\/a>/g); + + if (episodeMatches) { + episodeMatches.forEach((match) => { + const hrefMatch = match.match(/href="([^"]+)"/); + const episodeNumberMatch = match.match(/Episode (\d+)/); + + if (hrefMatch && episodeNumberMatch) { + episodes.push({ + href: hrefMatch[1].trim(), + number: parseInt(episodeNumberMatch[1], 10) + }); + } + }); + } + //console.log(episodes); + console.log(JSON.stringify(episodes)); + return JSON.stringify(episodes); +} + +async function extractStreamUrl(url) { + const response = await fetch(url); + const data = await response; + const iframeMatch = data.match(/var copyTexti= \['<iframe[^>]*src="(https:\/\/tukipasti\.com\/[^"]+)"[^>]*><\/iframe>'\]/); + + if (iframeMatch) { + const iframeUrl = iframeMatch[1]; + const responseTwo = await fetch(iframeUrl); + const dataTwo = await responseTwo; + const m3u8Match = dataTwo.match(/var urlPlay = '([^']+)'/); + + if (m3u8Match) { + const m3u8Url = m3u8Match[1]; + console.log(m3u8Url); + return m3u8Url; + } + return null; + } + return null; +} diff --git a/turkish123/turkish123.json b/turkish123/turkish123.json new file mode 100644 index 0000000..527612a --- /dev/null +++ b/turkish123/turkish123.json @@ -0,0 +1,17 @@ +{ + "sourceName": "Turkish123", + "iconUrl": "https://hds.turkish123.com/wp-content/uploads/favicon.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.5", + "language": "Turkish", + "streamType": "HLS", + "quality": "8K UHD", + "baseUrl": "https://hds.turkish123.com/", + "searchBaseUrl": "https://hds.turkish123.com/?s=%s", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/turkish123/turkish123.js", + "asyncJS": true, + "type": "movies/shows" +} diff --git a/vegamovies/vegamovies.js b/vegamovies/vegamovies.js new file mode 100644 index 0000000..6be6f85 --- /dev/null +++ b/vegamovies/vegamovies.js @@ -0,0 +1,142 @@ +async function searchResults(keyword) { + const results = []; + try { + const response = await fetchv2(`https://vegamovies10.com/search.php?query=${keyword}`); + const html = await response.text(); + + const regex = /<a[^>]+href="([^"]+)"[^>]+title="([^"]+)"[^>]*class="blog-img[^"]*"[^>]*>\s*<img[^>]+src="([^"]+)"[^>]*>/g; + + let match; + while ((match = regex.exec(html)) !== null) { + const title = match[2].trim(); + + if (/episodes?/i.test(title)) continue; + + results.push({ + title, + image: match[3].trim().startsWith("http") ? match[3].trim() : "https://vegamovies10.com" + match[3].trim(), + href: match[1].trim().startsWith("http") ? match[1].trim() : "https://vegamovies10.com" + match[1].trim() + }); + } + + return JSON.stringify(results); + } catch (err) { + console.error("Search error:" + 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 match = html.match(/<h3[^>]*>[\s\S]*?Movie-SYNOPSIS\/PLOT:[\s\S]*?<\/h3>\s*<p>([\s\S]*?)<\/p>/i); + + const rawDescription = match ? match[1] : ""; + const cleaned = rawDescription + .replace(/<br\s*\/?>/gi, "\n") + .replace(/<[^>]+>/g, "") + .trim(); + + return JSON.stringify([{ + description: cleaned || "N/A", + aliases: "N/A", + airdate: "N/A" + }]); + } catch (err) { + return JSON.stringify([{ + description: "Error", + aliases: "Error", + airdate: "Error" + }]); + } +} + +async function extractEpisodes(url) { + try { + const response = await fetchv2(url); + const html = await response.text(); + + let match = html.match(/<h5[^>]*>([\s\S]*?1080p[\s\S]*?)<\/h5>[\s\S]*?<a\s+href="([^"]+)"/i); + + if (!match) { + match = html.match(/<h5[^>]*>([\s\S]*?720p[\s\S]*?)<\/h5>[\s\S]*?<a\s+href="([^"]+)"/i); + } + + if (!match) { + match = html.match(/<h5[^>]*>([\s\S]*?480p[\s\S]*?)<\/h5>[\s\S]*?<a\s+href="([^"]+)"/i); + } + + let downloadLink = null; + if (match) { + downloadLink = match[2].trim(); + const qualityText = match[1].replace(/<[^>]+>/g, '').replace(/\s+/g, ' ').trim(); + console.log('Selected quality: ' + qualityText); + } + + if (downloadLink) { + return JSON.stringify([{ + href: downloadLink, + number: 1 + }]); + } else { + return JSON.stringify([{ + href: "No download link found", + number: 1 + }]); + } + } catch (err) { + return JSON.stringify([{ + href: "Error", + number: "Error" + }]); + } +} + +async function extractStreamUrl(url) { + try { + const headers = { + "Referer": "https://vegamovies10.com/" + }; + const response = await fetchv2(url, headers); + const html = await response.text(); + + const match = html.match(/<a[^>]+href="([^"]+)"[^>]*>[\s\S]*?V-Cloud[\s\S]*?<\/a>/i); + if (!match) { + console.log("No V-Cloud link found"); + return "Error"; + } + + const relativeUrl = match[1].trim(); + const finalUrl = relativeUrl.startsWith("http") + ? relativeUrl + : "https://www.9xlinks.xyz" + relativeUrl; + + const followResponse = await fetchv2(finalUrl); + const followText = await followResponse.text(); + + const downloadMatch = followText.match(/<div class="mt-6 flex justify-center space-x-3">[\s\S]*?<a href="([^"]+)"/i); + + if (downloadMatch) { + const downloadUrl = downloadMatch[1].trim(); + console.log("Direct Download URL: " + downloadUrl); + return downloadUrl; + } else { + console.log("No direct download link found"); + return "Error"; + } + + } catch (err) { + console.log("Error in extractStreamUrl: " + err); + return "Error"; + } +} + + + + diff --git a/vegamovies/vegamovies.json b/vegamovies/vegamovies.json new file mode 100644 index 0000000..89114dc --- /dev/null +++ b/vegamovies/vegamovies.json @@ -0,0 +1,19 @@ +{ + "sourceName": "VegaMovies", + "iconUrl": "https://www.arcgis.com/sharing/rest/content/items/e6b7ab2c49de42e0b4aa9ea75198737c/info/thumbnail/ago_downloaded.jpg?w=800", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.2", + "language": "Hindi (DUB/SUB)", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://vegamovies10.com/", + "searchBaseUrl": "https://vegamovies10.com/", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/vegamovies/vegamovies.js", + "type": "shows/movies", + "asyncJS": true, + "softsub": false, + "downloadSupport": false +} diff --git a/veranimes/veranimes.js b/veranimes/veranimes.js new file mode 100644 index 0000000..8dd4355 --- /dev/null +++ b/veranimes/veranimes.js @@ -0,0 +1,334 @@ +async function searchResults(keyword) { + const results = []; + try { + const response = await fetchv2("https://wwv.veranimes.net/animes?buscar=" + encodeURIComponent(keyword)); + const html = await response.text(); + + const regex = /<article class="li">.*?<a href="([^"]+)" title="([^"]+)">.*?<img [^>]*src="(https:\/\/[^"]*\.(?:webp|jpg|png|jpeg))"[^>]*alt="[^"]*">/gs; + + let match; + while ((match = regex.exec(html)) !== null) { + results.push({ + href: match[1].trim().replace("./", "https://wwv.veranimes.net/"), + title: match[2].trim(), + image: 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 match = html.match(/<div class="tx">.*?<p>(.*?)<\/p>/s); + const description = match ? match[1].replace(/<[^>]+>/g, '').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 = []; + const baseUrl = "https://wwv.veranimes.net/"; + + try { + const response = await fetchv2(url); + const html = await response.text(); + + const epsMatch = html.match(/var eps = \[(.*?)\];/); + if (!epsMatch) { + throw new Error("Episodes array not found"); + } + + const episodeNumbers = epsMatch[1].split(',').map(ep => + parseInt(ep.replace(/"/g, ''), 10) + ); + + const slugMatch = html.match(/data-sl="([^"]+)"/); + if (!slugMatch) { + throw new Error("Series slug not found"); + } + const seriesSlug = slugMatch[1]; + + episodeNumbers.reverse().forEach(episodeNum => { + results.push({ + href: `${baseUrl}ver/${seriesSlug}-${episodeNum}`, + number: episodeNum + }); + }); + + return JSON.stringify(results); + } catch (err) { + return JSON.stringify([{ + href: "Error", + number: "Error" + }]); + } +} + +async function extractStreamUrl(url) { + try { + const response = await fetchv2(url); + const html = await response.text(); + + const dataDwnMatch = html.match(/data-dwn="([^"]+)"/); + + if (!dataDwnMatch) { + console.log("No data-dwn attribute found"); + return null; + } + + let dataDwnContent = dataDwnMatch[1]; + dataDwnContent = dataDwnContent.replace(/"/g, '"').replace(/&/g, '&'); + + console.log("Raw data-dwn content:", dataDwnContent); + + let downloadData; + try { + downloadData = JSON.parse(dataDwnContent); + } catch (parseError) { + console.log("Failed to parse data-dwn JSON:", parseError); + return null; + } + + console.log("Parsed download data:", downloadData); + + let filemoonUrl = null; + for (const item of downloadData) { + if (Array.isArray(item) && item[0] === "filemoon" && item[2]) { + filemoonUrl = item[2]; + break; + } + } + + if (!filemoonUrl) { + console.log("No filemoon URL found in data-dwn"); + return null; + } + + filemoonUrl = filemoonUrl.replace("/d/", "/e/"); + + console.log("Extracted filemoon URL:", filemoonUrl); + + const filemoonResponse = await fetchv2(filemoonUrl); + const filemoonHtml = await filemoonResponse.text(); + + let streamUrl = null; + try { + streamUrl = await filemoonExtractor(filemoonHtml, filemoonUrl); + } catch (error) { + console.log("filemoon HD extraction error:", error); + } + + console.log("filemoon Stream URL:", streamUrl); + + if (streamUrl && streamUrl !== false && streamUrl !== null) { + return streamUrl; + } + + console.log("No stream URL found"); + return null; + } catch (error) { + console.log("Fetch error:", error); + return null; + } +} + +/* SCHEME START */ +/* {REQUIRED PLUGINS: unbaser} */ + +/** + * @name filemoonExtractor + * @author Cufiy - Inspired by Churly + */ + +async function filemoonExtractor(html, url = null) { + // check if contains iframe, if does, extract the src and get the url + const regex = /<iframe[^>]+src="([^"]+)"[^>]*><\/iframe>/; + const match = html.match(regex); + if (match) { + console.log("Iframe URL: " + match[1]); + const iframeUrl = match[1]; + const iframeResponse = await soraFetch(iframeUrl, { + headers: { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3", + "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", + "Referer": url, + } + }); + console.log("Iframe Response: " + iframeResponse.status); + html = await iframeResponse.text(); + } + // console.log("HTML: " + html); + // get /<script[^>]*>([\s\S]*?)<\/script>/gi + const scriptRegex = /<script[^>]*>([\s\S]*?)<\/script>/gi; + const scripts = []; + let scriptMatch; + while ((scriptMatch = scriptRegex.exec(html)) !== null) { + scripts.push(scriptMatch[1]); + } + // get the script with eval and m3u8 + const evalRegex = /eval\((.*?)\)/; + const m3u8Regex = /m3u8/; + // console.log("Scripts: " + scripts); + const evalScript = scripts.find(script => evalRegex.test(script) && m3u8Regex.test(script)); + if (!evalScript) { + console.log("No eval script found"); + return null; + } + const unpackedScript = unpack(evalScript); + // get the m3u8 url + const m3u8Regex2 = /https?:\/\/[^\s]+master\.m3u8[^\s]*?(\?[^"]*)?/; + const m3u8Match = unpackedScript.match(m3u8Regex2); + if (m3u8Match) { + return m3u8Match[0]; + } else { + console.log("No M3U8 URL found"); + return null; + } +} + + +/* REMOVE_START */ + + +class Unbaser { + constructor(base) { + this.ALPHABET = { + 62: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", + 95: "' !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'", + }; + this.dictionary = {}; + this.base = base; + if (36 < base && base < 62) { + this.ALPHABET[base] = this.ALPHABET[base] || + this.ALPHABET[62].substr(0, base); + } + if (2 <= base && base <= 36) { + this.unbase = (value) => parseInt(value, base); + } + else { + try { + [...this.ALPHABET[base]].forEach((cipher, index) => { + this.dictionary[cipher] = index; + }); + } + catch (er) { + throw Error("Unsupported base encoding."); + } + this.unbase = this._dictunbaser; + } + } + _dictunbaser(value) { + let ret = 0; + [...value].reverse().forEach((cipher, index) => { + ret = ret + ((Math.pow(this.base, index)) * this.dictionary[cipher]); + }); + return ret; + } +} + + +function unpack(source) { + let { payload, symtab, radix, count } = _filterargs(source); + if (count != symtab.length) { + throw Error("Malformed p.a.c.k.e.r. symtab."); + } + let unbase; + try { + unbase = new Unbaser(radix); + } + catch (e) { + throw Error("Unknown p.a.c.k.e.r. encoding."); + } + function lookup(match) { + const word = match; + let word2; + if (radix == 1) { + word2 = symtab[parseInt(word)]; + } + else { + word2 = symtab[unbase.unbase(word)]; + } + return word2 || word; + } + source = payload.replace(/\b\w+\b/g, lookup); + return _replacestrings(source); + function _filterargs(source) { + const juicers = [ + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\), *(\d+), *(.*)\)\)/, + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\)/, + ]; + for (const juicer of juicers) { + const args = juicer.exec(source); + if (args) { + let a = args; + if (a[2] == "[]") { + } + try { + return { + payload: a[1], + symtab: a[4].split("|"), + radix: parseInt(a[2]), + count: parseInt(a[3]), + }; + } + catch (ValueError) { + throw Error("Corrupted p.a.c.k.e.r. data."); + } + } + } + throw Error("Could not make sense of p.a.c.k.e.r data (unexpected code structure)"); + } + function _replacestrings(source) { + return source; + } +} + + +/** + * Uses Sora's fetchv2 on ipad, fallbacks to regular fetch on Windows + * @author ShadeOfChaos + * + * @param {string} url The URL to make the request to. + * @param {object} [options] The options to use for the request. + * @param {object} [options.headers] The headers to send with the request. + * @param {string} [options.method='GET'] The method to use for the request. + * @param {string} [options.body=null] The body of the request. + * + * @returns {Promise<Response|null>} The response from the server, or null if the + * request failed. + */ +async function soraFetch(url, options = { headers: {}, method: 'GET', body: null }) { + try { + return await fetchv2(url, options.headers ?? {}, options.method ?? 'GET', options.body ?? null); + } catch(e) { + try { + return await fetch(url, options); + } catch(error) { + return null; + } + } +} +/* REMOVE_END */ + +/* SCHEME END */ \ No newline at end of file diff --git a/veranimes/veranimes.json b/veranimes/veranimes.json new file mode 100644 index 0000000..2e5f478 --- /dev/null +++ b/veranimes/veranimes.json @@ -0,0 +1,19 @@ +{ + "sourceName": "VerAnimes", + "iconUrl": "https://wwv.veranimes.net/cdn/img/favicon.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.1", + "language": "Spanish", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://wwv.veranimes.net/", + "searchBaseUrl": "https://wwv.veranimes.net/", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/veranimes/veranimes.js", + "type": "anime", + "asyncJS": true, + "softsub": false, + "downloadSupport": false +} diff --git a/veziseriale/veziseriale.js b/veziseriale/veziseriale.js new file mode 100644 index 0000000..4cad9e2 --- /dev/null +++ b/veziseriale/veziseriale.js @@ -0,0 +1,293 @@ +function cleanTitle(title) { + return title + .replace(/’/g, "'") // right single quote + .replace(/‘/g, "'") // left single quote + .replace(/“/g, '"') // left double quote + .replace(/”/g, '"') // right double quote + .replace(/–/g, "-") // en dash + .replace(/—/g, "-") // em dash + .replace(/"/g, '"') // double quote + .replace(/'/g, "'") // apostrophe + .replace(/&/g, "&") // ampersand + .replace(/</g, "<") // less-than + .replace(/>/g, ">") // greater-than + .replace(/ /g, " ") // non-breaking space + .replace(/&#[0-9]+;/g, "") // other numeric entities + .replace(/&[a-z]+;/gi, "") // other named entities + .replace(/\s+/g, " ") // collapse multiple spaces + .trim(); // remove leading/trailing spaces +} + +async function searchResults(keyword) { + const results = []; + try { + const response = await fetchv2("https://www3.veziseriale.org/?s=" + keyword); + const html = await response.text(); + + const regex = /<article[^>]+class="item (?:tvshows|movies)"[^>]*>.*?<img src="([^"]+)"[^>]*alt="([^"]+)">.*?<a href="([^"]+)">/gs; + let match; + while ((match = regex.exec(html)) !== null) { + results.push({ + title: cleanTitle(match[2]), + 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 divMatch = html.match(/<div class="wp-content">([\s\S]*?)<\/div>/i); + var description = "Idk why it don't got a description twin"; + + if (divMatch) { + var rawText = divMatch[1].replace(/<[^>]+>/g, '').replace(/\s+/g, ' ').trim(); + + description = rawText + .replace(/ /g, ' ') + .replace(/&/g, '&') + .replace(/"/g, '"') + .replace(/</g, '<') + .replace(/>/g, '>') + .replace(/&#(\d+);/g, function(match, num) { + return String.fromCharCode(parseInt(num, 10)); + }); + } + + 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 { + if (url.includes("/filme/")) { + return JSON.stringify([{ href: url, number: 1 }]); + } + + const response = await fetchv2(url); + const html = await response.text(); + + const seasonRegex = /<div class=['"]se-c['"][^>]*>[\s\S]*?<div class=['"]se-a['"][^>]*>[\s\S]*?<ul class=['"]episodios['"][^>]*>([\s\S]*?)<\/ul>[\s\S]*?<\/div>[\s\S]*?<\/div>/gi; + let seasonMatch; + + while ((seasonMatch = seasonRegex.exec(html)) !== null) { + const episodesHtml = seasonMatch[1]; + + const episodeRegex = /<a\s+href=['"]([^'"]+)['"][^>]*>\s*<strong[^>]*>[^<]*?Episodul\s+(\d+)\s*<\/strong>\s*<\/a>/gi; + let episodeMatch; + + while ((episodeMatch = episodeRegex.exec(episodesHtml)) !== null) { + results.push({ + href: episodeMatch[1].trim(), + number: parseInt(episodeMatch[2], 10) + }); + } + } + + console.log(`[Debug] Found ${results.length} episodes`); + console.log(`[Debug]`, JSON.stringify(results, null, 2)); + return JSON.stringify(results.reverse()); + } catch (err) { + console.error('Error extracting episodes:', err); + return JSON.stringify([{ href: "Error", number: "Error" }]); + } +} + +async function extractStreamUrl(url) { + try { + const firstresponse = await fetchv2(url); + const firsthtml = await firstresponse.text(); + + const idMatch = firsthtml.match(/href=['"]https:\/\/www3\.veziseriale\.org\/\?p=(\d+)['"]/); + if (!idMatch) throw new Error('ID not found'); + const id = idMatch[1]; + + const response = await fetchv2( + `https://passthrough-worker.simplepostrequest.workers.dev/?url=https://manager.veziseriale.org/get_links.php&type=formdata&body=id%3D${id}` + ); + const html = await response.text(); + const data = JSON.parse(html); + + const filemoonLink = data.links.find(link => link.buttonName === "Filemoon")?.url; + if (!filemoonLink) throw new Error("Filemoon link not found"); + + const filemoonId = filemoonLink.match(/\/e\/([^\/]+)/)?.[1]; + if (!filemoonId) throw new Error("Filemoon ID not found"); + + const rewrittenStreamUrl = `https://l455o.com/bkg/${filemoonId}`; + + const subtitleFilename = data.subs2; + const subtitleUrl = `https://manager.veziseriale.org/subtitles/${subtitleFilename}`; + + const response2 = await fetchv2(rewrittenStreamUrl); + const streamHtml = await response2.text(); + + const obfuscatedScript = streamHtml.match(/<script[^>]*>\s*(eval\(function\(p,a,c,k,e,d.*?\)[\s\S]*?)<\/script>/); + if (!obfuscatedScript) throw new Error("Obfuscated script not found"); + + const unpackedScript = unpack(obfuscatedScript[1]); + + const hlsMatch = unpackedScript.match(/file\s*:\s*"([^"]+\.m3u8[^"]*)"/); + if (!hlsMatch) throw new Error("HLS stream not found"); + const streamUrl = hlsMatch[1]; + + return JSON.stringify({ + stream: streamUrl, + subtitles: subtitleUrl + }); + + } catch (err) { + console.error('Error extracting stream URL: ' + err); + return { + stream: "https://files.catbox.moe/avolvc.mp4", + subtitles: "" + }; + } +} + + + +/*********************************************************** + * UNPACKER MODULE + * Credit to GitHub user "mnsrulz" for Unpacker Node library + * https://github.com/mnsrulz/unpacker + ***********************************************************/ +class Unbaser { + constructor(base) { + /* Functor for a given base. Will efficiently convert + strings to natural numbers. */ + this.ALPHABET = { + 62: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", + 95: "' !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'", + }; + this.dictionary = {}; + this.base = base; + // fill elements 37...61, if necessary + if (36 < base && base < 62) { + this.ALPHABET[base] = this.ALPHABET[base] || + this.ALPHABET[62].substr(0, base); + } + // If base can be handled by int() builtin, let it do it for us + if (2 <= base && base <= 36) { + this.unbase = (value) => parseInt(value, base); + } + else { + // Build conversion dictionary cache + try { + [...this.ALPHABET[base]].forEach((cipher, index) => { + this.dictionary[cipher] = index; + }); + } + catch (er) { + throw Error("Unsupported base encoding."); + } + this.unbase = this._dictunbaser; + } + } + _dictunbaser(value) { + /* Decodes a value to an integer. */ + let ret = 0; + [...value].reverse().forEach((cipher, index) => { + ret = ret + ((Math.pow(this.base, index)) * this.dictionary[cipher]); + }); + return ret; + } +} + +function detect(source) { + /* Detects whether `source` is P.A.C.K.E.R. coded. */ + return source.replace(" ", "").startsWith("eval(function(p,a,c,k,e,"); +} + +function unpack(source) { + /* Unpacks P.A.C.K.E.R. packed js code. */ + let { payload, symtab, radix, count } = _filterargs(source); + if (count != symtab.length) { + throw Error("Malformed p.a.c.k.e.r. symtab."); + } + let unbase; + try { + unbase = new Unbaser(radix); + } + catch (e) { + throw Error("Unknown p.a.c.k.e.r. encoding."); + } + function lookup(match) { + /* Look up symbols in the synthetic symtab. */ + const word = match; + let word2; + if (radix == 1) { + //throw Error("symtab unknown"); + word2 = symtab[parseInt(word)]; + } + else { + word2 = symtab[unbase.unbase(word)]; + } + return word2 || word; + } + source = payload.replace(/\b\w+\b/g, lookup); + return _replacestrings(source); + function _filterargs(source) { + /* Juice from a source file the four args needed by decoder. */ + const juicers = [ + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\), *(\d+), *(.*)\)\)/, + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\)/, + ]; + for (const juicer of juicers) { + //const args = re.search(juicer, source, re.DOTALL); + const args = juicer.exec(source); + if (args) { + let a = args; + if (a[2] == "[]") { + //don't know what it is + // a = list(a); + // a[1] = 62; + // a = tuple(a); + } + try { + return { + payload: a[1], + symtab: a[4].split("|"), + radix: parseInt(a[2]), + count: parseInt(a[3]), + }; + } + catch (ValueError) { + throw Error("Corrupted p.a.c.k.e.r. data."); + } + } + } + throw Error("Could not make sense of p.a.c.k.e.r data (unexpected code structure)"); + } + function _replacestrings(source) { + /* Strip string lookup table (list) and replace values in source. */ + /* Need to work on this. */ + return source; + } +} + + + diff --git a/veziseriale/veziseriale.json b/veziseriale/veziseriale.json new file mode 100644 index 0000000..0f1ffc3 --- /dev/null +++ b/veziseriale/veziseriale.json @@ -0,0 +1,19 @@ +{ + "sourceName": "Veziseriale", + "iconUrl": "https://www3.veziseriale.org/wp-content/uploads/2019/12/popcorn-152-295665.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "Romanian", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://www3.veziseriale.org//", + "searchBaseUrl": "https://www3.veziseriale.org/?s=", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/veziseriale/veziseriale.js", + "type": "shows/movies", + "asyncJS": true, + "softsub": false, + "downloadSupport": true +} diff --git a/watchanimeworld/watchanimeworld.js b/watchanimeworld/watchanimeworld.js new file mode 100644 index 0000000..b004c03 --- /dev/null +++ b/watchanimeworld/watchanimeworld.js @@ -0,0 +1,152 @@ +async function searchResults(keyword) { + const results = []; + try { + const response = await fetchv2("https://watchanimeworld.in/?s=" + encodeURIComponent(keyword)); + const html = await response.text(); + + const regex = /<h2 class="entry-title"[^>]*>(.*?)<\/h2>[\s\S]*?<img[^>]+src="([^"]+)"[^>]*>[\s\S]*?<a href="([^"]+)" class="lnk-blk">/g; + + let match; + while ((match = regex.exec(html)) !== null) { + results.push({ + title: match[1].trim(), + image: match[2].startsWith("//") ? "https:" + match[2].trim() : match[2].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 regex = /<div class="description"[^>]*>\s*<p>(.*?)<\/p>/s; + const match = regex.exec(html); + + const description = match ? match[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) { + try { + const response = await fetchv2(url); + const html = await response.text(); + + const postMatch = html.match(/data-post="(\d+)"/); + const postId = postMatch ? postMatch[1] : null; + const seasonMatches = [...html.matchAll(/data-season="(\d+)"/g)]; + const seasons = seasonMatches.map(m => parseInt(m[1], 10)); + + if (!postId || seasons.length === 0) { + const metaMatch = html.match(/<meta property="og:url" content="([^"]+)"/); + const fallbackUrl = metaMatch ? metaMatch[1] : url; + + return JSON.stringify([{ + href: fallbackUrl, + number: 1, + season: 1 + }]); + } + + const seasonPromises = seasons.map(season => { + const body = `action=action_select_season&season=${season}&post=${postId}`; + const seasonUrl = `https://passthrough-worker.simplepostrequest.workers.dev/?url=${encodeURIComponent("https://watchanimeworld.in/wp-admin/admin-ajax.php")}&type=formdata&body=${encodeURIComponent(body)}`; + + return fetchv2(seasonUrl) + .then(res => res.text()) + .then(seasonHtml => { + const regex = /<span class="num-epi">.*?<\/span>[\s\S]*?<a href="([^"]+)" class="lnk-blk"><\/a>/g; + let match, episodeCount = 1, episodes = []; + + while ((match = regex.exec(seasonHtml)) !== null) { + episodes.push({ + href: match[1].trim(), + number: episodeCount++, + season: season + }); + } + + return episodes; + }) + .catch(err => { + console.log(`Error fetching season ${season}:`, err); + return []; + }); + }); + + const allSeasons = await Promise.all(seasonPromises); + const results = allSeasons.flat(); + + return JSON.stringify(results); + } catch (err) { + return JSON.stringify([{ href: "Error", number: "Error", season: "Error" }]); + } +} + +async function extractStreamUrl(url) { + try { + const html = await (await fetchv2(url)).text(); + const iframeMatch = html.match(/<iframe[^>]+src="https:\/\/play\.zephyrflick\.top\/video\/([a-z0-9]+)"/i); + if (!iframeMatch) + return "https://files.catbox.moe/avolvc.mp4"; + + const hash = iframeMatch[1]; + const postData = { + "ilovefeet": "WE LOVE FEET" + }; + const headers = { + "X-Requested-With": "XMLHttpRequest", + "Referer": "https://watchanimeworld.in/" + }; + const fetchUrl = `https://play.zephyrflick.top/player/index.php?data=${hash}&do=getVideo`; + const videoResponse = await fetchv2(fetchUrl, headers, "POST"); + const text = await videoResponse.text(); + console.log(text); + const match = text.match(/"videoSource":"(https:[^"]+)"/); + + if (!match || !match[1]) { + console.error("No videoSource found in response"); + return "https://files.catbox.moe/avolvc.mp4"; + } + + const decodedUrl = decodeURIComponent(match[1]); + const fixedUrl = decodedUrl.replace(/\\/g, '').replace(/%5C/g, '/'); + + return fixedUrl; + } catch (err) { + console.error("Error extracting stream URL: " + err); + return "https://files.catbox.moe/avolvc.mp4"; + } +} + + + + + + + + + diff --git a/watchanimeworld/watchanimeworld.json b/watchanimeworld/watchanimeworld.json new file mode 100644 index 0000000..334fe93 --- /dev/null +++ b/watchanimeworld/watchanimeworld.json @@ -0,0 +1,19 @@ +{ + "sourceName": "WatchAnimeWorld", + "iconUrl": "https://watchanimeworld.in/wp-content/uploads/cropped-AW_Smiley-192x192.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.1", + "language": "Hindi", + "streamType": "HLS", + "quality": "1080p", + "baseUrl": "https://watchanimeworld.in/", + "searchBaseUrl": "https://watchanimeworld.in/", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/watchanimeworld/watchanimeworld.js", + "type": "anime", + "asyncJS": true, + "softsub": false, + "downloadSupport": false +} diff --git a/wikipedia/wikipedia-logo.png b/wikipedia/wikipedia-logo.png new file mode 100644 index 0000000..a2a40bb Binary files /dev/null and b/wikipedia/wikipedia-logo.png differ diff --git a/wikipedia/wikipedia.js b/wikipedia/wikipedia.js new file mode 100644 index 0000000..7ac6d23 --- /dev/null +++ b/wikipedia/wikipedia.js @@ -0,0 +1,121 @@ +/////////////////////////////////////////////////////////////////////////////////////////// +///////////////////////////// Main Functions ////////////////////////////// +///////////////////////////////////////////////////////////////////////////////////////// +searchUrl = 'https://en.wikipedia.org/wiki/List_of_films_in_the_public_domain_in_the_United_States'; + +async function searchResults(keyword) { + try { + const response = await fetch(searchUrl); + const html = await response; + + // Regex to match the table rows + const tableRegex = /<table class="wikitable sortable">([\s\S]*?)<\/table>/; + const rowRegex = /<tr>([\s\S]*?)<\/tr>/g; + const cellRegex = /<td>([\s\S]*?)<\/td>/g; + + const tableMatch = html.match(tableRegex); + if (!tableMatch) { + throw new Error('Table not found'); + } + + const rows = tableMatch[1].match(rowRegex); + if (!rows) { + throw new Error('No rows found in the table'); + } + + const apiUrl = `https://en.wikipedia.org/api/rest_v1/page/summary/`; + console.log("Test"); + + const results = []; + for (const row of rows) { + const cells = [...row.matchAll(cellRegex)]; + if (cells.length > 0) { + // Extract the path after /wiki/ + const path = cells[0][1].match(/href="([^"]+)"/)[1].split('/wiki/')[1]; + const coverImage = apiUrl + path; + + try { + const title = cells[0][1].replace(/<[^>]+>/g, '').trim(); + if (title.toLowerCase().includes(keyword.toLowerCase())) { + const responseCover = await fetch(coverImage); + const dataCover = await JSON.parse(responseCover); + const imageUrl = dataCover.thumbnail.source; + results.push({ + title: title, + href: "https://en.wikipedia.org" + cells[0][1].match(/href="([^"]+)"/)[1], + image: imageUrl || "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/images/BigBuckBunny.jpg" + }); + } + } catch (error) { + console.log('Error fetching cover image:' + error); + } + } + } + + return JSON.stringify(results); + + } catch (error) { + console.log('Fetch error:' + error); + return JSON.stringify([{ title: 'Error', image: '', href: '' }]); + } +} + +async function extractDetails(url) { + try { + // Extract the path after /wiki/ + const path = url.split('/wiki/')[1]; + const apiUrl = `https://en.wikipedia.org/api/rest_v1/page/summary/${path}`; + const response = await fetch(apiUrl); + const data = await JSON.parse(response); + + + const transformedResults = [{ + description: data.extract || 'No description available', + aliases: '', + airdate: data.description || 'No airdate available' + }]; + + return JSON.stringify(transformedResults); + } catch (error) { + console.log('Details error:' + error); + return JSON.stringify([{ + description: 'Error loading description', + aliases: '', + airdate: 'Aired: Unknown' + }]); + } +} + +async function extractEpisodes(url) { + + try { + + const fetchUrl = `${url}`; + const response = await fetch(fetchUrl); + const htmlString = await response; + + // Updated regex to find video URLs including special characters + const regex = /(\/\/upload\.wikimedia\.org\/wikipedia\/commons\/[^\s"']+\.(mp4|webm|ogg))/gi; + + const matches = htmlString.match(regex); + + console.log(matches); // This will output an array of video URLs + + const finishedList = matches.map((url, index) => ({ + number: index + 1, + href: url + })); + + return JSON.stringify(finishedList); + + } catch (error) { + console.log('Fetch error:' + error); + return JSON.stringify([{ number: 'Error', href: '' }]); + + } + +} + +async function extractStreamUrl(url) { + return "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"; +} \ No newline at end of file diff --git a/wikipedia/wikipedia.json b/wikipedia/wikipedia.json new file mode 100644 index 0000000..db1a9c2 --- /dev/null +++ b/wikipedia/wikipedia.json @@ -0,0 +1,17 @@ +{ + "sourceName": "Public Domain in the US", + "iconUrl": "https://gitlab.com/50n50/sources/-/raw/main/wikipedia/wikipedia-logo.png", + "author": { + "name": "Sulfur", + "icon": "https://gitlab.com/50n50/sources/-/raw/main/asset.png" + }, + "version": "1.0.0", + "language": "English", + "streamType": "HLS", + "quality": "720p", + "baseUrl": "https://en.wikipedia.org/wiki/List_of_films_in_the_public_domain_in_the_United_States", + "searchBaseUrl": "https://en.wikipedia.org/wiki/List_of_films_in_the_public_domain_in_the_United_States", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/wikipedia/wikipedia.js", + "asyncJS": true, + "streamAsyncJS": false +} diff --git a/witanime/witanime.js b/witanime/witanime.js new file mode 100644 index 0000000..b0a4c4b --- /dev/null +++ b/witanime/witanime.js @@ -0,0 +1,322 @@ +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 = /<div class="anime-card-container">[\s\S]*?<img[^>]+src="([^"]+)"[^>]*alt="([^"]*)"[\s\S]*?<h3><a[^>]*href="([^"]+)"[^>]*>([^<]+)<\/a><\/h3>/gi; + + let match; + while ((match = regex.exec(html)) !== null) { + results.push({ + title: match[4].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 = /<p class="anime-story">([\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( + /<a[^>]+class="server-link"[^>]+data-server-id="(\d+)"[^>]*>\s*<span class="ser">([^<]+)<\/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(/<script[^>]*>\s*(eval\(function\(p,a,c,k,e,d.*?\)[\s\S]*?)<\/script>/); + + const unpackedScript = unpack(obfuscatedScript[1]); + + const m3u8Match = unpackedScript.match(/"hls2"\s*:\s*"([^"]+)"/); + + const m3u8Url = m3u8Match[1]; + return m3u8Url; +} + +class Unbaser { + constructor(base) { + this.ALPHABET = { + 62: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", + 95: "' !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'", + }; + this.dictionary = {}; + this.base = base; + if (36 < base && base < 62) { + this.ALPHABET[base] = this.ALPHABET[base] || + this.ALPHABET[62].substr(0, base); + } + if (2 <= base && base <= 36) { + this.unbase = (value) => parseInt(value, base); + } + else { + try { + [...this.ALPHABET[base]].forEach((cipher, index) => { + this.dictionary[cipher] = index; + }); + } + catch (er) { + throw Error("Unsupported base encoding."); + } + this.unbase = this._dictunbaser; + } + } + _dictunbaser(value) { + let ret = 0; + [...value].reverse().forEach((cipher, index) => { + ret = ret + ((Math.pow(this.base, index)) * this.dictionary[cipher]); + }); + return ret; + } +} + +function detect(source) { + return source.replace(" ", "").startsWith("eval(function(p,a,c,k,e,"); +} + +function unpack(source) { + let { payload, symtab, radix, count } = _filterargs(source); + if (count != symtab.length) { + throw Error("Malformed p.a.c.k.e.r. symtab."); + } + let unbase; + try { + unbase = new Unbaser(radix); + } + catch (e) { + throw Error("Unknown p.a.c.k.e.r. encoding."); + } + function lookup(match) { + const word = match; + let word2; + if (radix == 1) { + word2 = symtab[parseInt(word)]; + } + else { + word2 = symtab[unbase.unbase(word)]; + } + return word2 || word; + } + source = payload.replace(/\b\w+\b/g, lookup); + return _replacestrings(source); + function _filterargs(source) { + const juicers = [ + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\), *(\d+), *(.*)\)\)/, + /}\('(.*)', *(\d+|\[\]), *(\d+), *'(.*)'\.split\('\|'\)/, + ]; + for (const juicer of juicers) { + const args = juicer.exec(source); + if (args) { + let a = args; + if (a[2] == "[]") { + } + try { + return { + payload: a[1], + symtab: a[4].split("|"), + radix: parseInt(a[2]), + count: parseInt(a[3]), + }; + } + catch (ValueError) { + throw Error("Corrupted p.a.c.k.e.r. data."); + } + } + } + throw Error("Could not make sense of p.a.c.k.e.r data (unexpected code structure)"); + } + function _replacestrings(source) { + return source; + } +} + +async function c(data, url = null) { + const srcMatch = data.match(/src:\s*"([^"]+\.mp4)"/); + const srcUrl = srcMatch ? srcMatch[1] : null; + + return srcUrl; +} diff --git a/witanime/witanime.json b/witanime/witanime.json new file mode 100644 index 0000000..137bd60 --- /dev/null +++ b/witanime/witanime.json @@ -0,0 +1,20 @@ +{ + "sourceName": "WitAnime", + "iconUrl": "https://witanime.red/wp-content/uploads/2023/08/cropped-Logo-WITU-192x192.png", + "author": { + "name": "50/50", + "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" + }, + "version": "1.0.0", + "language": "Arabic", + "streamType": "HLS/MP4", + "encrypted":true, + "quality": "1080p", + "baseUrl": "https://mp4upload.com/", + "searchBaseUrl": "https://mp4upload.com/", + "scriptUrl": "https://gitlab.com/50n50/sources/-/raw/main/witanime/witanime.js", + "type": "anime", + "asyncJS": true, + "softsub": false, + "downloadSupport": false +}