mirror of
https://github.com/movie-web/providers.git
synced 2025-09-13 12:43:25 +00:00
Fix LookMovie caption codes, create removeDuplicateLanguages util
This commit is contained in:
@@ -31,3 +31,13 @@ export function isValidLanguageCode(code: string | null): boolean {
|
||||
if (!code) return false;
|
||||
return ISO6391.validate(code);
|
||||
}
|
||||
|
||||
export function removeDuplicatedLanguages(list: Caption[]) {
|
||||
const beenSeen: Record<string, true> = {};
|
||||
|
||||
return list.filter((sub) => {
|
||||
if (beenSeen[sub.language]) return false;
|
||||
beenSeen[sub.language] = true;
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
@@ -1,4 +1,9 @@
|
||||
import { Caption, getCaptionTypeFromUrl, isValidLanguageCode } from '@/providers/captions';
|
||||
import {
|
||||
Caption,
|
||||
getCaptionTypeFromUrl,
|
||||
isValidLanguageCode,
|
||||
removeDuplicatedLanguages as removeDuplicateLanguages,
|
||||
} from '@/providers/captions';
|
||||
import { captionsDomains } from '@/providers/sources/showbox/common';
|
||||
import { sendRequest } from '@/providers/sources/showbox/sendRequest';
|
||||
import { ScrapeContext } from '@/utils/context';
|
||||
@@ -36,8 +41,7 @@ export async function getSubtitles(
|
||||
|
||||
const subResult = (await sendRequest(ctx, subtitleApiQuery)) as CaptionApiResponse;
|
||||
const subtitleList = subResult.data.list;
|
||||
const output: Caption[] = [];
|
||||
const languagesAdded: Record<string, true> = {};
|
||||
let output: Caption[] = [];
|
||||
|
||||
subtitleList.forEach((sub) => {
|
||||
const subtitle = sub.subtitles.sort((a, b) => b.order - a.order)[0];
|
||||
@@ -56,9 +60,6 @@ export async function getSubtitles(
|
||||
const validCode = isValidLanguageCode(subtitle.lang);
|
||||
if (!validCode) return;
|
||||
|
||||
if (languagesAdded[subtitle.lang]) return;
|
||||
languagesAdded[subtitle.lang] = true;
|
||||
|
||||
output.push({
|
||||
id: subtitleFilePath,
|
||||
language: subtitle.lang,
|
||||
@@ -68,5 +69,7 @@ export async function getSubtitles(
|
||||
});
|
||||
});
|
||||
|
||||
output = removeDuplicateLanguages(output);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
@@ -33,7 +33,6 @@ export const lookmovieScraper = makeSourcerer({
|
||||
id: 'lookmovie',
|
||||
name: 'LookMovie',
|
||||
rank: 1,
|
||||
disabled: true,
|
||||
flags: [flags.IP_LOCKED],
|
||||
scrapeShow: universalScraper,
|
||||
scrapeMovie: universalScraper,
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import { MovieMedia, ShowMedia } from '@/entrypoint/utils/media';
|
||||
import { Caption } from '@/providers/captions';
|
||||
import { Caption, labelToLanguageCode, removeDuplicatedLanguages } from '@/providers/captions';
|
||||
import { ScrapeContext } from '@/utils/context';
|
||||
|
||||
import { StreamsDataResult } from './type';
|
||||
@@ -44,13 +44,21 @@ export async function getVideo(
|
||||
}
|
||||
}
|
||||
|
||||
const captions: Caption[] = data.subtitles.map((sub) => ({
|
||||
id: sub.url,
|
||||
type: 'vtt',
|
||||
url: `${baseUrl}${sub.url}`,
|
||||
hasCorsRestrictions: false,
|
||||
language: sub.language,
|
||||
}));
|
||||
let captions: Caption[] = [];
|
||||
|
||||
for (const sub of data.subtitles) {
|
||||
const language = labelToLanguageCode(sub.language);
|
||||
if (!language) continue;
|
||||
captions.push({
|
||||
id: sub.url,
|
||||
type: 'vtt',
|
||||
url: `${baseUrl}${sub.url}`,
|
||||
hasCorsRestrictions: false,
|
||||
language,
|
||||
});
|
||||
}
|
||||
|
||||
captions = removeDuplicatedLanguages(captions);
|
||||
|
||||
return {
|
||||
playlist: videoUrl,
|
||||
|
Reference in New Issue
Block a user