Error Fixes

This commit is contained in:
killer069 2021-08-20 12:43:58 +05:30
parent ad1ad2b918
commit b969de06e2
3 changed files with 5 additions and 6 deletions

4
package-lock.json generated
View File

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

View File

@ -1,6 +1,6 @@
{ {
"name": "play-dl", "name": "play-dl",
"version": "0.1.7", "version": "0.2.1",
"description": "YouTube, SoundCloud, Spotify downloader", "description": "YouTube, SoundCloud, Spotify downloader",
"main": "dist/index.js", "main": "dist/index.js",
"typings": "dist/index.d.ts", "typings": "dist/index.d.ts",

View File

@ -4,11 +4,10 @@ import { Video } from '../classes/Video'
import { PlayList } from '../classes/Playlist' import { PlayList } from '../classes/Playlist'
const DEFAULT_API_KEY = "AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8"; const DEFAULT_API_KEY = "AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8";
const youtube_url = /https:\/\/www.youtube.com\//g 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+)?$/;
export async function video_basic_info(url : string){ export async function video_basic_info(url : string){
if(!url.match(youtube_url) || !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 = url.split('watch?v=')[1].split('&')[0] let video_id = url.split('watch?v=')[1].split('&')[0]
let new_url = 'https://www.youtube.com/watch?v=' + video_id let new_url = 'https://www.youtube.com/watch?v=' + video_id
let body = await url_get(new_url) let body = await url_get(new_url)