Merge pull request #299 from AtariTom/main
Fix for JSON error and video bitrates
This commit is contained in:
commit
338758b298
@ -1,8 +1,5 @@
|
||||
# Play-dl
|
||||
|
||||
|
||||
# ⚠️ Play-dl is no longer being maintained. ⚠️
|
||||
|
||||
A **light-weight** YouTube, SoundCloud, Spotify and Deezer streaming and searching library.
|
||||
|
||||
- Search by video, playlist/album, channel/artist
|
||||
|
||||
2
package-lock.json
generated
2
package-lock.json
generated
@ -18,7 +18,7 @@
|
||||
"typedoc": "^0.22.11",
|
||||
"typedoc-plugin-extras": "^2.2.1",
|
||||
"typedoc-plugin-missing-exports": "^0.22.4",
|
||||
"typescript": "^4.5.5"
|
||||
"typescript": "^4.7.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=16.0.0"
|
||||
|
||||
@ -48,7 +48,7 @@
|
||||
"typedoc": "^0.22.11",
|
||||
"typedoc-plugin-extras": "^2.2.1",
|
||||
"typedoc-plugin-missing-exports": "^0.22.4",
|
||||
"typescript": "^4.5.5"
|
||||
"typescript": "^4.7.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"play-audio": "^0.5.2"
|
||||
|
||||
@ -63,6 +63,7 @@ export class SeekStream {
|
||||
* @param duration Duration of audio playback [ in seconds ]
|
||||
* @param headerLength Length of the header in bytes.
|
||||
* @param contentLength Total length of Audio file in bytes.
|
||||
* @param bitrate Bitrate provided by YouTube.
|
||||
* @param video_url YouTube video url.
|
||||
* @param options Options provided to stream function.
|
||||
*/
|
||||
@ -71,6 +72,7 @@ export class SeekStream {
|
||||
duration: number,
|
||||
headerLength: number,
|
||||
contentLength: number,
|
||||
bitrate: number,
|
||||
video_url: string,
|
||||
options: StreamOptions
|
||||
) {
|
||||
@ -83,7 +85,7 @@ export class SeekStream {
|
||||
this.type = StreamType.Opus;
|
||||
this.bytes_count = 0;
|
||||
this.video_url = video_url;
|
||||
this.per_sec_bytes = Math.ceil(contentLength / duration);
|
||||
this.per_sec_bytes = bitrate ? Math.ceil(bitrate / 8) : Math.ceil(contentLength / duration);
|
||||
this.header_length = headerLength;
|
||||
this.content_length = contentLength;
|
||||
this.request = null;
|
||||
|
||||
@ -65,6 +65,8 @@ export async function stream_from_info(
|
||||
): Promise<YouTubeStream> {
|
||||
if (info.format.length === 0)
|
||||
throw new Error('Upcoming and premiere videos that are not currently live cannot be streamed.');
|
||||
if (options.quality && !Number.isInteger(options.quality))
|
||||
throw new Error("Quality must be set to an integer.")
|
||||
|
||||
const final: any[] = [];
|
||||
if (
|
||||
@ -99,6 +101,7 @@ export async function stream_from_info(
|
||||
info.video_details.durationInSec,
|
||||
final[0].indexRange.end,
|
||||
Number(final[0].contentLength),
|
||||
Number(final[0].bitrate),
|
||||
info.video_details.url,
|
||||
options
|
||||
);
|
||||
|
||||
@ -151,7 +151,7 @@ export async function video_basic_info(url: string, options: InfoOptions = {}):
|
||||
const player_data = body
|
||||
.split('var ytInitialPlayerResponse = ')?.[1]
|
||||
?.split(';</script>')[0]
|
||||
.split(/;\s*(var|const|let)\s/)[0];
|
||||
.split(/(?<=}}});\s*(var|const|let)\s/)[0];
|
||||
if (!player_data) throw new Error('Initial Player Response Data is undefined.');
|
||||
const initial_data = body
|
||||
.split('var ytInitialData = ')?.[1]
|
||||
@ -349,7 +349,7 @@ export async function video_stream_info(url: string, options: InfoOptions = {}):
|
||||
const player_data = body
|
||||
.split('var ytInitialPlayerResponse = ')?.[1]
|
||||
?.split(';</script>')[0]
|
||||
.split(/;\s*(var|const|let)\s/)[0];
|
||||
.split(/(?<=}}});\s*(var|const|let)\s/)[0];
|
||||
if (!player_data) throw new Error('Initial Player Response Data is undefined.');
|
||||
const player_response = JSON.parse(player_data);
|
||||
let upcoming = false;
|
||||
|
||||
@ -146,7 +146,7 @@ export function parseVideo(data?: any): YouTubeVideo {
|
||||
id: data.videoRenderer.videoId,
|
||||
url: `https://www.youtube.com/watch?v=${data.videoRenderer.videoId}`,
|
||||
title: data.videoRenderer.title.runs[0].text,
|
||||
description: data.videoRenderer.detailedMetadataSnippets?.[0].snippetText.runs.length
|
||||
description: data.videoRenderer.detailedMetadataSnippets?.[0].snippetText.runs?.length
|
||||
? data.videoRenderer.detailedMetadataSnippets[0].snippetText.runs.map((run: any) => run.text).join('')
|
||||
: '',
|
||||
duration: durationText ? parseDuration(durationText.simpleText) : 0,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user