Skip to content

manhgdev/soundcloud-package

Repository files navigation

SoundCloud API Package

Package JavaScript để tương tác với SoundCloud API một cách dễ dàng và hiệu quả.

Cài đặt

bun add @manhgdev/soundcloud-web

Khởi tạo

import SoundCloudAPI from '@manhgdev/soundcloud-web';

const api = new SoundCloudAPI({
  clientId: 'YOUR_CLIENT_ID', // Tùy chọn
  autoFetchClientId: true // Tự động lấy client ID
});

Cách sử dụng

Search Module

Tìm kiếm tất cả

const result = await api.search.all('skrillex', {
  limit: 20,
  offset: 0,
  facet: 'model',
  linked_partitioning: 1
});

Tìm kiếm bài hát

const tracks = await api.search.tracks('skrillex', {
  limit: 20,
  offset: 0,
  facet: 'genre',
  linked_partitioning: 1
});

Tìm kiếm người dùng

const users = await api.search.users('skrillex', {
  limit: 20,
  offset: 0,
  facet: 'place',
  linked_partitioning: 1
});

Tìm kiếm album

const albums = await api.search.albums('skrillex', {
  limit: 20,
  offset: 0,
  facet: 'genre',
  linked_partitioning: 1
});

Tìm kiếm playlist

const playlists = await api.search.playlists('workout', {
  limit: 20,
  offset: 0,
  facet: 'genre',
  linked_partitioning: 1
});

Tìm kiếm bài hát theo thể loại

const tracks = await api.search.byGenre('electronic', {
  limit: 10,
  offset: 0,
  sort: 'popular',
  linked_partitioning: 1
});

Tracks Module

Lấy nhiều bài hát

const tracks = await api.tracks.getMultiple([956017639, 789012]);

Lấy bình luận của bài hát

const comments = await api.tracks.getComments(956017639, {
  threaded: 0,
  limit: 200,
  offset: 0,
  linked_partitioning: 1
});

Lấy bài hát liên quan

const related = await api.tracks.getRelated(956017639, {
  limit: 10,
  offset: 0,
  linked_partitioning: 1
});

Users Module

Lấy thông tin người dùng

const user = await api.users.getUser(856062);

Lấy spotlight của người dùng

const spotlight = await api.users.getSpotlight(856062, {
  limit: 10,
  offset: 0,
  linked_partitioning: 1
});

Lấy hồ sơ nổi bật của người dùng

const profiles = await api.users.getFeaturedProfiles(856062, {
  limit: 10,
  offset: 0,
  linked_partitioning: 1
});

Lấy danh sách bài hát được thích

const likes = await api.users.getLikes(856062, {
  limit: 10,
  offset: 0,
  linked_partitioning: 1
});

Lấy danh sách người đang theo dõi

const followings = await api.users.getFollowings(856062, {
  limit: 3,
  offset: 0,
  linked_partitioning: 1
});

Lấy danh sách nghệ sĩ liên quan

const artists = await api.users.getRelatedArtists(856062, {
  creators_only: false,
  page_size: 12,
  limit: 12,
  offset: 0,
  linked_partitioning: 1
});

Lấy bình luận của người dùng

const comments = await api.users.getComments(856062, {
  limit: 20,
  offset: 0,
  linked_partitioning: 1
});

Lấy stream của người dùng

const stream = await api.users.getStream(856062, {
  limit: 20,
  offset: 0,
  linked_partitioning: 1
});

Lấy bài hát nổi bật của người dùng

const topTracks = await api.users.getTopTracks(856062, {
  limit: 10,
  offset: 0,
  linked_partitioning: 1
});

Lấy bài hát của người dùng

const tracks = await api.users.getTracks(856062, {
  limit: 20
});

Lấy playlist của người dùng

const playlists = await api.users.getPlaylists(856062, {
  limit: 10,
  offset: 0,
  linked_partitioning: 1
});

Lấy hồ sơ web của người dùng

const webProfiles = await api.users.getWebProfiles(856062);

Playlists Module

Lấy thông tin playlist

const playlist = await api.playlists.getPlaylist(1236491080, {
  representation: 'full'
});

Lấy danh sách người thích playlist

const likers = await api.playlists.getLikers(1236491080, {
  limit: 9,
  offset: 0,
  linked_partitioning: 1
});

Lấy danh sách người repost playlist

const reposters = await api.playlists.getReposters(1236491080, {
  limit: 9,
  offset: 0,
  linked_partitioning: 1
});

Lấy playlist theo thể loại

const playlists = await api.playlists.getByGenre('electronic', {
  limit: 10,
  offset: 0,
  linked_partitioning: 1
});

Media Module

Lấy URL phát trực tuyến

const playbackUrl = await api.media.getPlaybackUrl(956017639);

Lấy URL tải xuống

const downloadUrl = await api.media.getDownloadUrl(956017639);

Discover Module

Lấy nội dung trang chủ

const homeContent = await api.discover.getHomeContent({
  limit: 10,
  offset: 0,
  linked_partitioning: 1
});

Lấy bài hát mới theo thể loại

const recentTracks = await api.discover.getRecentTracks('electronic', {
  limit: 10,
  offset: 0,
  linked_partitioning: 1
});

Lấy bài hát mới theo quốc gia

const countryTracks = await api.discover.getRecentTracksByCountry({
  limit: 10,
  offset: 0,
  linked_partitioning: 1
});

Tham số mặc định

Tất cả các phương thức đều có tham số mặc định phù hợp:

  • limit: Số lượng kết quả tối đa (thường là 10-20)
  • offset: Vị trí bắt đầu (mặc định: 0)
  • linked_partitioning: Phân trang liên kết (mặc định: 1)
  • facet: Loại facet cho search (mặc định: 'model', 'genre', 'place')
  • threaded: Hiển thị theo thread cho comments (mặc định: 0)
  • creators_only: Chỉ hiển thị người tạo (mặc định: false)
  • page_size: Kích thước trang (mặc định: 12)
  • representation: Kiểu biểu diễn (mặc định: 'full')

Lưu ý

  • Package tự động lấy và cache client ID từ SoundCloud
  • Tất cả các request đều có timeout và retry logic
  • Hỗ trợ đầy đủ các endpoint của SoundCloud API v2
  • Có JSDoc đầy đủ cho tất cả các phương thức

License

MIT

About

SKD JS

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published