refactor tidal api
This commit is contained in:
parent
8b823b3533
commit
8b01d28d74
|
@ -10,7 +10,6 @@ import {
|
|||
import spotifyUri from 'spotify-uri';
|
||||
import * as spotify from './spotify';
|
||||
import * as tidal from './tidal';
|
||||
import {isrc2deezer, upc2deezer} from './deezer';
|
||||
import PQueue from 'p-queue';
|
||||
import type {albumType, artistInfoType, playlistInfo, trackType} from '../types';
|
||||
|
||||
|
@ -134,13 +133,11 @@ export const parseInfo = async (url: string) => {
|
|||
break;
|
||||
|
||||
case 'tidal-track':
|
||||
const tidalTrack = await tidal.getTrack(info.id);
|
||||
tracks.push(await isrc2deezer(tidalTrack.title, tidalTrack.isrc));
|
||||
tracks.push(await tidal.track2deezer(info.id));
|
||||
break;
|
||||
|
||||
case 'tidal-album':
|
||||
const tidalAlbum = await tidal.getAlbum(info.id);
|
||||
const [tidalAlbumInfo, tidalAlbumTracks] = await upc2deezer(tidalAlbum.title, tidalAlbum.upc);
|
||||
const [tidalAlbumInfo, tidalAlbumTracks] = await tidal.album2deezer(info.id);
|
||||
tracks = tidalAlbumTracks;
|
||||
linkinfo = tidalAlbumInfo;
|
||||
linktype = 'album';
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import axios from 'axios';
|
||||
import PQueue from 'p-queue';
|
||||
import {isrc2deezer} from './deezer';
|
||||
import {isrc2deezer, upc2deezer} from './deezer';
|
||||
import type {playlistInfo, trackType} from '../types';
|
||||
|
||||
interface commonType {
|
||||
|
@ -93,7 +93,7 @@ const queue = new PQueue({concurrency: 25});
|
|||
|
||||
/**
|
||||
* Get a track by its id
|
||||
* @param {string} id - track id
|
||||
* @param string} id - track id
|
||||
* @example tidal.getTrack('64975224')
|
||||
*/
|
||||
export const getTrack = async (id: string): Promise<tidalTrackType> => {
|
||||
|
@ -101,6 +101,15 @@ export const getTrack = async (id: string): Promise<tidalTrackType> => {
|
|||
return data;
|
||||
};
|
||||
|
||||
/**
|
||||
* Convert a tidal track to deezer
|
||||
* @param {string} id - track id
|
||||
*/
|
||||
export const track2deezer = async (id: string) => {
|
||||
const track = await getTrack(id);
|
||||
return await isrc2deezer(track.title, track.isrc);
|
||||
};
|
||||
|
||||
/**
|
||||
* Get an album by its id
|
||||
* @param {string} id - album id
|
||||
|
@ -111,6 +120,15 @@ export const getAlbum = async (id: string): Promise<tidalAlbumType> => {
|
|||
return data;
|
||||
};
|
||||
|
||||
/**
|
||||
* Convert a tidal albums to deezer
|
||||
* @param {string} id - album id
|
||||
*/
|
||||
export const album2deezer = async (id: string) => {
|
||||
const album = await getAlbum(id);
|
||||
return await upc2deezer(album.title, album.upc);
|
||||
};
|
||||
|
||||
/**
|
||||
* Get album tracks by album id
|
||||
* @param {string} id - album id
|
||||
|
|
Loading…
Reference in New Issue