mirror of
https://github.com/movie-web/providers.git
synced 2025-09-13 10:23:24 +00:00
Subtitle label conversion
This commit is contained in:
@@ -79,6 +79,7 @@
|
||||
"cheerio": "^1.0.0-rc.12",
|
||||
"crypto-js": "^4.1.1",
|
||||
"form-data": "^4.0.0",
|
||||
"iso-639-1": "^3.1.0",
|
||||
"nanoid": "^3.3.6",
|
||||
"node-fetch": "^2.7.0",
|
||||
"unpacker": "^1.0.1"
|
||||
|
@@ -1,3 +1,5 @@
|
||||
import ISO6391 from 'iso-639-1';
|
||||
|
||||
export const captionTypes = {
|
||||
srt: 'srt',
|
||||
vtt: 'vtt',
|
||||
@@ -17,3 +19,14 @@ export function getCaptionTypeFromUrl(url: string): CaptionType | null {
|
||||
if (!type) return null;
|
||||
return type;
|
||||
}
|
||||
|
||||
export function labelToLanguageCode(label: string): string | null {
|
||||
const code = ISO6391.getCode(label);
|
||||
if (code.length === 0) return null;
|
||||
return code;
|
||||
}
|
||||
|
||||
export function isValidLanguageCode(code: string | null): boolean {
|
||||
if (!code) return false;
|
||||
return ISO6391.validate(code);
|
||||
}
|
||||
|
@@ -2,7 +2,7 @@ import crypto from 'crypto-js';
|
||||
|
||||
import { flags } from '@/main/targets';
|
||||
import { makeEmbed } from '@/providers/base';
|
||||
import { Caption, getCaptionTypeFromUrl } from '@/providers/captions';
|
||||
import { Caption, getCaptionTypeFromUrl, labelToLanguageCode } from '@/providers/captions';
|
||||
|
||||
const { AES, enc } = crypto;
|
||||
|
||||
@@ -102,8 +102,10 @@ export const upcloudScraper = makeEmbed({
|
||||
if (track.kind !== 'captions') return;
|
||||
const type = getCaptionTypeFromUrl(track.file);
|
||||
if (!type) return;
|
||||
const language = labelToLanguageCode(track.label);
|
||||
if (!language) return;
|
||||
captions.push({
|
||||
language: track.label, // TODO Turn language name into ISO code
|
||||
language,
|
||||
hasCorsRestrictions: false,
|
||||
type,
|
||||
url: track.file,
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import { Caption, getCaptionTypeFromUrl } from '@/providers/captions';
|
||||
import { Caption, getCaptionTypeFromUrl, isValidLanguageCode } from '@/providers/captions';
|
||||
import { sendRequest } from '@/providers/sources/superstream/sendRequest';
|
||||
import { ScrapeContext } from '@/utils/context';
|
||||
|
||||
@@ -42,6 +42,9 @@ export async function getSubtitles(
|
||||
const subtitleType = getCaptionTypeFromUrl(subtitle.file_path);
|
||||
if (!subtitleType) return;
|
||||
|
||||
const validCode = isValidLanguageCode(subtitle.lang);
|
||||
if (!validCode) return;
|
||||
|
||||
output.push({
|
||||
language: subtitle.lang,
|
||||
hasCorsRestrictions: true,
|
||||
|
Reference in New Issue
Block a user