Skip to content

Commit 89ee095

Browse files
committed
chore(Bugs): Address review feedback
1 parent d7432c5 commit 89ee095

9 files changed

Lines changed: 22 additions & 31 deletions

File tree

.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,5 @@ HARMONY_SPOTIFY_CLIENT_SECRET=
2323
# Tidal app config. See https://developer.tidal.com/reference/web-api
2424
HARMONY_TIDAL_CLIENT_ID=
2525
HARMONY_TIDAL_CLIENT_SECRET=
26+
# Bugs! app config.
27+
HARMONY_BUGS_CLIENT_SECRET=

providers/Bugs/__snapshots__/mod.test.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1240,7 +1240,7 @@ snapshot[`Bugs! provider > release lookup > Single (싱글) album 1`] = `
12401240
}
12411241
`;
12421242

1243-
snapshot[`Bugs! provider > release lookup > Compilation/Best of (베스트) album 1`] = `
1243+
snapshot[`Bugs! provider > release lookup > Compilation/Best of (베스트) album with an unavailable, CD-only bonus track 1`] = `
12441244
{
12451245
artists: [
12461246
{

providers/Bugs/mod.test.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ describe('Bugs! provider', () => {
4242
options: releaseOptions,
4343
assert: async (release, ctx) => {
4444
await assertSnapshot(ctx, release);
45-
assert(release.media.length === 1, 'Should have one disc');
46-
assert(release.media[0].tracklist.length === 10, 'Should have 10 tracks');
45+
assertEquals(release.media.length, 1, 'Should have one disc');
46+
assertEquals(release.media[0].tracklist.length, 10, 'Should have 10 tracks');
4747
assert(release.types?.includes('Album'), 'Should be classified as Album');
4848
},
4949
}, {
@@ -52,9 +52,9 @@ describe('Bugs! provider', () => {
5252
options: releaseOptions,
5353
assert: async (release, ctx) => {
5454
await assertSnapshot(ctx, release);
55-
assert(release.media.length === 2, 'Should have two discs');
56-
assert(release.media[0].tracklist.length === 10, 'Disc 1 should have 10 tracks');
57-
assert(release.media[1].tracklist.length === 7, 'Disc 2 should have 7 tracks');
55+
assertEquals(release.media.length, 2, 'Should have two discs');
56+
assertEquals(release.media[0].tracklist.length, 10, 'Disc 1 should have 10 tracks');
57+
assertEquals(release.media[1].tracklist.length, 7, 'Disc 2 should have 7 tracks');
5858
assert(release.types?.includes('Album'), 'Should be classified as Album');
5959
const lastTrack = release.media[1].tracklist.at(-1)!;
6060
assertEquals(
@@ -69,8 +69,8 @@ describe('Bugs! provider', () => {
6969
options: releaseOptions,
7070
assert: async (release, ctx) => {
7171
await assertSnapshot(ctx, release);
72-
assert(release.media.length === 1, 'Should have one disc');
73-
assert(release.media[0].tracklist.length === 5, 'Should have 5 tracks');
72+
assertEquals(release.media.length, 1, 'Should have one disc');
73+
assertEquals(release.media[0].tracklist.length, 5, 'Should have 5 tracks');
7474
assert(release.types?.includes('EP'), 'Should be classified as EP');
7575
},
7676
}, {
@@ -79,8 +79,8 @@ describe('Bugs! provider', () => {
7979
options: releaseOptions,
8080
assert: async (release, ctx) => {
8181
await assertSnapshot(ctx, release);
82-
assert(release.media.length === 1, 'Should have one disc');
83-
assert(release.media[0].tracklist.length === 1, 'Should have 1 track');
82+
assertEquals(release.media.length, 1, 'Should have one disc');
83+
assertEquals(release.media[0].tracklist.length, 1, 'Should have 1 track');
8484
assert(release.types?.includes('Single'), 'Should be classified as Single');
8585
},
8686
}, {
@@ -89,8 +89,8 @@ describe('Bugs! provider', () => {
8989
options: releaseOptions,
9090
assert: async (release, ctx) => {
9191
await assertSnapshot(ctx, release);
92-
assert(release.media.length === 1, 'Should have one disc');
93-
assert(release.media[0].tracklist.length === 23, 'Should have 23 tracks (without the CD-only track)');
92+
assertEquals(release.media.length, 1, 'Should have one disc');
93+
assertEquals(release.media[0].tracklist.length, 23, 'Should have 23 tracks (without the CD-only track)');
9494
assert(release.types?.includes('Compilation'), 'Should be classified as Compilation');
9595
},
9696
}],

providers/Bugs/mod.ts

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { DurationPrecision, FeatureQuality, type FeatureQualityMap } from '@/pro
99
import type { PartialDate } from '@/utils/date.ts';
1010
import { parseDuration } from '@/utils/time.ts';
1111
import { ProviderError } from '@/utils/errors.ts';
12-
import { getFromEnv } from '@/utils/config.ts';
1312
import type {
1413
ArtistCreditName,
1514
Artwork,
@@ -22,10 +21,11 @@ import type {
2221
ReleaseGroupType,
2322
} from '@/harmonizer/types.ts';
2423
import type { BugsAlbum, BugsArtist, BugsMultiResponse, BugsTrack } from './api_types.ts';
24+
import { getFromEnv } from '../../utils/config.ts';
2525

2626
const IMAGE_BASE = 'https://image.bugsm.co.kr/album/images';
2727

28-
const bugsDeviceId = getFromEnv('HARMONY_BUGS_DEVICE_ID') ?? 'harmony';
28+
const bugsMobileClientSecret = getFromEnv('HARMONY_BUGS_CLIENT_SECRET') || '';
2929

3030
export default class BugsProvider extends MetadataApiProvider {
3131
readonly name = 'Bugs!';
@@ -60,10 +60,6 @@ export default class BugsProvider extends MetadataApiProvider {
6060

6161
readonly apiBaseUrl = 'https://mapi.bugs.co.kr/music/5/multi/invoke/map';
6262

63-
override get internalName(): string {
64-
return 'bugs';
65-
}
66-
6763
constructUrl(entity: EntityId): URL {
6864
return new URL([entity.type, entity.id].join('/'), 'https://music.bugs.co.kr/');
6965
}
@@ -78,7 +74,6 @@ export default class BugsProvider extends MetadataApiProvider {
7874
{ id: 'album', args: { album_id: albumId, result_type: 'DETAIL' } },
7975
{ id: 'album_track', args: { album_id: albumId, result_type: 'LIST' } },
8076
]);
81-
if (bugsDeviceId) apiUrl.searchParams.set('device_id', bugsDeviceId);
8277
const accessToken = await this.cachedAccessToken(this.requestAccessToken);
8378
return this.fetchJSON<Data>(apiUrl, {
8479
policy: { maxTimestamp: options.snapshotMaxTimestamp },
@@ -87,10 +82,6 @@ export default class BugsProvider extends MetadataApiProvider {
8782
headers: {
8883
'Content-Type': 'application/json; charset=UTF-8',
8984
'Authorization': `Bearer ${accessToken}`,
90-
'User-Agent': 'Mobile|Bugs|5.07.00|Android|16|SM-F936B|samsung|market|105070000',
91-
'X-BUGS-MS': '58239824',
92-
'Invoke-page': 'ALBUM_INFO',
93-
'Invoke-ids': 'album|album_track|',
9485
},
9586
body,
9687
},
@@ -100,9 +91,8 @@ export default class BugsProvider extends MetadataApiProvider {
10091
private async requestAccessToken(): Promise<ApiAccessToken> {
10192
const url = new URL('https://secure.bugs.co.kr/api/5/appToken');
10293
url.searchParams.set('client_id', 'bugsapp_credentials_android');
103-
url.searchParams.set('client_secret', 'd33b!z7xeu');
94+
url.searchParams.set('client_secret', bugsMobileClientSecret);
10495
url.searchParams.set('grant_type', 'client_credentials');
105-
url.searchParams.set('device_id', bugsDeviceId);
10696
const { result } = await (await fetch(url, { method: 'POST' })).json();
10797
return {
10898
accessToken: result.access_token,
@@ -231,12 +221,11 @@ function parseYYYYMMDD(date: string): PartialDate {
231221

232222
function mapReleaseType(albumType?: string): ReleaseGroupType[] | undefined {
233223
if (!albumType) return undefined;
234-
if (albumType.includes('EP') || albumType.includes('미니')) return ['EP'];
235-
if (albumType.includes('정규')) return ['Album'];
236-
if (albumType.includes('싱글')) return ['Single'];
237-
if (albumType.includes('베스트') || albumType.includes('컴필')) return ['Compilation'];
224+
if (albumType === '싱글') return ['Single'];
225+
if (albumType === '정규') return ['Album'];
226+
if (albumType === 'EP(미니)') return ['EP'];
227+
if (albumType === '베스트' || albumType === '컴필레이션') return ['Compilation'];
238228
if (albumType === 'OST') return ['Soundtrack'];
239-
if (albumType.includes('라이브')) return ['Live'];
240-
if (albumType.includes('리믹스')) return ['Remix'];
229+
if (albumType === '라이브') return ['Live'];
241230
return undefined;
242231
}

testdata/https!/kr.co.bugs.mapi/music/5/multi/invoke/map!album_id=4078166&device_id=harmony renamed to testdata/https!/kr.co.bugs.mapi/music/5/multi/invoke/map!album_id=4078166

File renamed without changes.

testdata/https!/kr.co.bugs.mapi/music/5/multi/invoke/map!album_id=4111423&device_id=harmony renamed to testdata/https!/kr.co.bugs.mapi/music/5/multi/invoke/map!album_id=4111423

File renamed without changes.

testdata/https!/kr.co.bugs.mapi/music/5/multi/invoke/map!album_id=4119156&device_id=harmony renamed to testdata/https!/kr.co.bugs.mapi/music/5/multi/invoke/map!album_id=4119156

File renamed without changes.

testdata/https!/kr.co.bugs.mapi/music/5/multi/invoke/map!album_id=4134802&device_id=harmony renamed to testdata/https!/kr.co.bugs.mapi/music/5/multi/invoke/map!album_id=4134802

File renamed without changes.

testdata/https!/kr.co.bugs.mapi/music/5/multi/invoke/map!album_id=590752&device_id=harmony renamed to testdata/https!/kr.co.bugs.mapi/music/5/multi/invoke/map!album_id=590752

File renamed without changes.

0 commit comments

Comments
 (0)