Add video_info_from_basic_info function

This commit is contained in:
absidue 2021-10-16 16:32:49 +02:00
parent 7640267046
commit f1be72088f
5 changed files with 45 additions and 3 deletions

View File

@ -86,6 +86,16 @@ const video = await video_info(url)
console.log(video.format)
```
### video_info_from_basic_info(data : `InfoData`)
_This contains everything with deciphered formats along with `video_details`. It uses data returned by [`video_basic_info`](https://github.com/play-dl/play-dl/tree/main/docs/YouTube#video_basic_infourl--string-options--infooptions). This function is useful if you use [`video_basic_info`](https://github.com/play-dl/play-dl/tree/main/docs/YouTube#video_basic_infourl--string-options--infooptions) earlier in your code and want to convert the output for use with [`stream_from_info`](https://github.com/play-dl/play-dl/tree/main/docs#stream_from_infoinfo--infodata-options--streamoptions)_
```js
const basic_video = await video_basic_info(url);
const video = await video_info_from_basic_info(basic_video);
```
## Playlist
### playlist_info(url : `string`, options : `PlaylistOptions`)

View File

@ -85,7 +85,7 @@ export async function stream(url: string, options: StreamOptions = {}): Promise<
);
}
/**
* Stream command for YouTube using info from video_info function.
* Stream command for YouTube using info from video_info or video_info_from_basic_info function.
* @param info video_info data
* @param options lets you add quality, cookie, proxy support for stream
* @returns Stream class with type and stream for playing.

View File

@ -2,6 +2,7 @@ import { ProxyOptions as Proxy, request } from './../../Request/index';
import { format_decipher } from './cipher';
import { YouTubeVideo } from '../classes/Video';
import { YouTubePlayList } from '../classes/Playlist';
import { InfoData } from '../stream';
interface InfoOptions {
proxy?: Proxy[];
@ -176,6 +177,21 @@ export async function video_info(url: string, options: InfoOptions = {}) {
return data;
}
}
/**
* Function uses data from video_basic_info and deciphers it if it contains signatures.
* @param data basic_video_info data
* @returns Data containing video_details, LiveStreamData and formats of video url.
*/
export async function video_info_from_basic_info(data: InfoData) {
if (data.LiveStreamData.isLive === true && data.LiveStreamData.hlsManifestUrl !== null) {
return data;
} else if (data.format[0].signatureCipher || data.format[0].cipher) {
data.format = await format_decipher(data.format, data.html5player);
return data;
} else {
return data;
}
}
/**
* Function to get YouTube playlist info from a playlist url.
* @param url Playlist URL

View File

@ -1 +1,8 @@
export { video_basic_info, video_info, playlist_info, yt_validate, extractID } from './extractor';
export {
video_basic_info,
video_info,
video_info_from_basic_info,
playlist_info,
yt_validate,
extractID
} from './extractor';

View File

@ -1,4 +1,13 @@
export { playlist_info, video_basic_info, video_info, yt_validate, extractID, YouTube, YouTubeStream } from './YouTube';
export {
playlist_info,
video_basic_info,
video_info,
video_info_from_basic_info,
yt_validate,
extractID,
YouTube,
YouTubeStream
} from './YouTube';
export { spotify, sp_validate, refreshToken, is_expired, Spotify } from './Spotify';
export { soundcloud, so_validate, SoundCloud, SoundCloudStream } from './SoundCloud';
export { setToken } from './token';