From c2d1fdde671e55820af1c3ad5b59fc0ca730e147 Mon Sep 17 00:00:00 2001 From: Jonathan Barrow Date: Fri, 29 Sep 2023 14:37:01 -0400 Subject: [PATCH] happy path in mixdrop --- src/providers/embeds/mixdrop.ts | 55 +++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/src/providers/embeds/mixdrop.ts b/src/providers/embeds/mixdrop.ts index d394c48..b289ef7 100644 --- a/src/providers/embeds/mixdrop.ts +++ b/src/providers/embeds/mixdrop.ts @@ -16,31 +16,38 @@ export const mixdropScraper = makeEmbed({ const streamRes = await ctx.proxiedFetcher(ctx.url); const packed = streamRes.match(packedRegex); - if (packed) { - const unpacked = unpacker.unpack(packed[1]); - const link = unpacked.match(linkRegex); - - if (link) { - const url = link[1]; - return { - stream: { - type: 'file', - flags: [], - qualities: { - unknown: { - type: 'mp4', - url: url.startsWith('http') ? url : `https:${url}`, // URLs don't always start with the protocol - headers: { - // MixDrop requires this header on all streams - Referer: 'https://mixdrop.co/', - }, - }, - }, - }, - }; - } + // MixDrop uses a queue system for embeds + // If an embed is too new, the queue will + // not be completed and thus the packed + // JavaScript not present + if (!packed) { + throw new Error('failed to find packed mixdrop JavaScript'); } - throw new Error('mixdrop source not found'); + const unpacked = unpacker.unpack(packed[1]); + const link = unpacked.match(linkRegex); + + if (!link) { + throw new Error('failed to find packed mixdrop source link'); + } + + const url = link[1]; + + return { + stream: { + type: 'file', + flags: [], + qualities: { + unknown: { + type: 'mp4', + url: url.startsWith('http') ? url : `https:${url}`, // URLs don't always start with the protocol + headers: { + // MixDrop requires this header on all streams + Referer: 'https://mixdrop.co/', + }, + }, + }, + }, + }; }, });