Merge pull request #239 from play-dl/developer

1.8.1
This commit is contained in:
Killer069 2022-01-20 16:55:06 +05:30 committed by GitHub
commit a4d182fdf3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 20 deletions

View File

@ -50,6 +50,17 @@ import play from 'play-dl'; // Everything
import { video_basic_info, stream } from 'play-dl'; // Individual functions import { video_basic_info, stream } from 'play-dl'; // Individual functions
``` ```
## **Compatibility issues** - discord-player
Because discord-player doesn't work with raw opus packets you need to enable the compatibility mode in `play-dl`, if you want to use both frameworks together.
- To fix the playback of YouTube videos with `discord-player`, you can disable some of play-dl's optimisations and fixes by setting the `discordPlayerCompatibility` option for `stream` and `stream_from_info` to true
- The `discordPlayerCompatiblity` option might break the playback of long YouTube videos.
- Even with the `discordPlayerCompatibility` option set you will not be able to use the seek option for `stream` and `stream_from_info`.
### [Documentation](https://play-dl.github.io/modules.html) ### [Documentation](https://play-dl.github.io/modules.html)
### [Examples](./examples) ### [Examples](./examples)
### [Instructions](./instructions) ### [Instructions](./instructions)

View File

@ -19,6 +19,7 @@ export interface StreamOptions {
language?: string; language?: string;
htmldata?: boolean; htmldata?: boolean;
precache?: number; precache?: number;
discordPlayerCompatibility?: boolean
} }
/** /**
@ -86,24 +87,26 @@ export async function stream_from_info(
final[0].codec === 'opus' && final[0].container === 'webm' ? StreamType.WebmOpus : StreamType.Arbitrary; final[0].codec === 'opus' && final[0].container === 'webm' ? StreamType.WebmOpus : StreamType.Arbitrary;
await request_stream(`https://${new URL(final[0].url).host}/generate_204`); await request_stream(`https://${new URL(final[0].url).host}/generate_204`);
if (type === StreamType.WebmOpus) { if (type === StreamType.WebmOpus) {
options.seek ??= 0 if(!options.discordPlayerCompatibility){
if (options.seek >= info.video_details.durationInSec || options.seek < 0) options.seek ??= 0
throw new Error(`Seeking beyond limit. [ 0 - ${info.video_details.durationInSec - 1}]`); if (options.seek >= info.video_details.durationInSec || options.seek < 0)
return new SeekStream( throw new Error(`Seeking beyond limit. [ 0 - ${info.video_details.durationInSec - 1}]`);
final[0].url, return new SeekStream(
info.video_details.durationInSec, final[0].url,
final[0].indexRange.end, info.video_details.durationInSec,
Number(final[0].contentLength), final[0].indexRange.end,
info.video_details.url, Number(final[0].contentLength),
options info.video_details.url,
); options
} else );
return new Stream( } else if(options.seek) throw new Error("Can not seek with discordPlayerCompatibility set to true.")
final[0].url, }
type, return new Stream(
info.video_details.durationInSec, final[0].url,
Number(final[0].contentLength), type,
info.video_details.url, info.video_details.durationInSec,
options Number(final[0].contentLength),
); info.video_details.url,
options
);
} }

View File

@ -100,6 +100,7 @@ async function stream(url: string, options?: StreamOptions): Promise<YouTubeStre
* - `number` quality : Quality number. [ 0 = Lowest, 1 = Medium, 2 = Highest ] * - `number` quality : Quality number. [ 0 = Lowest, 1 = Medium, 2 = Highest ]
* - `boolean` htmldata : given data is html data or not * - `boolean` htmldata : given data is html data or not
* - `number` precache : No of segments of data to store before looping [YouTube Live Stream only]. [ Defaults to 3 ] * - `number` precache : No of segments of data to store before looping [YouTube Live Stream only]. [ Defaults to 3 ]
* - `boolean` discordPlayerCompatibility : Conversion of Webm to Opus [ Defaults to false ]
* @returns A {@link YouTubeStream} or {@link SoundCloudStream} Stream to play * @returns A {@link YouTubeStream} or {@link SoundCloudStream} Stream to play
*/ */
async function stream(url: string, options: StreamOptions = {}): Promise<YouTubeStream | SoundCloudStream> { async function stream(url: string, options: StreamOptions = {}): Promise<YouTubeStream | SoundCloudStream> {
@ -239,6 +240,7 @@ async function stream_from_info(info: InfoData, options?: StreamOptions): Promis
* - `number` quality : Quality number. [ 0 = Lowest, 1 = Medium, 2 = Highest ] * - `number` quality : Quality number. [ 0 = Lowest, 1 = Medium, 2 = Highest ]
* - `boolean` htmldata : given data is html data or not * - `boolean` htmldata : given data is html data or not
* - `number` precache : No of segments of data to store before looping [YouTube Live Stream only]. [ Defaults to 3 ] * - `number` precache : No of segments of data to store before looping [YouTube Live Stream only]. [ Defaults to 3 ]
* - `boolean` discordPlayerCompatibility : Conversion of Webm to Opus[ Defaults to false ]
* @returns A {@link YouTubeStream} or {@link SoundCloudStream} Stream to play * @returns A {@link YouTubeStream} or {@link SoundCloudStream} Stream to play
*/ */
async function stream_from_info( async function stream_from_info(