Skip to content

Instantly share code, notes, and snippets.

@Grafikart
Created August 24, 2023 08:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Grafikart/7b8f707b70fd009df5d55223a3cba9b6 to your computer and use it in GitHub Desktop.
Save Grafikart/7b8f707b70fd009df5d55223a3cba9b6 to your computer and use it in GitHub Desktop.
jetsetradio.live downloader (nodejs)
import {chromium, devices} from 'playwright';
import ora from 'ora';
import inquirer from 'inquirer'
import {createWriteStream} from 'node:fs'
import {mkdir} from 'node:fs/promises'
import {get} from 'node:https'
/**
* Download music from jetsetradio.live
*
* ## Usage
*
* pnpm add playwright ora inquirer
* node run jsr.js
*/
const browser = await chromium.launch({headless: true});
const context = await browser.newContext();
const page = await context.newPage();
// Load the page
await page.goto('https://jetsetradio.live/');
await page.waitForLoadState("networkidle")
// Find the list of available radio stations
const stations = await page.evaluate('window.stationsArray');
const station = (await inquirer.prompt({
type: 'list',
name: 'station',
message: 'Sélectionner une radio : ',
choices: stations
})).station
// Retrieve the tracks
const tracks = await page.evaluate(`window.${station}_tracks`);
const spinner = ora('Downloading tracks').start()
const audioDir = `audio/${station}`
await mkdir(audioDir, { recursive: true });
let progress = 0; // Track the number of track downloaded
const downloadFile = (source, output) => {
return new Promise((resolve, reject) => {
const file = createWriteStream(output);
get(source, function(response) {
response.pipe(file);
file.on("finish", () => {
progress++
spinner.text = `${progress}/${tracks.length} - ${output}`
resolve()
file.close();
});
});
})
}
const files = tracks
.map(track => downloadFile(`https://jetsetradio.live/radio/stations/${station}/${track}.mp3`, `${audioDir}/${track}.mp3`))
await Promise.all(files)
// Teardown
spinner.succeed('Finished downloading')
await context.close();
await browser.close();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment