1
0
mirror of https://github.com/musix-org/musix-oss synced 2025-06-17 01:16:00 +00:00
This commit is contained in:
MatteZ02
2020-03-03 22:30:50 +02:00
parent edfcc6f474
commit 30022c7634
11800 changed files with 1984416 additions and 1 deletions

21
node_modules/ytdl-core/LICENSE generated vendored Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (C) 2012-present by fent
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

198
node_modules/ytdl-core/README.md generated vendored Normal file
View File

@ -0,0 +1,198 @@
# node-ytdl-core
[![Dependency Status](https://david-dm.org/fent/node-ytdl-core.svg)](https://david-dm.org/fent/node-ytdl-core)
[![codecov](https://codecov.io/gh/fent/node-ytdl-core/branch/master/graph/badge.svg)](https://codecov.io/gh/fent/node-ytdl-core)
[![Discord](https://img.shields.io/discord/484464227067887645.svg)](https://discord.gg/V3vSCs7)
Yet another youtube downloading module. Written with only Javascript and a node-friendly streaming interface.
# Support
You can contact us for support on our [chat server](https://discord.gg/V3vSCs7)
# Usage
```js
const fs = require('fs');
const ytdl = require('ytdl-core');
// TypeScript: import ytdl from 'ytdl-core'; with --esModuleInterop
// TypeScript: import * as ytdl from 'ytdl-core'; with --allowSyntheticDefaultImports
// TypeScript: import ytdl = require('ytdl-core'); with neither of the above
ytdl('http://www.youtube.com/watch?v=A02s8omM_hI')
.pipe(fs.createWriteStream('video.flv'));
```
# API
### ytdl(url, [options])
Attempts to download a video from the given url. Returns a [readable stream](https://nodejs.org/api/stream.html#stream_class_stream_readable). `options` can have the following keys
* `quality` - Video quality to download. Can be an [itag value](http://en.wikipedia.org/wiki/YouTube#Quality_and_formats), a list of itag values, or `highest`/`lowest`/`highestaudio`/`lowestaudio`/`highestvideo`/`lowestvideo`. `highestaudio`/`lowestaudio`/`highestvideo`/`lowestvideo` all prefer audio/video only respectively. Defaults to `highest`, which prefers formats with both video and audio.
A typical video's formats will be sorted in the follwing way using `quality: 'highest'`
```
itag container quality codecs bitrate audio bitrate
18 mp4 360p avc1.42001E, mp4a.40.2 696.66KB 96KB
137 mp4 1080p avc1.640028 4.53MB
248 webm 1080p vp9 2.52MB
136 mp4 720p avc1.4d4016 2.2MB
247 webm 720p vp9 1.44MB
135 mp4 480p avc1.4d4014 1.1MB
134 mp4 360p avc1.4d401e 593.26KB
140 mp4 mp4a.40.2 128KB
```
format 18 at 360p will be chosen first since it's the highest quality format with both video and audio.
* `filter` - Used to filter the list of formats to choose from. Can be `audioandvideo` to filter formats that contain both video and audio, `video` to filter for formats that contain video, or `videoonly` for formats that contain video and no additional audio track. Can also be `audio` or `audioonly`. You can give a filtering function that gets called with each format available. This function is given the `format` object as its first argument, and should return true if the format is preferable.
```js
// Example with custom function.
ytdl(url, { filter: format => format.container === 'mp4' })
```
* `format` - Primarily used to download specific video or audio streams. This can be a specific `format` object returned from `getInfo`.
* Supplying this option will ignore the `filter` and `quality` options since the format is explicitly provided.
* `range` - A byte range in the form `{start: INT, end: INT}` that specifies part of the file to download, ie {start: 10355705, end: 12452856}.
* This downloads a portion of the file, and not a separately spliced video.
* `begin` - What time in the video to begin. Supports formats `00:00:00.000`, `0ms, 0s, 0m, 0h`, or number of milliseconds. Example: `1:30`, `05:10.123`, `10m30s`.
* For live videos, this also accepts a unix timestamp or Date, and defaults to `Date.now()`.
* This option is not very reliable, see [#129](https://github.com/fent/node-ytdl-core/issues/129), [#219](https://github.com/fent/node-ytdl-core/issues/219).
* `liveBuffer` - How much time buffer to use for live videos in milliseconds. Default is `20000`.
* `requestOptions` - Anything to merge into the request options which [miniget](https://github.com/fent/node-miniget) is called with, such as `headers`.
* `highWaterMark` - How much of the video download to buffer into memory. See [node's docs](https://nodejs.org/api/stream.html#stream_constructor_new_stream_writable_options) for more.
* `lang` - The 2 character symbol of a language. Default is `en`.
#### Event: info
* [`ytdl.videoInfo`](example/info.json) - Info.
* [`ytdl.videoFormat`](typings/index.d.ts#L22) - Video Format.
Emitted when the a video's `info` hash is fetched, along with the chosen format metadata to download. `format.url` might be different if `start` was given.
#### Event: response
* [`http.ServerResponse`](https://nodejs.org/api/http.html#http_class_http_serverresponse) - Response.
Emitted when the video response has been found and has started downloading or after any successful reconnects. Can be used to get the size of the download.
#### Event: progress
* `number` - Chunk byte length.
* `number` - Total bytes or segments downloaded.
* `number` - Total bytes or segments.
Emitted whenever a new chunk is received. Passes values describing the download progress.
### Stream#destroy()
Call to abort and stop downloading a video.
### ytdl.getBasicInfo(url, [options], [callback(err, info)])
Use this if you only want to get metainfo from a video. If `callback` isn't given, returns a promise.
### ytdl.getInfo(url, [options], [callback(err, info)])
Gets metainfo from a video. Includes additional formats, and ready to download deciphered URL. This is what the `ytdl()` function uses internally. If `callback` isn't given, returns a promise.
### ytdl.downloadFromInfo(info, options)
Once you have received metadata from a video with the `ytdl.getInfo` function, you may pass that information along with other options to this function.
### ytdl.chooseFormat(formats, options)
Can be used if you'd like to choose a format yourself with the [options above](#ytdlurl-options).
```js
// Example of choosing a video format.
ytdl.getInfo(videoID, (err, info) => {
if (err) throw err;
let format = ytdl.chooseFormat(info.formats, { quality: '134' });
if (format) {
console.log('Format found!');
}
});
```
### ytdl.filterFormats(formats, filter)
If you'd like to work with only some formats, you can use the [`filter` option above](#ytdlurl-options).
```js
// Example of filtering the formats to audio only.
ytdl.getInfo(videoID, (err, info) => {
if (err) throw err;
let audioFormats = ytdl.filterFormats(info.formats, 'audioonly');
console.log('Formats with only audio: ' + audioFormats.length);
});
```
### ytdl.validateID(id)
Returns true if the given string satisfies YouTube's ID format.
### ytdl.validateURL(url)
Returns true if able to parse out a valid video ID.
### ytdl.getURLVideoID(url)
Returns a video ID from a YouTube URL.
### ytdl.getVideoID(str)
Same as the above `ytdl.getURLVideoID()`, but can be called with the video ID directly, in which case it returns it. This is what ytdl uses internally.
## Limitations
ytdl cannot download videos that fall into the following
* Regionally restricted (requires a [proxy](example/proxy.js))
* Private
* Rentals
YouTube intentionally rate limits downloads, particularly audio only formats, likely to prevent bandwidth abuse. The download rate is still faster than a media player can play the video, even on 2x. See [#294](https://github.com/fent/node-ytdl-core/issues/294).
Generated download links are valid for 6 hours, for the same IP address.
## Handling Separate Streams
Typically 1080p or better video does not have audio encoded with it. The audio must be downloaded separately and merged via an appropriate encoding library. `ffmpeg` is the most widely used tool, with many [Node.js modules available](https://www.npmjs.com/search?q=ffmpeg). Use the `format` objects returned from `ytdl.getInfo` to download specific streams to combine to fit your needs. Look at [example/ffmpeg.js](example/ffmpeg.js) for an example on doing this.
## What if it stops working?
Youtube updates their website all the time, it's not that rare for this to stop working. If it doesn't work for you and you're using the latest version, feel free to open up an issue. Make sure to check if there isn't one already with the same error.
If you'd like to help fix the issue, look at the type of error first. The most common one is
Could not extract signature deciphering actions
Run the tests at `test/irl-test.js` just to make sure that this is actually an issue with ytdl-core.
mocha test/irl-test.js
These tests are not mocked, and they actually try to start downloading a few videos. If these fail, then it's time to debug.
For getting started with that, you can look at the `extractActions()` function in [`/lib/sig.js`](https://github.com/fent/node-ytdl-core/blob/master/lib/sig.js).
# Install
```bash
npm install ytdl-core@latest
```
Or for Yarn users:
```bash
yarn add ytdl-core@latest
```
If you're using a bot or app that uses ytdl-core, it may be dependent on an older version. Make sure you're installing the latest version of ytdl-core to keep up with the latest fixes.
# Related Projects
- [ytdl](https://github.com/fent/node-ytdl) - A cli wrapper of this.
- [pully](https://github.com/JimmyBoh/pully) - Another cli wrapper of this aimed at high quality formats.
- [ytsr](https://github.com/TimeForANinja/node-ytsr) - YouTube video search results.
- [ytpl](https://github.com/TimeForANinja/node-ytpl) - YouTube playlist and channel resolver.
# Tests
Tests are written with [mocha](https://mochajs.org)
```bash
npm test
```

32
node_modules/ytdl-core/lib/cache.js generated vendored Normal file
View File

@ -0,0 +1,32 @@
// A cache that expires.
module.exports = class Cache extends Map {
constructor() {
super();
this.timeout = 1000;
}
set(key, value) {
super.set(key, {
tid: setTimeout(this.delete.bind(this, key), this.timeout),
value,
});
}
get(key) {
let entry = super.get(key);
if (entry) {
return entry.value;
}
}
delete(key) {
let entry = super.get(key);
if (entry) {
clearTimeout(entry.tid);
super.delete(key);
}
}
clear() {
for (let entry of this.values()) {
clearTimeout(entry.tid);
}
super.clear();
}
};

517
node_modules/ytdl-core/lib/formats.js generated vendored Normal file
View File

@ -0,0 +1,517 @@
/**
* http://en.wikipedia.org/wiki/YouTube#Quality_and_formats
*/
module.exports = {
'5': {
mimeType: 'video/flv; codecs="Sorenson H.283, mp3"',
qualityLabel: '240p',
bitrate: 250000,
audioBitrate: 64,
},
'6': {
mimeType: 'video/flv; codecs="Sorenson H.263, mp3"',
qualityLabel: '270p',
bitrate: 800000,
audioBitrate: 64,
},
'13': {
mimeType: 'video/3gp; codecs="MPEG-4 Visual, aac"',
qualityLabel: null,
bitrate: 500000,
audioBitrate: null,
},
'17': {
mimeType: 'video/3gp; codecs="MPEG-4 Visual, aac"',
qualityLabel: '144p',
bitrate: 50000,
audioBitrate: 24,
},
'18': {
mimeType: 'video/mp4; codecs="H.264, aac"',
qualityLabel: '360p',
bitrate: 500000,
audioBitrate: 96,
},
'22': {
mimeType: 'video/mp4; codecs="H.264, aac"',
qualityLabel: '720p',
bitrate: 2000000,
audioBitrate: 192,
},
'34': {
mimeType: 'video/flv; codecs="H.264, aac"',
qualityLabel: '360p',
bitrate: 500000,
audioBitrate: 128,
},
'35': {
mimeType: 'video/flv; codecs="H.264, aac"',
qualityLabel: '480p',
bitrate: 800000,
audioBitrate: 128,
},
'36': {
mimeType: 'video/3gp; codecs="MPEG-4 Visual, aac"',
qualityLabel: '240p',
bitrate: 175000,
audioBitrate: 32,
},
'37': {
mimeType: 'video/mp4; codecs="H.264, aac"',
qualityLabel: '1080p',
bitrate: 3000000,
audioBitrate: 192,
},
'38': {
mimeType: 'video/mp4; codecs="H.264, aac"',
qualityLabel: '3072p',
bitrate: 3500000,
audioBitrate: 192,
},
'43': {
mimeType: 'video/webm; codecs="VP8, vorbis"',
qualityLabel: '360p',
bitrate: 500000,
audioBitrate: 128,
},
'44': {
mimeType: 'video/webm; codecs="VP8, vorbis"',
qualityLabel: '480p',
bitrate: 1000000,
audioBitrate: 128,
},
'45': {
mimeType: 'video/webm; codecs="VP8, vorbis"',
qualityLabel: '720p',
bitrate: 2000000,
audioBitrate: 192,
},
'46': {
mimeType: 'audio/webm; codecs="vp8, vorbis"',
qualityLabel: '1080p',
bitrate: null,
audioBitrate: 192,
},
'82': {
mimeType: 'video/mp4; codecs="H.264, aac"',
qualityLabel: '360p',
bitrate: 500000,
audioBitrate: 96,
},
'83': {
mimeType: 'video/mp4; codecs="H.264, aac"',
qualityLabel: '240p',
bitrate: 500000,
audioBitrate: 96,
},
'84': {
mimeType: 'video/mp4; codecs="H.264, aac"',
qualityLabel: '720p',
bitrate: 2000000,
audioBitrate: 192,
},
'85': {
mimeType: 'video/mp4; codecs="H.264, aac"',
qualityLabel: '1080p',
bitrate: 3000000,
audioBitrate: 192,
},
'91': {
mimeType: 'video/ts; codecs="H.264, aac"',
qualityLabel: '144p',
bitrate: 100000,
audioBitrate: 48,
},
'92': {
mimeType: 'video/ts; codecs="H.264, aac"',
qualityLabel: '240p',
bitrate: 150000,
audioBitrate: 48,
},
'93': {
mimeType: 'video/ts; codecs="H.264, aac"',
qualityLabel: '360p',
bitrate: 500000,
audioBitrate: 128,
},
'94': {
mimeType: 'video/ts; codecs="H.264, aac"',
qualityLabel: '480p',
bitrate: 800000,
audioBitrate: 128,
},
'95': {
mimeType: 'video/ts; codecs="H.264, aac"',
qualityLabel: '720p',
bitrate: 1500000,
audioBitrate: 256,
},
'96': {
mimeType: 'video/ts; codecs="H.264, aac"',
qualityLabel: '1080p',
bitrate: 2500000,
audioBitrate: 256,
},
'100': {
mimeType: 'audio/webm; codecs="VP8, vorbis"',
qualityLabel: '360p',
bitrate: null,
audioBitrate: 128,
},
'101': {
mimeType: 'audio/webm; codecs="VP8, vorbis"',
qualityLabel: '360p',
bitrate: null,
audioBitrate: 192,
},
'102': {
mimeType: 'audio/webm; codecs="VP8, vorbis"',
qualityLabel: '720p',
bitrate: null,
audioBitrate: 192,
},
'120': {
mimeType: 'video/flv; codecs="H.264, aac"',
qualityLabel: '720p',
bitrate: 2000000,
audioBitrate: 128,
},
'127': {
mimeType: 'audio/ts; codecs="aac"',
qualityLabel: null,
bitrate: null,
audioBitrate: 96,
},
'128': {
mimeType: 'audio/ts; codecs="aac"',
qualityLabel: null,
bitrate: null,
audioBitrate: 96,
},
'132': {
mimeType: 'video/ts; codecs="H.264, aac"',
qualityLabel: '240p',
bitrate: 150000,
audioBitrate: 48,
},
'133': {
mimeType: 'video/mp4; codecs="H.264"',
qualityLabel: '240p',
bitrate: 200000,
audioBitrate: null,
},
'134': {
mimeType: 'video/mp4; codecs="H.264"',
qualityLabel: '360p',
bitrate: 300000,
audioBitrate: null,
},
'135': {
mimeType: 'video/mp4; codecs="H.264"',
qualityLabel: '480p',
bitrate: 500000,
audioBitrate: null,
},
'136': {
mimeType: 'video/mp4; codecs="H.264"',
qualityLabel: '720p',
bitrate: 1000000,
audioBitrate: null,
},
'137': {
mimeType: 'video/mp4; codecs="H.264"',
qualityLabel: '1080p',
bitrate: 2500000,
audioBitrate: null,
},
'138': {
mimeType: 'video/mp4; codecs="H.264"',
qualityLabel: '4320p',
bitrate: 13500000,
audioBitrate: null,
},
'139': {
mimeType: 'audio/mp4; codecs="aac"',
qualityLabel: null,
bitrate: null,
audioBitrate: 48,
},
'140': {
mimeType: 'audio/m4a; codecs="aac"',
qualityLabel: null,
bitrate: null,
audioBitrate: 128,
},
'141': {
mimeType: 'audio/mp4; codecs="aac"',
qualityLabel: null,
bitrate: null,
audioBitrate: 256,
},
'151': {
mimeType: 'video/ts; codecs="H.264, aac"',
qualityLabel: '720p',
bitrate: 50000,
audioBitrate: 24,
},
'160': {
mimeType: 'video/mp4; codecs="H.264"',
qualityLabel: '144p',
bitrate: 100000,
audioBitrate: null,
},
'171': {
mimeType: 'audio/webm; codecs="vorbis"',
qualityLabel: null,
bitrate: null,
audioBitrate: 128,
},
'172': {
mimeType: 'audio/webm; codecs="vorbis"',
qualityLabel: null,
bitrate: null,
audioBitrate: 192,
},
'242': {
mimeType: 'video/webm; codecs="VP9"',
qualityLabel: '240p',
bitrate: 100000,
audioBitrate: null,
},
'243': {
mimeType: 'video/webm; codecs="VP9"',
qualityLabel: '360p',
bitrate: 250000,
audioBitrate: null,
},
'244': {
mimeType: 'video/webm; codecs="VP9"',
qualityLabel: '480p',
bitrate: 500000,
audioBitrate: null,
},
'247': {
mimeType: 'video/webm; codecs="VP9"',
qualityLabel: '720p',
bitrate: 700000,
audioBitrate: null,
},
'248': {
mimeType: 'video/webm; codecs="VP9"',
qualityLabel: '1080p',
bitrate: 1500000,
audioBitrate: null,
},
'249': {
mimeType: 'audio/webm; codecs="opus"',
qualityLabel: null,
bitrate: null,
audioBitrate: 48,
},
'250': {
mimeType: 'audio/webm; codecs="opus"',
qualityLabel: null,
bitrate: null,
audioBitrate: 64,
},
'251': {
mimeType: 'audio/webm; codecs="opus"',
qualityLabel: null,
bitrate: null,
audioBitrate: 160,
},
'264': {
mimeType: 'video/mp4; codecs="H.264"',
qualityLabel: '1440p',
bitrate: 4000000,
audioBitrate: null,
},
'266': {
mimeType: 'video/mp4; codecs="H.264"',
qualityLabel: '2160p',
bitrate: 12500000,
audioBitrate: null,
},
'271': {
mimeType: 'video/webm; codecs="VP9"',
qualityLabel: '1440p',
bitrate: 9000000,
audioBitrate: null,
},
'272': {
mimeType: 'video/webm; codecs="VP9"',
qualityLabel: '4320p',
bitrate: 20000000,
audioBitrate: null,
},
'278': {
mimeType: 'video/webm; codecs="VP9"',
qualityLabel: '144p 15fps',
bitrate: 80000,
audioBitrate: null,
},
'298': {
mimeType: 'video/mp4; codecs="H.264"',
qualityLabel: '720p',
bitrate: 3000000,
audioBitrate: null,
},
'299': {
mimeType: 'video/mp4; codecs="H.264"',
qualityLabel: '1080p',
bitrate: 5500000,
audioBitrate: null,
},
'302': {
mimeType: 'video/webm; codecs="VP9"',
qualityLabel: '720p HFR',
bitrate: 2500000,
audioBitrate: null,
},
'303': {
mimeType: 'video/webm; codecs="VP9"',
qualityLabel: '1080p HFR',
bitrate: 5000000,
audioBitrate: null,
},
'308': {
mimeType: 'video/webm; codecs="VP9"',
qualityLabel: '1440p HFR',
bitrate: 10000000,
audioBitrate: null,
},
'313': {
mimeType: 'video/webm; codecs="VP9"',
qualityLabel: '2160p',
bitrate: 13000000,
audioBitrate: null,
},
'315': {
mimeType: 'video/webm; codecs="VP9"',
qualityLabel: '2160p HFR',
bitrate: 20000000,
audioBitrate: null,
},
'330': {
mimeType: 'video/webm; codecs="VP9"',
qualityLabel: '144p HDR, HFR',
bitrate: 80000,
audioBitrate: null,
},
'331': {
mimeType: 'video/webm; codecs="VP9"',
qualityLabel: '240p HDR, HFR',
bitrate: 100000,
audioBitrate: null,
},
'332': {
mimeType: 'video/webm; codecs="VP9"',
qualityLabel: '360p HDR, HFR',
bitrate: 250000,
audioBitrate: null,
},
'333': {
mimeType: 'video/webm; codecs="VP9"',
qualityLabel: '240p HDR, HFR',
bitrate: 500000,
audioBitrate: null,
},
'334': {
mimeType: 'video/webm; codecs="VP9"',
qualityLabel: '720p HDR, HFR',
bitrate: 1000000,
audioBitrate: null,
},
'335': {
mimeType: 'video/webm; codecs="VP9"',
qualityLabel: '1080p HDR, HFR',
bitrate: 1500000,
audioBitrate: null,
},
'336': {
mimeType: 'video/webm; codecs="VP9"',
qualityLabel: '1440p HDR, HFR',
bitrate: 5000000,
audioBitrate: null,
},
'337': {
mimeType: 'video/webm; codecs="VP9"',
qualityLabel: '2160p HDR, HFR',
bitrate: 12000000,
audioBitrate: null,
}
};

158
node_modules/ytdl-core/lib/index.js generated vendored Normal file
View File

@ -0,0 +1,158 @@
const PassThrough = require('stream').PassThrough;
const getInfo = require('./info');
const util = require('./util');
const sig = require('./sig');
const request = require('miniget');
const m3u8stream = require('m3u8stream');
const parseTime = require('m3u8stream/dist/parse-time');
/**
* @param {string} link
* @param {!Object} options
* @return {ReadableStream}
*/
const ytdl = (link, options) => {
const stream = createStream(options);
ytdl.getInfo(link, options, (err, info) => {
if (err) {
stream.emit('error', err);
return;
}
downloadFromInfoCallback(stream, info, options);
});
return stream;
};
module.exports = ytdl;
ytdl.getBasicInfo = getInfo.getBasicInfo;
ytdl.getInfo = getInfo.getFullInfo;
ytdl.chooseFormat = util.chooseFormat;
ytdl.filterFormats = util.filterFormats;
ytdl.validateID = util.validateID;
ytdl.validateURL = util.validateURL;
ytdl.getURLVideoID = util.getURLVideoID;
ytdl.getVideoID = util.getVideoID;
ytdl.cache = {
sig: sig.cache,
info: getInfo.cache,
};
const createStream = (options) => {
const stream = new PassThrough({
highWaterMark: options && options.highWaterMark || null,
});
stream.destroy = () => { stream._isDestroyed = true; };
return stream;
};
/**
* Chooses a format to download.
*
* @param {stream.Readable} stream
* @param {Object} info
* @param {Object} options
*/
const downloadFromInfoCallback = (stream, info, options) => {
options = options || {};
const format = util.chooseFormat(info.formats, options);
if (format instanceof Error) {
// The caller expects this function to be async.
setImmediate(() => {
stream.emit('error', format);
});
return;
}
stream.emit('info', info, format);
if (stream._isDestroyed) { return; }
let contentLength, downloaded = 0;
const ondata = (chunk) => {
downloaded += chunk.length;
stream.emit('progress', chunk.length, downloaded, contentLength);
};
let req;
if (format.isHLS || format.isDashMPD) {
req = m3u8stream(format.url, {
chunkReadahead: +info.live_chunk_readahead,
begin: options.begin || format.live && Date.now(),
liveBuffer: options.liveBuffer,
requestOptions: options.requestOptions,
parser: format.isDashMPD ? 'dash-mpd' : 'm3u8',
id: format.itag,
});
req.on('progress', (segment, totalSegments) => {
stream.emit('progress', segment.size, segment.num, totalSegments);
});
} else {
if (options.begin) {
format.url += '&begin=' + parseTime.humanStr(options.begin);
}
let requestOptions = Object.assign({}, options.requestOptions, {
maxReconnects: 6,
maxRetries: 3,
backoff: { inc: 500, max: 10000 },
});
if (options.range && (options.range.start || options.range.end)) {
requestOptions.headers = Object.assign({}, requestOptions.headers, {
Range: `bytes=${options.range.start || '0'}-${options.range.end || ''}`
});
}
req = request(format.url, requestOptions);
req.on('response', (res) => {
if (stream._isDestroyed) { return; }
if (!contentLength) {
contentLength = parseInt(res.headers['content-length'], 10);
}
});
req.on('data', ondata);
}
stream.destroy = () => {
stream._isDestroyed = true;
if (req.abort) req.abort();
req.end();
req.removeListener('data', ondata);
req.unpipe();
};
// Forward events from the request to the stream.
[
'abort', 'request', 'response', 'error', 'retry', 'reconnect'
].forEach((event) => {
req.prependListener(event, (arg) => {
stream.emit(event, arg); });
});
req.pipe(stream);
};
/**
* Can be used to download video after its `info` is gotten through
* `ytdl.getInfo()`. In case the user might want to look at the
* `info` object before deciding to download.
*
* @param {Object} info
* @param {!Object} options
*/
ytdl.downloadFromInfo = (info, options) => {
const stream = createStream(options);
if (!info.full) {
throw Error('Cannot use `ytdl.downloadFromInfo()` when called ' +
'with info from `ytdl.getBasicInfo()`');
}
setImmediate(() => {
downloadFromInfoCallback(stream, info, options);
});
return stream;
};

171
node_modules/ytdl-core/lib/info-extras.js generated vendored Normal file
View File

@ -0,0 +1,171 @@
const qs = require('querystring');
const url = require('url');
const Entities = require('html-entities').AllHtmlEntities;
const util = require('./util');
const parseTime = require('m3u8stream/dist/parse-time');
const VIDEO_URL = 'https://www.youtube.com/watch?v=';
const getMetaItem = (body, name) => {
return util.between(body, `<meta itemprop="${name}" content="`, '">');
};
/**
* Get video description from html
*
* @param {string} html
* @return {string}
*/
exports.getVideoDescription = (html) => {
const regex = /<p.*?id="eow-description".*?>(.+?)<\/p>[\n\r\s]*?<\/div>/im;
const description = html.match(regex);
return description ?
Entities.decode(util.stripHTML(description[1])) : '';
};
/**
* Get video media (extra information) from html
*
* @param {string} body
* @return {Object}
*/
exports.getVideoMedia = (body) => {
let mediainfo = util.between(body,
'<div id="watch-description-extras">',
'<div id="watch-discussion" class="branded-page-box yt-card">');
if (mediainfo === '') {
return {};
}
const regexp = /<h4 class="title">([\s\S]*?)<\/h4>[\s\S]*?<ul .*?class=".*?watch-info-tag-list">[\s\S]*?<li>([\s\S]*?)<\/li>(?:\s*?<li>([\s\S]*?)<\/li>)?/g;
const contentRegexp = /(?: - (\d{4}) \()?<a .*?(?:href="([^"]+)")?.*?>(.*?)<\/a>/;
const imgRegexp = /<img src="([^"]+)".*?>/;
const media = {};
const image = imgRegexp.exec(mediainfo);
if (image) {
media.image = url.resolve(VIDEO_URL, image[1]);
}
let match;
while ((match = regexp.exec(mediainfo)) != null) {
let [, key, value, detail] = match;
key = Entities.decode(key).trim().replace(/\s/g, '_').toLowerCase();
const content = contentRegexp.exec(value);
if (content) {
let [, year, mediaUrl, value2] = content;
if (year) {
media.year = parseInt(year);
} else if (detail) {
media.year = parseInt(detail);
}
value = value.slice(0, content.index);
if (key !== 'game' || value2 !== 'YouTube Gaming') {
value += value2;
}
media[key + '_url'] = url.resolve(VIDEO_URL, mediaUrl);
}
media[key] = Entities.decode(value);
}
return media;
};
/**
* Get video Owner from html.
*
* @param {string} body
* @return {Object}
*/
const userRegexp = /<a href="\/user\/([^"]+)/;
const verifiedRegexp = /<span .*?(aria-label="Verified")(.*?(?=<\/span>))/;
exports.getAuthor = (body) => {
let ownerinfo = util.between(body,
'<div id="watch7-user-header" class=" spf-link ">',
'<div id="watch8-action-buttons" class="watch-action-buttons clearfix">');
if (ownerinfo === '') {
return {};
}
const channelName = Entities.decode(util.between(util.between(
ownerinfo, '<div class="yt-user-info">', '</div>'), '>', '</a>'));
const userMatch = ownerinfo.match(userRegexp);
const verifiedMatch = ownerinfo.match(verifiedRegexp);
const channelID = getMetaItem(body, 'channelId');
const username = userMatch ? userMatch[1] : util.between(
util.between(body, '<span itemprop="author"', '</span>'), '/user/', '">');
return {
id: channelID,
name: channelName,
avatar: url.resolve(VIDEO_URL, util.between(ownerinfo,
'data-thumb="', '"')),
verified: !!verifiedMatch,
user: username,
channel_url: 'https://www.youtube.com/channel/' + channelID,
user_url: 'https://www.youtube.com/user/' + username,
};
};
/**
* Get video published at from html.
*
* @param {string} body
* @return {string}
*/
exports.getPublished = (body) => {
return Date.parse(getMetaItem(body, 'datePublished'));
};
/**
* Get video published at from html.
* Credits to https://github.com/paixaop.
*
* @param {string} body
* @return {Array.<Object>}
*/
exports.getRelatedVideos = (body) => {
let jsonStr = util.between(body, '\'RELATED_PLAYER_ARGS\': ', ',\n');
let watchNextJson, rvsParams, secondaryResults;
try {
jsonStr = JSON.parse(jsonStr);
watchNextJson = JSON.parse(jsonStr.watch_next_response);
rvsParams = jsonStr.rvs.split(',').map((e) => qs.parse(e));
secondaryResults = watchNextJson.contents.twoColumnWatchNextResults.secondaryResults.secondaryResults.results;
}
catch (err) {
return [];
}
let videos = [];
for (let result of secondaryResults) {
let details = result.compactVideoRenderer;
if (details) {
try {
let viewCount = details.viewCountText.simpleText;
let shortViewCount = details.shortViewCountText.simpleText;
let rvsDetails = rvsParams.find((elem) => elem.id === details.videoId);
if (!/^\d/.test(shortViewCount)) {
shortViewCount = rvsDetails && rvsDetails.short_view_count_text || '';
}
viewCount = (/^\d/.test(viewCount) ? viewCount : shortViewCount).split(' ')[0];
videos.push({
id: details.videoId,
title: details.title.simpleText,
author: details.shortBylineText.runs[0].text,
ucid: details.shortBylineText.runs[0].navigationEndpoint.browseEndpoint.browseId,
author_thumbnail: details.channelThumbnail.thumbnails[0].url,
short_view_count_text: shortViewCount.split(' ')[0],
view_count: viewCount.replace(',', ''),
length_seconds: details.lengthText ?
Math.floor(parseTime.humanStr(details.lengthText.simpleText) / 1000) :
rvsParams && rvsParams.length_seconds + '',
video_thumbnail: details.thumbnail.thumbnails[0].url,
});
} catch (err) {
continue;
}
}
}
return videos;
};

348
node_modules/ytdl-core/lib/info.js generated vendored Normal file
View File

@ -0,0 +1,348 @@
const urllib = require('url');
const querystring = require('querystring');
const sax = require('sax');
const request = require('miniget');
const util = require('./util');
const extras = require('./info-extras');
const sig = require('./sig');
const Cache = require('./cache');
const VIDEO_URL = 'https://www.youtube.com/watch?v=';
const EMBED_URL = 'https://www.youtube.com/embed/';
const VIDEO_EURL = 'https://youtube.googleapis.com/v/';
const INFO_HOST = 'www.youtube.com';
const INFO_PATH = '/get_video_info';
/**
* Gets info from a video without getting additional formats.
*
* @param {string} id
* @param {Object} options
* @param {Function(Error, Object)} callback
*/
exports.getBasicInfo = (id, options, callback) => {
// Try getting config from the video page first.
const params = 'hl=' + (options.lang || 'en');
let url = VIDEO_URL + id + '&' + params +
'&bpctr=' + Math.ceil(Date.now() / 1000);
// Remove header from watch page request.
// Otherwise, it'll use a different framework for rendering content.
const reqOptions = Object.assign({}, options.requestOptions);
reqOptions.headers = Object.assign({}, reqOptions.headers, {
'User-Agent': '',
});
request(url, reqOptions, (err, res, body) => {
if (err) return callback(err);
// Check if there are any errors with this video page.
const unavailableMsg = util.between(body, '<div id="player-unavailable"', '>');
if (unavailableMsg &&
!/\bhid\b/.test(util.between(unavailableMsg, 'class="', '"'))) {
// Ignore error about age restriction.
if (!body.includes('<div id="watch7-player-age-gate-content"')) {
return callback(Error(util.between(body,
'<h1 id="unavailable-message" class="message">', '</h1>').trim()));
}
}
// Parse out additional metadata from this page.
const additional = {
// Get the author/uploader.
author: extras.getAuthor(body),
// Get the day the vid was published.
published: extras.getPublished(body),
// Get description.
description: extras.getVideoDescription(body),
// Get media info.
media: extras.getVideoMedia(body),
// Get related videos.
related_videos: extras.getRelatedVideos(body),
};
const jsonStr = util.between(body, 'ytplayer.config = ', '</script>');
let config;
if (jsonStr) {
config = jsonStr.slice(0, jsonStr.lastIndexOf(';ytplayer.load'));
gotConfig(id, options, additional, config, false, callback);
} else {
// If the video page doesn't work, maybe because it has mature content.
// and requires an account logged in to view, try the embed page.
url = EMBED_URL + id + '?' + params;
request(url, options.requestOptions, (err, res, body) => {
if (err) return callback(err);
config = util.between(body, 't.setConfig({\'PLAYER_CONFIG\': ', /\}(,'|\}\);)/);
gotConfig(id, options, additional, config, true, callback);
});
}
});
};
/**
* @param {Object} info
* @return {Array.<Object>}
*/
const parseFormats = (info) => {
let formats = [];
if (info.player_response.streamingData) {
if (info.player_response.streamingData.formats) {
formats = formats.concat(info.player_response.streamingData.formats);
}
if (info.player_response.streamingData.adaptiveFormats) {
formats = formats.concat(info.player_response.streamingData.adaptiveFormats);
}
}
return formats;
};
/**
* @param {Object} id
* @param {Object} options
* @param {Object} additional
* @param {Object} config
* @param {boolean} fromEmbed
* @param {Function(Error, Object)} callback
*/
const gotConfig = (id, options, additional, config, fromEmbed, callback) => {
if (!config) {
return callback(Error('Could not find player config'));
}
try {
config = JSON.parse(config + (fromEmbed ? '}' : ''));
} catch (err) {
return callback(Error('Error parsing config: ' + err.message));
}
const url = urllib.format({
protocol: 'https',
host: INFO_HOST,
pathname: INFO_PATH,
query: {
video_id: id,
eurl: VIDEO_EURL + id,
ps: 'default',
gl: 'US',
hl: (options.lang || 'en'),
sts: config.sts,
},
});
request(url, options.requestOptions, (err, res, body) => {
if (err) return callback(err);
let info = querystring.parse(body);
const player_response = config.args.player_response || info.player_response;
if (info.status === 'fail') {
return callback(
Error(`Code ${info.errorcode}: ${util.stripHTML(info.reason)}`));
} else try {
info.player_response = JSON.parse(player_response);
} catch (err) {
return callback(
Error('Error parsing `player_response`: ' + err.message));
}
let playability = info.player_response.playabilityStatus;
if (playability && playability.status === 'UNPLAYABLE') {
return callback(Error(util.stripHTML(playability.reason)));
}
info.formats = parseFormats(info);
// Add additional properties to info.
Object.assign(info, additional, {
video_id: id,
// Give the standard link to the video.
video_url: VIDEO_URL + id,
// Copy over a few props from `player_response.videoDetails`
// for backwards compatibility.
title: info.player_response.videoDetails && info.player_response.videoDetails.title,
length_seconds: info.player_response.videoDetails && info.player_response.videoDetails.lengthSeconds,
});
info.age_restricted = fromEmbed;
info.html5player = config.assets.js;
callback(null, info);
});
};
/**
* Gets info from a video additional formats and deciphered URLs.
*
* @param {string} id
* @param {Object} options
* @param {Function(Error, Object)} callback
*/
exports.getFullInfo = (id, options, callback) => {
return exports.getBasicInfo(id, options, (err, info) => {
if (err) return callback(err);
const hasManifest =
info.player_response && info.player_response.streamingData && (
info.player_response.streamingData.dashManifestUrl ||
info.player_response.streamingData.hlsManifestUrl
);
if (info.formats.length || hasManifest) {
const html5playerfile = urllib.resolve(VIDEO_URL, info.html5player);
sig.getTokens(html5playerfile, options, (err, tokens) => {
if (err) return callback(err);
sig.decipherFormats(info.formats, tokens, options.debug);
let funcs = [];
if (hasManifest && info.player_response.streamingData.dashManifestUrl) {
let url = info.player_response.streamingData.dashManifestUrl;
funcs.push(getDashManifest.bind(null, url, options));
}
if (hasManifest && info.player_response.streamingData.hlsManifestUrl) {
let url = info.player_response.streamingData.hlsManifestUrl;
funcs.push(getM3U8.bind(null, url, options));
}
util.parallel(funcs, (err, results) => {
if (err) return callback(err);
if (results[0]) { mergeFormats(info, results[0]); }
if (results[1]) { mergeFormats(info, results[1]); }
info.formats = info.formats.map(util.addFormatMeta);
info.formats.sort(util.sortFormats);
info.full = true;
callback(null, info);
});
});
} else {
callback(Error('This video is unavailable'));
}
});
};
/**
* Merges formats from DASH or M3U8 with formats from video info page.
*
* @param {Object} info
* @param {Object} formatsMap
*/
const mergeFormats = (info, formatsMap) => {
info.formats.forEach((f) => {
formatsMap[f.itag] = formatsMap[f.itag] || f;
});
info.formats = Object.values(formatsMap);
};
/**
* Gets additional DASH formats.
*
* @param {string} url
* @param {Object} options
* @param {Function(!Error, Array.<Object>)} callback
*/
const getDashManifest = (url, options, callback) => {
let formats = {};
const parser = sax.parser(false);
parser.onerror = callback;
parser.onopentag = (node) => {
if (node.name === 'REPRESENTATION') {
const itag = node.attributes.ID;
formats[itag] = { itag, url };
}
};
parser.onend = () => { callback(null, formats); };
const req = request(urllib.resolve(VIDEO_URL, url), options.requestOptions);
req.setEncoding('utf8');
req.on('error', callback);
req.on('data', (chunk) => { parser.write(chunk); });
req.on('end', parser.close.bind(parser));
};
/**
* Gets additional formats.
*
* @param {string} url
* @param {Object} options
* @param {Function(!Error, Array.<Object>)} callback
*/
const getM3U8 = (url, options, callback) => {
url = urllib.resolve(VIDEO_URL, url);
request(url, options.requestOptions, (err, res, body) => {
if (err) return callback(err);
let formats = {};
body
.split('\n')
.filter((line) => /https?:\/\//.test(line))
.forEach((line) => {
const itag = line.match(/\/itag\/(\d+)\//)[1];
formats[itag] = { itag: itag, url: line };
});
callback(null, formats);
});
};
// Cached for getting basic/full info.
exports.cache = new Cache();
// Cache get info functions.
// In case a user wants to get a video's info before downloading.
for (let fnName of ['getBasicInfo', 'getFullInfo']) {
/**
* @param {string} link
* @param {Object} options
* @param {Function(Error, Object)} callback
*/
const fn = exports[fnName];
exports[fnName] = (link, options, callback) => {
if (typeof options === 'function') {
callback = options;
options = {};
} else if (!options) {
options = {};
}
if (!callback) {
return new Promise((resolve, reject) => {
exports[fnName](link, options, (err, info) => {
if (err) return reject(err);
resolve(info);
});
});
}
const id = util.getVideoID(link);
if (id instanceof Error) return callback(id);
const key = [fnName, id, options.lang].join('-');
if (exports.cache.get(key)) {
process.nextTick(() => callback(null, exports.cache.get(key)));
} else {
fn(id, options, (err, info) => {
if (err) return callback(err);
exports.cache.set(key, info);
callback(null, info);
});
}
};
}
// Export a few helpers.
exports.validateID = util.validateID;
exports.validateURL = util.validateURL;
exports.getURLVideoID = util.getURLVideoID;
exports.getVideoID = util.getVideoID;

276
node_modules/ytdl-core/lib/sig.js generated vendored Normal file
View File

@ -0,0 +1,276 @@
const url = require('url');
const request = require('miniget');
const querystring = require('querystring');
// A shared cache to keep track of html5player.js tokens.
exports.cache = new Map();
/**
* Extract signature deciphering tokens from html5player file.
*
* @param {string} html5playerfile
* @param {Object} options
* @param {Function(!Error, Array.<string>)} callback
*/
exports.getTokens = (html5playerfile, options, callback) => {
let key, cachedTokens;
const rs = /(?:html5)?player[-_]([a-zA-Z0-9\-_]+)(?:\.js|\/)/
.exec(html5playerfile);
if (rs) {
key = rs[1];
cachedTokens = exports.cache.get(key);
} else {
console.warn('Could not extract html5player key:', html5playerfile);
}
if (cachedTokens) {
callback(null, cachedTokens);
} else {
request(html5playerfile, options.requestOptions, (err, res, body) => {
if (err) return callback(err);
const tokens = exports.extractActions(body);
if (key && (!tokens || !tokens.length)) {
callback(Error('Could not extract signature deciphering actions'));
return;
}
exports.cache.set(key, tokens);
callback(null, tokens);
});
}
};
/**
* Decipher a signature based on action tokens.
*
* @param {Array.<string>} tokens
* @param {string} sig
* @return {string}
*/
exports.decipher = (tokens, sig) => {
sig = sig.split('');
for (let i = 0, len = tokens.length; i < len; i++) {
let token = tokens[i], pos;
switch (token[0]) {
case 'r':
sig = sig.reverse();
break;
case 'w':
pos = ~~token.slice(1);
sig = swapHeadAndPosition(sig, pos);
break;
case 's':
pos = ~~token.slice(1);
sig = sig.slice(pos);
break;
case 'p':
pos = ~~token.slice(1);
sig.splice(0, pos);
break;
}
}
return sig.join('');
};
/**
* Swaps the first element of an array with one of given position.
*
* @param {Array.<Object>} arr
* @param {number} position
* @return {Array.<Object>}
*/
const swapHeadAndPosition = (arr, position) => {
const first = arr[0];
arr[0] = arr[position % arr.length];
arr[position] = first;
return arr;
};
const jsVarStr = '[a-zA-Z_\\$][a-zA-Z_0-9]*';
const jsSingleQuoteStr = `'[^'\\\\]*(:?\\\\[\\s\\S][^'\\\\]*)*'`;
const jsDoubleQuoteStr = `"[^"\\\\]*(:?\\\\[\\s\\S][^"\\\\]*)*"`;
const jsQuoteStr = `(?:${jsSingleQuoteStr}|${jsDoubleQuoteStr})`;
const jsKeyStr = `(?:${jsVarStr}|${jsQuoteStr})`;
const jsPropStr = `(?:\\.${jsVarStr}|\\[${jsQuoteStr}\\])`;
const jsEmptyStr = `(?:''|"")`;
const reverseStr = ':function\\(a\\)\\{' +
'(?:return )?a\\.reverse\\(\\)' +
'\\}';
const sliceStr = ':function\\(a,b\\)\\{' +
'return a\\.slice\\(b\\)' +
'\\}';
const spliceStr = ':function\\(a,b\\)\\{' +
'a\\.splice\\(0,b\\)' +
'\\}';
const swapStr = ':function\\(a,b\\)\\{' +
'var c=a\\[0\\];a\\[0\\]=a\\[b(?:%a\\.length)?\\];a\\[b(?:%a\\.length)?\\]=c(?:;return a)?' +
'\\}';
const actionsObjRegexp = new RegExp(
`var (${jsVarStr})=\\{((?:(?:` +
jsKeyStr + reverseStr + '|' +
jsKeyStr + sliceStr + '|' +
jsKeyStr + spliceStr + '|' +
jsKeyStr + swapStr +
'),?\\r?\\n?)+)\\};'
);
const actionsFuncRegexp = new RegExp(`function(?: ${jsVarStr})?\\(a\\)\\{` +
`a=a\\.split\\(${jsEmptyStr}\\);\\s*` +
`((?:(?:a=)?${jsVarStr}` +
jsPropStr +
'\\(a,\\d+\\);)+)' +
`return a\\.join\\(${jsEmptyStr}\\)` +
'\\}'
);
const reverseRegexp = new RegExp(`(?:^|,)(${jsKeyStr})${reverseStr}`, 'm');
const sliceRegexp = new RegExp(`(?:^|,)(${jsKeyStr})${sliceStr}`, 'm');
const spliceRegexp = new RegExp(`(?:^|,)(${jsKeyStr})${spliceStr}`, 'm');
const swapRegexp = new RegExp(`(?:^|,)(${jsKeyStr})${swapStr}`, 'm');
/**
* Extracts the actions that should be taken to decipher a signature.
*
* This searches for a function that performs string manipulations on
* the signature. We already know what the 3 possible changes to a signature
* are in order to decipher it. There is
*
* * Reversing the string.
* * Removing a number of characters from the beginning.
* * Swapping the first character with another position.
*
* Note, `Array#slice()` used to be used instead of `Array#splice()`,
* it's kept in case we encounter any older html5player files.
*
* After retrieving the function that does this, we can see what actions
* it takes on a signature.
*
* @param {string} body
* @return {Array.<string>}
*/
exports.extractActions = (body) => {
const objResult = actionsObjRegexp.exec(body);
const funcResult = actionsFuncRegexp.exec(body);
if (!objResult || !funcResult) { return null; }
const obj = objResult[1].replace(/\$/g, '\\$');
const objBody = objResult[2].replace(/\$/g, '\\$');
const funcBody = funcResult[1].replace(/\$/g, '\\$');
let result = reverseRegexp.exec(objBody);
const reverseKey = result && result[1]
.replace(/\$/g, '\\$')
.replace(/\$|^'|^"|'$|"$/g, '');
result = sliceRegexp.exec(objBody);
const sliceKey = result && result[1]
.replace(/\$/g, '\\$')
.replace(/\$|^'|^"|'$|"$/g, '');
result = spliceRegexp.exec(objBody);
const spliceKey = result && result[1]
.replace(/\$/g, '\\$')
.replace(/\$|^'|^"|'$|"$/g, '');
result = swapRegexp.exec(objBody);
const swapKey = result && result[1]
.replace(/\$/g, '\\$')
.replace(/\$|^'|^"|'$|"$/g, '');
const keys = `(${[reverseKey, sliceKey, spliceKey, swapKey].join('|')})`;
const myreg = '(?:a=)?' + obj +
`(?:\\.${keys}|\\['${keys}'\\]|\\["${keys}"\\])` +
'\\(a,(\\d+)\\)';
const tokenizeRegexp = new RegExp(myreg, 'g');
const tokens = [];
while ((result = tokenizeRegexp.exec(funcBody)) !== null) {
let key = result[1] || result[2] || result[3];
switch (key) {
case swapKey:
tokens.push('w' + result[4]);
break;
case reverseKey:
tokens.push('r');
break;
case sliceKey:
tokens.push('s' + result[4]);
break;
case spliceKey:
tokens.push('p' + result[4]);
break;
}
}
return tokens;
};
/**
* @param {Object} format
* @param {string} sig
* @param {boolean} debug
*/
exports.setDownloadURL = (format, sig, debug) => {
let decodedUrl;
if (format.url) {
decodedUrl = format.url;
} else {
if (debug) {
console.warn('Download url not found for itag ' + format.itag);
}
return;
}
try {
decodedUrl = decodeURIComponent(decodedUrl);
} catch (err) {
if (debug) {
console.warn('Could not decode url: ' + err.message);
}
return;
}
// Make some adjustments to the final url.
const parsedUrl = url.parse(decodedUrl, true);
// Deleting the `search` part is necessary otherwise changes to
// `query` won't reflect when running `url.format()`
delete parsedUrl.search;
let query = parsedUrl.query;
// This is needed for a speedier download.
// See https://github.com/fent/node-ytdl-core/issues/127
query.ratebypass = 'yes';
if (sig) {
// When YouTube provides a `sp` parameter the signature `sig` must go
// into the parameter it specifies.
// See https://github.com/fent/node-ytdl-core/issues/417
if (format.sp) {
query[format.sp] = sig;
} else {
query.signature = sig;
}
}
format.url = url.format(parsedUrl);
};
/**
* Applies `sig.decipher()` to all format URL's.
*
* @param {Array.<Object>} formats
* @param {Array.<string>} tokens
* @param {boolean} debug
*/
exports.decipherFormats = (formats, tokens, debug) => {
formats.forEach((format) => {
if (format.cipher) {
Object.assign(format, querystring.parse(format.cipher));
delete format.cipher;
}
const sig = tokens && format.s ? exports.decipher(tokens, format.s) : null;
exports.setDownloadURL(format, sig, debug);
});
};

382
node_modules/ytdl-core/lib/util.js generated vendored Normal file
View File

@ -0,0 +1,382 @@
const url = require('url');
const FORMATS = require('./formats');
// Use these to help sort formats, higher is better.
const audioEncodingRanks = [
'mp4a',
'mp3',
'vorbis',
'aac',
'opus',
'flac',
];
const videoEncodingRanks = [
'mp4v',
'avc1',
'Sorenson H.283',
'MPEG-4 Visual',
'VP8',
'VP9',
'H.264',
];
const getBitrate = (format) => parseInt(format.bitrate) || 0;
const audioScore = (format) => {
const abitrate = format.audioBitrate || 0;
const aenc = audioEncodingRanks.findIndex(enc => format.codecs && format.codecs.includes(enc));
return abitrate + aenc / 10;
};
/**
* Sort formats from highest quality to lowest.
* By resolution, then video bitrate, then audio bitrate.
*
* @param {Object} a
* @param {Object} b
*/
exports.sortFormats = (a, b) => {
const ares = a.qualityLabel ? parseInt(a.qualityLabel.slice(0, -1)) : 0;
const bres = b.qualityLabel ? parseInt(b.qualityLabel.slice(0, -1)) : 0;
const afeats = ~~!!ares * 2 + ~~!!a.audioBitrate;
const bfeats = ~~!!bres * 2 + ~~!!b.audioBitrate;
if (afeats === bfeats) {
if (ares === bres) {
let avbitrate = getBitrate(a);
let bvbitrate = getBitrate(b);
if (avbitrate === bvbitrate) {
let aascore = audioScore(a);
let bascore = audioScore(b);
if (aascore === bascore) {
const avenc = videoEncodingRanks.findIndex(enc => a.codecs && a.codecs.includes(enc));
const bvenc = videoEncodingRanks.findIndex(enc => b.codecs && b.codecs.includes(enc));
return bvenc - avenc;
} else {
return bascore - aascore;
}
} else {
return bvbitrate - avbitrate;
}
} else {
return bres - ares;
}
} else {
return bfeats - afeats;
}
};
/**
* Choose a format depending on the given options.
*
* @param {Array.<Object>} formats
* @param {Object} options
* @return {Object|Error}
*/
exports.chooseFormat = (formats, options) => {
if (typeof options.format === 'object') {
return options.format;
}
if (options.filter) {
formats = exports.filterFormats(formats, options.filter);
if (formats.length === 0) {
return Error('No formats found with custom filter');
}
}
let format;
const quality = options.quality || 'highest';
switch (quality) {
case 'highest':
format = formats[0];
break;
case 'lowest':
format = formats[formats.length - 1];
break;
case 'highestaudio':
formats = exports.filterFormats(formats, 'audio');
format = null;
for (let f of formats) {
if (!format
|| audioScore(f) > audioScore(format))
format = f;
}
break;
case 'lowestaudio':
formats = exports.filterFormats(formats, 'audio');
format = null;
for (let f of formats) {
if (!format
|| audioScore(f) < audioScore(format))
format = f;
}
break;
case 'highestvideo':
formats = exports.filterFormats(formats, 'video');
format = null;
for (let f of formats) {
if (!format
|| getBitrate(f) > getBitrate(format))
format = f;
}
break;
case 'lowestvideo':
formats = exports.filterFormats(formats, 'video');
format = null;
for (let f of formats) {
if (!format
|| getBitrate(f) < getBitrate(format))
format = f;
}
break;
default: {
let getFormat = (itag) => {
return formats.find((format) => '' + format.itag === '' + itag);
};
if (Array.isArray(quality)) {
quality.find((q) => format = getFormat(q));
} else {
format = getFormat(quality);
}
}
}
if (!format) {
return Error('No such format found: ' + quality);
}
return format;
};
/**
* @param {Array.<Object>} formats
* @param {Function} filter
* @return {Array.<Object>}
*/
exports.filterFormats = (formats, filter) => {
let fn;
const hasVideo = format => !!format.qualityLabel;
const hasAudio = format => !!format.audioBitrate;
switch (filter) {
case 'audioandvideo':
fn = (format) => hasVideo(format) && hasAudio(format);
break;
case 'video':
fn = hasVideo;
break;
case 'videoonly':
fn = (format) => hasVideo(format) && !hasAudio(format);
break;
case 'audio':
fn = hasAudio;
break;
case 'audioonly':
fn = (format) => !hasVideo(format) && hasAudio(format);
break;
default:
if (typeof filter === 'function') {
fn = filter;
} else {
throw TypeError(`Given filter (${filter}) is not supported`);
}
}
return formats.filter(fn);
};
/**
* String#indexOf() that supports regex too.
*
* @param {string} haystack
* @param {string|RegExp} needle
* @return {number}
*/
const indexOf = (haystack, needle) => {
return needle instanceof RegExp ?
haystack.search(needle) : haystack.indexOf(needle);
};
/**
* Extract string inbetween another.
*
* @param {string} haystack
* @param {string} left
* @param {string} right
* @return {string}
*/
exports.between = (haystack, left, right) => {
let pos = indexOf(haystack, left);
if (pos === -1) { return ''; }
haystack = haystack.slice(pos + left.length);
pos = indexOf(haystack, right);
if (pos === -1) { return ''; }
haystack = haystack.slice(0, pos);
return haystack;
};
/**
* Get video ID.
*
* There are a few type of video URL formats.
* - https://www.youtube.com/watch?v=VIDEO_ID
* - https://m.youtube.com/watch?v=VIDEO_ID
* - https://youtu.be/VIDEO_ID
* - https://www.youtube.com/v/VIDEO_ID
* - https://www.youtube.com/embed/VIDEO_ID
* - https://music.youtube.com/watch?v=VIDEO_ID
* - https://gaming.youtube.com/watch?v=VIDEO_ID
*
* @param {string} link
* @return {string|Error}
*/
const validQueryDomains = new Set([
'youtube.com',
'www.youtube.com',
'm.youtube.com',
'music.youtube.com',
'gaming.youtube.com',
]);
const validPathDomains = new Set([
'youtu.be',
'youtube.com',
'www.youtube.com',
]);
exports.getURLVideoID = (link) => {
const parsed = url.parse(link, true);
let id = parsed.query.v;
if (validPathDomains.has(parsed.hostname) && !id) {
const paths = parsed.pathname.split('/');
id = paths[paths.length - 1];
} else if (parsed.hostname && !validQueryDomains.has(parsed.hostname)) {
return Error('Not a YouTube domain');
}
if (!id) {
return Error('No video id found: ' + link);
}
id = id.substring(0, 11);
if (!exports.validateID(id)) {
return TypeError(`Video id (${id}) does not match expected ` +
`format (${idRegex.toString()})`);
}
return id;
};
/**
* Gets video ID either from a url or by checking if the given string
* matches the video ID format.
*
* @param {string} str
* @return {string|Error}
*/
exports.getVideoID = (str) => {
if (exports.validateID(str)) {
return str;
} else {
return exports.getURLVideoID(str);
}
};
/**
* Returns true if given id satifies YouTube's id format.
*
* @param {string} id
* @return {boolean}
*/
const idRegex = /^[a-zA-Z0-9-_]{11}$/;
exports.validateID = (id) => {
return idRegex.test(id);
};
/**
* Checks wether the input string includes a valid id.
*
* @param {string} string
* @return {boolean}
*/
exports.validateURL = (string) => {
return !(exports.getURLVideoID(string) instanceof Error);
};
/**
* @param {Object} format
* @return {Object}
*/
exports.addFormatMeta = (format) => {
format = Object.assign({}, FORMATS[format.itag], format);
format.container = format.mimeType ?
format.mimeType.split(';')[0].split('/')[1] : null;
format.codecs = format.mimeType ?
exports.between(format.mimeType, 'codecs="', '"') : null;
format.live = /\/source\/yt_live_broadcast\//.test(format.url);
format.isHLS = /\/manifest\/hls_(variant|playlist)\//.test(format.url);
format.isDashMPD = /\/manifest\/dash\//.test(format.url);
return format;
};
/**
* Get only the string from an HTML string.
*
* @param {string} html
* @return {string}
*/
exports.stripHTML = (html) => {
return html
.replace(/\n/g, ' ')
.replace(/\s*<\s*br\s*\/?\s*>\s*/gi, '\n')
.replace(/<\s*\/\s*p\s*>\s*<\s*p[^>]*>/gi, '\n')
.replace(/<.*?>/gi, '')
.trim();
};
/**
* @param {Array.<Function>} funcs
* @param {Function(!Error, Array.<Object>)} callback
*/
exports.parallel = (funcs, callback) => {
let funcsDone = 0;
let errGiven = false;
let results = [];
const len = funcs.length;
const checkDone = (index, err, result) => {
if (errGiven) { return; }
if (err) {
errGiven = true;
callback(err);
return;
}
results[index] = result;
if (++funcsDone === len) {
callback(null, results);
}
};
if (len > 0) {
funcs.forEach((f, i) => { f(checkDone.bind(null, i)); });
} else {
callback(null, results);
}
};

101
node_modules/ytdl-core/package.json generated vendored Normal file
View File

@ -0,0 +1,101 @@
{
"_from": "ytdl-core@latest",
"_id": "ytdl-core@1.0.7",
"_inBundle": false,
"_integrity": "sha512-gECPN5g5JnSy8hIq11xHIGe1T/Xzy0mWxQin3zhlJ3nG/YjPcEVEejrdd2XmA4Vv2Zw3+b1ZyDjmt37XfZri6A==",
"_location": "/ytdl-core",
"_phantomChildren": {},
"_requested": {
"type": "tag",
"registry": true,
"raw": "ytdl-core@latest",
"name": "ytdl-core",
"escapedName": "ytdl-core",
"rawSpec": "latest",
"saveSpec": null,
"fetchSpec": "latest"
},
"_requiredBy": [
"#USER",
"/"
],
"_resolved": "https://registry.npmjs.org/ytdl-core/-/ytdl-core-1.0.7.tgz",
"_shasum": "2cda813e6429eb35aee349656b8f5693314b6992",
"_spec": "ytdl-core@latest",
"_where": "C:\\Users\\matia\\Documents\\GitHub\\Musix-V3",
"author": {
"name": "fent",
"url": "https://github.com/fent"
},
"bugs": {
"url": "https://github.com/fent/node-ytdl-core/issues"
},
"bundleDependencies": false,
"contributors": [
{
"name": "Tobias Kutscha",
"url": "https://github.com/TimeForANinja"
},
{
"name": "Andrew Kelley",
"url": "https://github.com/andrewrk"
},
{
"name": "Mauricio Allende",
"url": "https://github.com/mallendeo"
},
{
"name": "Rodrigo Altamirano",
"url": "https://github.com/raltamirano"
},
{
"name": "Jim Buck",
"url": "https://github.com/JimmyBoh"
}
],
"dependencies": {
"html-entities": "^1.1.3",
"m3u8stream": "^0.6.3",
"miniget": "^1.6.0",
"sax": "^1.1.3"
},
"deprecated": false,
"description": "Youtube video downloader in pure javascript.",
"devDependencies": {
"@types/node": "^13.1.0",
"assert-diff": "^2.0.0",
"mocha": "^6.2.0",
"muk-prop": "^2.0.0",
"muk-require": "^1.2.0",
"nock": "^11.1.0",
"nyc": "^15.0.0",
"sinon": "^8.0.0",
"stream-equal": "~1.1.0"
},
"engines": {
"node": ">=6"
},
"files": [
"lib",
"typings"
],
"homepage": "https://github.com/fent/node-ytdl-core#readme",
"keywords": [
"youtube",
"video",
"download"
],
"license": "MIT",
"main": "./lib/index.js",
"name": "ytdl-core",
"repository": {
"type": "git",
"url": "git://github.com/fent/node-ytdl-core.git"
},
"scripts": {
"test": "nyc --reporter=lcov --reporter=text-summary mocha -- --ignore test/irl-test.js test/*-test.js",
"test:irl": "mocha --timeout 16000 test/irl-test.js"
},
"types": "./typings/index.d.ts",
"version": "1.0.7"
}

266
node_modules/ytdl-core/typings/index.d.ts generated vendored Normal file
View File

@ -0,0 +1,266 @@
declare module 'ytdl-core' {
import { ClientRequest } from 'http';
import { Readable } from 'stream';
namespace ytdl {
type Filter = 'audioandvideo' | 'video' | 'videoonly' | 'audio' | 'audioonly' | ((format: videoFormat) => boolean);
type downloadOptions = {
quality?: 'lowest' | 'highest' | 'highestaudio' | 'lowestaudio' | 'highestvideo' | 'lowestvideo' | string | number;
filter?: Filter;
format?: videoFormat;
range?: {
start?: number;
end?: number;
};
begin?: string | number | Date;
liveBuffer?: number;
requestOptions?: {};
highWaterMark?: number;
lang?: string;
}
type videoFormat = {
itag: number;
url: string;
mimeType?: string;
bitrate?: number | string;
width?: number;
height?: number;
initRange?: { start: string; end: string };
indexRange?: { start: string; end: string };
lastModified: string;
contentLength: string;
quality: 'tiny' | 'small' | 'medium' | 'large' | 'hd720' | 'hd1080' | 'hd1440' | string;
qualityLabel: '144p' | '240p' | '270p' | '360p' | '480p' | '720p' | '1080p' | '1440p' | '2160p' | '4320p';
projectionType: 'RECTANGULAR';
fps?: number;
averageBitrate: number;
audioQuality?: 'ADIO_QUALITY_LOW' | 'ADIO_QUALITY_MEDIUM';
colorInfo?: {
primaries: string;
transferCharacteristics: string;
matrixCoefficients: string;
};
highReplication?: boolean;
approxDurationMs: string;
audioSampleRate?: string;
audioChannels?: number;
// Added by ytdl-core
container: 'flv' | '3gp' | 'mp4' | 'webm' | 'ts';
codecs: string;
live: boolean;
isHLS: boolean;
isDashMPD: boolean;
}
type videoInfo = {
iv_load_policy?: string;
iv_allow_in_place_switch?: string;
iv_endscreen_url?: string;
iv_invideo_url?: string;
iv3_module?: string;
rmktEnabled?: string;
uid?: string;
vid?: string;
focEnabled?: string;
baseUrl?: string;
storyboard_spec?: string;
serialized_ad_ux_config?: string;
player_error_log_fraction?: string;
sffb?: string;
ldpj?: string;
videostats_playback_base_url?: string;
innertube_context_client_version?: string;
t?: string;
fade_in_start_milliseconds: string;
timestamp: string;
ad3_module: string;
relative_loudness: string;
allow_below_the_player_companion: string;
eventid: string;
token: string;
atc: string;
title: string;
cr: string;
apply_fade_on_midrolls: string;
cl: string;
fexp: string[];
apiary_host: string;
fade_in_duration_milliseconds: string;
fflags: string;
ssl: string;
pltype: string;
media: {
image?: string;
category: string;
category_url: string;
game?: string;
game_url?: string;
year?: number;
song?: string;
artist?: string;
artist_url?: string;
writers?: string;
licensed_by?: string;
};
author: {
id: string;
name: string;
avatar: string;
verified: boolean;
user: string;
channel_url: string;
user_url: string;
};
enabled_engage_types: string;
hl: string;
is_listed: string;
gut_tag: string;
apiary_host_firstparty: string;
enablecsi: string;
csn: string;
status: string;
afv_ad_tag: string;
idpj: string;
sfw_player_response: string;
account_playback_token: string;
encoded_ad_safety_reason: string;
tag_for_children_directed: string;
no_get_video_log: string;
ppv_remarketing_url: string;
fmt_list: string[][];
ad_slots: string;
fade_out_duration_milliseconds: string;
instream_long: string;
allow_html5_ads: string;
core_dbp: string;
ad_device: string;
itct: string;
root_ve_type: string;
excluded_ads: string;
aftv: string;
loeid: string;
cver: string;
shortform: string;
dclk: string;
csi_page_type: string;
ismb: string;
gpt_migration: string;
loudness: string;
ad_tag: string;
of: string;
probe_url: string;
vm: string;
afv_ad_tag_restricted_to_instream: string;
gapi_hint_params: string;
cid: string;
c: string;
oid: string;
ptchn: string;
as_launched_in_country: string;
avg_rating: string;
fade_out_start_milliseconds: string;
length_seconds: string;
midroll_prefetch_size: string;
allow_ratings: string;
thumbnail_url: string;
iurlsd: string;
iurlmq: string;
iurlhq: string;
iurlmaxres: string;
ad_preroll: string;
tmi: string;
trueview: string;
host_language: string;
innertube_api_key: string;
show_content_thumbnail: string;
afv_instream_max: string;
innertube_api_version: string;
mpvid: string;
allow_embed: string;
ucid: string;
plid: string;
midroll_freqcap: string;
ad_logging_flag: string;
ptk: string;
vmap: string;
watermark: string[];
video_id: string;
dbp: string;
ad_flags: string;
html5player: string;
formats: videoFormat[];
published: number;
description: string;
related_videos: relatedVideo[];
video_url: string;
no_embed_allowed?: boolean;
age_restricted: boolean;
player_response: {
playabilityStatus: {
status: string;
};
streamingData: {
expiresInSeconds: string;
formats: {}[];
adaptiveFormats: {}[];
};
videoDetails: {
videoId: string;
title: string;
lengthSeconds: number;
keywords: string[];
channelId: string;
isCrawlable: boolean;
thumbnail: {
thumbnails: {
url: string;
width: number;
height: number;
}[];
};
viewCount: number;
author: string;
isLiveContent: boolean;
};
};
}
type relatedVideo = {
id?: string;
title?: string;
author?: string;
length_seconds?: string;
iurlmq?: string;
short_view_count_text?: string;
session_data: string;
endscreen_autoplay_session_data?: string;
iurlhq?: string;
playlist_iurlhq?: string;
playlist_title?: string;
playlist_length?: string;
playlist_iurlmq?: string;
video_id?: string;
list?: string;
thumbnail_ids?: string;
}
function getBasicInfo(url: string, callback?: (err: Error, info: videoInfo) => void): Promise<videoInfo>;
function getBasicInfo(url: string, options?: downloadOptions, callback?: (err: Error, info: videoInfo) => void): Promise<videoInfo>;
function getInfo(url: string, callback?: (err: Error, info: videoInfo) => void): Promise<videoInfo>;
function getInfo(url: string, options?: downloadOptions, callback?: (err: Error, info: videoInfo) => void): Promise<videoInfo>;
function downloadFromInfo(info: videoInfo, options?: downloadOptions): Readable;
function chooseFormat(format: videoFormat | videoFormat[], options?: downloadOptions): videoFormat | Error;
function filterFormats(formats: videoFormat | videoFormat[], filter?: Filter): videoFormat[];
function validateID(string: string): boolean;
function validateURL(string: string): boolean;
function getURLVideoID(string: string): string | Error;
function getVideoID(string: string): string | Error;
}
function ytdl(link: string, options?: ytdl.downloadOptions): Readable;
export = ytdl;
}