Skip to content

Commit 86184ee

Browse files
committed
fix(demystify): pin the Kitchen Lights preview to a direct clip URL
Apple's search has no entry for the track, so it was marked `none` and fell back to the synthesised chord. A preview URL reaches it directly. Add a fourth form to the per-track preview override, alongside `none`, an iTunes track id and a replacement search term: an http(s) URL is played as-is and short-circuits resolution, so no lookup happens at all.
1 parent a3334cd commit 86184ee

4 files changed

Lines changed: 43 additions & 3 deletions

File tree

public/demystify/genre/boom-bap.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ tracks:
3737
- 4 More | De La Soul, Zhane
3838
- Stakes Is High | De La Soul
3939
- Baby Blue | Action Bronson, Chance the Rapper
40-
- KITCHEN LIGHTS | Westside Gunn, Stove God Cooks | none
40+
- KITCHEN LIGHTS | Westside Gunn, Stove God Cooks | https://audio-ssl.itunes.apple.com/itunes-assets/AudioPreview211/v4/7a/63/e9/7a63e9a3-ad46-9a88-1a90-9191d1b6d16b/mzaf_1122702822486154811.plus.aac.ep.m4a
4141
- Above The Clouds | Gang Starr, Inspectah Deck
4242
- Meet Joe Black | Nas
4343
- What It's Worth | Black Milk

public/demystify/genre/index.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ tracks:
346346
- 4 More | De La Soul, Zhane
347347
- Stakes Is High | De La Soul
348348
- Baby Blue | Action Bronson, Chance the Rapper
349-
- KITCHEN LIGHTS | Westside Gunn, Stove God Cooks | none
349+
- KITCHEN LIGHTS | Westside Gunn, Stove God Cooks | https://audio-ssl.itunes.apple.com/itunes-assets/AudioPreview211/v4/7a/63/e9/7a63e9a3-ad46-9a88-1a90-9191d1b6d16b/mzaf_1122702822486154811.plus.aac.ep.m4a
350350
- Above The Clouds | Gang Starr, Inspectah Deck
351351
- Meet Joe Black | Nas
352352
- What It's Worth | Black Milk

src/pages/demystify/demystifyPages.test.jsx

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ import DemystifyHubPage from './DemystifyHubPage';
77
import GenreCollectionPage from './GenreCollectionPage';
88
import { clearDemystifyCache } from './demystifyData';
99
import { renderSpectrum } from './spectrum';
10-
import { previewQuery, isMatch } from './trackPreview';
10+
import {
11+
previewQuery,
12+
isMatch,
13+
findPreview,
14+
clearPreviewCache,
15+
} from './trackPreview';
1116
// Aliased: the testing-library lint rule treats any `render*` call as a
1217
// component render and objects to how its result is named.
1318
import { renderInline as inline } from './RichText';
@@ -227,6 +232,31 @@ describe('previewQuery', () => {
227232
});
228233
});
229234

235+
describe('findPreview overrides', () => {
236+
afterEach(() => clearPreviewCache());
237+
238+
it('plays a pinned URL as-is, without contacting the catalogue', async () => {
239+
global.fetch = vi.fn();
240+
const url = 'https://audio-ssl.itunes.apple.com/clip.m4a';
241+
await expect(
242+
findPreview({ title: 'KITCHEN LIGHTS', artist: 'Westside Gunn', preview: url }),
243+
).resolves.toEqual({
244+
url,
245+
title: 'KITCHEN LIGHTS',
246+
artist: 'Westside Gunn',
247+
});
248+
expect(global.fetch).not.toHaveBeenCalled();
249+
});
250+
251+
it('does not search for a track marked as absent from the catalogue', async () => {
252+
global.fetch = vi.fn();
253+
await expect(
254+
findPreview({ title: 'Ghost', artist: 'Dizzee Rascal', preview: 'none' }),
255+
).resolves.toBeNull();
256+
expect(global.fetch).not.toHaveBeenCalled();
257+
});
258+
});
259+
230260
describe('isMatch', () => {
231261
// Apple's search always returns something. These are the actual wrong
232262
// results it gave for tracks it has no entry for — each must be rejected.

src/pages/demystify/trackPreview.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ const request = (url, pick) =>
8989
/**
9090
* `track.preview` overrides the lookup:
9191
* 'none' — this track is not in the catalogue; do not search
92+
* a URL — a clip to play as-is, for tracks the search cannot reach
9293
* a number — an iTunes track id, fetched directly and trusted
9394
* any text — a replacement search term
9495
*
@@ -98,6 +99,15 @@ export const findPreview = (track) => {
9899
const override = String(track?.preview || '').trim();
99100
if (override.toLowerCase() === 'none') return Promise.resolve(null);
100101

102+
// A pinned clip needs no resolution at all.
103+
if (/^https?:\/\//i.test(override)) {
104+
return Promise.resolve({
105+
url: override,
106+
title: track?.title || '',
107+
artist: track?.artist || '',
108+
});
109+
}
110+
101111
const byId = /^\d+$/.test(override);
102112
const term = override && !byId ? override : previewQuery(track);
103113
if (!byId && !term) return Promise.resolve(null);

0 commit comments

Comments
 (0)