mirror of
https://github.com/d-fi/d-fi-core.git
synced 2025-07-29 16:45:31 +02:00
export getUrlParts
This commit is contained in:
parent
b764b684dd
commit
89281d8497
@ -15,7 +15,7 @@ import type {albumType, artistInfoType, playlistInfo, trackType} from '../types'
|
|||||||
|
|
||||||
type linkType = 'track' | 'album' | 'artist' | 'playlist';
|
type linkType = 'track' | 'album' | 'artist' | 'playlist';
|
||||||
|
|
||||||
type urlPartsType = {
|
export type urlPartsType = {
|
||||||
id: string;
|
id: string;
|
||||||
type:
|
type:
|
||||||
| 'track'
|
| 'track'
|
||||||
@ -35,7 +35,7 @@ type urlPartsType = {
|
|||||||
|
|
||||||
const queue = new PQueue({concurrency: 10});
|
const queue = new PQueue({concurrency: 10});
|
||||||
|
|
||||||
const getUrlParts = async (url: string): Promise<urlPartsType> => {
|
export const getUrlParts = async (url: string, setToken = false): Promise<urlPartsType> => {
|
||||||
if (url.startsWith('spotify:')) {
|
if (url.startsWith('spotify:')) {
|
||||||
const spotify = url.split(':');
|
const spotify = url.split(':');
|
||||||
url = 'https://open.spotify.com/' + spotify[1] + '/' + spotify[2];
|
url = 'https://open.spotify.com/' + spotify[1] + '/' + spotify[2];
|
||||||
@ -53,7 +53,9 @@ const getUrlParts = async (url: string): Promise<urlPartsType> => {
|
|||||||
|
|
||||||
case 'spotify':
|
case 'spotify':
|
||||||
const spotifyUrlParts = spotifyUri.parse(url);
|
const spotifyUrlParts = spotifyUri.parse(url);
|
||||||
await spotify.setSpotifyAnonymousToken();
|
if (setToken) {
|
||||||
|
await spotify.setSpotifyAnonymousToken();
|
||||||
|
}
|
||||||
return {type: ('spotify-' + spotifyUrlParts.type) as any, id: (spotifyUrlParts as any).id};
|
return {type: ('spotify-' + spotifyUrlParts.type) as any, id: (spotifyUrlParts as any).id};
|
||||||
|
|
||||||
case 'tidal':
|
case 'tidal':
|
||||||
@ -70,7 +72,7 @@ const getUrlParts = async (url: string): Promise<urlPartsType> => {
|
|||||||
* @param {String} url
|
* @param {String} url
|
||||||
*/
|
*/
|
||||||
export const parseInfo = async (url: string) => {
|
export const parseInfo = async (url: string) => {
|
||||||
let info = await getUrlParts(url);
|
let info = await getUrlParts(url, true);
|
||||||
if (!info.id) {
|
if (!info.id) {
|
||||||
throw new Error('Unable to parse id');
|
throw new Error('Unable to parse id');
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user