PlayList added optional if incompleted playlists

This commit is contained in:
killer069 2021-08-24 21:11:54 +05:30
parent 5f4c19813a
commit 353ff1e0f6
3 changed files with 8 additions and 5 deletions

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{ {
"name": "play-dl", "name": "play-dl",
"version": "0.5.3", "version": "0.5.4",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "play-dl", "name": "play-dl",
"version": "0.5.2", "version": "0.5.4",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"got": "^11.8.2" "got": "^11.8.2"

View File

@ -1,6 +1,6 @@
{ {
"name": "play-dl", "name": "play-dl",
"version": "0.5.3", "version": "0.5.4",
"description": "YouTube, SoundCloud, Spotify streaming for discord.js bots", "description": "YouTube, SoundCloud, Spotify streaming for discord.js bots",
"main": "dist/index.js", "main": "dist/index.js",
"typings": "dist/index.d.ts", "typings": "dist/index.d.ts",

View File

@ -107,7 +107,7 @@ async function parseM3U8(m3u8_data : string, formats : any[]): Promise<any[]>{
return formats return formats
} }
export async function playlist_info(url : string) { export async function playlist_info(url : string, parseIncomplete : boolean) {
if (!url || typeof url !== "string") throw new Error(`Expected playlist url, received ${typeof url}!`); if (!url || typeof url !== "string") throw new Error(`Expected playlist url, received ${typeof url}!`);
if(url.search('(\\?|\\&)list\\=') === -1) throw new Error('This is not a PlayList URL') if(url.search('(\\?|\\&)list\\=') === -1) throw new Error('This is not a PlayList URL')
@ -118,7 +118,10 @@ export async function playlist_info(url : string) {
let body = await url_get(new_url) let body = await url_get(new_url)
let response = JSON.parse(body.split("var ytInitialData = ")[1].split(";</script>")[0]) let response = JSON.parse(body.split("var ytInitialData = ")[1].split(";</script>")[0])
if(response.alerts){ if(response.alerts){
if(response.alerts[0].alertWithButtonRenderer?.type === 'INFO') throw new Error(`While parsing playlist url\n ${response.alerts[0].alertWithButtonRenderer.text.simpleText}`) if(response.alerts[0].alertWithButtonRenderer?.type === 'INFO') {
if(parseIncomplete) console.log(`While parsing playlist url\n ${response.alerts[0].alertWithButtonRenderer.text.simpleText}`)
else throw new Error(`While parsing playlist url\n ${response.alerts[0].alertWithButtonRenderer.text.simpleText}`)
}
else if(response.alerts[0].alertRenderer?.type === 'ERROR') throw new Error(`While parsing playlist url\n ${response.alerts[0].alertRenderer.text.runs[0].text}`) else if(response.alerts[0].alertRenderer?.type === 'ERROR') throw new Error(`While parsing playlist url\n ${response.alerts[0].alertRenderer.text.runs[0].text}`)
else throw new Error('While parsing playlist url\n Unknown Playlist Error') else throw new Error('While parsing playlist url\n Unknown Playlist Error')
} }