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