soulseek-ts
TypeScript icon, indicating that this package has built-in type declarations

2.1.4 • Public • Published

soulseek-ts

NPM

A Soulseek client for Node. Fully-typed and promise-based :^)

Features

  • File search
  • File download

Not Implemented

  • File sharing
  • Chat

Getting Started

Check out some examples, or get up and running with this minimal starter:

// create a new client and login
const client = new SlskClient()
await client.login(USERNAME, PASSWORD)

// send a search request and wait for the results
const results = await client.search('autechre')

// grab the first result we find
const result = results.at(0)
if (!result) {
  throw new Error('No results')
}

// grab the first file from the result
const file = result.files.at(0)
if (!file) {
  throw new Error('No files')
}

// send a download request
const download = await client.download(result.username, file.filename)

// create a unique filename for our download and make sure the downloads directory exists
const parsedFilename = path.parse(file.filename.replaceAll('\\', '/'))
const filePath = path.join(
  DOWNLOADS_DIR,
  `slsk-${result.username}-${parsedFilename.name}-${Date.now()}${parsedFilename.ext}`
)
await fs.promises.mkdir(DOWNLOADS_DIR, { recursive: true })

// stream the download data into the file and wait until it is finished
await new Promise((resolve) => {
  const downloaded = fs.createWriteStream(filePath)
  download.stream.pipe(downloaded)
  download.stream.on('end', resolve)
})

// clean up our client
client.destroy()

Readme

Keywords

Package Sidebar

Install

npm i soulseek-ts

Weekly Downloads

7

Version

2.1.4

License

ISC

Unpacked Size

132 kB

Total Files

25

Last publish

Collaborators

  • jgchk