changing regex, allowing @ for channels
This commit is contained in:
parent
361dba2197
commit
a90a35343a
|
@ -1,10 +1,12 @@
|
||||||
|
const fetch = require('node-fetch')
|
||||||
|
|
||||||
async function validateVideoInput(input) {
|
async function validateVideoInput(input) {
|
||||||
if (!input) return {
|
if (!input) return {
|
||||||
fail: true,
|
fail: true,
|
||||||
message: 'Missing URL'
|
message: 'Missing URL'
|
||||||
}
|
}
|
||||||
|
|
||||||
const id = input.match(/https:\/\/(?:(?:www\.)?youtube\.com\/(?:watch\?v=|shorts\/)|youtu\.be\/)([A-Za-z0-9_-]{11})/)?.[1]
|
const id = (input.trim()).match(/^https:\/\/(?:(?:www\.)?youtube\.com\/(?:watch\?v=|shorts\/)|youtu\.be\/)([A-Za-z0-9_-]{11})$/m)?.[1]
|
||||||
if (!id) return {
|
if (!id) return {
|
||||||
fail: true,
|
fail: true,
|
||||||
message: 'Whoops! What is that? That is not a Youtube url.'
|
message: 'Whoops! What is that? That is not a Youtube url.'
|
||||||
|
@ -19,7 +21,7 @@ async function validatePlaylistInput(input) {
|
||||||
message: 'Missing URL'
|
message: 'Missing URL'
|
||||||
}
|
}
|
||||||
|
|
||||||
const id = input.match(/^.*(youtu.be\/|list=)([^#\&\?]*).*/)?.[2]
|
const id = (input.trim()).match(/^(?:https?:\/\/)?(?:www\.)?youtu(?:(?:\.be)|(?:be\.com))\/playlist\?list=([\w_-]{34})$/m)?.[1]
|
||||||
if (!id) return {
|
if (!id) return {
|
||||||
fail: true,
|
fail: true,
|
||||||
message: 'Whoops! What is that? That is not a Youtube Playlist.'
|
message: 'Whoops! What is that? That is not a Youtube Playlist.'
|
||||||
|
@ -34,13 +36,18 @@ async function validateChannelInput(input) {
|
||||||
message: 'Missing URL'
|
message: 'Missing URL'
|
||||||
}
|
}
|
||||||
|
|
||||||
const id = input.match(/https?:\/\/(?:www\.)?youtube\.com\/(?:channel\/(.*?)\/featured|(?:.*\/)*(.+))/)?.[2]
|
const id = input.match(/^(?:https?:\/\/)?(?:www\.)?youtu(?:(?:\.be)|(?:be\.com))\/(?:channel\/|@)([\w-]+)/m)?.[1]
|
||||||
if (!id) return {
|
if (!id) return {
|
||||||
fail: true,
|
fail: true,
|
||||||
message: 'Whoops! What is that? That is not a Youtube Channel.'
|
message: 'Whoops! What is that? That is not a Youtube Channel.'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (input.includes('@')) {
|
||||||
|
const channelId = await (await fetch(`https://yt.jaybee.digital/api/channels?part=channels&handle=${id}`)).json()
|
||||||
|
return channelId['items'][0]['id']
|
||||||
|
} else {
|
||||||
return id
|
return id
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { validateVideoInput, validatePlaylistInput, validateChannelInput }
|
module.exports = { validateVideoInput, validatePlaylistInput, validateChannelInput }
|
Loading…
Reference in New Issue