const YOUTUBE = /^(?:https:\/\/)?(?:www.)?(?:youtube.com\/watch\?v=|youtu.be\/)([a-zA-Z0-9_-]{11})(?:.+)?$/;
const VIMEO = /^(?:https:\/\/)?(?:www.)?vimeo.com\/([a-zA-Z0-9]*)$/;
// const SRF = /^(?:https:\/\/)?(?:www.)?srf.ch\/(?:[\w/-]*)[?&]id=([\w-]+)(?:[&\w=-]*)$/;
const SRF = /^(?:https:\/\/)?(?:www.)?srf.ch\/(?:[\w/-]*)[?&]id=([\w-]+)(?:[&\w=-]*)(?:&?startTime=([\d.]+))?/;

export function isYoutubeUrl(url: string) {
  return YOUTUBE.test(url);
}

export function isVimeoUrl(url: string) {
  return VIMEO.test(url);
}

export function isSrfUrl(url: string) {
  return SRF.test(url);
}

export function getVideoId(url: string) {
  if (isYoutubeUrl(url)) {
    return YOUTUBE.exec(url)[1];
  } else if (isVimeoUrl(url)) {
    return VIMEO.exec(url)[1];
  } else if (isSrfUrl(url)) {
    return SRF.exec(url)[1];
  } else {
    return '';
  }
}
