From bafff7a7de9842d76328b6eb54d94f032e3d7c3b Mon Sep 17 00:00:00 2001 From: Hailey Date: Wed, 27 Dec 2023 16:52:55 -0800 Subject: [PATCH] add vimeo embed --- __tests__/lib/string.test.ts | 14 ++++++++++++++ src/lib/strings/embed-player.ts | 13 +++++++++++++ 2 files changed, 27 insertions(+) diff --git a/__tests__/lib/string.test.ts b/__tests__/lib/string.test.ts index cb27d8f867..6dba812cb4 100644 --- a/__tests__/lib/string.test.ts +++ b/__tests__/lib/string.test.ts @@ -418,6 +418,9 @@ describe('parseEmbedPlayerFromUrl', () => { 'https://music.apple.com/us/playlist/playlistName/playlistId', 'https://music.apple.com/us/album/albumName/albumId', 'https://music.apple.com/us/album/albumName/albumId?i=songId', + + 'https://vimeo.com/videoId', + 'https://vimeo.com/videoId?autoplay=0', ] const outputs = [ @@ -530,6 +533,17 @@ describe('parseEmbedPlayerFromUrl', () => { playerUri: 'https://embed.music.apple.com/us/album/albumName/albumId?i=songId', }, + + { + type: 'vimeo_video', + videoId: 'videoId', + playerUri: 'https://player.vimeo.com/video/videoId?autoplay=1', + }, + { + type: 'vimeo_video', + videoId: 'videoId', + playerUri: 'https://player.vimeo.com/video/videoId?autoplay=1', + }, ] it('correctly grabs the correct id from uri', () => { diff --git a/src/lib/strings/embed-player.ts b/src/lib/strings/embed-player.ts index 54ed501020..32a7807354 100644 --- a/src/lib/strings/embed-player.ts +++ b/src/lib/strings/embed-player.ts @@ -15,6 +15,7 @@ export type EmbedPlayerParams = | {type: 'apple_music_playlist'; playlistId: string; playerUri: string} | {type: 'apple_music_album'; albumId: string; playerUri: string} | {type: 'apple_music_song'; songId: string; playerUri: string} + | {type: 'vimeo_video'; videoId: string; playerUri: string} export function parseEmbedPlayerFromUrl( url: string, @@ -158,6 +159,17 @@ export function parseEmbedPlayerFromUrl( } } } + + if (urlp.hostname === 'vimeo.com' || urlp.hostname === 'www.vimeo.com') { + const [_, videoId] = urlp.pathname.split('/') + if (videoId) { + return { + type: 'vimeo_video', + videoId, + playerUri: `https://player.vimeo.com/video/${videoId}?autoplay=1`, + } + } + } } export function getPlayerHeight({ @@ -174,6 +186,7 @@ export function getPlayerHeight({ switch (type) { case 'youtube_video': case 'twitch_live': + case 'vimeo_video': return (width / 16) * 9 case 'spotify_album': return 380