Exporting a Yandex Music Playlist via JavaScript in DevTools
Developers often need to extract a tracklist from Yandex Music to transfer to other services, back up, or analyze. There's no official export feature, but a JavaScript script solves the problem by simulating scrolling. It runs in the browser console, accounting for the virtualized list: tracks load dynamically, with the DOM containing only the visible portion.
The script collects artist, title, and duration data, exporting to TXT or CSV. The process takes seconds for playlists with up to thousands of tracks.
Preparation and Execution
- Open the desired playlist in Yandex Music.
- Launch DevTools (F12) and go to the Console tab.
- Paste the script into the console and execute it.
- Scroll the playlist to the end—the script will capture all tracks.
- Run the command
finalizeCapture()to finish. - Download the file via the provided link.
// Paste this code into the Console
let tracks = [];
const observer = new MutationObserver(() => {
const items = document.querySelectorAll('[data-testid="track-row"]');
items.forEach(item => {
if (!item.dataset.captured) {
const artist = item.querySelector('[data-testid="artist-name"]')?.textContent.trim();
const title = item.querySelector('[data-testid="track-title"]')?.textContent.trim();
const duration = item.querySelector('[data-testid="track-duration"]')?.textContent.trim();
if (artist && title) {
tracks.push({artist, title, duration});
item.dataset.captured = 'true';
}
}
});
});
observer.observe(document.body, {childList: true, subtree: true});
window.finalizeCapture = () => {
observer.disconnect();
const data = tracks.map(t => `${t.artist} - ${t.title}${t.duration ? ` (${t.duration})` : ''}`).join('\n');
const blob = new Blob([data], {type: 'text/plain'});
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'playlist.txt';
a.click();
console.log(`Captured ${tracks.length} tracks`);
};
This code uses MutationObserver to track new elements in the DOM. The selectors are adapted to the current structure of Yandex Music—check them if changes occur.
Output Formats and Examples
- TXT: A simple list of strings
Artist - Titleor with duration. - CSV: Columns
Artist,Title,Durationfor importing into spreadsheets.
Example TXT for an electronic playlist:
Daft Punk - One More Time
The Weeknd - Blinding Lights
Justice - D.A.N.C.E.
CSV version:
Daft Punk,One More Time,4:02
The Weeknd,Blinding Lights,3:20
Justice,D.A.N.C.E.,4:00
The virtualized list requires manual scrolling: the script doesn't automate scrolling to avoid blocks. For large playlists, use the wheel event or Page Down.
Technical Implementation Details
Virtualized list (e.g., based on react-window or similar) renders only visible rows, saving memory. A standard querySelectorAll will capture 20–50 tracks, with the rest hidden.
Key script components:
- MutationObserver: Responds to DOM node additions during scrolling.
- Dataset flag: Prevents duplicates (
item.dataset.captured). - Blob and URL.createObjectURL: Generates a downloadable file without a server.
- data-testid selectors: Stable, less likely to change in SPAs.
For CSV, add conversion:
const csv = tracks.map(t => `${t.artist},"${t.title}",${t.duration || ''}`).join('\n');
Handle quote escaping in titles for correct CSV.
Possible Improvements for Production
- Automatic scrolling:
setInterval(() => window.scrollBy(0, 500), 100)with pauses. - JSON export:
JSON.stringify(tracks, null, 2). - Album support: Similar selectors for /artist/ and /album/.
- Filters: Exclude duplicates by track ID.
- Browser extension: Content script with UI for buttons.
Test on different playlists—structure may vary for podcasts or live recordings.
Key Points
- The script works exclusively in the browser, without APIs or extensions.
- Accounts for virtualized list—collects tracks only during scrolling.
- TXT/CSV export is ready for import into Spotify, Apple Music.
- Easy to modify: add track ID or cover art.
- Useful for analysis: statistics by genre, duration.
— Editorial Team
No comments yet.