From 9046fd897b08cd799cfe594fb84fb073728c34ec Mon Sep 17 00:00:00 2001 From: snobu Date: Mon, 30 Mar 2020 11:05:42 +0300 Subject: [PATCH] Let's use an ES6 array filter cause we influencers boy --- destreamer.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/destreamer.ts b/destreamer.ts index f2421e9..24b0bd6 100644 --- a/destreamer.ts +++ b/destreamer.ts @@ -229,13 +229,17 @@ async function getVideoInfo(videoID: string, session: any) { if (argv.verbose) { console.log(JSON.stringify(data, undefined, 2)); } - for (const item of data["playbackUrls"]) { - if (item["mimeType"] == "application/vnd.apple.mpegurl") { - return item["playbackUrl"]; - } + let playbackUrl = null; + try { + playbackUrl = data["playbackUrls"].filter( + (item: { [x: string]: string; }) => item["mimeType"] == "application/vnd.apple.mpegurl")[0]["playbackUrl"]; } - console.error("Error fetching hlsUrl"); - process.exit(27); + catch (e) { + console.error(`Error fetching hlsUrl: ${e}`); + process.exit(27); + } + + return playbackUrl; }) return [title, hlsUrl];