From b6f0639ce2ee70104fc8cd504109f30ba2b24541 Mon Sep 17 00:00:00 2001 From: Irfan Date: Thu, 2 Dec 2021 13:53:10 +0530 Subject: [PATCH] fix: use correct url (#13) --- src/index.js | 8 +++----- test/index.test.js | 8 ++++---- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/index.js b/src/index.js index 37a4010..ae4a7aa 100644 --- a/src/index.js +++ b/src/index.js @@ -13,17 +13,15 @@ export async function getSubtitles({ lang: 'en' | 'de' | 'fr' | void, }) { const { data } = await axios.get( - `https://youtube.com/get_video_info?video_id=${videoID}` + `https://youtube.com/watch?v=${videoID}` ); - const decodedData = decodeURIComponent(data); - // * ensure we have access to captions data - if (!decodedData.includes('captionTracks')) + if (!data.includes('captionTracks')) throw new Error(`Could not find captions for video: ${videoID}`); const regex = /({"captionTracks":.*isTranslatable":(true|false)}])/; - const [match] = regex.exec(decodedData); + const [match] = regex.exec(data); const { captionTracks } = JSON.parse(`${match}}`); const subtitle = diff --git a/test/index.test.js b/test/index.test.js index e9aa96e..3dce3e8 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -4,13 +4,13 @@ import { getSubtitles } from '../src'; test('Extract estonia war subtitles', async t => { const subtitles = await getSubtitles({ videoID: 'HBA0xDHZjko' }); t.deepEqual(subtitles[0], { - dur: '5.87', - start: '6.62', - text: 'November 19', + dur: '5.679', + start: '7.12', + text: 'november 1918', }); }); test('Extract passive income video', async t => { const subtitles = await getSubtitles({ videoID: 'JueUvj6X3DA' }); - t.deepEqual('creating passive income takes work but', subtitles[0].text); + t.deepEqual('- Creating passive income takes work,', subtitles[0].text); });