From ffcdf16d877f634017670c3f244c46d5a40295f3 Mon Sep 17 00:00:00 2001 From: TPN Date: Thu, 30 Jan 2025 16:31:59 +0000 Subject: [PATCH] Fix soaper search idk if it was broken or not but anyway --- src/providers/sources/soapertv/index.ts | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/providers/sources/soapertv/index.ts b/src/providers/sources/soapertv/index.ts index c9878d9..2a1885a 100644 --- a/src/providers/sources/soapertv/index.ts +++ b/src/providers/sources/soapertv/index.ts @@ -3,6 +3,7 @@ import { load } from 'cheerio'; import { flags } from '@/entrypoint/utils/targets'; import { Caption, labelToLanguageCode } from '@/providers/captions'; import { Stream } from '@/providers/streams'; +import { compareMedia } from '@/utils/compare'; import { MovieScrapeContext, ShowScrapeContext } from '@/utils/context'; import { NotFoundError } from '@/utils/errors'; import { convertPlaylistsToDataUrls } from '@/utils/playlist'; @@ -19,10 +20,21 @@ const universalScraper = async (ctx: MovieScrapeContext | ShowScrapeContext): Pr keyword: ctx.media.title, }, }); - const searchResult$ = load(searchResult); - let showLink = searchResult$('a') - .filter((_, el) => searchResult$(el).text() === ctx.media.title) - .attr('href'); + const search$ = load(searchResult); + + const searchResults: { title: string; year?: number | undefined; url: string }[] = []; + + search$('.thumbnail').each((_, element) => { + const title = search$(element).find('h5').find('a').first().text().trim(); + const year = search$(element).find('.img-tip').first().text().trim(); + const url = search$(element).find('h5').find('a').first().attr('href'); + + if (!title || !url) return; + + searchResults.push({ title, year: year ? parseInt(year, 10) : undefined, url }); + }); + + const showLink = searchResults.find((x) => x && compareMedia(ctx.media, x.title, x.year))?.url; if (!showLink) throw new NotFoundError('Content not found'); if (ctx.media.type === 'show') {