Resolved issue #45. Replaced try/catch statement with if/else for search. (#120)

This commit is contained in:
Daniel Ng 2018-06-22 09:10:59 -04:00 committed by Preston
parent ac56d82848
commit 20b23facad
1 changed files with 26 additions and 8 deletions

View File

@ -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();
}
}
/**