Validate URL + All Errors Fixed

This commit is contained in:
killer069
2021-08-31 09:09:10 +05:30
parent f2d030cdc7
commit eaf18cfca4
4 changed files with 25 additions and 21 deletions

View File

@@ -6,6 +6,11 @@ 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+)?$/;
export function validate(url : string): boolean{
if(!url.match(video_pattern)) return false
else 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;