fix: use correct url (#13)
This commit is contained in:
@@ -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 =
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user