-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use alternate API request for fetching playlist, added searching for …
…related tracks
- Loading branch information
1 parent
56d90c8
commit 84d8d9a
Showing
9 changed files
with
96 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,29 @@ | ||
/* eslint-disable camelcase */ | ||
import axios from 'axios' | ||
import { TrackInfo } from './info' | ||
import { TrackInfo, User, SetInfo } from './info' | ||
|
||
/** @internal */ | ||
const baseURL = 'https://api-v2.soundcloud.com/search' | ||
|
||
export type SearchResponse = { | ||
collection: TrackInfo[] | ||
export type SearchResponse<T> = { | ||
collection: T[] | ||
total_results: number, | ||
next_href: string, | ||
query_urn: string | ||
} | ||
|
||
export type SearchResponseAll = SearchResponse<User | SetInfo | TrackInfo> | ||
|
||
export type SoundcloudResource = 'tracks' | 'people' | 'albums' | 'playlists' | ||
|
||
/** @internal */ | ||
export const search = async (type: SoundcloudResource | 'all', query: string, clientID?: string): Promise<SearchResponseAll> => { | ||
const { data } = await axios.get(`${baseURL}${type === 'all' ? '' : `/${type}/`}?client_id=${clientID}&q=${query}`) | ||
return data as SearchResponseAll | ||
} | ||
|
||
/** @internal */ | ||
export const search = async (query: string, clientID?: string): Promise<SearchResponse> => { | ||
const { data } = await axios.get(`${baseURL}?client_id=${clientID}&q=${query}`) | ||
return data as SearchResponse | ||
export const related = async <T extends TrackInfo | User | SetInfo> (type: SoundcloudResource, id: number, limit = 10, offset = 0, clientID: string): Promise<SearchResponse<T>> => { | ||
const { data } = await axios.get(`https://api-v2.soundcloud.com/${type}/${id}/related?client_id=${clientID}&offset=${offset}&limit=${limit}`) | ||
return data as SearchResponse<T> | ||
} |
Oops, something went wrong.