Merge pull request #30 from play-dl/developer

Validation methods added
This commit is contained in:
Killer069 2021-08-31 10:17:44 +05:30 committed by GitHub
commit 7985f03de0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 27 additions and 5 deletions

View File

@ -33,12 +33,24 @@ const results = await youtube.search('post malone sunflower', options);
```
# Validate
### validate( url : `string` )
*Much faster and easier way to validate url.*
```js
if(validate(url)) // Will return true if url is a YouTube url
```
### validate_playlist( url : `string` )
*Much faster and easier way to validate url.*
```js
if(validate_playlist(url)) // Will return true if url is a YouTube Playlist url
```
> Want to Check both, use this
```js
if(validate(url) || validate_playlist(url)) // This will check both and if anyone is true, it will execute the below function
```
# Stream
### stream(url : `string`)

4
package-lock.json generated
View File

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

View File

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

View File

@ -5,12 +5,22 @@ import { PlayList } from '../classes/Playlist'
const DEFAULT_API_KEY = "AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8";
const video_pattern = /^((?:https?:)?\/\/)?(?:(?:www|m)\.)?((?:youtube\.com|youtu.be))(\/(?:[\w\-]+\?v=|embed\/|v\/)?)([\w\-]+)(\S+)?$/;
const playlist_pattern = /^((?:https?:)?\/\/)?(?:(?:www|m)\.)?(youtube\.com)\/(?:(playlist|watch))(.*)?((\?|\&)list=)/
export function validate(url : string): boolean{
if(!url.match(video_pattern)) return false
else return true
}
export function validate_playlist(url : string): boolean{
if(!url.match(playlist_pattern)) return false
let Playlist_id = url.split('list=')[1].split('&')[0]
if(Playlist_id.length !== 34 || !Playlist_id.startsWith('PL')){
return false
}
return true
}
export async function video_basic_info(url : string){
if(!url.match(video_pattern)) throw new Error('This is not a YouTube URL')
let video_id : string;

View File

@ -1 +1 @@
export { video_basic_info, video_info, playlist_info, validate } from './extractor'
export { video_basic_info, video_info, playlist_info, validate, validate_playlist } from './extractor'

View File

@ -1 +1 @@
export { playlist_info, video_basic_info, video_info, search, stream, stream_from_info, validate } from "./YouTube";
export { playlist_info, video_basic_info, video_info, search, stream, stream_from_info, validate, validate_playlist } from "./YouTube";