add album info from public api

This commit is contained in:
Sayem Chowdhury 2021-03-05 16:41:49 +06:00
parent d4aab8af8a
commit cd4bdef5fe
4 changed files with 83 additions and 2 deletions

View File

@ -12,6 +12,7 @@ import type {
profileType,
searchType,
trackTypePublicApi,
albumTypePublicApi,
} from './types';
// expire cache in 60 minutes
@ -73,6 +74,12 @@ export const requestPublicApi = async (slug: string) => {
export const getTrackInfoPublicApi = (sng_id: string): Promise<trackTypePublicApi> =>
requestPublicApi('/track/' + sng_id);
/**
* @param {String} alb_id album id
*/
export const getAlbumInfoPublicApi = (alb_id: string): Promise<albumTypePublicApi> =>
requestPublicApi('/album/' + alb_id);
/**
* @param {String} sng_id song id
*/

View File

@ -61,6 +61,14 @@ test('GET ALBUM INFO', async (t) => {
t.is(response.__TYPE__, 'album');
});
test('GET ALBUM INFO - PUBLIC API', async (t) => {
const response = await api.getAlbumInfoPublicApi(ALB_ID);
t.is(response.id, Number(ALB_ID));
t.is(response.upc, '724384960650');
t.is(response.type, 'album');
});
test('GET ALBUM TRACKS', async (t) => {
const response = await api.getAlbumTracks(ALB_ID);

View File

@ -1,5 +1,5 @@
import type {artistType} from './artist';
import type {trackType} from './tracks';
import type {trackType, contributorsPublicApi} from './tracks';
export interface albumTypeMinimal {
ALB_ID: string;
@ -60,3 +60,69 @@ export interface albumTracksType {
filtered_items?: number[];
next?: number;
}
interface trackDataPublicApi {
id: number; // 3135556
readable: boolean;
title: string; // 'Harder, Better, Faster, Stronger'
title_short: string; // 'Harder, Better, Faster, Stronger'
title_version?: string; // ''
link: 'https://www.deezer.com/track/3135556';
duration: number; // 224
rank: number; // 956167
explicit_lyrics: boolean;
explicit_content_lyrics: number; // 0
explicit_content_cover: number; // 0
preview: string; // 'https://cdns-preview-d.dzcdn.net/stream/c-deda7fa9316d9e9e880d2c6207e92260-8.mp3'
md5_image: string; // '2e018122cb56986277102d2041a592c8'
artist: {
id: number; // 27
name: number; // 'Daft Punk'
tracklist: string; // 'https://api.deezer.com/artist/27/top?limit=50'
type: 'artist';
};
type: 'track';
}
interface genreTypePublicApi {
id: number; // 113
name: string; // 'Dance'
picture: string; // 'https://api.deezer.com/genre/113/image'
type: 'genre';
}
export interface albumTypePublicApi {
id: number; // 302127'
title: 'Discovery';
upc: string; // '724384960650'
link: string; // 'https://www.deezer.com/album/302127'
share: string; // 'https://www.deezer.com/album/302127?utm_source=deezer&utm_content=album-302127&utm_term=0_1614940071&utm_medium=web'
cover: string; // 'https://api.deezer.com/album/302127/image'
cover_small: string; // 'https://e-cdns-images.dzcdn.net/images/cover/2e018122cb56986277102d2041a592c8/56x56-000000-80-0-0.jpg'
cover_medium: string; // 'https://e-cdns-images.dzcdn.net/images/cover/2e018122cb56986277102d2041a592c8/250x250-000000-80-0-0.jpg'
cover_big: string; // 'https://e-cdns-images.dzcdn.net/images/cover/2e018122cb56986277102d2041a592c8/500x500-000000-80-0-0.jpg'
cover_xl: string; // 'https://e-cdns-images.dzcdn.net/images/cover/2e018122cb56986277102d2041a592c8/1000x1000-000000-80-0-0.jpg'
md5_image: string; // '2e018122cb56986277102d2041a592c8'
genre_id: number; // 113;
genres: {
data: genreTypePublicApi[];
};
label: string; // 'Parlophone (France)'
nb_tracks: number; // 14;
duration: number; // 3660;
fans: number; // 229369
rating: number; // 0
release_date: string; // '2001-03-07'
record_type: string; // 'album'
available: boolean;
tracklist: string; // 'https://api.deezer.com/album/302127/tracks'
explicit_lyrics: boolean;
explicit_content_lyrics: number; // 7
explicit_content_cover: number; // 0
contributors: contributorsPublicApi[];
artist: contributorsPublicApi;
type: 'album';
tracks: {
data: trackDataPublicApi[];
};
}

View File

@ -92,7 +92,7 @@ export interface trackType extends songType {
TRACK_POSITION?: number;
}
interface contributorsPublicApi {
export interface contributorsPublicApi {
id: number; // 27
name: string; // 'Daft Punk'
link: string; // 'https://www.deezer.com/artist/27'