Bandcamp embed (#9445)
This commit is contained in:
@@ -24,6 +24,7 @@ export const embedPlayerSources = [
|
||||
'giphy',
|
||||
'tenor',
|
||||
'flickr',
|
||||
'bandcamp',
|
||||
] as const
|
||||
|
||||
export type EmbedPlayerSource = (typeof embedPlayerSources)[number]
|
||||
@@ -44,6 +45,8 @@ export type EmbedPlayerType =
|
||||
| 'giphy_gif'
|
||||
| 'tenor_gif'
|
||||
| 'flickr_album'
|
||||
| 'bandcamp_album'
|
||||
| 'bandcamp_track'
|
||||
|
||||
export const externalEmbedLabels: Record<EmbedPlayerSource, string> = {
|
||||
youtube: 'YouTube',
|
||||
@@ -56,6 +59,7 @@ export const externalEmbedLabels: Record<EmbedPlayerSource, string> = {
|
||||
appleMusic: 'Apple Music',
|
||||
soundcloud: 'SoundCloud',
|
||||
flickr: 'Flickr',
|
||||
bandcamp: 'Bandcamp',
|
||||
}
|
||||
|
||||
export interface EmbedPlayerParams {
|
||||
@@ -459,6 +463,32 @@ export function parseEmbedPlayerFromUrl(
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
const bandcampRegex = /^[a-z\d][a-z\d-]{2,}[a-z\d]\.bandcamp\.com$/i
|
||||
|
||||
if (bandcampRegex.test(urlp.hostname)) {
|
||||
const pathComponents = urlp.pathname.split('/')
|
||||
switch (pathComponents[1]) {
|
||||
case 'album':
|
||||
return {
|
||||
type: 'bandcamp_album',
|
||||
source: 'bandcamp',
|
||||
playerUri: `https://bandcamp.com/EmbeddedPlayer/url=${encodeURIComponent(
|
||||
urlp.href,
|
||||
)}/size=large/bgcol=ffffff/linkcol=0687f5/minimal=true/transparent=true/`,
|
||||
}
|
||||
case 'track':
|
||||
return {
|
||||
type: 'bandcamp_track',
|
||||
source: 'bandcamp',
|
||||
playerUri: `https://bandcamp.com/EmbeddedPlayer/url=${encodeURIComponent(
|
||||
urlp.href,
|
||||
)}/size=large/bgcol=ffffff/linkcol=0687f5/minimal=true/transparent=true/`,
|
||||
}
|
||||
default:
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function getPlayerAspect({
|
||||
@@ -498,6 +528,9 @@ export function getPlayerAspect({
|
||||
return {height: 165}
|
||||
case 'apple_music_song':
|
||||
return {height: 150}
|
||||
case 'bandcamp_album':
|
||||
case 'bandcamp_track':
|
||||
return {aspectRatio: 1}
|
||||
default:
|
||||
return {aspectRatio: 16 / 9}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user