# spdl-core

> Spotify track downloader module. Written in pure javascript.

Latest version **2.0.2** (published 2021-05-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install spdl-core
pnpm add spdl-core
yarn add spdl-core
bun add spdl-core
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.2 |
| Published | 2021-05-21 |
| First published | 2021-02-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 10.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | skydonald |
| Maintainers | skydonald |
| Keywords | spotify, download, spotifydl, spotify-dl, api, dl, downloader, spotify-downloader, discord, discord-spotify, discord-music, discord-player, music, spdl-core, node-spdl, spdl, song, ffmpeg, opus, filter, filters |

## Links

- npm: https://www.npmjs.com/package/spdl-core
- Repository: https://github.com/SkyDonald/spdl-core
- Homepage: https://github.com/SkyDonald/spdl-core#readme
- Issues: https://github.com/SkyDonald/spdl-core/issues
- npm.io page: https://npm.io/package/spdl-core

## Dependencies (5)

- [ytdl-core](https://npm.io/package/ytdl-core.md) ^4.8.0
- [node-fetch](https://npm.io/package/node-fetch.md) ^2.6.1
- [youtube-sr](https://npm.io/package/youtube-sr.md) ^4.0.1
- [spotify-url-info](https://npm.io/package/spotify-url-info.md) ^2.2.0
- [discord-ytdl-core](https://npm.io/package/discord-ytdl-core.md) ^5.0.2

## Alternatives

- [localforage](https://npm.io/package/localforage.md) — 6.2M weekly downloads
- [localforage-observable](https://npm.io/package/localforage-observable.md) — 30.8K weekly downloads
- [@y/y](https://npm.io/package/@y/y.md) — 30.1K weekly downloads
- [@metaobjectsdev/render](https://npm.io/package/@metaobjectsdev/render.md) — 3.5K weekly downloads
- [@ledgerhq/coin-algorand](https://npm.io/package/@ledgerhq/coin-algorand.md) — 1.1K weekly downloads

## Recent versions

- 2.0.2 (latest) — 2021-05-21
- 2.0.1 — 2021-05-19
- 2.0.0 — 2021-05-19
- 1.7.0 — 2021-04-24
- 1.6.0 — 2021-03-27
- 1.5.1 — 2021-02-23
- 1.5.0 — 2021-02-23
- 1.4.5 — 2021-02-23
- 1.4.4 — 2021-02-22
- 1.4.3 — 2021-02-22
- 1.4.2 — 2021-02-22
- 1.4.0 — 2021-02-22
- 1.3.2 — 2021-02-22
- 1.3.1 — 2021-02-22
- 1.3.0 — 2021-02-22
- … 15 more at https://npm.io/package/spdl-core/versions

## README

# spdl-core

Spotify track downloader module. Written in pure javascript.

# Support
You can contact us for support on our [chat server](https://discord.gg/AUfTUJA)

# Usage

```js
const fs = require('fs');
const spdl = require('spdl-core').default;
// Typescript: import spdl from 'spdl-core';

spdl.getInfo('https://open.spotify.com/track/3fjmSxt0PskST13CSdBUFx?si=e420cd3a80834011').then(infos => {
  spdl(infos.url).then(stream => {
    stream.on('end', () => console.log('Done!'));
    stream.pipe(fs.createWriteStream(`${infos.title}.mp3`));
  });
});
```

# API
### async spdl(url, options?)

Downloads the track from the given url. Returns a [readable stream](https://nodejs.org/api/stream.html#stream_class_stream_readable)
Options are the options for discord-ytdl-core

### async spdl.getInfo(url)

Gives the information of a track

### spdl.validateURL(url, type?)

Returns true if url is a spotify link

## Limitations

Generated download links are valid for 6 hours, and may only be downloadable from the same IP address.

# Install

```bash
npm install spdl-core@latest
```

Or for Yarn users:
```bash
yarn add spdl-core@latest
```

Make sure you're installing the latest version of spdl-core to keep up with the latest fixes.

# Discord Bot

You'll need to install `discord.js` and `@discordjs/opus`.

```js
const { MessageEmbed, Client } = require('discord.js');
const spdl = require('spdl-core');
function formatDuration(duration) {
  let seconds = duration / 1000;
  return `${Math.floor(seconds / 60)}m ${Math.floor(seconds % 60)}s`;
}

const client = new Client();
client.login('Your Discord Bot Token');
client.on('ready', () => console.log('Ready'));

client.on('message', async (msg) => {
  if (!msg.content.startsWith('!play')) return;
  const url = msg.content.split('!play ')[1];
  if (!spdl.validateURL(url)) return msg.channel.send('Invalid URL');
  const channel = msg.member.voice.channel;
  if (!channel) return msg.channel.send('Not in a voc channel');
  try {
    const connection = await channel.join();
    connection
      .play(await spdl(url))
      .on('error', e => console.error(e));
    const infos = await spdl.getInfo(url);
    const embed = new MessageEmbed()
      .setTitle(`Now playing: ${infos.title}`)
      .setURL(infos.url)
      .setColor('#1DB954')
      .addField('Artist', infos.artist, true)
      .addField('Duration', formatDuration(infos.duration), true)
      .setThumbnail(infos.thumbnail);
    msg.channel.send(embed);
  } catch (err) {
    console.error(err);
    msg.channel.send(`An error occurred: ${err.message}`);
  }
});
```

# Note

There is nothing illegal here, the module just searches for the song on Youtube and downloads it.

---
_Source: https://npm.io/package/spdl-core · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
