Tracks
getTrack
getTrack(
params
)
Get a track by id.
- Params
- Example
- Response
Create an object with the following fields and pass it as the first argument, as shown in the example above.
Name | Type | Description | Required? |
---|---|---|---|
trackId | string | The ID of the track | Required |
const { data: track } = await audiusSdk.tracks.getTrack({
trackId: 'D7KyD',
})
console.log(track)
Returns a Promise
containing an object with a data
field. data
contains information about the
track as described below.
{
artwork?: {
_1000x1000?: string;
_150x150?: string;
_480x480?: string;
};
description?: string;
downloadable?: boolean;
duration: number;
favoriteCount: number;
genre?: string;
id: string;
isStreamable?: string;
mood?: string;
permalink?: string;
playCount: number;
releaseDate: string;
remixOf?: {
tracks: { parentTrackId: string }[];
};
repostCount: number;
tags?: string[];
title: string;
trackCid?: string;
user: {
albumCount: number;
artistPickTrackId?: string;
bio?: string;
coverPhoto?: {
_2000?: string;
_640?: string;
};
doesFollowCurrentUser?: boolean;
ercWallet: string;
followeeCount: number;
followerCount: number;
handle: string;
id: string;
isAvailable: boolean;
isDeactivated: boolean;
isVerified: boolean;
location?: string;
name: string;
playlistCount: number;
profilePicture?: {
_1000x1000?: string;
_150x150?: string;
_480x480?: string;
};
repostCount: number;
splWallet: string;
supporterCount: number;
supportingCount: number;
totalAudioBalance: number;
trackCount: number;
};
};
getBulkTracks
getBulkTracks(
params
)
Get a list of tracks using their IDs or permalinks.
- Params
- Example
- Response
Create an object with the following fields and pass it as the first argument, as shown in the example above.
Name | Type | Description | Required? |
---|---|---|---|
id | string[] | An array of IDs of tracks | Optional |
permalink | string[] | An array of permalinks of tracks | Optional |
const { data: tracks } = await audiusSdk.tracks.getBulkTracks({
id: ['D7KyD', 'PjdWN', 'Jwo2A'],
})
console.log(tracks)
Returns a Promise
containing an object with a data
field. data
is an array of items containing
information about the tracks as described below.
{
artwork?: {
_1000x1000?: string;
_150x150?: string;
_480x480?: string;
};
description?: string;
downloadable?: boolean;
duration: number;
favoriteCount: number;
genre?: string;
id: string;
isStreamable?: string;
mood?: string;
permalink?: string;
playCount: number;
releaseDate: string;
remixOf?: {
tracks: { parentTrackId: string }[];
};
repostCount: number;
tags?: string[];
title: string;
trackCid?: string;
user: {
albumCount: number;
artistPickTrackId?: string;
bio?: string;
coverPhoto?: {
_2000?: string;
_640?: string;
};
doesFollowCurrentUser?: boolean;
ercWallet: string;
followeeCount: number;
followerCount: number;
handle: string;
id: string;
isAvailable: boolean;
isDeactivated: boolean;
isVerified: boolean;
location?: string;
name: string;
playlistCount: number;
profilePicture?: {
_1000x1000?: string;
_150x150?: string;
_480x480?: string;
};
repostCount: number;
splWallet: string;
supporterCount: number;
supportingCount: number;
totalAudioBalance: number;
trackCount: number;
};
}[];
getTrendingTracks
getTrendingTracks(
params
)
Get the top 100 trending (most popular) tracks on Audius.
- Params
- Example
- Response
Optionally create an object with the following fields and pass it as the first argument.
Name | Type | Description | Required? |
---|---|---|---|
genre | Genre (can be imported from @audius/sdk ) | If provided, the top 100 trending tracks of the genre will be returned | Optional |
time | GetTrendingTracksTimeEnum (can be imported from @audius/sdk ) | A time range for which to return the trending tracks. Default value is GetTrendingTracksTimeEnum.AllTime | Optional |
const { data: tracks } = await audiusSdk.tracks.getTrendingTracks()
console.log(tracks)
Returns a Promise
containing an object with a data
field. data
is an array of items containing
information about the tracks as described below.
{
artwork?: {
_1000x1000?: string;
_150x150?: string;
_480x480?: string;
};
description?: string;
downloadable?: boolean;
duration: number;
favoriteCount: number;
genre?: string;
id: string;
isStreamable?: string;
mood?: string;
permalink?: string;
playCount: number;
releaseDate: string;
remixOf?: {
tracks: { parentTrackId: string }[];
};
repostCount: number;
tags?: string[];
title: string;
trackCid?: string;
user: {
albumCount: number;
artistPickTrackId?: string;
bio?: string;
coverPhoto?: {
_2000?: string;
_640?: string;
};
doesFollowCurrentUser?: boolean;
ercWallet: string;
followeeCount: number;
followerCount: number;
handle: string;
id: string;
isAvailable: boolean;
isDeactivated: boolean;
isVerified: boolean;
location?: string;
name: string;
playlistCount: number;
profilePicture?: {
_1000x1000?: string;
_150x150?: string;
_480x480?: string;
};
repostCount: number;
splWallet: string;
supporterCount: number;
supportingCount: number;
totalAudioBalance: number;
trackCount: number;
};
}[];
getUndergroundTrendingTracks
getUndergroundTrendingTracks(
params
)
Get the top 100 trending underground tracks on Audius.
- Params
- Example
- Response
Optionally create an object with the following fields and pass it as the first argument.
Name | Type | Description | Required? |
---|---|---|---|
limit | number | If provided, will return only the given number of tracks. Default is 100 | Optional |
offset | number | An offset to apply to the list of results. Default value is 0 | Optional |
const { data: tracks } = await audiusSdk.tracks.getUndergroundTrendingTracks()
console.log(tracks)
Returns a Promise
containing an object with a data
field. data
is an array of items containing
information about the tracks as described below.
{
artwork?: {
_1000x1000?: string;
_150x150?: string;
_480x480?: string;
};
description?: string;
downloadable?: boolean;
duration: number;
favoriteCount: number;
genre?: string;
id: string;
isStreamable?: string;
mood?: string;
permalink?: string;
playCount: number;
releaseDate: string;
remixOf?: {
tracks: { parentTrackId: string }[];
};
repostCount: number;
tags?: string[];
title: string;
trackCid?: string;
user: {
albumCount: number;
artistPickTrackId?: string;
bio?: string;
coverPhoto?: {
_2000?: string;
_640?: string;
};
doesFollowCurrentUser?: boolean;
ercWallet: string;
followeeCount: number;
followerCount: number;
handle: string;
id: string;
isAvailable: boolean;
isDeactivated: boolean;
isVerified: boolean;
location?: string;
name: string;
playlistCount: number;
profilePicture?: {
_1000x1000?: string;
_150x150?: string;
_480x480?: string;
};
repostCount: number;
splWallet: string;
supporterCount: number;
supportingCount: number;
totalAudioBalance: number;
trackCount: number;
};
}[];
searchTracks
searchTracks(
params
)
Search for tracks.
- Params
- Example
- Response
Create an object with the following fields and pass it as the first argument, as shown in the example above.
Name | Type | Description | Required? |
---|---|---|---|
query | string | The query to search for | Required |
const { data: tracks } = await audiusSdk.tracks.searchTracks({
query: 'skrillex',
})
console.log(tracks)
Returns a Promise
containing an object with a data
field. data
is an array of items containing
information about the tracks as described below.
{
artwork?: {
_1000x1000?: string;
_150x150?: string;
_480x480?: string;
};
description?: string;
downloadable?: boolean;
duration: number;
favoriteCount: number;
genre?: string;
id: string;
isStreamable?: string;
mood?: string;
permalink?: string;
playCount: number;
releaseDate: string;
remixOf?: {
tracks: { parentTrackId: string }[];
};
repostCount: number;
tags?: string[];
title: string;
trackCid?: string;
user: {
albumCount: number;
artistPickTrackId?: string;
bio?: string;
coverPhoto?: {
_2000?: string;
_640?: string;
};
doesFollowCurrentUser?: boolean;
ercWallet: string;
followeeCount: number;
followerCount: number;
handle: string;
id: string;
isAvailable: boolean;
isDeactivated: boolean;
isVerified: boolean;
location?: string;
name: string;
playlistCount: number;
profilePicture?: {
_1000x1000?: string;
_150x150?: string;
_480x480?: string;
};
repostCount: number;
splWallet: string;
supporterCount: number;
supportingCount: number;
totalAudioBalance: number;
trackCount: number;
};
}[];
getTrackStreamUrl
getTrackStreamUrl(
params
)
Get the url of the track's streamable mp3 file.
- Params
- Example
- Response
Create an object with the following fields and pass it as the first argument, as shown in the example above.
Name | Type | Description | Required? |
---|---|---|---|
trackId | string | The ID of the track | Required |
const url = await audiusSdk.tracks.getTrackStreamUrl({
trackId: 'PjdWN',
})
const audio = new Audio(url)
audio.play()
Returns a Promise
containing a string
url which can be used to stream the track.
uploadTrack
uploadTrack(
params
,advancedOptions?
)
Upload a track.
- Params
- Example
- Response
Create an object with the following fields and pass it as the first argument, as shown in the example above.
Name | Type | Description | Required? |
---|---|---|---|
coverArtFile | File | A file that will be used as the cover art for the track | Optional |
metadata | UploadTrackMetadata | An object containing the details of the track | Required |
onProgress | (progress: number) => void | A function that will be called with progress events as the files upload | Optional |
trackFile | File | The audio file of the track | Required |
userId | string | The ID of the user | Required |
advancedOptions
You can pass an optional advancedOptions
object as the second
argument.
import { Mood, Genre } from '@audius/sdk'
import fs from 'fs'
const coverArtBuffer = fs.readFileSync('path/to/cover-art.png')
const trackBuffer = fs.readFileSync('path/to/track.mp3')
const { trackId } = await audiusSdk.tracks.uploadTrack({
userId: '7eP5n',
coverArtFile: {
buffer: Buffer.from(coverArtBuffer),
name: 'coverArt',
},
metadata: {
title: 'Monstera',
description: 'Dedicated to my favorite plant',
genre: Genre.METAL,
mood: Mood.AGGRESSIVE,
},
trackFile: {
buffer: Buffer.from(trackBuffer),
name: 'monsteraAudio',
},
})
Returns a Promise
containing an object with the new track's ID (trackId
), as well as the block
hash (blockHash
) and block number (blockNumber
) for the transaction.
{
blockHash: string
blockNumber: number
trackId: string
}
updateTrack
updateTrack(
params
,advancedOptions?
)
Update a track. If cover art or any metadata fields are not provided, their values will be kept the same as before.
- Params
- Example
- Response
Create an object with the following fields and pass it as the first argument, as shown in the example above.
Name | Type | Description | Required? |
---|---|---|---|
trackId | string | The ID of the track | Required |
userId | string | The ID of the user | Required |
coverArtFile | File | A file that will be used as the cover art for the track | Optional |
metadata | Partial< UploadTrackMetadata > | An object containing the details of the track | Required |
onProgress | (progress: number) => void | A function that will be called with progress events as the image file uploads | Optional |
advancedOptions
You can pass an optional advancedOptions
object as the second
argument.
import fs from 'fs'
import { Mood } from '@audius/sdk'
const coverArtBuffer = fs.readFileSync('path/to/updated-cover-art.png')
const { trackId } = await audiusSdk.tracks.updateTrack({
trackId: 'h5pJ3Bz',
coverArtFile: {
buffer: Buffer.from(coverArtBuffer),
name: 'coverArt',
},
metadata: {
description: 'Dedicated to my favorite plant... new cover art!',
mood: Mood.YEARNING,
},
onProgress: (progress) => {
console.log('Progress: ', progress / 100)
},
userId: '7eP5n',
})
Returns a Promise
containing an object with the block hash (blockHash
) and block number
(blockNumber
) for the transaction.
{
blockHash: string
blockNumber: number
}
deleteTrack
deleteTrack(
params
,advancedOptions?
)
Delete a track
- Params
- Example
- Response
Create an object with the following fields and pass it as the first argument, as shown in the example above.
Name | Type | Description | Required? |
---|---|---|---|
trackId | string | The ID of the track | Required |
userId | string | The ID of the user | Required |
advancedOptions
You can pass an optional advancedOptions
object as the second
argument.
await audiusSdk.tracks.deleteTrack({
trackId: 'h5pJ3Bz',
userId: '7eP5n',
})
Returns a Promise
containing an object with the block hash (blockHash
) and block number
(blockNumber
) for the transaction.
{
blockHash: string
blockNumber: number
}
favoriteTrack
favoriteTrack(
params
,advancedOptions?
)
Favorite a track
- Params
- Example
- Response
Create an object with the following fields and pass it as the first argument, as shown in the example above.
Name | Type | Description | Required? |
---|---|---|---|
trackId | string | The ID of the track | Required |
userId | string | The ID of the user | Required |
metadata | see code block below | Set isSaveOfRepost to true if you are favoriting a reposted track. | Optional |
{
isSaveOfRepost: boolean
}
advancedOptions
You can pass an optional advancedOptions
object as the second
argument.
await audiusSdk.tracks.favoriteTrack({
trackId: 'x5pJ3Az'
userId: "7eP5n",
});
Returns a Promise
containing an object with the block hash (blockHash
) and block number
(blockNumber
) for the transaction.
{
blockHash: string
blockNumber: number
}
unfavoriteTrack
unfavoriteTrack(
params
,advancedOptions?
)
Unfavorite a track
- Params
- Example
- Response
Create an object with the following fields and pass it as the first argument, as shown in the example above.
Name | Type | Description | Required? |
---|---|---|---|
trackId | string | The ID of the track | Required |
userId | string | The ID of the user | Required |
advancedOptions
You can pass an optional advancedOptions
object as the second
argument.
await audiusSdk.tracks.unfavoriteTrack({
trackId: 'x5pJ3Az'
userId: "7eP5n",
});
Returns a Promise
containing an object with the block hash (blockHash
) and block number
(blockNumber
) for the transaction.
{
blockHash: string
blockNumber: number
}
repostTrack
repostTrack(
params
,advancedOptions?
)
Repost a track
- Params
- Example
- Response
Create an object with the following fields and pass it as the first argument, as shown in the example above.
Name | Type | Description | Required? |
---|---|---|---|
trackId | string | The ID of the track | Required |
userId | string | The ID of the user | Required |
metadata | see code block below | Set isRepostOfRepost to true if you are reposting a reposted track. | Optional |
{
isRepostOfRepost: boolean
}
advancedOptions
You can pass an optional advancedOptions
object as the second
argument.
await audiusSdk.tracks.repostTrack({
trackId: 'x5pJ3Az'
userId: "7eP5n",
});
Returns a Promise
containing an object with the block hash (blockHash
) and block number
(blockNumber
) for the transaction.
Return type:
{
blockHash: string
blockNumber: number
}
unrepostTrack
unrepostTrack(
params
,advancedOptions?
)
Unrepost a track
- Params
- Example
- Response
Create an object with the following fields and pass it as the first argument, as shown in the example above.
Name | Type | Description | Required? |
---|---|---|---|
trackId | string | The ID of the track | Required |
userId | string | The ID of the user | Required |
advancedOptions
You can pass an optional advancedOptions
object as the second
argument.
await audiusSdk.tracks.unrepostTrack({
trackId: 'x5pJ3Az',
userId: '7eP5n',
})
Returns a Promise
containing an object with the block hash (blockHash
) and block number
(blockNumber
) for the transaction.
{
blockHash: string
blockNumber: number
}