Fixed find chapter error, soundcloud 403 and watch playlists
This commit is contained in:
parent
76c237346e
commit
6a8569feb8
4
package-lock.json
generated
4
package-lock.json
generated
@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "play-dl",
|
||||
"version": "1.9.6",
|
||||
"version": "1.9.7",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "play-dl",
|
||||
"version": "1.9.6",
|
||||
"version": "1.9.7",
|
||||
"license": "GPL-3.0",
|
||||
"dependencies": {
|
||||
"play-audio": "^0.5.2"
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "play-dl",
|
||||
"version": "1.9.6",
|
||||
"version": "1.9.7",
|
||||
"description": "YouTube, SoundCloud, Spotify, Deezer searching and streaming for discord-js bots",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
|
||||
@ -111,10 +111,14 @@ export async function stream(url: string, quality?: number): Promise<SoundCloudS
|
||||
* @returns client ID
|
||||
*/
|
||||
export async function getFreeClientID(): Promise<string> {
|
||||
const data = await request('https://soundcloud.com/');
|
||||
const data: any = await request('https://soundcloud.com/', {headers: {}}).catch(err => err);
|
||||
|
||||
if (data instanceof Error)
|
||||
throw new Error("Failed to get response from soundcloud.com: " + data.message);
|
||||
|
||||
const splitted = data.split('<script crossorigin src="');
|
||||
const urls: string[] = [];
|
||||
splitted.forEach((r) => {
|
||||
splitted.forEach((r: string) => {
|
||||
if (r.startsWith('https')) {
|
||||
urls.push(r.split('"')[0]);
|
||||
}
|
||||
|
||||
@ -24,7 +24,7 @@ export interface SpotifyDataOptions {
|
||||
file?: boolean;
|
||||
}
|
||||
|
||||
const pattern = /^((https:)?\/\/)?open.spotify.com\/(track|album|playlist)\//;
|
||||
const pattern = /^((https:)?\/\/)?open\.spotify\.com\/(?:intl\-.{2}\/)?(track|album|playlist)\//;
|
||||
/**
|
||||
* Gets Spotify url details.
|
||||
*
|
||||
@ -55,7 +55,9 @@ export async function spotify(url: string): Promise<Spotify> {
|
||||
return err;
|
||||
});
|
||||
if (response instanceof Error) throw response;
|
||||
return new SpotifyTrack(JSON.parse(response));
|
||||
const resObj = JSON.parse(response);
|
||||
if (resObj.error) throw new Error(`Got ${resObj.error.status} from the spotify request: ${resObj.error.message}`);
|
||||
return new SpotifyTrack(resObj);
|
||||
} else if (url_.indexOf('album/') !== -1) {
|
||||
const albumID = url.split('album/')[1].split('&')[0].split('?')[0];
|
||||
const response = await request(`https://api.spotify.com/v1/albums/${albumID}?market=${spotifyData.market}`, {
|
||||
@ -66,7 +68,9 @@ export async function spotify(url: string): Promise<Spotify> {
|
||||
return err;
|
||||
});
|
||||
if (response instanceof Error) throw response;
|
||||
return new SpotifyAlbum(JSON.parse(response), spotifyData, false);
|
||||
const resObj = JSON.parse(response);
|
||||
if (resObj.error) throw new Error(`Got ${resObj.error.status} from the spotify request: ${resObj.error.message}`);
|
||||
return new SpotifyAlbum(resObj, spotifyData, false);
|
||||
} else if (url_.indexOf('playlist/') !== -1) {
|
||||
const playlistID = url.split('playlist/')[1].split('&')[0].split('?')[0];
|
||||
const response = await request(
|
||||
@ -80,7 +84,9 @@ export async function spotify(url: string): Promise<Spotify> {
|
||||
return err;
|
||||
});
|
||||
if (response instanceof Error) throw response;
|
||||
return new SpotifyPlaylist(JSON.parse(response), spotifyData, false);
|
||||
const resObj = JSON.parse(response);
|
||||
if (resObj.error) throw new Error(`Got ${resObj.error.status} from the spotify request: ${resObj.error.message}`);
|
||||
return new SpotifyPlaylist(resObj, spotifyData, false);
|
||||
} else throw new Error('URL is out of scope for play-dl.');
|
||||
}
|
||||
/**
|
||||
|
||||
@ -20,7 +20,7 @@ const video_id_pattern = /^[a-zA-Z\d_-]{11,12}$/;
|
||||
const playlist_id_pattern = /^(PL|UU|LL|RD|OL)[a-zA-Z\d_-]{10,}$/;
|
||||
const DEFAULT_API_KEY = 'AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8';
|
||||
const video_pattern =
|
||||
/^((?:https?:)?\/\/)?(?:(?:www|m|music)\.)?((?:youtube\.com|youtu.be))(\/(?:[\w\-]+\?v=|shorts\/|embed\/|v\/)?)([\w\-]+)(\S+)?$/;
|
||||
/^((?:https?:)?\/\/)?(?:(?:www|m|music)\.)?((?:youtube\.com|youtu.be))(\/(?:[\w\-]+\?v=|shorts\/|embed\/|live\/|v\/)?)([\w\-]+)(\S+)?$/;
|
||||
const playlist_pattern =
|
||||
/^((?:https?:)?\/\/)?(?:(?:www|m|music)\.)?((?:youtube\.com|youtu.be))\/(?:(playlist|watch))?(.*)?((\?|\&)list=)(PL|UU|LL|RD|OL)[a-zA-Z\d_-]{10,}(&.*)?$/;
|
||||
/**
|
||||
@ -81,6 +81,8 @@ function extractVideoId(urlOrId: string): string | false {
|
||||
id = urlOrId.split('youtube.com/embed/')[1].split(/(\?|\/|&)/)[0];
|
||||
} else if (urlOrId.includes('youtube.com/shorts/')) {
|
||||
id = urlOrId.split('youtube.com/shorts/')[1].split(/(\?|\/|&)/)[0];
|
||||
} else if (urlOrId.includes('youtube.com/live/')) {
|
||||
id = urlOrId.split('youtube.com/live/')[1].split(/(\?|\/|&)/)[0];
|
||||
} else {
|
||||
id = (urlOrId.split('watch?v=')[1] ?? urlOrId.split('&v=')[1]).split(/(\?|\/|&)/)[0];
|
||||
}
|
||||
@ -231,7 +233,7 @@ export async function video_basic_info(url: string, options: InfoOptions = {}):
|
||||
});
|
||||
}
|
||||
const rawChapters =
|
||||
initial_response.playerOverlays.playerOverlayRenderer.decoratedPlayerBarRenderer?.decoratedPlayerBarRenderer.playerBar?.multiMarkersPlayerBarRenderer.markersMap.find(
|
||||
initial_response.playerOverlays.playerOverlayRenderer.decoratedPlayerBarRenderer?.decoratedPlayerBarRenderer.playerBar?.multiMarkersPlayerBarRenderer.markersMap?.find(
|
||||
(m: any) => m.key === 'DESCRIPTION_CHAPTERS'
|
||||
)?.value?.chapters;
|
||||
const chapters: VideoChapter[] = [];
|
||||
@ -542,7 +544,7 @@ export async function playlist_info(url: string, options: PlaylistOptions = {}):
|
||||
throw new Error(`While parsing playlist url\n${response.alerts[0].alertRenderer.text.runs[0].text}`);
|
||||
else throw new Error('While parsing playlist url\nUnknown Playlist Error');
|
||||
}
|
||||
if (url_.indexOf('watch?v=') !== -1) {
|
||||
if (response.currentVideoEndpoint) {
|
||||
return getWatchPlaylist(response, body, url_);
|
||||
} else return getNormalPlaylist(response, body);
|
||||
}
|
||||
@ -629,7 +631,7 @@ async function acceptViewerDiscretion(
|
||||
},
|
||||
nextEndpoint: {
|
||||
urlEndpoint: {
|
||||
url: `watch?v=${videoId}`
|
||||
url: `/watch?v=${videoId}&has_verified=1`
|
||||
}
|
||||
},
|
||||
setControvercy: true
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user