This is a Node.js wrapper for the Yandex.Music API that is used in mobile apps (iOS/Android).
npm install yamd2yarn add yamd2pnpm add yamd2bun add yamd2npm install github:Dirold2/yamd2#__dist__import { YMApi, WrappedYMApi } from "yamd2";
// Basic API usage
const api = new YMApi();
await api.init({ access_token: "EXAMPLE_TOKEN", uid: 0 });
const result = await api.searchArtists("gorillaz");
console.log({ result });
// Enhanced API with additional features
const wrappedApi = new WrappedYMApi();
await wrappedApi.init({ access_token: "EXAMPLE_TOKEN", uid: 0 });
// Get track download info with codec support
const downloadInfo = await wrappedApi.getDownloadInfo("123456", {
codec: "flac",
quality: "lossless"
});
// Get best available download URL
const bestUrl = await wrappedApi.getBestDownloadUrl("123456");
// Support for URLs and IDs
const track = await wrappedApi.getTrack("https://music.yandex.ru/track/123456");Get token from here and uid from here.
This library provides following methods:
- getAccountStatus
- getFeed
- getChart
- getNewReleases
- getPodcasts
- getGenres
- search
- searchArtists
- searchTracks
- searchAlbums
- searchAll
- getNewPlaylists
- getPlaylist
- getPlaylists
- getUserPlaylists
- createPlaylist
- removePlaylist
- renamePlaylist
- addTracksToPlaylist
- removeTracksFromPlaylist
- getTrack
- getArtistTracks
- getSingleTrack
- getTrackSupplement
- getTrackDownloadInfo
- getTrackDownloadInfoNew
- getTrackDirectLink
- getTrackDirectLinkNew
- getTrackShareLink
- getSimilarTracks
- getDislikedTracks
- getLikedTracks
- getAlbums
- getAlbum
- getAlbumWithTracks
- getArtist
- getArtists
- getAllStationsList
- getRecomendedStationsList
- getStationTracks
- getStationInfo
Enhanced API with additional features and convenience methods:
- getDownloadInfo - Get download information with codec support
- getDownloadUrl - Get direct download URL
- getBestDownloadUrl - Get best available URL by codec priority
- getDownloadUrlForFFmpeg - Get FFmpeg-compatible URL (RAW MP3)
- getMp3DownloadInfo - Get MP3 download info
- getMp3DownloadUrl - Get MP3 download URL
- getAacDownloadInfo - Get AAC download info
- getAacDownloadUrl - Get AAC download URL
- getFlacDownloadInfo - Get FLAC download info
- getFlacDownloadUrl - Get FLAC download URL
- getFlacMP4DownloadInfo - Get FLAC-MP4 download info
- getFlacMP4DownloadUrl - Get FLAC-MP4 download URL
- getTrack - Get track by ID or URL
- isEncryptedUrl - Check if URL is encrypted
- getPlaylist - Get playlist by ID or URL
- getAlbum - Get album by ID or URL
- getAlbumWithTracks - Get album with tracks by ID or URL
- getArtist - Get artist by ID or URL
- getShortenedLink - Get shortened link
The WrappedYMApi supports multiple audio codecs with automatic quality selection:
- FLAC - Lossless, high quality
- FLAC-MP4 - Lossless in MP4 container
- AAC - Standard compression
- AAC-MP4 - AAC in MP4 container
- HE-AAC - High efficiency
- HE-AAC-MP4 - HE-AAC in MP4 container
- MP3 - Wide compatibility
All methods accept both entity IDs and URLs:
// By ID
const track = await wrappedApi.getTrack(123456);
// By URL
const track = await wrappedApi.getTrack("https://music.yandex.ru/track/123456");Comprehensive error handling with specific error types:
import { YMApiError, ExtractionError, DownloadError } from "yamd2";
try {
const result = await wrappedApi.getDownloadUrl("invalid-url");
} catch (error) {
if (error instanceof ExtractionError) {
console.log(`Failed to extract ID from URL: ${error.input}`);
} else if (error instanceof DownloadError) {
console.log(`URL not found for track ${error.trackId} with codec ${error.codec}`);
}
}When using getBestDownloadUrl(), codecs are checked in priority order:
- FLAC-MP4
- FLAC
- AAC-MP4
- AAC
- HE-AAC-MP4
- HE-AAC
- MP3
See the examples directory for detailed usage examples: