Skip to content

Commit 69bea2c

Browse files
authored
fix(smartlinks_importer): ldjson for promolinks has two variants (album and release) (#1093)
- this PR implements support for both
1 parent 738bb19 commit 69bea2c

3 files changed

Lines changed: 31 additions & 5 deletions

File tree

src/userscripts/smartlink_importer/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Test links:
4141

4242
### PromoLinks.me
4343

44-
The PromoLinks adapter supports branded subdomains. Provider destinations are read from the page’s `MusicRelease` JSON-LD metadata; provider search fallbacks and track-only URLs are ignored.
44+
The PromoLinks adapter supports branded subdomains. Provider destinations are read from the page’s `MusicRelease` or `MusicAlbum` JSON-LD metadata; provider search fallbacks and track-only URLs are ignored.
4545

4646
Test link: [slowecho.promolinks.me/from-dust](https://slowecho.promolinks.me/from-dust)
4747

src/userscripts/smartlink_importer/utils/extractors/promolinks.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,25 +38,25 @@ function providerForUrl(rawUrl: string): readonly [service: string, label: strin
3838
return undefined;
3939
}
4040

41-
function findMusicRelease(value: unknown): Record<string, unknown> | undefined {
41+
function findReleaseMetadata(value: unknown): Record<string, unknown> | undefined {
4242
const object = record(value);
4343
if (!object) return undefined;
4444

4545
const types = Array.isArray(object['@type']) ? object['@type'] : [object['@type']];
46-
if (types.includes('MusicRelease')) return object;
46+
if (types.includes('MusicRelease') || types.includes('MusicAlbum')) return object;
4747

4848
const graph = object['@graph'];
4949
if (!Array.isArray(graph)) return undefined;
5050
for (const node of graph) {
51-
const release = findMusicRelease(node);
51+
const release = findReleaseMetadata(node);
5252
if (release) return release;
5353
}
5454
return undefined;
5555
}
5656

5757
/** Read exact provider destinations from PromoLinks’ schema.org metadata. */
5858
export function extractPromoLinksServiceData(payload: unknown): PromoLinksServiceData[] {
59-
const sameAs = findMusicRelease(payload)?.['sameAs'];
59+
const sameAs = findReleaseMetadata(payload)?.['sameAs'];
6060
if (!Array.isArray(sameAs)) return [];
6161

6262
const links: PromoLinksServiceData[] = [];

tests/smartlink-importer/site-logic.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,32 @@ describe('Smartlink importer site adapters', () => {
183183
expect(extractPromoLinksServiceData({ '@type': 'Organization' })).toEqual([]);
184184
});
185185

186+
it('extracts PromoLinks providers from MusicAlbum JSON-LD', () => {
187+
expect(
188+
extractPromoLinksServiceData({
189+
'@context': 'https://schema.org',
190+
'@type': 'MusicAlbum',
191+
sameAs: [
192+
'https://open.spotify.com/album/0OcobWxBbatAcL1aazq07e',
193+
'https://firstsnowoftheyear.bandcamp.com/album/the-sun-rose-a-breeze',
194+
'https://listen.tidal.com/album/495828845',
195+
],
196+
}),
197+
).toEqual([
198+
{
199+
service: 'spotify',
200+
label: 'Spotify',
201+
sourceUrl: 'https://open.spotify.com/album/0OcobWxBbatAcL1aazq07e',
202+
},
203+
{
204+
service: 'bandcamp',
205+
label: 'Bandcamp',
206+
sourceUrl: 'https://firstsnowoftheyear.bandcamp.com/album/the-sun-rose-a-breeze',
207+
},
208+
{ service: 'tidal', label: 'Tidal', sourceUrl: 'https://listen.tidal.com/album/495828845' },
209+
]);
210+
});
211+
186212
it('extracts displayed bfan.link URLs in CTA order and skips empty search fallbacks', () => {
187213
const payload = {
188214
props: {

0 commit comments

Comments
 (0)