Skip to content

Commit

Permalink
fix subtitles request lang, fix yandex subtitles without tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyhalight committed Aug 25, 2024
1 parent 87f107f commit 51db09c
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/subtitles.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,16 @@ function getSubtitlesTokens(subtitles, subtitlesObject) {
const { source, isAutoGenerated } = subtitlesObject;
for (let i = 0; i < subtitles.subtitles.length; i++) {
const line = subtitles.subtitles[i];
if (line?.tokens?.length && !["yandex", "youtube"].includes(source)) {
const hasTokens = line?.tokens?.length;
if (hasTokens && !["yandex", "youtube"].includes(source)) {
console.warn("[VOT] Unsupported subtitles tokens type: ", source);
subtitles.containsTokens = false;
return null;
}

let tokens =
source === "yandex" || (source === "youtube" && isAutoGenerated)
hasTokens &&
(source === "yandex" || (source === "youtube" && isAutoGenerated))
? formatYandexSubtitlesTokens(line)
: createSubtitlesTokens(line, lastToken);
lastToken = tokens[tokens.length - 1];
Expand Down Expand Up @@ -180,7 +182,13 @@ export async function fetchSubtitles(subtitlesObject) {
}

export async function getSubtitles(client, videoData) {
const { host, url, requestLang, videoId, duration } = videoData;
const {
host,
url,
detectedLanguage: requestLang,
videoId,
duration,
} = videoData;
const ytSubtitles = host === "youtube" ? youtubeUtils.getSubtitles() : [];

const timeoutPromise = new Promise((_, reject) =>
Expand Down

0 comments on commit 51db09c

Please sign in to comment.