mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-04 14:57:10 +00:00
Merge pull request #34147 from DadUndead/musicmatch
[musicmatch] added basic definitions and tests
This commit is contained in:
Vendored
+202
@@ -0,0 +1,202 @@
|
||||
// Type definitions for musicmatch 0.3
|
||||
// Project: https://github.com/c0b41/musixmatch, https://www.npmjs.com/package/musicmatch
|
||||
// Definitions by: Aleksei Klimenko <https://github.com/DadUndead>
|
||||
// Definitions: https://github.com/DefinitelyTyped/
|
||||
|
||||
export type TFormat = 'json' | 'xml';
|
||||
export type TSort = 'asc' | 'desc';
|
||||
export type TBoolean = 0 | 1;
|
||||
|
||||
export interface Pageable {
|
||||
page?: number;
|
||||
page_size?: number;
|
||||
}
|
||||
|
||||
export interface AlbumParams {
|
||||
album_id: number;
|
||||
}
|
||||
|
||||
export interface AlbumTracksParams {
|
||||
album_id?: number;
|
||||
album_mbid?: number;
|
||||
format?: TFormat;
|
||||
}
|
||||
|
||||
export interface ArtistParams {
|
||||
artist_id?: number;
|
||||
artist_mbid?: number;
|
||||
}
|
||||
|
||||
export interface ArtistRelatedParams extends ArtistParams, Pageable {
|
||||
}
|
||||
|
||||
export interface ArtistAlbumsParams extends ArtistParams, Pageable {
|
||||
g_album_name?: TBoolean;
|
||||
s_release_date?: TSort;
|
||||
}
|
||||
|
||||
export interface ArtistSearchParams extends Pageable {
|
||||
q_artist?: string;
|
||||
f_artist_id?: number;
|
||||
f_artist_mbid?: number;
|
||||
}
|
||||
|
||||
export interface MatcherLyricsParams {
|
||||
q_track?: string;
|
||||
q_artist?: string;
|
||||
}
|
||||
|
||||
export interface MatcherSubtitleParams extends MatcherLyricsParams {
|
||||
f_subtitle_length?: number;
|
||||
f_subtitle_length_max_deviation?: number;
|
||||
}
|
||||
|
||||
export interface MatcherTrackParams extends MatcherLyricsParams {
|
||||
f_has_lyrics?: TBoolean;
|
||||
f_has_subtitle?: TBoolean;
|
||||
}
|
||||
|
||||
export interface TrackLyricsFeedbackParams {
|
||||
lyrics_id?: number;
|
||||
track_id?: number;
|
||||
feedback?: 'wrong_lyrics' | 'wrong_attribution' | 'bad_characters' | 'lines_too_long' | 'wrong_verses' | 'wrong_formatting';
|
||||
}
|
||||
|
||||
export interface TrackLyricsAddParams {
|
||||
lyrics_id?: number;
|
||||
lyrics_body?: string;
|
||||
}
|
||||
|
||||
export interface TrackSnippetParams {
|
||||
track_id: number;
|
||||
}
|
||||
|
||||
export interface TrackLyricsParams {
|
||||
track_id?: number;
|
||||
track_mbid?: number;
|
||||
}
|
||||
|
||||
export interface TrackSubtitleParams {
|
||||
track_id?: number;
|
||||
track_mbid?: number;
|
||||
subtitle_format?: 'lrc' | 'dfxp' | 'stledu';
|
||||
f_subtitle_length?: number;
|
||||
f_subtitle_length_max_deviation?: number;
|
||||
}
|
||||
|
||||
export interface TrackParams {
|
||||
track_id?: number;
|
||||
track_mbid?: number;
|
||||
}
|
||||
|
||||
export interface TrackSearchParams extends Pageable {
|
||||
q?: string;
|
||||
q_lyrics?: string;
|
||||
f_has_lyrics?: TBoolean;
|
||||
f_artist_id?: number;
|
||||
f_music_genre_id?: number;
|
||||
f_artist_mbid?: number;
|
||||
f_lyrics_language?: string;
|
||||
s_track_rating?: TSort;
|
||||
s_artist_rating?: TSort;
|
||||
quorum_factor?: number;
|
||||
}
|
||||
|
||||
export interface TrackSearchResult {
|
||||
message: {
|
||||
body: {
|
||||
track_list: TrackResult[];
|
||||
},
|
||||
header: {
|
||||
available: number;
|
||||
execute_time: number;
|
||||
status_code: number;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export interface MusicGenre {
|
||||
music_genre_id: number;
|
||||
music_genre_parent_id: number;
|
||||
music_genre_name: string;
|
||||
music_genre_name_extended: string;
|
||||
music_genre_vanity: string;
|
||||
}
|
||||
|
||||
export interface PrimaryGenres {
|
||||
music_genre_list: Array<{ music_genre: MusicGenre }>;
|
||||
}
|
||||
|
||||
export interface TrackResult {
|
||||
track: {
|
||||
track_id: number;
|
||||
track_name: string;
|
||||
track_name_translation_list: any[];
|
||||
track_rating: number;
|
||||
commontrack_id: number;
|
||||
instrumental: TBoolean;
|
||||
explicit: TBoolean;
|
||||
has_lyrics: TBoolean;
|
||||
has_subtitles: TBoolean;
|
||||
has_richsync: TBoolean;
|
||||
num_favourite: number;
|
||||
album_id: number;
|
||||
album_name: string;
|
||||
artist_id: number;
|
||||
artist_name: string;
|
||||
track_share_url: string;
|
||||
track_edit_url: string;
|
||||
restricted: TBoolean;
|
||||
updated_time: string;
|
||||
primary_genres: PrimaryGenres;
|
||||
};
|
||||
}
|
||||
|
||||
export interface ChartTracksParams extends Pageable {
|
||||
country?: string;
|
||||
f_has_lyrics?: TBoolean;
|
||||
}
|
||||
|
||||
export interface ChartArtistsParams extends Pageable {
|
||||
country?: string;
|
||||
}
|
||||
|
||||
export default class Musicmatch {
|
||||
constructor(obj?: { apikey?: string, format?: string });
|
||||
|
||||
album(params: AlbumParams): Promise<any>;
|
||||
|
||||
albumTracks(params: AlbumTracksParams): Promise<any>;
|
||||
|
||||
artist(params: ArtistParams): Promise<any>;
|
||||
|
||||
artistAlbums(params: ArtistAlbumsParams): Promise<any>;
|
||||
|
||||
artistRelated(params: ArtistRelatedParams): Promise<any>;
|
||||
|
||||
artistSearch(params: ArtistSearchParams): Promise<any>;
|
||||
|
||||
chartArtists(params: ChartArtistsParams): Promise<any>;
|
||||
|
||||
chartTracks(params: ChartTracksParams): Promise<any>;
|
||||
|
||||
matcherLyrics(params: MatcherLyricsParams): Promise<any>;
|
||||
|
||||
matcherSubtitle(params: MatcherSubtitleParams): Promise<any>;
|
||||
|
||||
matcherTrack(params: MatcherTrackParams): Promise<any>;
|
||||
|
||||
track(params: TrackParams): Promise<any>;
|
||||
|
||||
trackLyrics(params: TrackLyricsParams): Promise<any>;
|
||||
|
||||
trackLyricsAdd(params: TrackLyricsAddParams): Promise<any>;
|
||||
|
||||
trackLyricsFeedback(params: TrackLyricsFeedbackParams): Promise<any>;
|
||||
|
||||
trackSearch(params: TrackSearchParams): Promise<TrackSearchResult>;
|
||||
|
||||
trackSnippet(params: TrackSnippetParams): Promise<any>;
|
||||
|
||||
trackSubtitle(params: TrackSubtitleParams): Promise<any>;
|
||||
}
|
||||
@@ -0,0 +1,212 @@
|
||||
// Project: https://github.com/c0b41/musixmatch, https://www.npmjs.com/package/musicmatch
|
||||
// Definitions by: Aleksei Klimenko <https://github.com/DadUndead>
|
||||
// Definitions: https://github.com/DefinitelyTyped/
|
||||
|
||||
import Musicmatch, {
|
||||
AlbumParams,
|
||||
AlbumTracksParams,
|
||||
ArtistAlbumsParams,
|
||||
ArtistParams,
|
||||
ArtistRelatedParams,
|
||||
ArtistSearchParams,
|
||||
ChartArtistsParams,
|
||||
MatcherLyricsParams,
|
||||
MatcherSubtitleParams,
|
||||
MatcherTrackParams,
|
||||
TrackLyricsAddParams,
|
||||
TrackLyricsFeedbackParams,
|
||||
TrackLyricsParams,
|
||||
TrackParams,
|
||||
TrackSearchParams,
|
||||
TrackSearchResult,
|
||||
TrackSnippetParams,
|
||||
TrackSubtitleParams
|
||||
} from 'musicmatch';
|
||||
|
||||
const musicmatch = new Musicmatch({ apikey: 'api_key', format: '' });
|
||||
|
||||
const COUNTRY = 'USA';
|
||||
const Q_ARTIST = 'artist name';
|
||||
const Q_TRACK = 'track title';
|
||||
|
||||
const trackSearchParams: TrackSearchParams = {
|
||||
f_music_genre_id: 18,
|
||||
page_size: 100,
|
||||
page: 1,
|
||||
s_track_rating: 'desc',
|
||||
f_lyrics_language: 'en',
|
||||
};
|
||||
|
||||
const albumParams: AlbumParams = {
|
||||
album_id: 1,
|
||||
};
|
||||
|
||||
const albumTrackParams: AlbumTracksParams = {
|
||||
album_id: 1,
|
||||
album_mbid: 1,
|
||||
format: 'json',
|
||||
};
|
||||
|
||||
const artisParams: ArtistParams = {
|
||||
artist_id: 1,
|
||||
artist_mbid: 1,
|
||||
};
|
||||
|
||||
const artistAlbumsParams: ArtistAlbumsParams = {
|
||||
artist_mbid: 1,
|
||||
artist_id: 1,
|
||||
g_album_name: 1,
|
||||
page: 1,
|
||||
page_size: 10,
|
||||
s_release_date: 'desc',
|
||||
};
|
||||
|
||||
const artistRelatedParams: ArtistRelatedParams = {
|
||||
page_size: 10,
|
||||
page: 1,
|
||||
artist_id: 1,
|
||||
artist_mbid: 1,
|
||||
};
|
||||
|
||||
const artistSearchParams: ArtistSearchParams = {
|
||||
page: 1,
|
||||
page_size: 10,
|
||||
f_artist_id: 1,
|
||||
f_artist_mbid: 1,
|
||||
q_artist: Q_ARTIST
|
||||
};
|
||||
|
||||
const chartArtistsParams: ChartArtistsParams = {
|
||||
page: 1,
|
||||
page_size: 10,
|
||||
country: COUNTRY
|
||||
};
|
||||
|
||||
const chartTracksParams: ChartArtistsParams = {
|
||||
page: 1,
|
||||
page_size: 10,
|
||||
country: COUNTRY,
|
||||
};
|
||||
|
||||
const matcherLyricsParams: MatcherLyricsParams = {
|
||||
q_artist: Q_ARTIST,
|
||||
q_track: Q_TRACK,
|
||||
};
|
||||
|
||||
const matcherSubtitleParams: MatcherSubtitleParams = {
|
||||
q_artist: Q_ARTIST,
|
||||
q_track: Q_TRACK,
|
||||
f_subtitle_length: 100,
|
||||
f_subtitle_length_max_deviation: 10,
|
||||
};
|
||||
|
||||
const matcherTrackParams: MatcherTrackParams = {
|
||||
q_artist: Q_ARTIST,
|
||||
q_track: Q_TRACK,
|
||||
f_has_lyrics: 1,
|
||||
f_has_subtitle: 1,
|
||||
};
|
||||
|
||||
const trackParams: TrackParams = {
|
||||
track_id: 1,
|
||||
track_mbid: 1,
|
||||
};
|
||||
|
||||
const trackLyricsParams: TrackLyricsParams = {
|
||||
track_id: 1,
|
||||
track_mbid: 1,
|
||||
};
|
||||
|
||||
const trackLyricsAddParams: TrackLyricsAddParams = {
|
||||
lyrics_body: 'Lyrics',
|
||||
lyrics_id: 1,
|
||||
};
|
||||
|
||||
const trackLyricsFeedbackParams: TrackLyricsFeedbackParams = {
|
||||
feedback: 'bad_characters',
|
||||
lyrics_id: 1,
|
||||
track_id: 1,
|
||||
};
|
||||
|
||||
const trackSnippetParams: TrackSnippetParams = {
|
||||
track_id: 1,
|
||||
};
|
||||
|
||||
const trackSubtitleParams: TrackSubtitleParams = {
|
||||
f_subtitle_length: 100,
|
||||
f_subtitle_length_max_deviation: 10,
|
||||
subtitle_format: 'dfxp',
|
||||
track_id: 1,
|
||||
track_mbid: 1,
|
||||
};
|
||||
|
||||
/**
|
||||
* Example of track search result
|
||||
*/
|
||||
const trackSearchResult: TrackSearchResult = {
|
||||
message: {
|
||||
header: { status_code: 200, execute_time: 0.27148103713989, available: 10000 }, body: {
|
||||
track_list: [{
|
||||
track: {
|
||||
track_id: 164289228,
|
||||
track_name: '7 rings',
|
||||
track_name_translation_list: [],
|
||||
track_rating: 100,
|
||||
commontrack_id: 91473047,
|
||||
instrumental: 0,
|
||||
explicit: 1,
|
||||
has_lyrics: 1,
|
||||
has_subtitles: 1,
|
||||
has_richsync: 1,
|
||||
num_favourite: 2130,
|
||||
album_id: 31234760,
|
||||
album_name: 'thank u, next',
|
||||
artist_id: 13958599,
|
||||
artist_name: 'Ariana Grande',
|
||||
track_share_url: 'https:\/\/www.musixmatch.com\/lyrics\/Ariana-Grande\/7-rings?utm_source=application&utm_campaign=api&utm_medium=FruitSarcop%3A1409618278546',
|
||||
track_edit_url: 'https:\/\/www.musixmatch.com\/lyrics\/Ariana-Grande\/7-rings\/edit?utm_source=application&utm_campaign=api&utm_medium=FruitSarcop%3A1409618278546',
|
||||
restricted: 0,
|
||||
updated_time: '2019-03-22T15:28:01Z',
|
||||
primary_genres: {
|
||||
music_genre_list: [{
|
||||
music_genre: {
|
||||
music_genre_id: 14,
|
||||
music_genre_parent_id: 34,
|
||||
music_genre_name: 'Pop',
|
||||
music_genre_name_extended: 'Pop',
|
||||
music_genre_vanity: 'Pop'
|
||||
}
|
||||
}]
|
||||
}
|
||||
}
|
||||
}]
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Promise
|
||||
.all([
|
||||
musicmatch.album(albumParams), // 0
|
||||
musicmatch.albumTracks(albumTrackParams), // 1
|
||||
musicmatch.artist(artisParams), // 2
|
||||
musicmatch.artistAlbums(artistAlbumsParams), // 3
|
||||
musicmatch.artistRelated(artistRelatedParams), // 4
|
||||
musicmatch.artistSearch(artistSearchParams), // 5
|
||||
musicmatch.chartArtists(chartArtistsParams), // 6
|
||||
musicmatch.chartTracks(chartTracksParams), // 7
|
||||
musicmatch.matcherLyrics(matcherLyricsParams), // 8
|
||||
musicmatch.matcherSubtitle(matcherSubtitleParams), // 9
|
||||
musicmatch.matcherTrack(matcherTrackParams), // 10
|
||||
musicmatch.track(trackParams), // 11
|
||||
musicmatch.trackLyrics(trackLyricsParams), // 12
|
||||
musicmatch.trackLyricsAdd(trackLyricsAddParams), // 13
|
||||
musicmatch.trackLyricsFeedback(trackLyricsFeedbackParams), // 14
|
||||
musicmatch.trackSearch(trackSearchParams), // 15
|
||||
musicmatch.trackSnippet(trackSnippetParams), // 16
|
||||
musicmatch.trackSubtitle(trackSubtitleParams), // 17
|
||||
])
|
||||
.then((results) => {
|
||||
const trackSearchResult: TrackSearchResult = results[15];
|
||||
|
||||
console.log('No. of tracks found by search:', trackSearchResult.message.body.track_list.length);
|
||||
});
|
||||
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6",
|
||||
"dom"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"musicmatch-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json"
|
||||
}
|
||||
Reference in New Issue
Block a user