Skip to content
This repository has been archived by the owner on Dec 3, 2023. It is now read-only.

Commit

Permalink
Fix: Checking if we have args before testing them
Browse files Browse the repository at this point in the history
Was using ".indexOf" without testing wether we had args or not which could throw error

+ easier formatting for better understanding
  • Loading branch information
Coriou committed May 22, 2019
1 parent cfff104 commit 113ed2a
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions lib/youtube-dl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 113ed2a

Please sign in to comment.