diff --git a/src/providers/embeds/vidify.ts b/src/providers/embeds/vidify.ts index 0c38268..ceb084d 100644 --- a/src/providers/embeds/vidify.ts +++ b/src/providers/embeds/vidify.ts @@ -1,11 +1,59 @@ /* eslint-disable no-console */ import { flags } from '@/entrypoint/utils/targets'; import { NotFoundError } from '@/utils/errors'; -import { findFirstM3U8Url } from '@/utils/m3u8'; import { createM3U8ProxyUrl } from '@/utils/proxy'; import { EmbedOutput, makeEmbed } from '../base'; +// Do not do this. This is very lazy! +const M3U8_URL_REGEX = /https?:\/\/[^\s"'<>]+?\.m3u8[^\s"'<>]*/i; + +function extractFromString(input: string): string | null { + const match = input.match(M3U8_URL_REGEX); + return match ? match[0] : null; +} + +function findFirstM3U8Url(input: unknown): string | null { + // eslint-disable-next-line no-console + console.log(input); + const visited = new Set(); + + function dfs(node: unknown): string | null { + if (node == null) return null; + if (visited.has(node)) return null; + // Only mark objects/arrays as visited to avoid blocking primitives + if (typeof node === 'object') visited.add(node); + + if (typeof node === 'string') { + return extractFromString(node); + } + + if (Array.isArray(node)) { + for (const element of node) { + const found = dfs(element); + if (found) return found; + } + return null; + } + + if (typeof node === 'object') { + for (const value of Object.values(node as Record)) { + if (typeof value === 'string') { + const foundInString = extractFromString(value); + if (foundInString) return foundInString; + } else { + const found = dfs(value); + if (found) return found; + } + } + } + + return null; + } + + return dfs(input); +} + const baseUrl = 'api.vidify.top'; const headers = { referer: 'https://player.vidify.top/', diff --git a/src/utils/m3u8.ts b/src/utils/m3u8.ts deleted file mode 100644 index 0e397fe..0000000 --- a/src/utils/m3u8.ts +++ /dev/null @@ -1,51 +0,0 @@ -/** - * Utilities for extracting HLS playlist URLs from arbitrary data structures. - */ - -const M3U8_URL_REGEX = /https?:\/\/[^\s"'<>]+?\.m3u8[^\s"'<>]*/i; - -function extractFromString(input: string): string | null { - const match = input.match(M3U8_URL_REGEX); - return match ? match[0] : null; -} - -export function findFirstM3U8Url(input: unknown): string | null { - // eslint-disable-next-line no-console - console.log(input); - const visited = new Set(); - - function dfs(node: unknown): string | null { - if (node == null) return null; - if (visited.has(node)) return null; - // Only mark objects/arrays as visited to avoid blocking primitives - if (typeof node === 'object') visited.add(node); - - if (typeof node === 'string') { - return extractFromString(node); - } - - if (Array.isArray(node)) { - for (const element of node) { - const found = dfs(element); - if (found) return found; - } - return null; - } - - if (typeof node === 'object') { - for (const value of Object.values(node as Record)) { - if (typeof value === 'string') { - const foundInString = extractFromString(value); - if (foundInString) return foundInString; - } else { - const found = dfs(value); - if (found) return found; - } - } - } - - return null; - } - - return dfs(input); -}