Add null, undefined and string type check to the YouTube info functions

This commit is contained in:
absidue 2021-12-22 18:14:48 +01:00
parent 6d04866e0c
commit 2f522b9140

View File

@ -100,6 +100,8 @@ export function extractID(url: string): string {
* @returns Video Basic Info {@link InfoData}.
*/
export async function video_basic_info(url: string, options: InfoOptions = {}): Promise<InfoData> {
if (url === null || url === undefined || typeof url !== 'string')
throw new Error('url parameter is not a URL string or a string of HTML');
let body: string;
if (options.htmldata) {
body = url;
@ -205,6 +207,8 @@ export async function video_basic_info(url: string, options: InfoOptions = {}):
* @returns Deciphered Video Info {@link StreamInfoData}.
*/
export async function video_stream_info(url: string, options: InfoOptions = {}): Promise<StreamInfoData> {
if (url === null || url === undefined || typeof url !== 'string')
throw new Error('url parameter is not a URL string or a string of HTML');
let body: string;
if (options.htmldata) {
body = url;