commit
7985f03de0
12
README.md
12
README.md
@ -33,12 +33,24 @@ const results = await youtube.search('post malone sunflower', options);
|
|||||||
```
|
```
|
||||||
|
|
||||||
# Validate
|
# Validate
|
||||||
|
|
||||||
### validate( url : `string` )
|
### validate( url : `string` )
|
||||||
*Much faster and easier way to validate url.*
|
*Much faster and easier way to validate url.*
|
||||||
```js
|
```js
|
||||||
if(validate(url)) // Will return true if url is a YouTube url
|
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
|
||||||
|
|
||||||
### stream(url : `string`)
|
### stream(url : `string`)
|
||||||
|
|||||||
4
package-lock.json
generated
4
package-lock.json
generated
@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "play-dl",
|
"name": "play-dl",
|
||||||
"version": "0.6.9",
|
"version": "0.7.0",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "play-dl",
|
"name": "play-dl",
|
||||||
"version": "0.6.9",
|
"version": "0.7.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"got": "^11.8.2"
|
"got": "^11.8.2"
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "play-dl",
|
"name": "play-dl",
|
||||||
"version": "0.6.9",
|
"version": "0.7.0",
|
||||||
"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",
|
||||||
|
|||||||
@ -5,12 +5,22 @@ import { PlayList } from '../classes/Playlist'
|
|||||||
|
|
||||||
const DEFAULT_API_KEY = "AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8";
|
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 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{
|
export function validate(url : string): boolean{
|
||||||
if(!url.match(video_pattern)) return false
|
if(!url.match(video_pattern)) return false
|
||||||
else return true
|
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){
|
export async function video_basic_info(url : string){
|
||||||
if(!url.match(video_pattern)) throw new Error('This is not a YouTube URL')
|
if(!url.match(video_pattern)) throw new Error('This is not a YouTube URL')
|
||||||
let video_id : string;
|
let video_id : string;
|
||||||
|
|||||||
@ -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'
|
||||||
@ -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";
|
||||||
Loading…
x
Reference in New Issue
Block a user