Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const hbs = require('hbs');

// require spotify-web-api-node package here:

const SpotifyWebApi = require('spotify-web-api-node');

const app = express();

app.set('view engine', 'hbs');
Expand All @@ -13,6 +15,64 @@ app.use(express.static(__dirname + '/public'));

// setting the spotify-api goes here:

const spotifyApi = new SpotifyWebApi({
clientId: process.env.CLIENT_ID,
clientSecret: process.env.CLIENT_SECRET
});

// Retrieve an access token
spotifyApi
.clientCredentialsGrant()
.then(data => spotifyApi.setAccessToken(data.body['access_token']))
.catch(error => console.log('Something went wrong when retrieving an access token', error));


// Our routes go here:

app.get('/', (req, res) => {
res.render('index.hbs')
});


app.get('/artist-search', (req, res) => {
spotifyApi
.searchArtists(req.query.artist)
.then(data => {
console.log('The received data from the API: ', data.body.artists.items);
// ----> 'HERE'S WHAT WE WANT TO DO AFTER RECEIVING THE DATA FROM THE API'
res.render('artist-search-results', {artists: data.body.artists.items})
})
.catch(err => console.log('The error while searching artists occurred: ', err));

});

app.get('/albums/:artistId', (req, res) => {
// .getArtistAlbums() code goes here
console.log(req.params.artistId);
spotifyApi
.getArtistAlbums(req.params.artistId)
.then(data => {
console.log(data.body.items[0]);
//console.log('Albums received from the API:', data.body.items)
res.render('albums', {
artistName: data.body.items[0].artists[0].name ,
albums: data.body.items
})
})
.catch(err => console.log('The error while fetching albums occurred:', err))
});

app.get('/tracks/:albumId', (req, res) => {
spotifyApi
.getAlbumTracks(req.params.albumId)
.then(data => {
console.log('tracks received from the API:', data.body.items)
res.render('tracks', {
tracks : data.body.items
})
})
})



app.listen(3000, () => console.log('My Spotify project running on port 3000 🎧 🥁 🎸 🔊'));
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,11 @@
"license": "ISC",
"devDependencies": {
"nodemon": "^2.0.2"
},
"dependencies": {
"dotenv": "^16.4.5",
"express": "^4.19.2",
"hbs": "^4.2.0",
"spotify-web-api-node": "^5.0.2"
}
}
60 changes: 60 additions & 0 deletions public/styles/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
html{
height: 100%;
width: 100%;
}
body{
background-image: url(/images/spotify-background.jpeg);
background-size: cover;
width: 100%;
height: 100%;
}

.index-form-container{
display: flex;
justify-content: center;
height: 100%;
width: 100%;
align-items: center;
}
.index-form-container form{
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
width: 640px;
height: 300px;
background-color: rgb(235 225 224 / 39%);
}
.index-form-container form input{
margin:10px;
}

.artist-items{
display: flex;
flex-direction: row;
flex-wrap: wrap;
}
.artist-item{
display: flex;
flex-wrap: wrap;
width: fit-content;
flex-direction: column;
margin: 30px;
align-items: center;
background-color: grey;

}

.artist-item img{
height: 235px;
width: 235px;
}

.track{
display: flex;
margin: 20px;
background-color: rgb(235 225 224 / 39%);
border-radius: 3%;
justify-content: space-between;
padding: 12px;
}
10 changes: 10 additions & 0 deletions views/albums.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<h1>Albums for: {{artistName}}</h1>
<div class="artist-items">
{{#each albums}}
<div class="album artist-item">
<h2>{{name}}</h2>
<img src="{{images.[0].url}}" alt=" Album Cover of {{name}}">
<button><a href="/tracks/{{id}}"> View Songs</a></button>
</div>
{{/each}}
</div>
11 changes: 11 additions & 0 deletions views/artist-search-results.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

<div class="artist-items">
{{#each artists}}
<div class="artist-item">
<img src="{{images.[0].url}}" alt=" Image of {{name}}">
<p>{{name}}</p>
<button><a href="/albums/{{id}}"> View Albums</a></button>
</div>
{{/each}}
</div>

6 changes: 6 additions & 0 deletions views/index.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<div class="index-form-container">
<form action="/artist-search" method="GET">
<input type="text" name="artist" id="">
<button type="submit">Search for an Artist</button>
</form>
</div>
12 changes: 12 additions & 0 deletions views/layout.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="/styles/style.css">
<title>Document</title>
</head>
<body>
{{{ body }}}
</body>
</html>
10 changes: 10 additions & 0 deletions views/tracks.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{{#each tracks}}
<div class="track">
<p>{{name}}</p>
{{#if preview-url}}
<audio src="{{preview_url}}"></audio>
{{else}}
<div>Doesnt have a preview linkg</div>
{{/if}}
</div>
{{/each}}