Skip to content

Commit afb2e76

Browse files
committed
feat: Improve track credits parsing to recognize post-feat suffixes
* Refactor credit parsing into two stages: joiner separation and credits parsing * Break credit parsing into wrapped vs. non-wrapped for simpler regexes * Implement suffix matching after credits * Add tests for wrapped vs. non-wrapped credits and with suffixes
1 parent 4781254 commit afb2e76

File tree

6 files changed

+302
-18
lines changed

6 files changed

+302
-18
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"typedoc": "typedoc",
1313
"circular": "madge --circular --extensions ts src/index.ts",
1414
"test": "react-scripts test",
15-
"test:backend": "mocha --extension ts --reporter spec --recursive src/backend/tests/scrobbler/**/*.test.ts",
15+
"test:backend": "mocha --extension ts --reporter spec --recursive src/backend/tests/**/*.test.ts",
1616
"eject": "react-scripts eject",
1717
"dev": "concurrently -p name -c \"yellow,magenta,blue\" -n \"webpack-server,nodemon-server,CRA\" \"npm run dev:server:webpack\" \"npm run dev:server:nodemon\" \"npm run dev:client\"",
1818
"dev:client": "BROWSER=none REACT_APP_VERSION=$npm_package_version react-scripts start",

src/backend/tests/listenbrainz/listenbrainz.test.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,8 @@ import dayjs from "dayjs";
1919
import {withRequestInterception} from "../utils/networking";
2020
import {http, HttpResponse} from "msw";
2121
import {UpstreamError} from "../../common/errors/UpstreamError";
22+
import {ExpectedResults} from "../utils/interfaces";
2223

23-
interface ExpectedResults {
24-
artists: string[]
25-
track: string
26-
}
2724
interface LZTestFixture {
2825
data: ListenResponse
2926
expected: ExpectedResults

src/backend/tests/utils/interfaces.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export interface ExpectedResults {
2+
artists: string[]
3+
track: string
4+
album?: String
5+
}
Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
[
2+
{
3+
"caseHints": [
4+
"track",
5+
"joiner"
6+
],
7+
"data": {
8+
"artists": [
9+
"Eugene Naumenko"
10+
],
11+
"track": "Take-Off feat. Diag",
12+
"album": "1000 Years"
13+
},
14+
"expected": {
15+
"artists": [
16+
"Eugene Naumenko",
17+
"Diag"
18+
],
19+
"track": "Take-Off",
20+
"album": "1000 Years"
21+
}
22+
},
23+
{
24+
"caseHints": [
25+
"track",
26+
"remix"
27+
],
28+
"data": {
29+
"artists": [
30+
"Djfredse"
31+
],
32+
"track": "Anny Sky - Together With You (Djfredse Remix)"
33+
},
34+
"expected": {
35+
"artists": [
36+
"Djfredse",
37+
"Anny Sky"
38+
],
39+
"track": "Together With You (Djfredse Remix)"
40+
}
41+
},
42+
{
43+
"caseHints": [
44+
"track",
45+
"remix",
46+
"joiner"
47+
],
48+
"data": {
49+
"artists": [
50+
"Chriss"
51+
],
52+
"track": "Criminal mind Ft Akon (Remix Braquer vos têtes)",
53+
"album": "Music Is Life"
54+
},
55+
"expected": {
56+
"artists": [
57+
"Chriss",
58+
"Akon"
59+
],
60+
"track": "Criminal mind (Remix Braquer vos têtes)",
61+
"album": "Music Is Life"
62+
}
63+
},
64+
{
65+
"caseHints": [
66+
"track",
67+
"joiner"
68+
],
69+
"data": {
70+
"artists": [
71+
"Luis Zunel"
72+
],
73+
"track": "Reset my Blues (Featuring Peergynt Lobogris)"
74+
},
75+
"expected": {
76+
"artists": [
77+
"Luis Zunel",
78+
"Peergynt Lobogris"
79+
],
80+
"track": "Reset my Blues"
81+
}
82+
},
83+
{
84+
"caseHints": [
85+
"track",
86+
"joiner"
87+
],
88+
"data": {
89+
"artists": [
90+
"Woochia"
91+
],
92+
"track": "La Flaque (feat.Ecstatik)"
93+
},
94+
"expected": {
95+
"artists": [
96+
"Woochia",
97+
"Ecstatik"
98+
],
99+
"track": "La Flaque"
100+
}
101+
},
102+
{
103+
"caseHints": [
104+
"track",
105+
"joiner",
106+
"remix"
107+
],
108+
"data": {
109+
"artists": [
110+
"Alicia Keys",
111+
"Kaash Paige",
112+
"Diamond Platnumz"
113+
],
114+
"track": "Wasted Energy (feat. Kaash Paige & Diamond Platnumz) - Remix"
115+
},
116+
"expected": {
117+
"artists": [
118+
"Alicia Keys",
119+
"Kaash Paige",
120+
"Diamond Platnumz"
121+
],
122+
"track": "Wasted Energy - Remix"
123+
}
124+
},
125+
{
126+
"caseHints": [
127+
"track",
128+
"joiner"
129+
],
130+
"data": {
131+
"artists": [
132+
"Tyler, the Creator"
133+
],
134+
"track": "WUSYANAME (feat. Youngboy Never Broke Again & Ty Dolla $ign)"
135+
},
136+
"expected": {
137+
"artists": [
138+
"Tyler, the Creator",
139+
"Youngboy Never Broke Again",
140+
"Ty Dolla $ign"
141+
],
142+
"track": "WUSYANAME"
143+
}
144+
},
145+
{
146+
"caseHints": [
147+
"track",
148+
"joiner"
149+
],
150+
"data": {
151+
"artists": [
152+
"Tyler, the Creator"
153+
],
154+
"track": "Trashwang (feat. Na' kel, Jasper Dolphin, Lucas & L-Boy)"
155+
},
156+
"expected": {
157+
"artists": [
158+
"Tyler, the Creator",
159+
"Na' kel",
160+
"Jasper Dolphin",
161+
"L-Boy",
162+
"Lucas"
163+
],
164+
"track": "Trashwang"
165+
}
166+
},
167+
{
168+
"caseHints": [
169+
"track",
170+
"joiner"
171+
],
172+
"data": {
173+
"artists": [
174+
"Childish Gambino"
175+
],
176+
"track": "12.38 (feat. 21 Savage, Ink & Kadhja Bonet)"
177+
},
178+
"expected": {
179+
"artists": [
180+
"Childish Gambino",
181+
"21 Savage",
182+
"Ink",
183+
"Kadhja Bonet"
184+
],
185+
"track": "12.38"
186+
}
187+
}
188+
]

src/backend/tests/strings.test.ts renamed to src/backend/tests/utils/strings.test.ts

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
import {describe, it} from 'mocha';
22
import {assert} from 'chai';
3-
import {compareNormalizedStrings} from "../utils/StringUtils";
4-
3+
import {compareNormalizedStrings, parseTrackCredits, uniqueNormalizedStrArr} from "../../utils/StringUtils";
4+
import testData from './playTestData.json';
5+
import {ExpectedResults} from "./interfaces";
6+
import {intersect} from "../../utils";
7+
8+
interface PlayTestFixture {
9+
caseHints: string[]
10+
data: {
11+
track: string
12+
artists: string[]
13+
album?: string
14+
}
15+
expected: ExpectedResults
16+
}
517

618
describe('String Comparisons', function () {
719

@@ -95,3 +107,21 @@ describe('String Comparisons', function () {
95107
assert.equal( result1.highScore, result2.highScore, `Comparing: '${longerString}' | '${shorterString}'`);
96108
});
97109
});
110+
111+
describe('Play Strings',function () {
112+
113+
const testFixtures = testData as unknown as PlayTestFixture[];
114+
const joinerData = testFixtures.filter(x => intersect(['joiner','track'], x.caseHints).length === 2);
115+
116+
it('should parse joiners from track title', function() {
117+
for(const test of joinerData) {
118+
const res = parseTrackCredits(test.data.track);
119+
let artists: string[] = [...test.data.artists];
120+
if(res.secondary !== undefined) {
121+
artists = uniqueNormalizedStrArr([...artists, ...res.secondary]);
122+
}
123+
assert.equal(res.primaryComposite, test.expected.track);
124+
assert.sameDeepMembers(artists, test.expected.artists);
125+
}
126+
});
127+
});

0 commit comments

Comments
 (0)