Get transcript summaries of Web videos.
No puede seleccionar más de 25 temas
Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
|
- import { InvalidVideoIdError } from './errors';
-
- const STANDARD_YOUTUBE_VIDEO_ID_LENGTH = 11 as const;
-
- export const RE_YOUTUBE = /^.*(?:(?:youtu\.be\/|v\/|vi\/|u\/\w\/|embed\/)|(?:(?:watch)?\?v?:i?=|&v?:i?=))([^#&?]*).*/im;
-
- export const retrieveVideoId = (videoId: string): string => {
- if (typeof (videoId as unknown) !== 'string') {
- throw new InvalidVideoIdError('The video ID must be a string.');
- }
- if (videoId.length === STANDARD_YOUTUBE_VIDEO_ID_LENGTH) {
- return videoId;
- }
- const matchId = videoId.match(RE_YOUTUBE);
- if (matchId && matchId.length > 1) {
- return matchId[1];
- }
- throw new InvalidVideoIdError('Impossible to retrieve Youtube video ID.');
- };
|