-
Notifications
You must be signed in to change notification settings - Fork 796
Expand file tree
/
Copy pathSoundCloud.ts
More file actions
59 lines (54 loc) · 1.27 KB
/
Copy pathSoundCloud.ts
File metadata and controls
59 lines (54 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { Track } from "../../js/types";
const CLIENT_ID = "T9EbIJ75SnsJK3iX8lOZaDlGIYgQB32G";
/* eslint-disable camelcase */
export type SoundCloudPlaylist = {
permalink_url: string;
title: string;
uri: string;
tracks_uri: string;
user: {
avatar_url: string;
id: number;
permalink_url: string;
uri: string;
username: string;
};
tracks: {
artwork_url: string;
description: string;
user: {
username: string;
};
title: string;
stream_url: string;
duration: number;
}[];
};
/* eslint-enable camelcase */
export async function getPlaylist(
playlistId: string
): Promise<SoundCloudPlaylist> {
const result = await fetch(
`https://api.soundcloud.com/playlists/${playlistId}?client_id=${CLIENT_ID}`,
{
headers: {
accept: "application/json, text/javascript, */*; q=0.1",
},
mode: "cors",
credentials: "omit",
}
);
return await result.json();
}
export function tracksFromPlaylist(playlist: SoundCloudPlaylist): Track[] {
return playlist.tracks.map((track) => {
return {
metaData: {
artist: track.user.username,
title: track.title,
},
url: `${track.stream_url}?client_id=${CLIENT_ID}`,
duration: track.duration / 1000,
};
});
}