From faa49feec8a1f9bbaac1e7e25c9271d6067c4489 Mon Sep 17 00:00:00 2001 From: Jason Ericson Date: Thu, 30 Oct 2025 12:25:42 -0400 Subject: [PATCH] Fixed Apple Music song embeds. (#9220) * Fixed Apple Music song embeds when using a direct song link (vs playlist or album). * Fixed song embed test. * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Jason Ericson Co-authored-by: Samuel Newman Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- __tests__/lib/string.test.ts | 6 ++++++ src/lib/strings/embed-player.ts | 13 +++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/__tests__/lib/string.test.ts b/__tests__/lib/string.test.ts index 0f53d386a3..6087ba5b14 100644 --- a/__tests__/lib/string.test.ts +++ b/__tests__/lib/string.test.ts @@ -378,6 +378,7 @@ 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://music.apple.com/us/song/songName/songId', 'https://vimeo.com/videoId', 'https://vimeo.com/videoId?autoplay=0', @@ -604,6 +605,11 @@ describe('parseEmbedPlayerFromUrl', () => { playerUri: 'https://embed.music.apple.com/us/album/albumName/albumId?i=songId', }, + { + type: 'apple_music_song', + source: 'appleMusic', + playerUri: 'https://embed.music.apple.com/us/song/songName/songId', + }, { type: 'vimeo_video', diff --git a/src/lib/strings/embed-player.ts b/src/lib/strings/embed-player.ts index a7ce441fcc..4680be26e4 100644 --- a/src/lib/strings/embed-player.ts +++ b/src/lib/strings/embed-player.ts @@ -239,10 +239,13 @@ export function parseEmbedPlayerFromUrl( const type = pathParams[2] const songId = urlp.searchParams.get('i') - if (pathParams.length === 5 && (type === 'playlist' || type === 'album')) { + if ( + pathParams.length === 5 && + (type === 'playlist' || type === 'album' || type === 'song') + ) { // We want to append the songId to the end of the url if it exists const embedUri = `https://embed.music.apple.com${urlp.pathname}${ - urlp.search ? '?i=' + songId : '' + songId ? `?i=${songId}` : '' }` if (type === 'playlist') { @@ -265,6 +268,12 @@ export function parseEmbedPlayerFromUrl( playerUri: embedUri, } } + } else if (type === 'song') { + return { + type: 'apple_music_song', + source: 'appleMusic', + playerUri: embedUri, + } } } }