# youtube-audio-stream

> youtube-audio-stream

Latest version **0.3.61** (published 2022-04-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install youtube-audio-stream
pnpm add youtube-audio-stream
yarn add youtube-audio-stream
bun add youtube-audio-stream
```

Provides the command `youtube-audio-stream`.

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.61 |
| Published | 2022-04-29 |
| First published | 2013-08-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 5.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 355 |
| Maintainers | jameskyburz |
| Keywords | audio, youtube, stream, streaming |

## Links

- npm: https://www.npmjs.com/package/youtube-audio-stream
- Repository: https://github.com/jameskyburz/youtube-audio-stream
- Homepage: https://github.com/jameskyburz/youtube-audio-stream#readme
- Issues: https://github.com/jameskyburz/youtube-audio-stream/issues
- npm.io page: https://npm.io/package/youtube-audio-stream

## Dependencies (2)

- [ytdl-core](https://npm.io/package/ytdl-core.md) 4.11.0
- [fluent-ffmpeg](https://npm.io/package/fluent-ffmpeg.md) 2.1.2

## Alternatives

- [byte-size](https://npm.io/package/byte-size.md) — 2.1M weekly downloads
- [speed-limiter](https://npm.io/package/speed-limiter.md) — 16.0K weekly downloads
- [@powersync/node](https://npm.io/package/@powersync/node.md) — 10.9K weekly downloads
- [@ledgerhq/coin-cardano](https://npm.io/package/@ledgerhq/coin-cardano.md) — 1.0K weekly downloads
- [@jayesol/jayeson.lib.streamfinder](https://npm.io/package/@jayesol/jayeson.lib.streamfinder.md) — 1.0K weekly downloads

## Recent versions

- 0.3.61 (latest) — 2022-04-29
- 0.3.60 — 2022-04-29
- 0.3.59 — 2022-04-29
- 0.3.58 — 2022-03-24
- 0.3.57 — 2022-03-22
- 0.3.56 — 2022-03-22
- 0.3.55 — 2022-02-15
- 0.3.54 — 2022-02-11
- 0.3.53 — 2022-02-08
- 0.3.52 — 2022-02-07
- 0.3.51 — 2022-02-03
- 0.3.50 — 2022-02-02
- 0.3.49 — 2022-01-28
- 0.3.48 — 2022-01-26
- 0.3.47 — 2022-01-25
- … 93 more at https://npm.io/package/youtube-audio-stream/versions

## README

# youtube-audio-stream

[![js-standard-style](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://github.com/feross/standard)
[![ci](https://github.com/JamesKyburz/youtube-audio-stream/actions/workflows/ci.yml/badge.svg)](https://github.com/JamesKyburz/youtube-audio-stream/actions/workflows/ci.yml)

This module streams youtube using [ytdl](https://github.com/fent/node-ytdl) to get the youtube download stream.

To convert to audio the module [fluent-ffmpeg](https://github.com/schaermu/node-fluent-ffmpeg) is used.

You will need to have [ffmpeg](http://www.ffmpeg.org/) and the necessary encoding libraries installed, as well as in your PATH.

If you're on OSX, this can be handled easily using [Homebrew](http://brew.sh/) with `brew install ffmpeg`.

## Getting Started

1. With [npm](http://npmjs.org), run `npm install youtube-audio-stream`
2. `const stream = require('youtube-audio-stream')`

## Usage

Here is an example that:

1. queries for a video by video ID
2. Retrieves the audio via this package
3. write it to `res`

```js
const stream = require('youtube-audio-stream')
async function handleView (req, res) {
  try {
    for await (const chunk of stream(`http://youtube.com/watch?v=${req.params.videoId}`)) {
      res.write(chunk)
    }
    res.end()
  } catch (err) {
    console.error(err)
    if (!res.headersSent) {
      res.writeHead(500)
      res.end('internal system error')
    }
  }
}
```

## Node example playing directly to speaker
```js
const stream = require('youtube-audio-stream')
const url = 'http://youtube.com/watch?v=34aQNMvGEZQ'
const decoder = require('lame').Decoder
const speaker = require('speaker')

stream(url)
.pipe(decoder())
.pipe(speaker())
```

## Testing

This package comes with a simple example for testing. This can be run with the command `npm test`, which will then serve the example at `localhost:3000`. The example consists of an `<audio>` component whose source is retrieved via this package.

### Testing inside a docker container

You can test this module without the need o have [ffmeg](http://www.ffmpeg.org/) locally installed
doing it inside a container.

To build the Docker image:
```
docker build . -t youtube-audio-stream-test
```

To run the test:
```
docker run --rm -it -p 3000:3000 youtube-audio-stream-test
```

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