Skip to content

PANCHO7532/twitch-streamlink-extractor

Repository files navigation

twitch-streamlink-extractor

Extract m3u8 from livestreams/VODs on Twitch

Visit the official npm page here: NPM Page

(project not related to the streamlink project)

Installing

npm install twitch-streamlink-extractor --save

(or just download a zip from here 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

// 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:

[{"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"}]
// 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:

[{"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, 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.

About

Extract m3u8 from livestreams/VODs on Twitch

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published