diff --git a/client/src/helpers/video.ts b/client/src/helpers/video.ts index 3e2a9599..204b468c 100644 --- a/client/src/helpers/video.ts +++ b/client/src/helpers/video.ts @@ -1,7 +1,12 @@ 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.]+))?/; +/* + * Handles URLs like + * - https://www.srf.ch/play/tv/popupvideoplayer?id=6db02b8b-975c-4e3e-8260-f1e6eca1d8ed + * - https://www.srf.ch/play/tv/we-myself--why/video/nein-sagen-so-klappt-es?urn=urn:srf:video:6db02b8b-975c-4e3e-8260-f1e6eca1d8e + */ +const SRF = + /^(?:https:\/\/)?(?:www.)?srf.ch\/(?:[\w/-]*)[?&](?:id=|urn=urn:srf:video:)([\w-]+)(?:[&\w=-]*)(?:&?startTime=([\d.]+))?/; export function isYoutubeUrl(url: string) { return YOUTUBE.test(url); diff --git a/client/tests/unit/srf.spec.ts b/client/tests/unit/srf.spec.ts index ad1b88a1..3cb4cf30 100644 --- a/client/tests/unit/srf.spec.ts +++ b/client/tests/unit/srf.spec.ts @@ -2,14 +2,31 @@ import { getVideoId } from '../../src/helpers/video'; import { mount } from '@vue/test-utils'; import SrfEmbed from '@/components/videos/SrfEmbed.vue'; -const url = 'https://www.srf.ch/play/tv/popupvideoplayer?id=6db02b8b-975c-4e3e-8260-f1e6eca1d8ed'; -const embedUrl = - 'https://www.srf.ch/play/embed?urn=urn:srf:video:6db02b8b-975c-4e3e-8260-f1e6eca1d8ed&subdivisions=false'; -describe('SRF Video Embed', () => { +describe('Legacy SRF Video Embed', () => { + const videoId = '6db02b8b-975c-4e3e-8260-f1e6eca1d8ed'; + const url = `https://www.srf.ch/play/tv/popupvideoplayer?id=${videoId}`; + const embedUrl = `https://www.srf.ch/play/embed?urn=urn:srf:video:${videoId}&subdivisions=false`; it('should return the correct embed url', () => { - const videoId = getVideoId(url); - const embedId = '6db02b8b-975c-4e3e-8260-f1e6eca1d8ed'; - expect(videoId).toBe(embedId); + const extractedId = getVideoId(url); + expect(extractedId).toBe(videoId); + }); + it('should construct the correct iframe', () => { + const props = { + url, + }; + const wrapper = mount(SrfEmbed, { + props, + }); + expect(wrapper.attributes('src')).toBe(embedUrl); + }); +}); +describe('New SRF Video Embed', () => { + const videoId = '6db02b8b-975c-4e3e-8260-f1e6eca1d8ed'; + const url = `https://www.srf.ch/play/tv/we-myself--why/video/nein-sagen-so-klappt-es?urn=urn:srf:video:${videoId}`; + const embedUrl = `https://www.srf.ch/play/embed?urn=urn:srf:video:${videoId}&subdivisions=false`; + it('should return the correct embed url', () => { + const extractedId = getVideoId(embedUrl); + expect(extractedId).toBe(videoId); }); it('should construct the correct iframe', () => { const props = {