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.
 
 

20 líneas
687 B

  1. import { InvalidVideoIdError } from './errors';
  2. const STANDARD_YOUTUBE_VIDEO_ID_LENGTH = 11 as const;
  3. export const RE_YOUTUBE = /^.*(?:(?:youtu\.be\/|v\/|vi\/|u\/\w\/|embed\/)|(?:(?:watch)?\?v?:i?=|&v?:i?=))([^#&?]*).*/im;
  4. export const retrieveVideoId = (videoId: string): string => {
  5. if (typeof (videoId as unknown) !== 'string') {
  6. throw new InvalidVideoIdError('The video ID must be a string.');
  7. }
  8. if (videoId.length === STANDARD_YOUTUBE_VIDEO_ID_LENGTH) {
  9. return videoId;
  10. }
  11. const matchId = videoId.match(RE_YOUTUBE);
  12. if (matchId && matchId.length > 1) {
  13. return matchId[1];
  14. }
  15. throw new InvalidVideoIdError('Impossible to retrieve Youtube video ID.');
  16. };