Simplify regular expressions
This commit is contained in:
parent
6c607f062f
commit
770e896cc0
@ -92,7 +92,7 @@ async function internalValidate(url: string): Promise<TypeData> {
|
|||||||
return { type: false };
|
return { type: false };
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((path[1] === 'track' || path[1] === 'album' || path[1] === 'playlist') && path[2].match(/^[0-9]+$/)) {
|
if ((path[1] === 'track' || path[1] === 'album' || path[1] === 'playlist') && path[2].match(/^\d+$/)) {
|
||||||
return {
|
return {
|
||||||
type: path[1],
|
type: path[1],
|
||||||
id: path[2]
|
id: path[2]
|
||||||
@ -105,7 +105,7 @@ async function internalValidate(url: string): Promise<TypeData> {
|
|||||||
if (
|
if (
|
||||||
path.length === 3 &&
|
path.length === 3 &&
|
||||||
(path[1] === 'track' || path[1] === 'album' || path[1] === 'playlist') &&
|
(path[1] === 'track' || path[1] === 'album' || path[1] === 'playlist') &&
|
||||||
path[2].match(/^[0-9]+$/)
|
path[2].match(/^\d+$/)
|
||||||
) {
|
) {
|
||||||
return {
|
return {
|
||||||
type: path[1],
|
type: path[1],
|
||||||
|
|||||||
@ -9,7 +9,7 @@ interface formatOptions {
|
|||||||
s?: string;
|
s?: string;
|
||||||
}
|
}
|
||||||
// RegExp for various js functions
|
// RegExp for various js functions
|
||||||
const var_js = '[a-zA-Z_\\$][a-zA-Z_0-9]*';
|
const var_js = '[a-zA-Z_\\$]\\w*';
|
||||||
const singlequote_js = `'[^'\\\\]*(:?\\\\[\\s\\S][^'\\\\]*)*'`;
|
const singlequote_js = `'[^'\\\\]*(:?\\\\[\\s\\S][^'\\\\]*)*'`;
|
||||||
const duoblequote_js = `"[^"\\\\]*(:?\\\\[\\s\\S][^"\\\\]*)*"`;
|
const duoblequote_js = `"[^"\\\\]*(:?\\\\[\\s\\S][^"\\\\]*)*"`;
|
||||||
const quote_js = `(?:${singlequote_js}|${duoblequote_js})`;
|
const quote_js = `(?:${singlequote_js}|${duoblequote_js})`;
|
||||||
|
|||||||
@ -468,12 +468,12 @@ function getNormalPlaylist(response: any, body: any): YouTubePlayList {
|
|||||||
if (!data.title.runs || !data.title.runs.length) throw new Error('Failed to Parse Playlist info.');
|
if (!data.title.runs || !data.title.runs.length) throw new Error('Failed to Parse Playlist info.');
|
||||||
|
|
||||||
const author = playlist_details[1]?.playlistSidebarSecondaryInfoRenderer.videoOwner;
|
const author = playlist_details[1]?.playlistSidebarSecondaryInfoRenderer.videoOwner;
|
||||||
const views = data.stats.length === 3 ? data.stats[1].simpleText.replace(/[^0-9]/g, '') : 0;
|
const views = data.stats.length === 3 ? data.stats[1].simpleText.replace(/\D/g, '') : 0;
|
||||||
const lastUpdate =
|
const lastUpdate =
|
||||||
data.stats
|
data.stats
|
||||||
.find((x: any) => 'runs' in x && x['runs'].find((y: any) => y.text.toLowerCase().includes('last update')))
|
.find((x: any) => 'runs' in x && x['runs'].find((y: any) => y.text.toLowerCase().includes('last update')))
|
||||||
?.runs.pop()?.text ?? null;
|
?.runs.pop()?.text ?? null;
|
||||||
const videosCount = data.stats[0].runs[0].text.replace(/[^0-9]/g, '') || 0;
|
const videosCount = data.stats[0].runs[0].text.replace(/\D/g, '') || 0;
|
||||||
|
|
||||||
const res = new YouTubePlayList({
|
const res = new YouTubePlayList({
|
||||||
continuation: {
|
continuation: {
|
||||||
|
|||||||
@ -146,7 +146,7 @@ export function parseVideo(data?: any): YouTubeVideo {
|
|||||||
artist: Boolean(badge?.includes('artist'))
|
artist: Boolean(badge?.includes('artist'))
|
||||||
},
|
},
|
||||||
uploadedAt: data.videoRenderer.publishedTimeText?.simpleText ?? null,
|
uploadedAt: data.videoRenderer.publishedTimeText?.simpleText ?? null,
|
||||||
views: data.videoRenderer.viewCountText?.simpleText?.replace(/[^0-9]/g, '') ?? 0,
|
views: data.videoRenderer.viewCountText?.simpleText?.replace(/\D/g, '') ?? 0,
|
||||||
live: durationText ? false : true
|
live: durationText ? false : true
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -179,7 +179,7 @@ export function parsePlaylist(data?: any): YouTubePlayList {
|
|||||||
name: channel?.text,
|
name: channel?.text,
|
||||||
url: `https://www.youtube.com${channel?.navigationEndpoint.commandMetadata.webCommandMetadata.url}`
|
url: `https://www.youtube.com${channel?.navigationEndpoint.commandMetadata.webCommandMetadata.url}`
|
||||||
},
|
},
|
||||||
videos: parseInt(data.playlistRenderer.videoCount.replace(/[^0-9]/g, ''))
|
videos: parseInt(data.playlistRenderer.videoCount.replace(/\D/g, ''))
|
||||||
},
|
},
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user