Skip to content

Commit

Permalink
finish Spotify,OMDB, and BandsinTown, working on moment and do what i…
Browse files Browse the repository at this point in the history
…t says
  • Loading branch information
motoko104 committed Oct 13, 2018
1 parent a9fd2b3 commit 09020fb
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 34 deletions.
98 changes: 64 additions & 34 deletions liri.js
Original file line number Diff line number Diff line change
@@ -1,77 +1,105 @@
//Necessary Files and Packages for running Liri
require("dotenv").config();
let keys = require("./keys");
let fs = require("fs");
let request = require("request");
let Spotify = require("node-spotify-api");
let omdb = require("omdb");
let BandsIT = require("bandsintown");
const chalk = require('chalk');
const keys = require("./keys");
const fs = require("fs");
const request = require("request");
const Spotify = require("node-spotify-api");
const omdb = require("omdb");
const BandsIT = require("bandsintown");

//Keys for Spotify, OMDB, and Bands in Town API's
let spotify = new Spotify(keys.spotify);
let omdbKey = keys.omdb;
//let bands = new BandsIT();
let bands = keys.bands;

//Variables to save users command and input
let command = process.argv[2];
let input = process.argv.splice(3);

// Funtions that perform specific task
// Searching Spotify by song
let spotifySong = (song) => {

// cannot get default to work for some reason
if (song.length < 1) {
if (song === '') {
song = "The Sign";
};

// search request through spotify
spotify.search({ type: 'track', query: song }, function (err, data) {
if (err) {
console.log("Oops! error: " + err);
console.log(chalk.redBright("Oops! error: " + err));
return;
} else {
console.log("\n-------------------\n Song Info " + song + " \n------------------- \n");
console.log("Artist: " + data.tracks.items[0].album.artists[0].name);
console.log("Song Name: " + data.tracks.items[0].name);
console.log("Preview Link: " + data.tracks.items[0].preview_url);
console.log("Album: " + data.tracks.items[0].album.name);
console.log("\n -------------------\n");
console.log(chalk.magentaBright("\n-------------------------------------------------------------\n \tSong Info For '" + song + "' \n-------------------------------------------------------------\n"));
console.log(chalk.blueBright("Artist: ") + data.tracks.items[0].album.artists[0].name);
console.log(chalk.blueBright("Song Name: ") + data.tracks.items[0].name);
console.log(chalk.blueBright("Preview Link: ") + data.tracks.items[0].preview_url);
console.log(chalk.blueBright("Album: ") + data.tracks.items[0].album.name);
console.log(chalk.magentaBright("\n-------------------------------------------------------------\n"));
}
});
}
//Searching Bands in town by band
let BandEvnt = (input) => {

let BandEvnt = (band) => {
//need to fix default band conditions
if (band === '') {
band = 'Marilyn Manson';
}
let search = "https://rest.bandsintown.com/artists/" + band + "/events?app_id=" + bands.id;
//request to the BandsInTown API
request(search, function (err, res, body) {
if (err) {
console.log(chalk.bold.redBright("Ooops! Error occured: " + err));
return;
} else {
let data = JSON.parse(body);
console.log(chalk.bold.magentaBright("\n-------------------------------------------------------------\n \t Concert \"" + band + "\" Info \n-------------------------------------------------------------\n"));
for (let i = 0; i < data.length; i++) {
console.log(chalk.bold.magentaBright("-------------------------------------------------------------\n"));
console.log(chalk.yellow("Venue: ") + data[i].venue.name);
console.log(chalk.yellow("Location: ") + data[i].venue.city);
console.log(chalk.yellow("Date of Concert: ") + data[i].datetime);
console.log(chalk.bold.magentaBright("\n-------------------------------------------------------------\n"));
}
}
});
};

//Searching IMDB by movie titles
let movieSearch = (mov) => {
if (!mov) {
//need to find solution for default movie search
if (mov === '') {
mov = 'Mr. Nobody';
}
let search = "http://www.omdbapi.com/?apikey=" + omdbKey.key + "&t=" + mov + "&plot=short";

// need to fix defaul error
request(search, function (err, res, body) {
if (err) {
console.log("Ooops! Error occured: " + err);
console.log(chalk.bold.redBright("Ooops! Error occured: " + err));
return;
} else {
let data = JSON.parse(body);
console.log("\n-------------------\n Movie \"" + mov + "\" Info \n------------------- \n");
console.log("Title: " + data.Title);
console.log("Year: " + data.Year);
console.log("IMDB Rating: " + data.imdbRating);
console.log("Rotten Tomatoes Rating: " + data.Ratings[1].Value);
console.log("County of Production: " + data.Country);
console.log("Language: " + data.Language);
console.log("Plot: " + data.Plot)
console.log("Actors: " + data.Actors);
console.log("\n -------------------\n");
console.log(chalk.bold.magentaBright("\n-------------------------------------------------------------\n \tMovie Info \n-------------------------------------------------------------\n"));
console.log(chalk.greenBright("Title: ") + data.Title);
console.log(chalk.greenBright("Year: ") + data.Year);
console.log(chalk.greenBright("IMDB Rating: ") + data.imdbRating);
console.log(chalk.greenBright("Rotten Tomatoes Rating: ") + data.Ratings[1].Value);
console.log(chalk.greenBright("County of Production: ") + data.Country);
console.log(chalk.greenBright("Language: ") + data.Language);
console.log(chalk.greenBright("Plot: ") + data.Plot)
console.log(chalk.greenBright("Actors: ") + data.Actors);
console.log(chalk.bold.magentaBright("\n-------------------------------------------------------------\n"));
}
});
}
//Using text in the random.txt file to call one of LIRI's commands
const doingIt = () => {

}
//Displays list of commands that are acceptable
const optionsList = () => {

console.log(chalk.bold.red("\nSorry invalid command was entered. Please try again. \n \n The requests you can make are:"));
console.log(chalk.greenBright("\t spotify-this-song 'SONG TITLE GOES HERE' \n \t concert-this 'ARTIST/BAND NAME GOES HERE'\n \t movie-this 'MOVIE TITLE GOES HERE'\n \t do-what-it-says \n"));
};

// Codes for each command input
Expand All @@ -80,11 +108,13 @@ switch (command) {
spotifySong(input);
break;
case 'concert-this':
BandEvnt();
BandEvnt(input);
break;
case 'movie-this':
movieSearch(input);
break;
case 'do-what-it-says':
doingIt();
default:
optionsList();
}
49 changes: 49 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
"keywords": [],
"dependencies": {
"bandsintown": "^1.0.1",
"chalk": "^2.4.1",
"dotenv": "^6.1.0",
"fs": "0.0.1-security",
"moment": "^2.22.2",
"node-spotify-api": "^1.0.7",
"omdb": "^0.8.0",
"request": "^2.88.0",
Expand Down

0 comments on commit 09020fb

Please sign in to comment.