From 113ed2a1d61e434f35d7fa173770043c80704ddd Mon Sep 17 00:00:00 2001 From: Benjamin C Date: Wed, 22 May 2019 12:53:35 +0200 Subject: [PATCH] Fix: Checking if we have args before testing them Was using ".indexOf" without testing wether we had args or not which could throw error + easier formatting for better understanding --- lib/youtube-dl.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/youtube-dl.js b/lib/youtube-dl.js index 2b95228..f433f63 100644 --- a/lib/youtube-dl.js +++ b/lib/youtube-dl.js @@ -239,9 +239,8 @@ ytdl.exec = function exec(url, args, options, callback) { */ function parseInfo(data) { // Youtube-dl might return just an url as a string when using the "-g" or "--get-url" flag - if (typeof data === "string") - if (data.startsWith("http")) - data = JSON.stringify({url: data}) + if (typeof data === "string" && data.startsWith("http")) + data = JSON.stringify({url: data}); const info = JSON.parse(data); @@ -323,10 +322,9 @@ ytdl.getInfo = function getInfo(url, args, options, callback) { // If using the "-g" or "--get-url" flag youtube-dl will return just a string (the URL to the video) which messes up the parsing // This fixes this behaviour - if (args.indexOf('-g') > -1 || args.indexOf('--get-url') > -1 ) - if (Array.isArray(data)) - if(data.length >= 2) - data.splice(0, 1) + if (args && (args.indexOf("-g") > -1 || args.indexOf("--get-url") > -1)) + if (Array.isArray(data) && data.length >= 2) data.splice(0, 1); + try { info = data.map(parseInfo);