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 <jasonmarkericson@gmail.com>
Co-authored-by: Samuel Newman <mozzius@protonmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Jason Ericson
2025-10-30 12:25:42 -04:00
committed by GitHub
parent 55b3474ad2
commit faa49feec8
2 changed files with 17 additions and 2 deletions
+6
View File
@@ -378,6 +378,7 @@ describe('parseEmbedPlayerFromUrl', () => {
'https://music.apple.com/us/playlist/playlistName/playlistId', 'https://music.apple.com/us/playlist/playlistName/playlistId',
'https://music.apple.com/us/album/albumName/albumId', 'https://music.apple.com/us/album/albumName/albumId',
'https://music.apple.com/us/album/albumName/albumId?i=songId', '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',
'https://vimeo.com/videoId?autoplay=0', 'https://vimeo.com/videoId?autoplay=0',
@@ -604,6 +605,11 @@ describe('parseEmbedPlayerFromUrl', () => {
playerUri: playerUri:
'https://embed.music.apple.com/us/album/albumName/albumId?i=songId', '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', type: 'vimeo_video',
+11 -2
View File
@@ -239,10 +239,13 @@ export function parseEmbedPlayerFromUrl(
const type = pathParams[2] const type = pathParams[2]
const songId = urlp.searchParams.get('i') 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 // We want to append the songId to the end of the url if it exists
const embedUri = `https://embed.music.apple.com${urlp.pathname}${ const embedUri = `https://embed.music.apple.com${urlp.pathname}${
urlp.search ? '?i=' + songId : '' songId ? `?i=${songId}` : ''
}` }`
if (type === 'playlist') { if (type === 'playlist') {
@@ -265,6 +268,12 @@ export function parseEmbedPlayerFromUrl(
playerUri: embedUri, playerUri: embedUri,
} }
} }
} else if (type === 'song') {
return {
type: 'apple_music_song',
source: 'appleMusic',
playerUri: embedUri,
}
} }
} }
} }