slsk-client icon indicating copy to clipboard operation
slsk-client copied to clipboard

Here's how you can use this with async / await

Open nlspnsgen opened this issue 3 years ago • 2 comments

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();

nlspnsgen avatar Aug 14 '21 13:08 nlspnsgen

Oh my gosh, thank you so much! I almost thought this couldn't be done.

B1zguy avatar May 25 '22 10:05 B1zguy

tks for sharing

theaccessvirus avatar Jul 10 '23 07:07 theaccessvirus