slsk-client
slsk-client copied to clipboard
Here's how you can use this with async / await
Hi, great project! Just leaving this here in case someone else wants to rewrite the example code with async / await.
const { promisify } = require('util');
const slsk = require('slsk-client');
const connect = promisify(slsk.connect);
const main = async () => {
try {
const client = await connect({
user: 'your_username',
pass: 'your_password'
});
const search = promisify(client.search);
const download = promisify(client.download);
console.log("searching...");
const searchResults = await search.call(client, ({ req: 'random', timeout: 2000 }));
console.log("search done!")
console.log("downloading: ", searchResults[0]);
await download({ file: searchResults[0], path: __dirname + '/random.mp3'});
console.log("download done!");
} catch (err) {
console.log(err);
}
}
main();
Oh my gosh, thank you so much! I almost thought this couldn't be done.
tks for sharing