-
Notifications
You must be signed in to change notification settings - Fork 30
feat(Melon): Implement Melon provider #234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Maxr1998
wants to merge
3
commits into
kellnerd:main
Choose a base branch
from
Maxr1998:melon-provider
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| export interface MelonAlbumInfoResponse { | ||
| response?: { | ||
| ALBUMINFO: MelonAlbumInfo; | ||
| /** The type of the album, e.g. "정규", "EP", "싱글" */ | ||
| ALBUMTYPE?: string; | ||
| /** The agency/label name (기획사) */ | ||
| PLANCNPY?: string; | ||
| /** The distributor/publisher (발매사) */ | ||
| SELLCNPY?: string; | ||
| }; | ||
| /** Error notification for deleted or nonexistent albums. */ | ||
| notification?: { | ||
| message: string; | ||
| }; | ||
| } | ||
|
|
||
| export interface MelonAlbumInfo { | ||
| ALBUMID: string; | ||
| ALBUMNAME: string; | ||
| /** The album's release date, formatted as YYYY.MM.DD */ | ||
| ISSUEDATE: string; | ||
| /** 500px thumbnail CDN URL with query string */ | ||
| ALBUMIMG: string; | ||
| /** 1000px CDN URL with query string */ | ||
| ALBUMIMGLARGE: string; | ||
| ISSERVICE: boolean; | ||
| ARTISTLIST: MelonArtist[]; | ||
| } | ||
|
|
||
| export interface MelonArtist { | ||
| ARTISTID: string; | ||
| ARTISTNAME: string; | ||
| } | ||
|
|
||
| export interface MelonSongListResponse { | ||
| response?: { | ||
| CDLIST?: MelonDisc[]; | ||
| }; | ||
| /** Error notification for deleted or nonexistent albums. */ | ||
| notification?: { | ||
| message: string; | ||
| }; | ||
| } | ||
|
|
||
| export interface MelonDisc { | ||
| /** Disc number as a string, e.g. "1" */ | ||
| CDNO: string; | ||
| SONGLIST: MelonSong[]; | ||
| } | ||
|
|
||
| export interface MelonSong { | ||
| SONGID: string; | ||
| SONGNAME: string; | ||
| ARTISTLIST: MelonArtist[]; | ||
| /** Duration in seconds as a string */ | ||
| PLAYTIME: string; | ||
| /** Track number as a string */ | ||
| TRACKNO: string; | ||
| ISSERVICE: boolean; | ||
| /** Whether the song is marked as a title song, which is usually actively promoted, has an MV, and/or was previously released as a single. */ | ||
| ISTITLESONG: boolean; | ||
| ISHOLDBACK: boolean; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| import type { ReleaseOptions } from '@/harmonizer/types.ts'; | ||
| import { describeProvider, makeProviderOptions } from '@/providers/test_spec.ts'; | ||
| import { stubProviderLookups } from '@/providers/test_stubs.ts'; | ||
| import { afterAll, describe } from '@std/testing/bdd'; | ||
| import { assertSnapshot } from '@std/testing/snapshot'; | ||
| import { assertArrayIncludes, assertEquals, assertExists } from 'std/assert/mod.ts'; | ||
|
|
||
| import MelonProvider from './mod.ts'; | ||
|
|
||
| describe('Melon provider', () => { | ||
| const melon = new MelonProvider(makeProviderOptions()); | ||
| const stubs = [stubProviderLookups(melon)]; | ||
|
|
||
| const releaseOptions: ReleaseOptions = { | ||
| withISRC: false, | ||
| withAllTrackArtists: true, | ||
| }; | ||
|
|
||
| describeProvider(melon, { | ||
| urls: [{ | ||
| description: 'album page', | ||
| url: new URL('https://www.melon.com/album/detail.htm?albumId=13693526'), | ||
| id: { type: 'album', id: '13693526' }, | ||
| isCanonical: true, | ||
| }, { | ||
| description: 'album page with additional query parameters', | ||
| url: new URL('https://www.melon.com/album/detail.htm?albumId=13693526&ref=share'), | ||
| id: { type: 'album', id: '13693526' }, | ||
| }, { | ||
| description: 'mobile album page', | ||
| url: new URL('https://m2.melon.com/album/music.htm?albumId=13816948'), | ||
| id: { type: 'album', id: '13816948' }, | ||
| }, { | ||
| description: 'artist page', | ||
| url: new URL('https://www.melon.com/artist/detail.htm?artistId=1273010'), | ||
| id: { type: 'artist', id: '1273010' }, | ||
| isCanonical: true, | ||
| }, { | ||
| description: 'song page', | ||
| url: new URL('https://www.melon.com/song/detail.htm?songId=602111505'), | ||
| id: { type: 'song', id: '602111505' }, | ||
| isCanonical: true, | ||
| }, { | ||
| description: 'search page (unsupported)', | ||
| url: new URL('https://www.melon.com/search/total/index.htm?q=test'), | ||
| id: undefined, | ||
| }], | ||
| invalidIds: ['abc', 'not-a-number', '123abc'], | ||
| releaseLookup: [{ | ||
| description: 'Compilation (베스트) album with an unavailable CD-only track', | ||
| release: new URL('https://www.melon.com/album/detail.htm?albumId=12416346'), | ||
| options: releaseOptions, | ||
| assert: async (release, ctx) => { | ||
| await assertSnapshot(ctx, release); | ||
| assertEquals(release.media.length, 1, 'Should have one disc'); | ||
| assertEquals(release.media[0].tracklist.length, 23, 'Should have 23 tracks (without the CD-only track)'); | ||
| assertExists(release.types, 'Should have a release type'); | ||
| assertArrayIncludes(release.types, ['Compilation'], 'Should be classified as Compilation'); | ||
| }, | ||
| }, { | ||
| description: 'Regular (정규) album with multiple discs and multiple artists', | ||
| release: new URL('https://www.melon.com/album/detail.htm?albumId=10000727'), | ||
| options: releaseOptions, | ||
| assert: async (release, ctx) => { | ||
| await assertSnapshot(ctx, release); | ||
| assertEquals(release.media.length, 2, 'Should have two discs'); | ||
| assertEquals(release.media[0].tracklist.length, 10, 'Disc 1 should have 10 tracks'); | ||
| assertEquals(release.media[1].tracklist.length, 7, 'Disc 2 should have 7 tracks'); | ||
| assertExists(release.types, 'Should have a release type'); | ||
| assertArrayIncludes(release.types, ['Album'], 'Should be classified as Album'); | ||
| const lastTrack = release.media[1].tracklist.at(-1)!; | ||
| assertEquals( | ||
| lastTrack.artists?.map((a) => a.name), | ||
| ['웨이 (크레용팝)', '초아 (크레용팝)'], | ||
| 'Track with multiple artists should have correct artists', | ||
| ); | ||
| }, | ||
| }, { | ||
| description: 'EP (미니) album', | ||
| release: new URL('https://www.melon.com/album/detail.htm?albumId=13693526'), | ||
| options: releaseOptions, | ||
| assert: async (release, ctx) => { | ||
| await assertSnapshot(ctx, release); | ||
| assertEquals(release.media.length, 1, 'Should have one disc'); | ||
| assertEquals(release.media[0].tracklist.length, 7, 'Should have 7 tracks'); | ||
| assertExists(release.types, 'Should have a release type'); | ||
| assertArrayIncludes(release.types, ['EP'], 'Should be classified as EP'); | ||
| }, | ||
| }, { | ||
| description: 'Single (싱글) album', | ||
| release: new URL('https://www.melon.com/album/detail.htm?albumId=13732020'), | ||
| options: releaseOptions, | ||
| assert: async (release, ctx) => { | ||
| await assertSnapshot(ctx, release); | ||
| assertEquals(release.media.length, 1, 'Should have one disc'); | ||
| assertEquals(release.media[0].tracklist.length, 1, 'Should have 1 track'); | ||
| assertExists(release.types, 'Should have a release type'); | ||
| assertArrayIncludes(release.types, ['Single'], 'Should be classified as Single'); | ||
| }, | ||
| }, { | ||
| description: 'EP with two labels', | ||
| release: new URL('https://www.melon.com/album/detail.htm?albumId=10830226'), | ||
| options: releaseOptions, | ||
| assert: async (release, ctx) => { | ||
| await assertSnapshot(ctx, release); | ||
| assertEquals(release.media.length, 1, 'Should have one disc'); | ||
| assertEquals(release.media[0].tracklist.length, 6, 'Should have 6 tracks'); | ||
| assertExists(release.types, 'Should have a release type'); | ||
| assertArrayIncludes(release.types, ['EP'], 'Should be classified as EP'); | ||
| assertExists(release.labels, 'Should have labels'); | ||
| const labels = release.labels.map((l) => l.name); | ||
| assertEquals(labels, ['WAKEONE', '스윙엔터테인먼트'], 'Should have correct labels'); | ||
| }, | ||
| }], | ||
| }); | ||
|
|
||
| afterAll(() => { | ||
| stubs.forEach((s) => s.restore()); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.