Bandcamp album and track embedded players from shared URLs
This commit is contained in:
committed by
Samuel Newman
parent
8424083de9
commit
5ecdeafc7b
@@ -437,6 +437,13 @@ describe('parseEmbedPlayerFromUrl', () => {
|
||||
|
||||
'https://www.flickr.com/groups/898944@N23/',
|
||||
'https://www.flickr.com/groups',
|
||||
|
||||
'https://maxblansjaar.bandcamp.com/album/false-comforts',
|
||||
'https://grmnygrmny.bandcamp.com/track/fluid',
|
||||
'https://sufjanstevens.bandcamp.com/',
|
||||
'https://sufjanstevens.bandcamp.com',
|
||||
'https://bandcamp.com/',
|
||||
'https://bandcamp.com',
|
||||
]
|
||||
|
||||
const outputs = [
|
||||
@@ -815,6 +822,23 @@ describe('parseEmbedPlayerFromUrl', () => {
|
||||
|
||||
undefined,
|
||||
undefined,
|
||||
|
||||
{
|
||||
type: 'bandcamp_album',
|
||||
source: 'bandcamp',
|
||||
playerUri:
|
||||
'https://bandcamp.com/EmbeddedPlayer/url=https%3A%2F%2Fmaxblansjaar.bandcamp.com%2Falbum%2Ffalse-comforts/size=large/bgcol=ffffff/linkcol=0687f5/minimal=true/transparent=true/',
|
||||
},
|
||||
{
|
||||
type: 'bandcamp_track',
|
||||
source: 'bandcamp',
|
||||
playerUri:
|
||||
'https://bandcamp.com/EmbeddedPlayer/url=https%3A%2F%2Fgrmnygrmny.bandcamp.com%2Ftrack%2Ffluid/size=large/bgcol=ffffff/linkcol=0687f5/minimal=true/transparent=true/',
|
||||
},
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
]
|
||||
|
||||
it('correctly grabs the correct id from uri', () => {
|
||||
|
||||
@@ -25,6 +25,7 @@ export const embedPlayerSources = [
|
||||
'giphy',
|
||||
'tenor',
|
||||
'flickr',
|
||||
'bandcamp',
|
||||
] as const
|
||||
|
||||
export type EmbedPlayerSource = (typeof embedPlayerSources)[number]
|
||||
@@ -45,6 +46,8 @@ export type EmbedPlayerType =
|
||||
| 'giphy_gif'
|
||||
| 'tenor_gif'
|
||||
| 'flickr_album'
|
||||
| 'bandcamp_album'
|
||||
| 'bandcamp_track'
|
||||
|
||||
export const externalEmbedLabels: Record<EmbedPlayerSource, string> = {
|
||||
youtube: 'YouTube',
|
||||
@@ -57,6 +60,7 @@ export const externalEmbedLabels: Record<EmbedPlayerSource, string> = {
|
||||
appleMusic: 'Apple Music',
|
||||
soundcloud: 'SoundCloud',
|
||||
flickr: 'Flickr',
|
||||
bandcamp: 'Bandcamp',
|
||||
}
|
||||
|
||||
export interface EmbedPlayerParams {
|
||||
@@ -460,6 +464,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({
|
||||
@@ -499,6 +529,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