# twitch-streamlink-extractor

> Extract m3u8's links from Livestreams/VODs in Twitch

Latest version **3.1.2** (published 2024-07-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install twitch-streamlink-extractor
pnpm add twitch-streamlink-extractor
yarn add twitch-streamlink-extractor
bun add twitch-streamlink-extractor
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.1.2 |
| Published | 2024-07-11 |
| First published | 2020-10-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 23.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 11 |
| Author | PANCHO7532 |
| Maintainers | pancho7532 |
| Keywords | livestream, twitch, twitch.tv, vod, links, link extractor, javascript, backend |

## Links

- npm: https://www.npmjs.com/package/twitch-streamlink-extractor
- Repository: https://github.com/PANCHO7532/twitch-streamlink-extractor
- Homepage: https://github.com/PANCHO7532/twitch-streamlink-extractor#readme
- Issues: https://github.com/PANCHO7532/twitch-streamlink-extractor/issues
- npm.io page: https://npm.io/package/twitch-streamlink-extractor

## Dependencies (1)

- [m3u8-file-parser](https://npm.io/package/m3u8-file-parser.md) ^0.2.4

## 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

- 3.1.2 (latest) — 2024-07-11
- 3.1.1 — 2024-07-11
- 3.1.0 — 2024-07-11
- 3.0.1 — 2024-07-09
- 3.0.0 — 2024-07-09
- 2.0.1 — 2021-03-01
- 2.0.0 — 2021-03-01
- 1.0.2 — 2020-11-15
- 1.0.1 — 2020-10-29
- 1.0.0 — 2020-10-28
- 0.0.2 — 2020-10-26
- 0.0.1 — 2020-10-26

## README

# twitch-streamlink-extractor
Extract m3u8 from livestreams/VODs on Twitch

Visit the official npm page here: [NPM Page](https://www.npmjs.com/package/twitch-streamlink-extractor)

#### (project not related to the streamlink project)

## Installing
```bash
npm install twitch-streamlink-extractor --save
```

(or just download a zip from [here](https://github.com/PANCHO7532/twitch-streamlink-extractor/archive/master.zip) and append it manually to your Node.JS project)

## Functions/API/Usage
### .extract(channel_name_or_vod_id, client_id, device_id, oauth_token, useragent)
Description: Retrieve and parse the master m3u8 file obtained from the Usher API on Twitch.

#### channel_name - [string or number]
The channel or VOD number that you want to extract.

#### client_id - [string]
Twitch Client ID that you will use for the request.

#### device_id - [string]
Some Device ID that will be used to identify your request to the server as it came *from that* device

#### oauth_token - [string - optional]
OAuth token of an real Twitch account, if not provided, it will be set to "undefined"

This can be used for retrieve restricted streams that normally with an public/no-account can't be watched.

#### useragent - [string - optional]
HTTP User Agent for the API requests, if not provided, it will use an default one.

### .getToken(channel_name_or_vod_id, client_id, device_id, oauth_token, useragent)
Description: Retrieve the authorization token for the Usher API and a valid signature

#### channel_name - [string or number]
The channel or VOD number that you want to extract.

#### client_id - [string]
Twitch client id that you will use for the request.

#### device_id - [string]
Some Device ID that will be used to identify your request to the server as it came *from that* device

#### oauth_token - [string - optional]
OAuth token of an real Twitch account, if not provided, it will be set to "undefined"

This can be used for retrieve restricted streams that normally with an public/no-account can't be watched.

#### useragent - [string - optional]
HTTP User Agent for the API requests, if not provided, it will use an default one.

### .getMaster(token, signature, channel_name, useragent)
Description: Retrieve the master m3u8 file from the Usher API on Twitch

#### token - [json string]
The JSON token string retrieved from Twitch API

#### signature - [string]
Hashed signature string retrieved from Twitch API

#### channel_name - [string or number]
The channel or VOD number that you want to extract.

#### useragent - [string - optional]
HTTP User Agent for the API requests, if not provided, it will use an default one.

## Usage Examples
```js
// Example of getting an m3u8's from an actual livestream using the example values.
const twitchStream = require('twitch-streamlink-extractor');
var returnedData = await twitchStream.extract("awesome_channel_name", "jknof83ly4odx7cthm5nv7xji6h2ek", "gw45n55ceowp2klfhpcjvp0cy95xed", "fv34m44bdnvo1jkegobiuo9bx84", "Mozilla/4.0; (UserAgent/1.0");
console.log(returnedData)
```

Returned data for the requested livestream should look like this:
```json
[{"quality":"1080p","link":"https://video-weaver.jfk04.hls.ttvnw.net/v1/playlist/CqAENULH9QMi75PRzZb-VqJFT...z89g.m3u8"},{"quality":"720p60","link":"https://video-weaver.jfk04.hls.ttvnw.net/v1/playlist/Cp4EKo_punwHjm9MQcXm...wg.m3u8"},{"quality":"720p30","link":"https://video-weaver.jfk04.hls.ttvnw.net/v1/playlist/Cp4EakBjgnDikohPqD501YcaW0sQe8SiuULC0...GxA.m3u8"},{"quality":"480p30","link":"https://video-weaver.jfk04.hls.ttvnw.net/v1/playlist/Cp4ELeLn9jqhb1jgrUoa7xFfqQl...VKZ2tAZ1w.m3u8"},{"quality":"360p30","link":"https://video-weaver.jfk04.hls.ttvnw.net/v1/playlist/Cp4E_ldXeK0EeE0woAtn7...PlpNdWiQ.m3u8"},{"quality":"160p30","link":"https://video-weaver.jfk04.hls.ttvnw.net/v1/playlist/Cp4ELp4A-lcwFSCa0m...SPPyuA.m3u8"},{"quality":"audio_only","link":"https://video-weaver.jfk04.hls.ttvnw.net/v1/playlist/CroEgFSchiJalTMO...7YqCs.m3u8"}]
```

```js
// Example of getting an m3u8's from an actual VOD using the example values.
const twitchStream = require('twitch-streamlink-extractor');
var returnedData = await twitchStream.extract("vod_number_id", "jknof83ly4odx7cthm5nv7xji6h2ek", "gw45n55ceowp2klfhpcjvp0cy95xed", "fv34m44bdnvo1jkegobiuo9bx84", "Mozilla/4.0; (UserAgent/1.0");
console.log(returnedData)
```

Returned data for the requested VOD should look like this:
```json
[{"quality":"1080p","link":"https://d2nvs31859zcd8.cloudfront.net/c2c985c.../chunked/index-dvr.m3u8"},{"quality":"720p60","link":"https://d2nvs31859zcd8.cloudfront.net/c2c985c.../720p60/index-dvr.m3u8"},{"quality":"720p30","link":"https://d2nvs31859zcd8.cloudfront.net/c2c985c.../720p30/index-dvr.m3u8"},{"quality":"480p30","link":"https://d2nvs31859zcd8.cloudfront.net/c2c985c.../480p30/index-dvr.m3u8"},{"quality":"360p30","link":"https://d2nvs31859zcd8.cloudfront.net/c2c985c.../360p30/index-dvr.m3u8"},{"quality":"160p30","link":"https://d2nvs31859zcd8.cloudfront.net/c2c985c.../160p30/index-dvr.m3u8"},{"quality":"audio_only","link":"https://d2nvs31859zcd8.cloudfront.net/c2c985c.../audio-only/index-dvr.m3u8"}]
```

## How to obtain an Client-ID and Device-ID
There are many ways on obtaining it, the main one is by opening the developer tools on a twitch stream and capturing it from the headers of `gql.twitch.tv` requests, also you can try on registering an app on [https://dev.twitch.tv](https://dev.twitch.tv), keep on mind this last option might give you a valid Client-ID, but you 100% have to extract the Device-ID from GQL headers.

An example of how a valid client ID for Twitch should look like: `jknof83ly4odx7cthm5nv7xji6h2ek`

An example of how a valid device ID for Twitch should look like: `gw45n55ceowp2klfhpcjvp0cy95xed`

(Please note these aren't valid IDs and you shouldn't use them)

## How to obtain my OAuth token
As you may have guessed, you can obtain it too by opening developer tools on a twitch stream and capturing it from the Authorization header of gql.twitch.tv requests, it should look like "Authorization: OAuth fv34m44bdnvo1jkegobiuo9bx84" where "fv34m44bdnvo1jkegobiuo9bx84" is the token you should use on OAuth parameters of this script.

An example of an OAuth token is: `fv34m44bdnvo1jkegobiuo9bx84`

(Please note this is not a valid token and you shouldn't use it)

## Future of this project - Long term releases - Disclaimer
This project may or may not be patched by me if Twitch makes changes on how it retrieves the stream/VOD information, however feel free to make a pull request with updates/bugfixes.

No copyright intended, you use this tool as you want, i'm not responsible of anything.

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