diff --git a/.DS_Store b/.DS_Store index 169e4b4..4a374fb 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/bin/www b/bin/www index 9a715f7..1459c4e 100755 --- a/bin/www +++ b/bin/www @@ -12,7 +12,8 @@ var http = require('http'); * Get port from environment and store in Express. */ -var port = normalizePort('3001'); + +var port = normalizePort('3000'); app.set('port', port); /** diff --git a/models/track.js b/models/track.js index ce58db9..90ef31c 100644 --- a/models/track.js +++ b/models/track.js @@ -1,11 +1,11 @@ class Track{ - constructor(album_name, popularity, artist, song_name, uri){ + constructor(album_name, popularity, artist, song_name, id){ this.album_name = album_name; this.popularity = popularity; this.artist = artist; this.song_name = song_name; - this.uri = uri; + this.id = id; } } diff --git a/package-lock.json b/package-lock.json index 085fa85..4400f8a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,6 +13,17 @@ "negotiator": "0.6.1" } }, + "ajv": { + "version": "5.5.2", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-5.5.2.tgz", + "integrity": "sha1-c7Xuyj+rZT49P5Qis0GtQiBdyWU=", + "requires": { + "co": "4.6.0", + "fast-deep-equal": "1.1.0", + "fast-json-stable-stringify": "2.0.0", + "json-schema-traverse": "0.3.1" + } + }, "align-text": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/align-text/-/align-text-0.1.4.tgz", @@ -33,11 +44,36 @@ "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", "integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=" }, + "asn1": { + "version": "0.2.3", + "resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.3.tgz", + "integrity": "sha1-2sh4dxPJlmhJ/IGAd36+nB3fO4Y=" + }, + "assert-plus": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz", + "integrity": "sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU=" + }, "async": { "version": "1.5.2", "resolved": "https://registry.npmjs.org/async/-/async-1.5.2.tgz", "integrity": "sha1-7GphrlZIDAw8skHJVhjiCJL5Zyo=" }, + "asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=" + }, + "aws-sign2": { + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/aws-sign2/-/aws-sign2-0.7.0.tgz", + "integrity": "sha1-tG6JCTSpWR8tL2+G1+ap8bP+dqg=" + }, + "aws4": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.7.0.tgz", + "integrity": "sha512-32NDda82rhwD9/JBCCkB+MRYDp0oSvlo2IL6rQWA10PQi7tDUM3eqMSltXmY+Oyl/7N3P3qNtAlv7X0d9bI28w==" + }, "basic-auth": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/basic-auth/-/basic-auth-2.0.0.tgz", @@ -46,6 +82,20 @@ "safe-buffer": "5.1.1" } }, + "bcrypt-pbkdf": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.2.tgz", + "integrity": "sha1-pDAdOJtqQ/m2f/PKEaP2Y342Dp4=", + "optional": true, + "requires": { + "tweetnacl": "0.14.5" + } + }, + "bluebird": { + "version": "3.5.1", + "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.1.tgz", + "integrity": "sha512-MKiLiV+I1AA596t9w1sQJ8jkiSr5+ZKi0WKrYGUn6d1Fx+Ij4tIj+m2WMQSGczs5jZVxV339chE8iwk6F64wjA==" + }, "body-parser": { "version": "1.18.2", "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.18.2.tgz", @@ -74,6 +124,11 @@ "integrity": "sha1-m7UwTS4LVmmLLHWLCKPqqdqlijk=", "optional": true }, + "caseless": { + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz", + "integrity": "sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=" + }, "center-align": { "version": "0.1.3", "resolved": "https://registry.npmjs.org/center-align/-/center-align-0.1.3.tgz", @@ -103,6 +158,11 @@ } } }, + "co": { + "version": "4.6.0", + "resolved": "https://registry.npmjs.org/co/-/co-4.6.0.tgz", + "integrity": "sha1-bqa989hTrlTMuOR7+gvz+QMfsYQ=" + }, "combined-stream": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.6.tgz", @@ -155,6 +215,14 @@ "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=" }, + "dashdash": { + "version": "1.14.1", + "resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz", + "integrity": "sha1-hTz6D3y+L+1d4gMmuN1YEDX24vA=", + "requires": { + "assert-plus": "1.0.0" + } + }, "debug": { "version": "2.6.9", "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", @@ -189,6 +257,15 @@ "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-6.0.0.tgz", "integrity": "sha512-FlWbnhgjtwD+uNLUGHbMykMOYQaTivdHEmYwAKFjn6GKe/CqY0fNae93ZHTd20snh9ZLr8mTzIL9m0APQ1pjQg==" }, + "ecc-jsbn": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.1.tgz", + "integrity": "sha1-D8c6ntXw1Tw4GTOYUj735UN3dQU=", + "optional": true, + "requires": { + "jsbn": "0.1.1" + } + }, "ee-first": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", @@ -251,6 +328,21 @@ "resolved": "https://registry.npmjs.org/extend/-/extend-3.0.1.tgz", "integrity": "sha1-p1Xqe8Gt/MWjHOfnYtuq3F5jZEQ=" }, + "extsprintf": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/extsprintf/-/extsprintf-1.3.0.tgz", + "integrity": "sha1-lpGEQOMEGnpBT4xS48V06zw+HgU=" + }, + "fast-deep-equal": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-1.1.0.tgz", + "integrity": "sha1-wFNHeBfIa1HaqFPIHgWbcz0CNhQ=" + }, + "fast-json-stable-stringify": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz", + "integrity": "sha1-1RQsDK7msRifh9OnYREGT4bIu/I=" + }, "finalhandler": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.1.1.tgz", @@ -270,6 +362,11 @@ "resolved": "https://registry.npmjs.org/foreachasync/-/foreachasync-3.0.0.tgz", "integrity": "sha1-VQKYfchxS+M5IJfzLgBxyd7gfPY=" }, + "forever-agent": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/forever-agent/-/forever-agent-0.6.1.tgz", + "integrity": "sha1-+8cfDEGt6zf5bFd60e1C2P2sypE=" + }, "form-data": { "version": "1.0.0-rc4", "resolved": "https://registry.npmjs.org/form-data/-/form-data-1.0.0-rc4.tgz", @@ -295,6 +392,14 @@ "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", "integrity": "sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac=" }, + "getpass": { + "version": "0.1.7", + "resolved": "https://registry.npmjs.org/getpass/-/getpass-0.1.7.tgz", + "integrity": "sha1-Xv+OPmhNVprkyysSgmBOi6YhSfo=", + "requires": { + "assert-plus": "1.0.0" + } + }, "handlebars": { "version": "4.0.5", "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.0.5.tgz", @@ -306,6 +411,20 @@ "uglify-js": "2.8.29" } }, + "har-schema": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/har-schema/-/har-schema-2.0.0.tgz", + "integrity": "sha1-qUwiJOvKwEeCoNkDVSHyRzW37JI=" + }, + "har-validator": { + "version": "5.0.3", + "resolved": "https://registry.npmjs.org/har-validator/-/har-validator-5.0.3.tgz", + "integrity": "sha1-ukAsJmGU8VlW7xXg/PJCmT9qff0=", + "requires": { + "ajv": "5.5.2", + "har-schema": "2.0.0" + } + }, "hbs": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/hbs/-/hbs-4.0.1.tgz", @@ -326,6 +445,16 @@ "statuses": "1.4.0" } }, + "http-signature": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/http-signature/-/http-signature-1.2.0.tgz", + "integrity": "sha1-muzZJRFHcvPZW2WmCruPfBj7rOE=", + "requires": { + "assert-plus": "1.0.0", + "jsprim": "1.4.1", + "sshpk": "1.14.2" + } + }, "iconv-lite": { "version": "0.4.19", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.19.tgz", @@ -346,11 +475,53 @@ "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.6.tgz", "integrity": "sha1-76ouqdqg16suoTqXsritUf776L4=" }, + "is-typedarray": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz", + "integrity": "sha1-5HnICFjfDBsR3dppQPlgEfzaSpo=" + }, "isarray": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=" }, + "isstream": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz", + "integrity": "sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo=" + }, + "jsbn": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz", + "integrity": "sha1-peZUwuWi3rXyAdls77yoDA7y9RM=", + "optional": true + }, + "json-schema": { + "version": "0.2.3", + "resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.2.3.tgz", + "integrity": "sha1-tIDIkuWaLwWVTOcnvT8qTogvnhM=" + }, + "json-schema-traverse": { + "version": "0.3.1", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.3.1.tgz", + "integrity": "sha1-NJptRMU6Ud6JtAgFxdXlm0F9M0A=" + }, + "json-stringify-safe": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz", + "integrity": "sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus=" + }, + "jsprim": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.1.tgz", + "integrity": "sha1-MT5mvB5cwG5Di8G3SZwuXFastqI=", + "requires": { + "assert-plus": "1.0.0", + "extsprintf": "1.3.0", + "json-schema": "0.2.3", + "verror": "1.10.0" + } + }, "kind-of": { "version": "3.2.2", "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-3.2.2.tgz", @@ -365,6 +536,11 @@ "integrity": "sha1-odePw6UEdMuAhF07O24dpJpEbo4=", "optional": true }, + "lodash": { + "version": "4.17.10", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.10.tgz", + "integrity": "sha512-UejweD1pDoXu+AD825lWwp4ZGtSwgnpZxb3JDViD7StjQz+Nb/6l093lx4OQ0foGWNRoc19mWy7BzL+UAK2iVg==" + }, "longest": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/longest/-/longest-1.0.1.tgz", @@ -430,6 +606,20 @@ "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.1.tgz", "integrity": "sha1-KzJxhOiZIQEXeyhWP7XnECrNDKk=" }, + "node-spotify-api": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/node-spotify-api/-/node-spotify-api-1.0.7.tgz", + "integrity": "sha512-/nM5ImBjgatzdRHc3MVY+t9iynC0LpO1PEkOlfyG1ogtlny2dQ++oq9m3qLJocbEqtZxtg66w5z4DXxdlSOsSg==", + "requires": { + "request": "2.87.0", + "request-promise": "4.2.2" + } + }, + "oauth-sign": { + "version": "0.8.2", + "resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.8.2.tgz", + "integrity": "sha1-Rqarfwrq2N6unsBWV4C31O/rnUM=" + }, "on-finished": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz", @@ -462,6 +652,11 @@ "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz", "integrity": "sha1-32BBeABfUi8V60SQ5yR6G/qmf4w=" }, + "performance-now": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz", + "integrity": "sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=" + }, "process-nextick-args": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.0.tgz", @@ -476,6 +671,11 @@ "ipaddr.js": "1.6.0" } }, + "punycode": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/punycode/-/punycode-1.4.1.tgz", + "integrity": "sha1-wNWmOycYgArY4esPpSachN1BhF4=" + }, "qs": { "version": "6.5.1", "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.1.tgz", @@ -539,6 +739,64 @@ "resolved": "https://registry.npmjs.org/repeat-string/-/repeat-string-1.6.1.tgz", "integrity": "sha1-jcrkcOHIirwtYA//Sndihtp15jc=" }, + "request": { + "version": "2.87.0", + "resolved": "https://registry.npmjs.org/request/-/request-2.87.0.tgz", + "integrity": "sha512-fcogkm7Az5bsS6Sl0sibkbhcKsnyon/jV1kF3ajGmF0c8HrttdKTPRT9hieOaQHA5HEq6r8OyWOo/o781C1tNw==", + "requires": { + "aws-sign2": "0.7.0", + "aws4": "1.7.0", + "caseless": "0.12.0", + "combined-stream": "1.0.6", + "extend": "3.0.1", + "forever-agent": "0.6.1", + "form-data": "2.3.2", + "har-validator": "5.0.3", + "http-signature": "1.2.0", + "is-typedarray": "1.0.0", + "isstream": "0.1.2", + "json-stringify-safe": "5.0.1", + "mime-types": "2.1.18", + "oauth-sign": "0.8.2", + "performance-now": "2.1.0", + "qs": "6.5.1", + "safe-buffer": "5.1.1", + "tough-cookie": "2.3.4", + "tunnel-agent": "0.6.0", + "uuid": "3.3.2" + }, + "dependencies": { + "form-data": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-2.3.2.tgz", + "integrity": "sha1-SXBJi+YEwgwAXU9cI67NIda0kJk=", + "requires": { + "asynckit": "0.4.0", + "combined-stream": "1.0.6", + "mime-types": "2.1.18" + } + } + } + }, + "request-promise": { + "version": "4.2.2", + "resolved": "https://registry.npmjs.org/request-promise/-/request-promise-4.2.2.tgz", + "integrity": "sha1-0epG1lSm7k+O5qT+oQGMIpEZBLQ=", + "requires": { + "bluebird": "3.5.1", + "request-promise-core": "1.1.1", + "stealthy-require": "1.1.1", + "tough-cookie": "2.3.4" + } + }, + "request-promise-core": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/request-promise-core/-/request-promise-core-1.1.1.tgz", + "integrity": "sha1-Pu4AssWqgyOc+wTFcA2jb4HNCLY=", + "requires": { + "lodash": "4.17.10" + } + }, "right-align": { "version": "0.1.3", "resolved": "https://registry.npmjs.org/right-align/-/right-align-0.1.3.tgz", @@ -553,6 +811,11 @@ "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz", "integrity": "sha1-iTMSr2myEj3vcfV4iQAWce6yyFM=" }, + "safer-buffer": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" + }, "send": { "version": "0.16.2", "resolved": "https://registry.npmjs.org/send/-/send-0.16.2.tgz", @@ -605,11 +868,32 @@ "superagent": "2.3.0" } }, + "sshpk": { + "version": "1.14.2", + "resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.14.2.tgz", + "integrity": "sha1-xvxhZIo9nE52T9P8306hBeSSupg=", + "requires": { + "asn1": "0.2.3", + "assert-plus": "1.0.0", + "bcrypt-pbkdf": "1.0.2", + "dashdash": "1.14.1", + "ecc-jsbn": "0.1.1", + "getpass": "0.1.7", + "jsbn": "0.1.1", + "safer-buffer": "2.1.2", + "tweetnacl": "0.14.5" + } + }, "statuses": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.4.0.tgz", "integrity": "sha1-u3PURtonlhBu/MG2AaJT1sRr0Ic=" }, + "stealthy-require": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/stealthy-require/-/stealthy-require-1.1.1.tgz", + "integrity": "sha1-NbCYdbT/SfJqd35QmzCQoyJr8ks=" + }, "string_decoder": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", @@ -635,6 +919,28 @@ "readable-stream": "2.3.6" } }, + "tough-cookie": { + "version": "2.3.4", + "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.3.4.tgz", + "integrity": "sha512-TZ6TTfI5NtZnuyy/Kecv+CnoROnyXn2DN97LontgQpCwsX2XyLYCC0ENhYkehSOwAp8rTQKc/NUIF7BkQ5rKLA==", + "requires": { + "punycode": "1.4.1" + } + }, + "tunnel-agent": { + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz", + "integrity": "sha1-J6XeoGs2sEoKmWZ3SykIaPD8QP0=", + "requires": { + "safe-buffer": "5.1.1" + } + }, + "tweetnacl": { + "version": "0.14.5", + "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz", + "integrity": "sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q=", + "optional": true + }, "type-is": { "version": "1.6.16", "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.16.tgz", @@ -684,11 +990,26 @@ "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz", "integrity": "sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM=" }, + "uuid": { + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.3.2.tgz", + "integrity": "sha512-yXJmeNaw3DnnKAOKJE51sL/ZaYfWJRl1pK9dr19YFCu0ObS231AB1/LbqTKRAQ5kw8A90rA6fr4riOUpTZvQZA==" + }, "vary": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", "integrity": "sha1-IpnwLG3tMNSllhsLn3RSShj2NPw=" }, + "verror": { + "version": "1.10.0", + "resolved": "https://registry.npmjs.org/verror/-/verror-1.10.0.tgz", + "integrity": "sha1-OhBcoXBTr1XW4nDB+CiGguGNpAA=", + "requires": { + "assert-plus": "1.0.0", + "core-util-is": "1.0.2", + "extsprintf": "1.3.0" + } + }, "walk": { "version": "2.3.9", "resolved": "https://registry.npmjs.org/walk/-/walk-2.3.9.tgz", diff --git a/public/javascripts/methods.js b/public/javascripts/methods.js index 6c509b9..0270c7a 100644 --- a/public/javascripts/methods.js +++ b/public/javascripts/methods.js @@ -1,41 +1,109 @@ const SpotifyWebApi = require('spotify-web-api-node'); const { Track } = require('../../models/track'); require('dotenv').config(); - var spotifyApi = new SpotifyWebApi({ - clientId: process.env.CLIENTID, - clientSecret: process.env.CLIENTSECRET, + clientId: process.env.CLIENTID, + clientSecret: process.env.CLIENTSECRET, }); spotifyApi.initCredential = function() { - spotifyApi.clientCredentialsGrant() - .then( - function (data) { - console.log('The access token expires in ' + data.body['expires_in']); - console.log('The access token is ' + data.body['access_token']); - - // Save the access token so that it's used in future calls - spotifyApi.setAccessToken(data.body['access_token']); - }) - .catch( function(err) { - console.log(err) - }) + spotifyApi.clientCredentialsGrant() + .then( + function (data) { + console.log('The access token expires in ' + data.body['expires_in']); + console.log('The access token is ' + data.body['access_token']); + + // Save the access token so that it's used in future calls + spotifyApi.setAccessToken(data.body['access_token']); + }) + .catch( function(err) { + console.log(err) + }) } +function shuffle(array) { + var currentIndex = array.length, temporaryValue, randomIndex; -spotifyApi.searchCategory = (category) => { + // While there remain elements to shuffle... + while (0 !== currentIndex) { + + // Pick a remaining element... + randomIndex = Math.floor(Math.random() * currentIndex); + currentIndex -= 1; + + // And swap it with the current element. + temporaryValue = array[currentIndex]; + array[currentIndex] = array[randomIndex]; + array[randomIndex] = temporaryValue; + } + + return array; +} + + +spotifyApi.findTracks = (category, pop) => { const tracklist = []; - return spotifyApi.searchTracks('genre:' + category, {limit: 16}) - .then((data) => { - console.log('Search tracks by ' + data + ' in the artist name', data.body.tracks.items[0].album.name); - data.body.tracks.items.forEach( (data)=> { - tracklist.push(new Track(data.album.name, data.popularity, data.artists[0].name, data.name, data.uri)) - }) - return tracklist; + let count = 0; + let os = 0; + if(pop == 40) + os = 2000; + if(pop == 65) + os = 750; + if(pop == 80) + os = 100; + + return recursive(tracklist, category, os, pop, count); +} + +function recursive(arr, category, os, pop, count){ + return spotifyApi.searchTracks('genre:' + category, { limit: 50, offset: os, time_range: 'short_term'}) + .then((data) => { + data.body.tracks.items.forEach((data) => { + if (data.popularity <= pop) + arr.push(new Track(data.album.name, data.popularity, data.artists[0].name, data.name, data.id)) }) - .catch((err) =>{ - console.log(err); - }); + console.log(arr.length) + return arr; + }) + .then((data) =>{ + count++; + console.log("THIS IS COUNT: " + count); + if(arr.length < 50 && count < 30){ + return recursive(arr, category, os+50, pop, count); + }else{ + return shuffle(arr); + } + }) + .catch( (err) => { console.log(err)}); } +function shuffle(array) { + var currentIndex = array.length, temporaryValue, randomIndex; + + // While there remain elements to shuffle... + while (0 !== currentIndex) { + + // Pick a remaining element... + randomIndex = Math.floor(Math.random() * currentIndex); + currentIndex -= 1; + + // And swap it with the current element. + temporaryValue = array[currentIndex]; + array[currentIndex] = array[randomIndex]; + array[randomIndex] = temporaryValue; + } + const tracklist = []; + let x = 0; + if(array.length < 20) + x = 20; + else + x = array.length; + for( let i = 0; i < x; i++) + { + tracklist.push(array[i]); + } + + return tracklist; + } + exports.spotifyApi = spotifyApi; diff --git a/public/js/main.js b/public/js/main.js index 26f54c3..9efe885 100644 --- a/public/js/main.js +++ b/public/js/main.js @@ -1,10 +1,45 @@ -const cardTop = document.getElementById('card-track'); +var allAddButtons = document.getElementsByClassName("btn-floating"); -const cardTop2 = document.getElementById('card-track2'); +var artistList = []; +var songList = []; +var albumList = []; -console.log('cardTop'); +var addSongToList = function() { + var musicList = document.getElementById('musiclist'); + + var songName = this.getAttribute('name'); + var artistName = this.getAttribute('artist'); + var albumName = this.getAttribute('album'); + var uri = this.getAttribute('uri'); + console.log(songName); + console.log(uri); + + var htmlToInsert = + '\n' + + '\n' + + 'music_note\n' + + ''+ songName+'\n' + + '

'+artistName+ '

\n' + + '

'+albumName+'

\n' + + 'remove_circle\n'+ + '
'; + + musicList.insertAdjacentHTML('beforeend', htmlToInsert); + + var descriptionItem = document.getElementById('description-list'); + descriptionItem.remove(); + + artistList.push(artistName); + songList.push(songName); + albumList.push(albumName); + + console.log (artistList); + console.log(songName); + console.log(albumName); -function rejectImage(){ - cardTop.classList.add("scale-out"); - cardTop2.classList.add("scale-out"); }; + +for (var i = 0; i < allAddButtons.length; i++) { + allAddButtons[i].addEventListener('click', addSongToList, false); +} + diff --git a/public/stylesheets/style.css b/public/stylesheets/style.css index c867db3..353faaa 100644 --- a/public/stylesheets/style.css +++ b/public/stylesheets/style.css @@ -1,3 +1,8 @@ +/* color pallete: +teal: #008080, #26a69a +black: #2e2e2e +grey: #5d5d5d */ + body { padding: 20px; background-image: url("../images/background.jpg"); @@ -29,7 +34,7 @@ body { .third-section{ display: flex; align-items: center; - margin-top: 80px; + margin-top: 30px; justify-content: center; } @@ -40,8 +45,8 @@ h1{ font-weight: bold; } -h2{ - font-family: 'Indie Flower', cursive; +h2 { + font-family: 'Montserrat', sans-serif; font-size: 5em; color: white; font-weight: bold; @@ -53,66 +58,145 @@ h2{ margin: 0 10px; } -.submit{ - background-color: white; - margin: 0 10px; +.submitButton{ + margin: 10px; + background-color: #008080; + position: absolute; + right: 5px; } -#submitIcon{ - color: black; -} -#submitIcon:hover{ +#submitIcon{ color: white; } -#popularity{ +.filterButton{ + width: 300px; + height: 50px; background-color: #008080; - transition: 200ms; + border-radius: 15px; + display: flex; + align-items: center; + justify-content: center; } -#popularity:hover{ - background-color: #009696; +.modal{ + width: 70%; + max-height: 80%; + border-radius: 10px; + background-color: #2e2e2e; } -#genre{ - background-color: #3b3b3b; - transition: 200ms; +.popularityButton{ + background-color: #008080; + width: 170px; + height: 40px; + display: flex; + align-items: center; + justify-content: center; + border-radius: 5px; + color: white; + margin: 10px 10px; + } -#genre:hover{ - background-color: #5b5b5b; +.popularityButton:hover{ + background-color: white; + color: #2e2e2e; } -.dropdown{ - color: white; +.popupButtonsPopularitySection{ + display: flex; + align-items: center; + justify-content: center; + background-color: #2e2e2e; + flex-wrap: wrap; +} - background-color: #008080; - border: #008080; - width: 300px; - height: 50px; +.popupButtonsGenreSection{ + display: flex; + flex-wrap: wrap; + align-items: center; + justify-content: center; + background-color: #2e2e2e; + padding-bottom: 0px; } -select { +.genreButton{ + margin: 10px 10px; + width: 150px; + height: 80px; display: flex; + align-items: center; + justify-content: center; + background-color: #008080; + border-radius: 5px; + line-height: 1; } -h1 { - text-align: center; +.genreButton:hover{ + color: #2e2e2e; + background-color: white; +} +.genreButton:checked{ + color: #2e2e2e; + background-color: white; } -.submit:hover{ - background-color: #008080; + +.legend{ + display: grid; + justify-content: center; + color: white; + background-color: #2e2e2e; + +} + +legend{ + padding: 5px; + font-family: 'Montserrat', sans-serif; + font-size: 2em; + font-weight: bold; +} + +.p{ + display: flex; + justify-content: center; + margin: 0; + color: #696766; } .genreForm { display: flex; +} -img { +img{ width: 250px; - length: 250px; + height: 250px; } -.buttoncolor { - color: #008080; + +input:checked + label{ + color: #2e2e2e; + background-color: white; +} + +label { + background-color: #5d5d5d; + height: 30px; + width: 150px; +} + +label { + background-color: #5d5d5d; + height: 30px; + width: 150px; +} + +#content{ + text-shadow: 3px 3px 3px teal; + +.dropdown { + margin: 20px 20px; + } diff --git a/public/stylesheets/styleResults.css b/public/stylesheets/styleResults.css index 6103890..1fc07d0 100644 --- a/public/stylesheets/styleResults.css +++ b/public/stylesheets/styleResults.css @@ -20,6 +20,12 @@ h1 { flex-wrap: wrap; } +nav{ + position: fixed; + background-color: black; + +} + .cardsDisplay{ display: flex; flex-wrap: wrap; @@ -27,38 +33,41 @@ h1 { img { width: 250px; - length: 250px; + height: 250px; } .card { width: 300px; - length: 300px; + height: 300px; margin-top: 30px; align-items: center; position: absolute; - left: 50%; - transform: translate(-50%, 0); + left: 50%; + transform: translate(-50%, 0); } + .card-panel{ width: 350px; - margin-top: 30px; - margin-left: 4px; + margin-left: 17px; + height: 430px; + margin: 10px auto; + box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2); + transition: 0.3s; - /* position: absolute; - left: 50%; - transform: translate(-50%, 0); */ } +.card-panel:hover { + box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.3); +} .card .card-content{ padding: 0px; padding-bottom: 5px; } .logo{ - font-size: 2rem; - margin-top: 20px; - margin-right: 10px; - color: white; + font-size: 2.3rem !important; + margin-top: 2px; + margin-right: 5px; } .buttoncolor { @@ -85,7 +94,6 @@ img { } .row { - margin-top: 0px; margin-bottom: 0px; } @@ -96,5 +104,98 @@ img { } .collection{ - margin-top: 30px; + margin-top: 62px; + border:0px; +} + +.load-more{ + margin: 25px; +} + +button { + margin: 50px; +} + +.btn-floating.halfway-fab{ + position: relative; + top: -80px; + right: -229px; + +} +iframe{ + padding: 12px; +} + +.btn-floating.btn-large i { + line-height: 70px; +} + +.btn-large i { + font-size: 2.3rem; +} + +.btn-floating.btn-large { + width: 70px; + height: 70px; +} + +.sidenav{ + z-index: 99; +} + +main { + padding-left: 300px; + } + + @media only screen and (max-width : 992px) { + header, main { + padding-left: 0; + } + } + +#list-header{ + background-color: black; + padding-left: 25px; +} + + +h5{ + font-weight: 200; +} + +.collection .collection-item.avatar i.circle { + background-color: black; +} + +p{ + font-size: 13px; +} + +#playlist-description{ + position: absolute; +} + +.white-text{ + display: flex; + align-items: center; + font-size: 2em; +} + +#button-remove{ + top: 26px; + color: #500000; +} + +.collection a.collection-item { +color: #383838; + +} + +#add-playlist-button{ + margin-left: 110px; + margin-top: 8px; +} +#search-again { + top: -35px; + margin-right: -5px; } diff --git a/routes/index.js b/routes/index.js index c80d05d..ef746ef 100644 --- a/routes/index.js +++ b/routes/index.js @@ -12,11 +12,11 @@ router.get('/results', function(req, res, next){ res.render('results'); }); -router.get('/categories', function(req, res){ - console.log(req.query.categories) - spotify.spotifyApi.searchCategory(req.query.categories) +router.get('/genre', function(req, res){ + console.log('Genre: ' + req.query.genre) + console.log('Popularity: ' + req.query.pop); + spotify.spotifyApi.findTracks(req.query.genre, req.query.pop) .then(function(result) { - console.log("THIS IS THE TRACKLIST\n" + result); res.render('results', {tracklist: result} ) } ) }) diff --git a/views/index.hbs b/views/index.hbs index ac1752d..c99c15c 100644 --- a/views/index.hbs +++ b/views/index.hbs @@ -5,85 +5,64 @@

Spotify Filter

-
-

Let's Dance

+
+

Discover New Music

- - + + Choose your filters - + +
+
+
diff --git a/views/layout.hbs b/views/layout.hbs index b7ae2c2..6d60e61 100644 --- a/views/layout.hbs +++ b/views/layout.hbs @@ -2,7 +2,7 @@ - {{title}} + Spotify Filter @@ -18,13 +18,19 @@ - + {{{body}}} + + diff --git a/views/results.hbs b/views/results.hbs index 05edd6c..f744391 100644 --- a/views/results.hbs +++ b/views/results.hbs @@ -5,84 +5,46 @@ -
-
-
-
- -

Spotify Filter

+ + + +
+
+
+
+
My playlist
+ playlist_add +
+
    +
  • Create a playlist of songs you likearrow_upward
  • +
  • Add a song here by clicking the
    plus buttonarrow_forward
  • +
-
- - +
+
+
- {{#each tracklist}} -
- +
+ + add
- {{/each}} - - - - -
- +
+