From 67d936f58c121092ad85061d4cf772dd2aa3a610 Mon Sep 17 00:00:00 2001 From: Mahir <128459141+iMahir@users.noreply.github.com> Date: Sun, 31 Dec 2023 21:26:27 +0530 Subject: [PATCH] feat(lookmovie): add captions support --- src/providers/sources/lookmovie/index.ts | 8 ++++---- src/providers/sources/lookmovie/type.ts | 9 +++++++++ src/providers/sources/lookmovie/util.ts | 14 ++++++++------ src/providers/sources/lookmovie/video.ts | 23 ++++++++++++++++++----- 4 files changed, 39 insertions(+), 15 deletions(-) diff --git a/src/providers/sources/lookmovie/index.ts b/src/providers/sources/lookmovie/index.ts index 5cd82e9..8611373 100644 --- a/src/providers/sources/lookmovie/index.ts +++ b/src/providers/sources/lookmovie/index.ts @@ -10,8 +10,8 @@ async function universalScraper(ctx: MovieScrapeContext | ShowScrapeContext): Pr if (!lookmovieData) throw new NotFoundError('Media not found'); ctx.progress(30); - const videoUrl = await scrape(ctx, ctx.media, lookmovieData); - if (!videoUrl) throw new NotFoundError('No video found'); + const video = await scrape(ctx, ctx.media, lookmovieData); + if (!video.playlist) throw new NotFoundError('No video found'); ctx.progress(60); @@ -20,10 +20,10 @@ async function universalScraper(ctx: MovieScrapeContext | ShowScrapeContext): Pr stream: [ { id: 'primary', - playlist: videoUrl, + playlist: video.playlist, type: 'hls', flags: [flags.IP_LOCKED], - captions: [], + captions: video.captions, }, ], }; diff --git a/src/providers/sources/lookmovie/type.ts b/src/providers/sources/lookmovie/type.ts index 8335c96..47ccc55 100644 --- a/src/providers/sources/lookmovie/type.ts +++ b/src/providers/sources/lookmovie/type.ts @@ -39,8 +39,17 @@ interface VideoSources { [key: string]: string; } +interface VideoSubtitles { + id?: number; + id_movie?: number; + url: string; + language: string; + shard?: string; +} + export interface StreamsDataResult { streams: VideoSources; + subtitles: VideoSubtitles[]; } export interface ResultItem { diff --git a/src/providers/sources/lookmovie/util.ts b/src/providers/sources/lookmovie/util.ts index 7c8f202..6057f76 100644 --- a/src/providers/sources/lookmovie/util.ts +++ b/src/providers/sources/lookmovie/util.ts @@ -4,7 +4,9 @@ import { ScrapeContext } from '@/utils/context'; import { NotFoundError } from '@/utils/errors'; import { Result, ResultItem, ShowDataResult, episodeObj } from './type'; -import { getVideoUrl } from './video'; +import { getVideo } from './video'; + +export const baseUrl = 'https://lmscript.xyz'; export async function searchAndFindMedia( ctx: ScrapeContext, @@ -12,7 +14,7 @@ export async function searchAndFindMedia( ): Promise { if (media.type === 'show') { const searchRes = await ctx.fetcher(`/v1/shows`, { - baseUrl: 'https://lmscript.xyz', + baseUrl, query: { 'filters[q]': media.title }, }); @@ -23,7 +25,7 @@ export async function searchAndFindMedia( } if (media.type === 'movie') { const searchRes = await ctx.fetcher(`/v1/movies`, { - baseUrl: 'https://lmscript.xyz', + baseUrl, query: { 'filters[q]': media.title }, }); @@ -40,7 +42,7 @@ export async function scrape(ctx: ScrapeContext, media: MovieMedia | ShowMedia, id = result.id_movie; } else if (media.type === 'show') { const data = await ctx.fetcher(`/v1/shows`, { - baseUrl: 'https://lmscript.xyz', + baseUrl, query: { expand: 'episodes', id: result.id_show }, }); @@ -54,6 +56,6 @@ export async function scrape(ctx: ScrapeContext, media: MovieMedia | ShowMedia, // Check ID if (id === null) throw new NotFoundError('Not found'); - const videoUrl = await getVideoUrl(ctx, id, media); - return videoUrl; + const video = await getVideo(ctx, id, media); + return video; } diff --git a/src/providers/sources/lookmovie/video.ts b/src/providers/sources/lookmovie/video.ts index f439229..48bcafc 100644 --- a/src/providers/sources/lookmovie/video.ts +++ b/src/providers/sources/lookmovie/video.ts @@ -1,7 +1,9 @@ import { MovieMedia, ShowMedia } from '@/entrypoint/utils/media'; +import { Caption } from '@/providers/captions'; import { ScrapeContext } from '@/utils/context'; import { StreamsDataResult } from './type'; +import { baseUrl } from './util'; export async function getVideoSources( ctx: ScrapeContext, @@ -17,17 +19,17 @@ export async function getVideoSources( path = `/v1/movies/view`; } const data = await ctx.fetcher(path, { - baseUrl: 'https://lmscript.xyz', - query: { expand: 'streams', id }, + baseUrl, + query: { expand: 'streams,subtitles', id }, }); return data; } -export async function getVideoUrl( +export async function getVideo( ctx: ScrapeContext, id: string, media: MovieMedia | ShowMedia, -): Promise { +): Promise<{ playlist: string | null; captions: Caption[] }> { // Get sources const data = await getVideoSources(ctx, id, media); const videoSources = data.streams; @@ -42,5 +44,16 @@ export async function getVideoUrl( } } - return videoUrl; + const captions: Caption[] = data.subtitles.map((sub) => ({ + id: sub.url, + type: 'vtt', + url: `${baseUrl}${sub.url}`, + hasCorsRestrictions: false, + language: sub.language, + })); + + return { + playlist: videoUrl, + captions, + }; }