Get transcript summaries of Web videos.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 

20 lignes
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. };