From 7b3097abf6790c59093422cc8df690da156004d6 Mon Sep 17 00:00:00 2001 From: Daniel Ng Date: Fri, 22 Jun 2018 09:10:59 -0400 Subject: [PATCH] Resolved issue #45. Replaced try/catch statement with if/else for search. (#120) --- src/js/videos.js | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/src/js/videos.js b/src/js/videos.js index 5f018e353..f31435464 100644 --- a/src/js/videos.js +++ b/src/js/videos.js @@ -358,15 +358,33 @@ function parseSearchText(url = '') { let match = input.match(rx); console.log(match); - - // Play video if a match is found. - try { - console.log('Match Found'); - playVideo(match[2]); - } catch (err) { - console.log('Video not found'); - search(); + let urlSplit = input.split('/'); + if(match){ + console.log('Video found'); + playVideo(match[2]); } + else if (urlSplit[3] == 'channel'){ + console.log('channel found'); + goToChannel(urlSplit[4]); + } + else if (urlSplit[3] == 'user'){ + console.log('user found'); + // call api to get the ID and then call goToChannel(id) + youtubeAPI('channels', { + part: 'id', + forUsername: urlSplit[4] + }, (data) => { + console.log(data.items[0].id); + let channelID = data.items[0].id; + goToChannel(channelID); + }); + } + else { + console.log('Video not found'); + search(); + } + + } /**