Fix: Fix fails for some Id's (#4)

fixes #3 

* Add tests, and test runner

* Add failing test

* Add flowconfig

* Fix #3: Fails for `en` and videoId `JueUvj6X3DA`
This commit is contained in:
syzer
2018-08-31 15:25:45 +02:00
committed by Haroen Viaene
parent e344fdd5f6
commit de7581ac7b
5 changed files with 1247 additions and 34 deletions

View File

@@ -10,7 +10,7 @@ export async function getSubtitles({
lang = 'en',
}: {
videoID: string,
lang: 'en',
lang: 'en' | 'de' | 'fr' | void,
}) {
const { data } = await axios.get(
`https://youtube.com/get_video_info?video_id=${videoID}`
@@ -32,7 +32,8 @@ export async function getSubtitles({
}) ||
find(captionTracks, {
vssId: `a.${lang}`,
});
}) ||
find(captionTracks, ({ vssId }) => vssId && vssId.match(`.${lang}`));
// * ensure we have found the correct subtitle lang
if (!subtitle || (subtitle && !subtitle.baseUrl))