├── icon.png ├── favicon.ico ├── page-handler.js ├── manifest.json ├── README.md ├── helpers.js ├── progressbar.js ├── index.php ├── vibrant.min.js ├── styles.css ├── LICENSE ├── spotify-handler.js └── spotify-web-api.js /icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FreekBes/spotify_web_controller/HEAD/icon.png -------------------------------------------------------------------------------- /favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FreekBes/spotify_web_controller/HEAD/favicon.ico -------------------------------------------------------------------------------- /page-handler.js: -------------------------------------------------------------------------------- 1 | var pageHandler = { 2 | shown: "loadingpage", 3 | 4 | showPage: function(pageId) { 5 | pageHandler.hidePage(); 6 | $("#"+pageId).addClass("active"); 7 | pageHandler.shown = pageId; 8 | if (pageId == "playerpage") { 9 | spotifyHandler.fixArtSize(); 10 | } 11 | if (pageId == "searchpage") { 12 | document.getElementById("searchbar").focus(); 13 | } 14 | }, 15 | 16 | hidePage: function() { 17 | var pages = document.getElementsByClassName("page"); 18 | for (var i = 0; i < pages.length; i++) 19 | { 20 | $(pages[i]).removeClass("active"); 21 | } 22 | pageHandler.shown = null; 23 | } 24 | }; -------------------------------------------------------------------------------- /manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "lang": "en-US", 3 | "dir": "ltr", 4 | "name": "Spotify Remote Web Controller", 5 | "short_name": "Spotify Web Remote", 6 | "description": "A web controller for Spotify, targeted for Android Go, because I've heard the official Spotify application runs like shit and sometimes you just wanna control what's playing without getting up from bed or something", 7 | "developer": "Freek Bes", 8 | "start_url": "/spotify/", 9 | "scope": "/spotify/", 10 | "display": "standalone", 11 | "orientation": "portrait", 12 | "background_color": "#191414", 13 | "theme_color": "#1DB954", 14 | "icons": [ 15 | { 16 | "src": "icon.png", 17 | "sizes": "256x256" 18 | } 19 | ] 20 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Spotify Web Controller 2 | A web controller for Spotify, targeted for Android Go, because I've heard the official Spotify application runs like shit and sometimes you just wanna control what's playing without getting up from bed or something 3 | 4 | It's currently available at https://freekb.es/spotify/ 5 | 6 | *Reminder that you need to open Spotify on another device in order for this to function correctly (or the same one, actually, but why would you do that)* 7 | 8 | ## Supported features 9 | - an overview of the user's library: playlists and saved albums 10 | - searching for songs, albums and playlists 11 | - overview of all songs in the album/playlist that's currently being played (a replacement for the queue, as the queue is sadly not fetchable with Spotify's API) 12 | - changing the playback volume 13 | - switching between devices using Spotify Connect 14 | - liking and unliking the currently playing song 15 | - enabling and disabling shuffle, repeat 16 | 17 | ## Possible features that I might add one day 18 | - support for podcasts 19 | - simple artist overviews 20 | - album & playlist overviews 21 | - adding tracks to the queue 22 | - liking and unliking tracks not currently being played 23 | - liking and unliking playlists, albums 24 | - browse through your recommendations 25 | - category playlists 26 | - liked & recently played songs overview 27 | - small overview of your top played artists and songs 28 | - media control notification 29 | -------------------------------------------------------------------------------- /helpers.js: -------------------------------------------------------------------------------- 1 | function getParameterByName(name, url) { 2 | if (!url) url = window.location.href; 3 | name = name.replace(/[\[\]]/g, "\\$&"); 4 | var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)", "i"), 5 | results = regex.exec(url); 6 | if (!results) return null; 7 | if (!results[2]) return ''; 8 | return decodeURIComponent(results[2].replace(/\+/g, " ")); 9 | } 10 | 11 | function stripTags(text) { 12 | var tmp = document.createElement("div"); 13 | tmp.innerHTML = text; 14 | return tmp.textContent || tmp.innerText; 15 | } 16 | 17 | function getCookie(name) { 18 | var re = new RegExp(name + "=([^;]+)"); 19 | var value = re.exec(document.cookie); 20 | return (value != null) ? unescape(value[1]) : null; 21 | } 22 | 23 | function setCookie(name, value) { 24 | document.cookie = name + " = " + value + "; expires=Mon, 14 Sep 2025 18:49:22 GMT; path=/"; 25 | } 26 | 27 | function formatSeconds(seconds) { 28 | var s = Math.floor(seconds % 60); 29 | var m = Math.floor((seconds / 60) % 60); 30 | var u = Math.floor(((seconds / 60) / 60 ) % 60); 31 | if (u > 0 && m < 10) { 32 | m = '0' + m; 33 | } 34 | if (s < 10) { 35 | s = '0' + s; 36 | } 37 | if (u < 1) { 38 | return (m + ':' + s); 39 | } 40 | else if (u >= 1) { 41 | return (u + ':' + m + ':' + s); 42 | } 43 | } 44 | 45 | function getDeviceIcon(type) { 46 | switch (type) { 47 | case "smartphone": 48 | return ""; 49 | case "computer": 50 | return ""; 51 | case "speaker": 52 | case "avr": 53 | return ""; 54 | case "tv": 55 | case "stb": 56 | return "" 57 | case "gameconsole": 58 | return ""; 59 | case "castvideo": 60 | case "castaudio": 61 | return ""; 62 | case "automobile": 63 | return ""; 64 | case "audiodongle": 65 | return ""; 66 | case "unknown": 67 | default: 68 | return ""; 69 | } 70 | } -------------------------------------------------------------------------------- /progressbar.js: -------------------------------------------------------------------------------- 1 | var progressBar = { 2 | elemOuter: document.getElementById("progressbar-outer"), 3 | elemInner: document.getElementById("progressbar"), 4 | buffer: document.getElementById("bufferbar"), 5 | value: 0, 6 | bufferValue: 0, 7 | hovering: false, 8 | firstSeek: false, 9 | 10 | setValue: function(value) { 11 | if (value < 0) { 12 | value = 0; 13 | } 14 | else if (value > 100) { 15 | value = 100; 16 | } 17 | 18 | progressBar.value = value; 19 | progressBar.elemInner.style.width = value+"%"; 20 | progressBar.elemInner.setAttribute("value", value); 21 | }, 22 | 23 | getValue: function() { 24 | return progressBar.value; 25 | }, 26 | 27 | setValueBuffer: function(value) { 28 | if (value < 0) { 29 | value = 0; 30 | } 31 | else if (value > 100) { 32 | value = 100; 33 | } 34 | 35 | progressBar.bufferValue = value; 36 | progressBar.buffer.style.width = value+"%"; 37 | progressBar.buffer.setAttribute("value", value); 38 | 39 | if (value >= 100) { 40 | progressBar.buffer.style.backgroundColor = "rgba(0,0,0,0)"; 41 | } 42 | else { 43 | progressBar.buffer.style.backgroundColor = null; 44 | } 45 | }, 46 | 47 | progressMouseEnter: function(e) { 48 | e=e || window.event; 49 | if ((e.which == 1 || e.type == "touchstart")) { 50 | progressBar.firstSeek = true; 51 | // spotifyHandler.api.pause(); 52 | progressBar.hovering = true; 53 | progressBar.elemInner.style.transition = "none"; 54 | $(progressBar.elemInner).addClass("hovering"); 55 | window.addEventListener("mousemove", progressBar.progressMouseMove); 56 | window.addEventListener("touchmove", progressBar.progressMouseMove); 57 | window.addEventListener("mouseup", progressBar.progressMouseLeave); 58 | window.addEventListener("touchend", progressBar.progressMouseLeave); 59 | window.addEventListener("touchcancel", progressBar.progressMouseLeave); 60 | 61 | /* Cursor Styling */ 62 | var css = '* { cursor: inherit !important; } body { cursor: w-resize !important; }', 63 | head = document.head || document.getElementsByTagName('head')[0], 64 | style = document.createElement('style'); 65 | style.type = 'text/css'; 66 | style.id = 'cursorstyling'; 67 | if (style.styleSheet){ 68 | style.styleSheet.cssText = css; 69 | } 70 | else { 71 | style.appendChild(document.createTextNode(css)); 72 | } 73 | head.appendChild(style); 74 | progressBar.progressMouseMoveCalc(e); 75 | } 76 | }, 77 | 78 | pauseEvent: function(e){ 79 | if(e.stopPropagation) e.stopPropagation(); 80 | if(e.preventDefault) e.preventDefault(); 81 | e.cancelBubble=true; 82 | e.returnValue=false; 83 | return false; 84 | }, 85 | 86 | 87 | progressMouseMove: function(e) { 88 | e=e || window.event; 89 | if (e.type != "touchstart" && e.type != "touchmove" && e.type != "touchend") { 90 | progressBar.pauseEvent(e); // stop selecting and moving text on page 91 | } 92 | progressBar.progressMouseMoveCalc(e); 93 | }, 94 | 95 | progressMouseMoveCalc: function(e) { 96 | var progressOffset = $("#progressbar-outer").offset(); 97 | var progressOffsetRight = (document.body.clientWidth - ($("#progressbar-outer").offset().left + $("#progressbar-outer").outerWidth())); 98 | var progressOffsetLeft = progressOffset.left; 99 | var progressBorderWidth = ($("#progressbar-outer").outerWidth() - $("#progressbar-outer").innerWidth()) / 2; 100 | var maxX = ($("#progressbar-outer").offset().left + $("#progressbar-outer").outerWidth()); 101 | var minX = progressOffset.left; 102 | if (e.type == "touchstart" || e.type == "touchmove" || e.type == "touchend") { 103 | var x = e.changedTouches[0].pageX; 104 | var y = e.changedTouches[0].pageY; 105 | } 106 | else { 107 | var x = e.clientX; 108 | var y = e.clientY; 109 | } 110 | 111 | // add scrollbar position to x to fix bugs when scrolled a bit to the right of the page 112 | if (window.pageXOffset > 0) { 113 | x = x + window.pageXOffset; 114 | } 115 | else if (document.body.scrollLeft > 0) { 116 | x = x + document.body.scrollLeft; 117 | } 118 | else if (document.documentElement.scrollLeft > 0) { 119 | x = x + document.documentElement.scrollLeft; 120 | } 121 | 122 | // console.log("x: " + x + "\nminX: " + minX + "\nmaxX: " + maxX); 123 | 124 | if (x <= minX) { 125 | progressBar.progressMouseSet(0); 126 | } 127 | else if (x >= maxX) { 128 | progressBar.progressMouseSet(100); 129 | } 130 | else { 131 | var progressPerc = ((x - progressOffsetLeft - progressBorderWidth) / ($("#progressbar-outer").innerWidth())) * 100; 132 | progressBar.progressMouseSet(progressPerc); 133 | } 134 | }, 135 | 136 | progressMouseSet: function(val) { 137 | if (spotifyHandler.duration != 0) { 138 | progressBar.setValue(val); 139 | 140 | var timeToBeSet = (progressBar.getValue() / 100) * spotifyHandler.duration; 141 | spotifyHandler.updateTimes(timeToBeSet, spotifyHandler.duration); 142 | } 143 | }, 144 | 145 | progressMouseLeave: function(e) { 146 | progressBar.hovering = false; 147 | progressBar.elemInner.style.transition = null; 148 | window.removeEventListener("mousemove", progressBar.progressMouseMove); 149 | window.removeEventListener("touchmove", progressBar.progressMouseMove); 150 | window.removeEventListener("mouseup", progressBar.progressMouseLeave); 151 | window.removeEventListener("touchend", progressBar.progressMouseLeave); 152 | window.removeEventListener("touchcancel", progressBar.progressMouseLeave); 153 | $("#cursorstyling").remove(); 154 | $(progressBar.elemInner).removeClass("hovering"); 155 | progressBar.progressMouseMoveCalc(e); 156 | spotifyHandler.api.seek(Math.floor((progressBar.getValue() / 100) * (spotifyHandler.duration * 1000)), {}); 157 | // spotifyHandler.api.play(); 158 | setTimeout(function() { 159 | spotifyHandler.setCurrentlyPlaying(); 160 | }, 250); 161 | }, 162 | 163 | init: function() { 164 | progressBar.elemOuter.addEventListener("mousedown", progressBar.progressMouseEnter); 165 | progressBar.elemOuter.addEventListener("touchstart", progressBar.progressMouseEnter); 166 | } 167 | }; 168 | 169 | progressBar.init(); -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | 17 | 18 | 19 | 20 | 21 | 22 | Spotify Remote Web Controller 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |

Welcome to the Spotify Web Controller

60 |

You have to sign in with your Spotify account in order to control playback.

61 | 62 |

This website uses cookies to store preferences and required user data. By clicking above button, we take that to mean that you accept their use.

63 | 64 |
65 |
66 |
67 |
68 |

Looking for instances of Spotify...

69 |

Open Spotify on your computer, smartphone, or anything else. You will be able to control playback here once you've done so.

70 |
71 | 75 |
76 |
77 |
78 |
79 |
80 |
81 |
Listening on
82 |
83 |
84 |
85 |
Select a device
86 | 87 |
88 |
89 |
90 |
91 | 92 |
93 |
94 |

95 |
96 | 97 |
98 | 99 |
100 |
101 |

Playlists & albums

102 |
103 | 104 |
105 | 106 |
107 |
108 |

Search

109 |
110 |
111 | 112 |
113 | 114 |
115 | 116 |
117 |
118 |
119 | 120 |
121 |
122 |
123 |
124 | 125 |
126 |
127 | 128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 | 136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 | 147 | 148 | 149 | 150 | 151 |
152 |
153 | 154 | 155 |
156 |
157 |
158 | 159 | 182 | 183 | 184 | -------------------------------------------------------------------------------- /vibrant.min.js: -------------------------------------------------------------------------------- 1 | (function e$$0(x,z,l){function h(p,b){if(!z[p]){if(!x[p]){var a="function"==typeof require&&require;if(!b&&a)return a(p,!0);if(g)return g(p,!0);a=Error("Cannot find module '"+p+"'");throw a.code="MODULE_NOT_FOUND",a;}a=z[p]={exports:{}};x[p][0].call(a.exports,function(a){var b=x[p][1][a];return h(b?b:a)},a,a.exports,e$$0,x,z,l)}return z[p].exports}for(var g="function"==typeof require&&require,w=0;wg?1:0},sum:function(h,g){var l={};return h.reduce(g?function(h,b,a){l.index=a;return h+g.call(l,b)}:function(h,b){return h+b},0)},max:function(h,g){return Math.max.apply(null,g?l.map(h,g):h)}};A=function(){function h(f,c,a){return(f<<2*d)+(c<>e;m=f[1]>>e;r=f[2]>>e;a=h(b,m,r);c[a]=(c[a]||0)+1});return c} 4 | function a(f,c){var a=1E6,b=0,m=1E6,d=0,q=1E6,n=0,h,k,l;f.forEach(function(c){h=c[0]>>e;k=c[1]>>e;l=c[2]>>e;hb&&(b=h);kd&&(d=k);ln&&(n=l)});return new w(a,b,m,d,q,n,c)}function n(a,c){function b(a){var f=a+"1";a+="2";var v,d,m,e;d=0;for(k=c[f];k<=c[a];k++)if(y[k]>n/2){m=c.copy();e=c.copy();v=k-c[f];d=c[a]-k;for(v=v<=d?Math.min(c[a]-1,~~(k+d/2)):Math.max(c[f],~~(k-1-v/2));!y[v];)v++;for(d=s[v];!d&&y[v-1];)d=s[--v];m[a]=v;e[f]=m[a]+1;return[m,e]}}if(c.count()){var d=c.r2- 5 | c.r1+1,m=c.g2-c.g1+1,e=l.max([d,m,c.b2-c.b1+1]);if(1==c.count())return[c.copy()];var n=0,y=[],s=[],k,g,t,u,p;if(e==d)for(k=c.r1;k<=c.r2;k++){u=0;for(g=c.g1;g<=c.g2;g++)for(t=c.b1;t<=c.b2;t++)p=h(k,g,t),u+=a[p]||0;n+=u;y[k]=n}else if(e==m)for(k=c.g1;k<=c.g2;k++){u=0;for(g=c.r1;g<=c.r2;g++)for(t=c.b1;t<=c.b2;t++)p=h(g,k,t),u+=a[p]||0;n+=u;y[k]=n}else for(k=c.b1;k<=c.b2;k++){u=0;for(g=c.r1;g<=c.r2;g++)for(t=c.g1;t<=c.g2;t++)p=h(g,t,k),u+=a[p]||0;n+=u;y[k]=n}y.forEach(function(a,c){s[c]=n-a});return e== 6 | d?b("r"):e==m?b("g"):b("b")}}var d=5,e=8-d;w.prototype={volume:function(a){if(!this._volume||a)this._volume=(this.r2-this.r1+1)*(this.g2-this.g1+1)*(this.b2-this.b1+1);return this._volume},count:function(a){var c=this.histo;if(!this._count_set||a){a=0;var b,d,n;for(b=this.r1;b<=this.r2;b++)for(d=this.g1;d<=this.g2;d++)for(n=this.b1;n<=this.b2;n++)index=h(b,d,n),a+=c[index]||0;this._count=a;this._count_set=!0}return this._count},copy:function(){return new w(this.r1,this.r2,this.g1,this.g2,this.b1, 7 | this.b2,this.histo)},avg:function(a){var c=this.histo;if(!this._avg||a){a=0;var b=1<<8-d,n=0,e=0,g=0,q,l,s,k;for(l=this.r1;l<=this.r2;l++)for(s=this.g1;s<=this.g2;s++)for(k=this.b1;k<=this.b2;k++)q=h(l,s,k),q=c[q]||0,a+=q,n+=q*(l+0.5)*b,e+=q*(s+0.5)*b,g+=q*(k+0.5)*b;this._avg=a?[~~(n/a),~~(e/a),~~(g/a)]:[~~(b*(this.r1+this.r2+1)/2),~~(b*(this.g1+this.g2+1)/2),~~(b*(this.b1+this.b2+1)/2)]}return this._avg},contains:function(a){var c=a[0]>>e;gval=a[1]>>e;bval=a[2]>>e;return c>=this.r1&&c<=this.r2&& 8 | gval>=this.g1&&gval<=this.g2&&bval>=this.b1&&bval<=this.b2}};p.prototype={push:function(a){this.vboxes.push({vbox:a,color:a.avg()})},palette:function(){return this.vboxes.map(function(a){return a.color})},size:function(){return this.vboxes.size()},map:function(a){for(var c=this.vboxes,b=0;bb[0]&&5>b[1]&&5>b[2]&&(a[0].color=[0,0,0]);var b=a.length-1,n=a[b].color;251d;)if(f=a.pop(),f.count()){var m=n(h,f);f=m[0];m=m[1];if(!f)break; 10 | a.push(f);m&&(a.push(m),c++);if(c>=b)break;if(1E3c||256this.yiq?"#fff":"#000"};b.prototype.getBodyTextColor=function(){this._ensureTextColors();return 150>this.yiq?"#fff":"#000"};b.prototype._ensureTextColors=function(){if(!this.yiq)return this.yiq=(299*this.rgb[0]+587*this.rgb[1]+114*this.rgb[2])/1E3};return b}();window.Vibrant=g=function(){function b(a,b,d){this.swatches=w(this.swatches,this);var e,f, 13 | c,g,p,m,r,q;"undefined"===typeof b&&(b=64);"undefined"===typeof d&&(d=5);p=new l(a);r=p.getImageData().data;m=p.getPixelCount();a=[];for(g=0;g=f&&s<=c&&m>=b&&m<=d&&!this.isAlreadySelected(k)&&(m=this.createComparisonValue(s,e,m,a, 19 | k.getPopulation(),this.HighestPopulation),void 0===l||m>q))l=k,q=m;return l};b.prototype.createComparisonValue=function(a,b,d,e,f,c){return this.weightedMean(this.invertDiff(a,b),this.WEIGHT_SATURATION,this.invertDiff(d,e),this.WEIGHT_LUMA,f/c,this.WEIGHT_POPULATION)};b.prototype.invertDiff=function(a,b){return 1-Math.abs(a-b)};b.prototype.weightedMean=function(){var a,b,d,e,f,c;f=1<=arguments.length?p.call(arguments,0):[];for(a=d=b=0;ac&&(c+=1);1c?b:c<2/3?a+(b-a)*(2/3-c)*6:a};0===b?c=f=e=d:(b=0.5>d?d*(1+b):d+b-d*b,d=2*d-b,c=e(d,b,a+1/3),f=e(d,b,a),e=e(d,b,a-1/3));return[255*c,255*f,255*e]};return b}();window.CanvasImage=l=function(){function b(a){this.canvas= 22 | document.createElement("canvas");this.context=this.canvas.getContext("2d");document.body.appendChild(this.canvas);this.width=this.canvas.width=a.width;this.height=this.canvas.height=a.height;this.context.drawImage(a,0,0,this.width,this.height)}b.prototype.clear=function(){return this.context.clearRect(0,0,this.width,this.height)};b.prototype.update=function(a){return this.context.putImageData(a,0,0)};b.prototype.getPixelCount=function(){return this.width*this.height};b.prototype.getImageData=function(){return this.context.getImageData(0, 23 | 0,this.width,this.height)};b.prototype.removeCanvas=function(){return this.canvas.parentNode.removeChild(this.canvas)};return b}()}).call(this)},{quantize:1}]},{},[2]); 24 | -------------------------------------------------------------------------------- /styles.css: -------------------------------------------------------------------------------- 1 | html, body { 2 | display: block; 3 | padding: 0px; 4 | margin: 0px; 5 | background-color: #191414; 6 | color: #FFFFFF; 7 | font-family: Roboto, Verdana, Arial, Sans-Serif; 8 | font-size: 16px; 9 | cursor: default; 10 | height: 100%; 11 | width: 100%; 12 | user-select: none; 13 | } 14 | 15 | a, a:visited { 16 | color: #1DB954; 17 | transition: color .15s ease; 18 | } 19 | 20 | a:hover { 21 | color: #1ed760; 22 | } 23 | 24 | .page { 25 | display: none; 26 | box-sizing: border-box; 27 | -webkit-box-sizing: border-box; 28 | -moz-box-sizing: border-box; 29 | height: 100%; 30 | width: 100%; 31 | margin: 0px; 32 | padding: 0px; 33 | } 34 | 35 | .page.active { 36 | display: block; 37 | } 38 | 39 | .bigbutton { 40 | display: block; 41 | margin: 24px auto 8px auto; 42 | font-size: 14px; 43 | line-height: 1.5; 44 | border-radius: 500px; 45 | padding: 7px 35px 7px; 46 | color: #ffffff; 47 | background-color: #2ebd59; 48 | transition: background-color .15s ease, border-color .15s ease, color .15s ease; 49 | border-width: 0; 50 | letter-spacing: 1.2px; 51 | min-width: 130px; 52 | text-transform: uppercase; 53 | white-space: normal; 54 | border: 1px solid; 55 | border-color: #29a84f; 56 | text-align: center; 57 | -ms-touch-action: manipulation; 58 | touch-action: manipulation; 59 | cursor: pointer; 60 | background-image: none; 61 | -webkit-user-select: none; 62 | -moz-user-select: none; 63 | -ms-user-select: none; 64 | user-select: none; 65 | text-decoration: none; 66 | -webkit-box-sizing: border-box; 67 | box-sizing: border-box; 68 | font-weight: 500; 69 | } 70 | 71 | .bigbutton:focus { 72 | outline: 0; 73 | } 74 | 75 | .bigbutton:hover { 76 | background-color: #1ed760; 77 | border-color: #1d7738; 78 | outline: 0; 79 | } 80 | 81 | .bigbutton:active { 82 | background-color: #2ebd59; 83 | box-shadow: none; 84 | outline: 0; 85 | } 86 | 87 | #signinpage { 88 | text-align: center; 89 | padding: 96px 16px; 90 | } 91 | 92 | h1 { 93 | margin: 8px 0px 16px 0px; 94 | } 95 | 96 | #welcome { 97 | margin-bottom: 54px; 98 | } 99 | 100 | p { 101 | margin: 8px 0px; 102 | } 103 | 104 | #signinbtn { 105 | margin-top: 24px; 106 | } 107 | 108 | .disclaimer { 109 | margin-top: 14px; 110 | font-size: small; 111 | color: #555555; 112 | } 113 | 114 | .disclaimer.footer { 115 | display: block; 116 | position: fixed; 117 | bottom: 0px; 118 | left: 0px; 119 | right: 0px; 120 | padding: 8px; 121 | } 122 | 123 | .disclaimer a { 124 | color: inherit !important; 125 | } 126 | 127 | .disclaimer a:hover { 128 | color: #757575 !important; 129 | } 130 | 131 | .spinner { 132 | display: inline-block; 133 | width: 60px; 134 | height: 60px; 135 | padding: 0px; 136 | box-sizing: border-box; 137 | -webkit-box-sizing: border-box; 138 | -moz-box-sizing: border-box; 139 | 140 | border: 7px solid rgba(0,0,0,0); 141 | border-top: 7px solid; 142 | border-top-color: #1DB954; 143 | transition: border-top-color 1s; 144 | border-radius: 30px; 145 | animation: spin 0.8s linear infinite; 146 | } 147 | 148 | @keyframes spin { 149 | 0% { transform: rotate(0deg); } 150 | 100% { transform: rotate(360deg); } 151 | } 152 | 153 | #playerpage { 154 | background-color: #15161A; 155 | } 156 | 157 | #topbar { 158 | display: block; 159 | height: 42px; 160 | padding: 8px 12px 0px 12px; 161 | white-space: nowrap; 162 | } 163 | 164 | #playing-from-holder { 165 | text-align: center; 166 | height: inherit; 167 | padding: 4px 42px 6px 42px; 168 | overflow: hidden; 169 | white-space: nowrap; 170 | } 171 | 172 | #playing-from { 173 | text-transform: uppercase; 174 | font-size: 10px; 175 | letter-spacing: 1px; 176 | text-overflow: ellipsis; 177 | overflow: hidden; 178 | } 179 | 180 | #playing-from-name { 181 | font-size: 13px; 182 | font-weight: bold; 183 | text-overflow: ellipsis; 184 | overflow: hidden; 185 | } 186 | 187 | #art-holder { 188 | margin: 24px; 189 | text-align: center; 190 | } 191 | 192 | #artwork { 193 | display: inline-block; 194 | width: 100%; 195 | object-fit: cover; 196 | background: #000000; 197 | pointer-events: none; 198 | } 199 | 200 | #below-art-holder { 201 | display: block; 202 | position: fixed; 203 | bottom: 0px; 204 | left: 0px; 205 | right: 0px; 206 | padding: 18px 24px 28px 24px; 207 | } 208 | 209 | #metadata-holder-holder { 210 | 211 | } 212 | 213 | #metadata-holder { 214 | display: inline-block; 215 | vertical-align: middle; 216 | padding: 10px 0px 10px 8px; 217 | width: 80%; 218 | width: calc(100% - 62px); 219 | width: -webkit-calc(100% - 62px); 220 | width: -moz-calc(100% - 62px); 221 | overflow: hidden; 222 | white-space: nowrap; 223 | } 224 | 225 | #title, #artist { 226 | text-overflow: ellipsis; 227 | overflow: hidden; 228 | } 229 | 230 | #title { 231 | font-size: 19px; 232 | font-weight: bold; 233 | } 234 | 235 | #artist { 236 | color: #B3B3B3; 237 | font-size: 17px; 238 | } 239 | 240 | #like-button { 241 | display: inline-block; 242 | vertical-align: middle; 243 | margin-left: 8px; 244 | width: 40px; 245 | height: 40px; 246 | font-size: 24px; 247 | } 248 | 249 | #seekbar-holder { 250 | 251 | } 252 | 253 | /* seekbar */ 254 | #progressbar-outer { 255 | width: 100%; 256 | height: 4px; 257 | border-radius: 1px; 258 | padding: 0px; 259 | padding-top: 14px; 260 | padding-bottom: 14px; 261 | margin: 0px; 262 | white-space: nowrap; 263 | background-color: rgba(0,0,0,0); 264 | position: relative; 265 | cursor: default; 266 | } 267 | 268 | #progressbar-outer .progressbar-inner { 269 | width: 0%; 270 | height: inherit; 271 | border-radius: inherit; 272 | position: absolute; 273 | left: 0; 274 | transition: 0.5s; 275 | transition-timing-function: linear; 276 | } 277 | 278 | #progressbar-outer #barbackground { 279 | width: 100%; 280 | background-color: #353942; 281 | z-index: 1; 282 | } 283 | 284 | #progressbar-outer #progressbar { 285 | background-color: #FFFFFF; 286 | z-index: 3; 287 | } 288 | 289 | #progressbar-outer #bufferbar { 290 | background-color: rgba(255,255,255,0.2); 291 | z-index: 2; 292 | transition-timing-function: ease; 293 | } 294 | 295 | #progressbar:after { 296 | content: ''; 297 | display: inline-block; 298 | width: 8px; 299 | height: 8px; 300 | border-radius: 4px; 301 | background-color: #FFFFFF; 302 | position: absolute; 303 | position: absolute; 304 | right: -4px; 305 | top: -2px; 306 | 307 | animation: progresshover 0.1s 1 alternate ease-in-out; 308 | animation-fill-mode: backwards; 309 | } 310 | 311 | #progressbar.hovering:after { 312 | width: 10px; 313 | height: 10px; 314 | border-radius: 5px; 315 | 316 | right: -5px; 317 | top: -3px; 318 | 319 | animation: progresshover 0.1s 1 alternate ease-in-out; 320 | animation-fill-mode: forwards; 321 | } 322 | 323 | @keyframes progresshover { 324 | from { 325 | 326 | } 327 | to { 328 | width: 16px; 329 | height: 16px; 330 | border-radius: 8px; 331 | right: -6px; 332 | top: -6px; 333 | } 334 | } 335 | 336 | #times { 337 | color: #B3B3B3; 338 | font-size: 13px; 339 | white-space: nowrap; 340 | margin-top: -9px; 341 | pointer-events: none; 342 | } 343 | 344 | #times > span { 345 | display: inline-block; 346 | width: 50%; 347 | vertical-align: middle; 348 | } 349 | 350 | #playback-time { 351 | text-align: left; 352 | } 353 | 354 | #duration-time { 355 | text-align: right; 356 | } 357 | 358 | button { 359 | display: inline-block; 360 | vertical-align: middle; 361 | border: none; 362 | background: none; 363 | outline: none; 364 | color: #FFFFFF; 365 | cursor: pointer; 366 | } 367 | 368 | button[disabled] { 369 | opacity: 0.3; 370 | cursor: default; 371 | } 372 | 373 | #controls-holder { 374 | text-align: center; 375 | white-space: nowrap; 376 | } 377 | 378 | .main-button { 379 | font-size: 76px; 380 | width: 88px; 381 | height: 88px; 382 | margin: 0px -12px; 383 | border-radius: 44px; 384 | } 385 | 386 | .skip-button { 387 | font-size: 48px; 388 | width: 60px; 389 | height: 60px; 390 | margin: 0px 8px; 391 | } 392 | 393 | .side-button { 394 | font-size: 20px; 395 | width: 50px; 396 | height: 50px; 397 | } 398 | 399 | #bottombar { 400 | white-space: nowrap; 401 | } 402 | 403 | .bar-button { 404 | width: 40px; 405 | height: 40px; 406 | font-size: 24px; 407 | } 408 | 409 | #devices-button { 410 | color: #B3B3B3; 411 | } 412 | 413 | #devices-button::after { 414 | display: inline-block; 415 | vertical-align: middle; 416 | margin-left: 4px; 417 | text-align: left; 418 | font-family: Roboto, Verdana, Arial, Sans-Serif; 419 | font-size: 13px; 420 | content: attr(data-curdevice); 421 | max-width: 170px; 422 | overflow: hidden; 423 | text-overflow: ellipsis; 424 | white-space: nowrap; 425 | } 426 | 427 | #queue-button { 428 | float: right; 429 | } 430 | 431 | #listeningon-holder { 432 | padding: 56px 16px 24px 16px; 433 | height: 48px; 434 | } 435 | 436 | #listeningon-title { 437 | font-weight: bold; 438 | font-size: 21px; 439 | margin: 2px 0px; 440 | } 441 | 442 | #listeningon-icon { 443 | float: left; 444 | color: #1DB954; 445 | width: 48px; 446 | height: 48px; 447 | padding: 9px; 448 | box-sizing: border-box; 449 | -webkit-box-sizing: border-box; 450 | -moz-box-sizing: border-box; 451 | font-size: 30px; 452 | text-align: center; 453 | margin-right: 16px; 454 | } 455 | 456 | #listeningon { 457 | color: #1DB954; 458 | } 459 | 460 | #devicelist-holder, #discoverlist-holder { 461 | padding: 16px; 462 | } 463 | 464 | #discoverlist-holder { 465 | max-width: 500px; 466 | margin: 0 auto; 467 | } 468 | 469 | .selectdevice { 470 | font-weight: bold; 471 | } 472 | 473 | #devicelist, #discoverlist { 474 | text-align: left; 475 | padding: 0px; 476 | margin: 10px 0px; 477 | list-style-type: none; 478 | } 479 | 480 | .devicelist-item { 481 | display: list-item; 482 | padding: 12px 0px; 483 | margin: 0px; 484 | cursor: pointer; 485 | } 486 | 487 | .devicelist-icon { 488 | display: inline-block; 489 | font-size: 30px; 490 | width: 48px; 491 | text-align: center; 492 | margin-right: 16px; 493 | vertical-align: middle; 494 | } 495 | 496 | .devicelist-name { 497 | display: inline-block; 498 | vertical-align: middle; 499 | } 500 | 501 | #volumebar-holder { 502 | position: absolute; 503 | bottom: 8px; 504 | left: 0px; 505 | right: 0px; 506 | padding: 8px; 507 | } 508 | 509 | #volumebar-icon { 510 | display: inline-block; 511 | vertical-align: middle; 512 | font-size: 24px; 513 | text-align: center; 514 | padding: 8px 0px; 515 | width: 40px; 516 | } 517 | 518 | #volumebar { 519 | display: inline-block; 520 | vertical-align: middle; 521 | appearance: none; 522 | -webkit-appearance: none; 523 | -moz-appearance: none; 524 | width: 80%; 525 | width: calc(100% - 64px); 526 | width: -webkit-calc(100% - 64px); 527 | width: -moz-calc(100% - 64px); 528 | height: 4px; 529 | border-radius: 2px; 530 | outline: none; 531 | background-color: #353942; 532 | background: linear-gradient(to right, #1DB954 0%, #1DB954 50%, #353942 50%, #353942 100%); 533 | } 534 | 535 | #volumebar::-webkit-slider-thumb { 536 | -webkit-appearance: none; 537 | appearance: none; 538 | width: 14px; 539 | height: 14px; 540 | border-radius: 7px; 541 | background: #FFFFFF; 542 | cursor: pointer; 543 | } 544 | 545 | #volumebar::-moz-range-thumb { 546 | width: 14px; 547 | height: 14px; 548 | border-radius: 7px; 549 | background: #FFFFFF; 550 | cursor: pointer; 551 | } 552 | 553 | .close-button { 554 | position: absolute; 555 | top: 8px; 556 | right: 8px; 557 | width: 40px; 558 | height: 40px; 559 | font-size: 32px; 560 | z-index: 10; 561 | } 562 | 563 | #library-button { 564 | position: absolute; 565 | top: 6px; 566 | left: 6px; 567 | width: 40px; 568 | height: 40px; 569 | font-size: 32px; 570 | z-index: 10; 571 | } 572 | 573 | #search-button { 574 | position: absolute; 575 | top: 6px; 576 | right: 6px; 577 | width: 40px; 578 | height: 40px; 579 | font-size: 25px; 580 | z-index: 10; 581 | } 582 | 583 | #discoverpage { 584 | text-align: center; 585 | } 586 | 587 | h2 { 588 | padding: 32px 16px 16px 16px; 589 | margin: 0px; 590 | font-size: 24px; 591 | font-weight: bold; 592 | } 593 | 594 | #discover-disclaimer { 595 | margin-bottom: 64px; 596 | padding: 16px; 597 | } 598 | 599 | .dotted { 600 | position: relative; 601 | } 602 | 603 | .dotted::before { 604 | content: ''; 605 | display: block; 606 | position: absolute; 607 | left: 50%; 608 | left: calc(50% - 2px); 609 | left: -webkit-calc(50% - 2px); 610 | left: -moz-calc(50% - 2px); 611 | bottom: 0; 612 | width: 4px; 613 | height: 4px; 614 | border-radius: 2px; 615 | background: #1DB954; 616 | } 617 | 618 | .side-button.dotted::before { 619 | bottom: 7px; 620 | } 621 | 622 | .list-header { 623 | display: block; 624 | padding-top: 14px; 625 | white-space: nowrap; 626 | overflow: hidden; 627 | text-overflow: ellipsis; 628 | position: absolute; 629 | top: 0px; 630 | left: 0px; 631 | width: 80%; 632 | width: calc(100% - 66px); 633 | width: -webkit-calc(100% - 66px); 634 | width: -moz-calc(100% - 66px); 635 | z-index: 2; 636 | } 637 | 638 | .list-header::before { 639 | content: ''; 640 | position: fixed; 641 | top: 0px; 642 | left: 0px; 643 | right: 0px; 644 | background: linear-gradient(#191414, #191414, rgba(0,0,0,0)); 645 | width: 200%; 646 | height: 60px; 647 | z-index: -1; 648 | } 649 | 650 | #queuepage, #librarypage, #search-page { 651 | overflow-x: hidden; 652 | overflow-y: auto; 653 | } 654 | 655 | #queue-holder, #library-holder, #search-holder { 656 | padding-top: 60px; 657 | } 658 | 659 | .tracklist { 660 | text-align: left; 661 | padding: 0px; 662 | margin: 10px 0px; 663 | list-style-type: none; 664 | } 665 | 666 | .queue-item { 667 | display: list-item; 668 | height: 48px; 669 | padding: 8px 12px; 670 | margin: 0px; 671 | cursor: pointer; 672 | white-space: nowrap; 673 | } 674 | 675 | .queue-item.divider { 676 | display: list-item; 677 | height: auto; 678 | padding: 8px 4px 8px 60px; 679 | margin: 24px 8px 8px 8px; 680 | cursor: default; 681 | white-space: nowrap; 682 | font-weight: bold; 683 | font-size: 18px; 684 | border-bottom: solid 1px #353942; 685 | } 686 | 687 | .queue-item-cover, .queue-item-metadata { 688 | display: inline-block; 689 | vertical-align: top; 690 | } 691 | 692 | .queue-item-cover { 693 | width: 48px; 694 | height: 48px; 695 | margin-right: 9px; 696 | } 697 | 698 | .queue-item-cover img { 699 | object-fit: cover; 700 | width: inherit; 701 | height: inherit; 702 | } 703 | 704 | .queue-item-cover span { 705 | display: inline-block; 706 | text-align: center; 707 | width: 100%; 708 | line-height: 48px; 709 | color: #B3B3B3; 710 | font-size: 13px; 711 | } 712 | 713 | .queue-item-metadata { 714 | padding: 6px 0px; 715 | width: 75%; 716 | width: calc(100% - 60px); 717 | width: -webkit-calc(100% - 60px); 718 | width: -moz-calc(100% - 60px); 719 | } 720 | 721 | .queue-item-name { 722 | font-size: 15px; 723 | text-overflow: ellipsis; 724 | overflow: hidden; 725 | } 726 | 727 | .queue-item-artist { 728 | color: #B3B3B3; 729 | font-size: 13px; 730 | text-overflow: ellipsis; 731 | overflow: hidden; 732 | } 733 | 734 | #searchbar-wrapper { 735 | padding: 12px 24px; 736 | } 737 | 738 | #searchbar { 739 | display: block; 740 | -webkit-box-sizing: border-box; 741 | -moz-box-sizing: border-box; 742 | box-sizing: border-box; 743 | width: 100%; 744 | margin: 0px; 745 | padding: 4px 12px; 746 | border: none; 747 | outline: 0; 748 | font-size: 17px; 749 | height: 34px; 750 | border-radius: 17px; 751 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /spotify-handler.js: -------------------------------------------------------------------------------- 1 | var spotifyHandler = { 2 | scopes: ["user-read-private", "user-read-currently-playing", "user-read-playback-state", "user-modify-playback-state", "user-read-recently-played", "user-library-read", "user-library-modify", "playlist-read-private", "playlist-read-collaborative"], 3 | accessToken: null, 4 | expires: -1, 5 | api: new SpotifyWebApi(), 6 | dom: {}, 7 | progress: 0, 8 | duration: 0, 9 | lastTrackId: "null2", 10 | lastQueueId: "null2", 11 | lastPlaybackStatus: {}, 12 | 13 | signIn: function() { 14 | window.location.href = "https://accounts.spotify.com/authorize?client_id=44219fb334174bc6b2c634d8f9e4f6eb&response_type=token&redirect_uri="+encodeURIComponent(window.location.origin + window.location.pathname)+"&scope="+spotifyHandler.scopes.join("%20")+"&show_dialog=false&state="+state; 15 | }, 16 | 17 | checkAccessToken: function() { 18 | if ((new Date().getTime() + 25000) >= spotifyHandler.expires) { 19 | console.warn("Spotify Access Token has expired! Refreshing page to refresh the access token..."); 20 | window.location.href = window.location.origin + window.location.pathname; 21 | } 22 | }, 23 | 24 | setCurrentlyPlaying: function() { 25 | if (!document.hidden) { 26 | spotifyHandler.api.getMyCurrentPlaybackState({}, function(err, data) { 27 | if (err) { 28 | console.error(err); 29 | } 30 | else if (data != undefined && typeof data != "string" && data.item != null) { 31 | // console.log(data); 32 | spotifyHandler.lastPlaybackStatus = data; 33 | if (pageHandler.shown == "discoverpage") { 34 | pageHandler.showPage("playerpage"); 35 | } 36 | if (data.item.id == null) { 37 | data.item.id = data.item.uri.split(":").pop(); 38 | } 39 | if (data.item.id != spotifyHandler.lastTrackId) { 40 | spotifyHandler.lastTrackId = data.item.id; 41 | if (data.item.album.images.length > 0) { 42 | spotifyHandler.dom.artwork.src = data.item.album.images[0].url; 43 | } 44 | else { 45 | spotifyHandler.dom.artwork.src = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"; 46 | } 47 | spotifyHandler.dom.title.innerHTML = stripTags(data.item.name); 48 | var tempArtists = ""; 49 | for (var i = 0; i < data.item.artists.length; i++) { 50 | tempArtists += data.item.artists[i].name; 51 | if (i != data.item.artists.length - 1) { 52 | tempArtists += ", "; 53 | } 54 | } 55 | spotifyHandler.dom.artist.innerHTML = stripTags(tempArtists); 56 | if (data.context != null) { 57 | switch (data.context.type) { 58 | case "playlist": { 59 | spotifyHandler.api.getPlaylist(data.context.uri.split(":").pop(), {fields: "name,id"}, function(err, data) { 60 | if (err) { 61 | console.error(err); 62 | } 63 | else { 64 | // console.log(data); 65 | spotifyHandler.dom.playingFrom.innerHTML = "Playing from playlist"; 66 | spotifyHandler.dom.playingFromName.innerHTML = stripTags(data.name); 67 | spotifyHandler.dom.contextName.innerHTML = stripTags(data.name); 68 | spotifyHandler.fillQueue("playlist", data.id); 69 | } 70 | }); 71 | break; 72 | } 73 | case "album": { 74 | spotifyHandler.api.getAlbum(data.context.uri.split(":").pop(), {}, function(err, data) { 75 | if (err) { 76 | console.error(err); 77 | } 78 | else { 79 | // console.log(data); 80 | spotifyHandler.dom.playingFrom.innerHTML = "Playing from album"; 81 | spotifyHandler.dom.playingFromName.innerHTML = stripTags(data.name); 82 | spotifyHandler.dom.contextName.innerHTML = stripTags(data.name); 83 | spotifyHandler.fillQueue("album", data.id); 84 | } 85 | }); 86 | break; 87 | } 88 | case "artist": { 89 | spotifyHandler.api.getArtist(data.context.uri.split(":").pop(), {}, function(err, data) { 90 | if (err) { 91 | console.error(err); 92 | } 93 | else { 94 | // console.log(data); 95 | spotifyHandler.dom.playingFrom.innerHTML = "Playing from artist"; 96 | spotifyHandler.dom.playingFromName.innerHTML = stripTags(data.name); 97 | spotifyHandler.dom.contextName.innerHTML = stripTags(data.name); 98 | spotifyHandler.fillQueue("artist", data.id); 99 | } 100 | }); 101 | break; 102 | } 103 | default: { 104 | spotifyHandler.dom.playingFrom.innerHTML = ""; 105 | spotifyHandler.dom.playingFromName.innerHTML = ""; 106 | spotifyHandler.dom.contextName.innerHTML = ""; 107 | spotifyHandler.fillQueue(null, null); 108 | break; 109 | } 110 | } 111 | } 112 | else { 113 | spotifyHandler.dom.playingFrom.innerHTML = "Playing from Your Library"; 114 | spotifyHandler.dom.playingFromName.innerHTML = "Liked Songs"; 115 | spotifyHandler.dom.contextName.innerHTML = "Liked Songs"; 116 | spotifyHandler.fillQueue("library", "library"); 117 | console.log("No context for currently playing track, assuming library is being played"); 118 | } 119 | if ('mediaSession' in navigator) 120 | { 121 | navigator.mediaSession.playbackState = "playing"; 122 | var tempArtwork = []; 123 | for (var i = 0; i < data.item.album.images.length; i++) { 124 | tempArtwork[i] = { 125 | sizes: data.item.album.images[i].width+"x"+data.item.album.images[i].height, 126 | src: data.item.album.images[i].url, 127 | type: "image/jpeg" 128 | }; 129 | } 130 | navigator.mediaSession.metadata = new MediaMetadata({ 131 | title: data.item.name, 132 | artist: tempArtists, 133 | artwork: tempArtwork 134 | }); 135 | } 136 | spotifyHandler.duration = Math.floor(data.item.duration_ms / 1000); 137 | } 138 | spotifyHandler.progress = Math.floor(data.progress_ms / 1000); 139 | if (!progressBar.hovering) { 140 | progressBar.setValue((data.progress_ms / data.item.duration_ms) * 100); 141 | spotifyHandler.updateTimes(spotifyHandler.progress, spotifyHandler.duration); 142 | } 143 | 144 | if (data.device.volume_percent != null) { 145 | spotifyHandler.dom.volumebar.disabled = false; 146 | spotifyHandler.setVolume(data.device.volume_percent, true); 147 | } 148 | else { 149 | spotifyHandler.dom.volumebar.disabled = true; 150 | } 151 | 152 | if (data.is_playing) { 153 | spotifyHandler.dom.playPauseButton.title = "Pause"; 154 | spotifyHandler.dom.playPauseButton.innerHTML = ""; 155 | } 156 | else { 157 | spotifyHandler.dom.playPauseButton.title = "Play"; 158 | spotifyHandler.dom.playPauseButton.innerHTML = ""; 159 | } 160 | 161 | if (!data.item.is_local) { 162 | spotifyHandler.dom.likeButton.disabled = false; 163 | spotifyHandler.dom.likeButton.style.display = "inline-block"; 164 | spotifyHandler.api.containsMySavedTracks([data.item.id], {}, function(err, data) { 165 | if (err) { 166 | console.error(err); 167 | } 168 | else if (data[0]) { 169 | spotifyHandler.dom.likeButton.innerHTML = ""; 170 | spotifyHandler.dom.likeButton.style.color = "#1DB954"; 171 | spotifyHandler.dom.likeButton.title = "Remove from liked songs"; 172 | spotifyHandler.dom.likeButton.setAttribute("data-liked", "true"); 173 | } 174 | else { 175 | spotifyHandler.dom.likeButton.innerHTML = ""; 176 | spotifyHandler.dom.likeButton.style.color = null; 177 | spotifyHandler.dom.likeButton.title = "Add to liked songs"; 178 | spotifyHandler.dom.likeButton.setAttribute("data-liked", "false"); 179 | } 180 | }); 181 | } 182 | else { 183 | spotifyHandler.dom.likeButton.disabled = true; 184 | spotifyHandler.dom.likeButton.style.display = "none"; 185 | } 186 | 187 | if (data.shuffle_state) { 188 | spotifyHandler.dom.shuffleButton.style.color = "#1DB954"; 189 | spotifyHandler.dom.shuffleButton.className = "material-icons side-button dotted"; 190 | } 191 | else { 192 | spotifyHandler.dom.shuffleButton.style.color = null; 193 | spotifyHandler.dom.shuffleButton.className = "material-icons side-button"; 194 | } 195 | 196 | switch (data.repeat_state) { 197 | case "context": 198 | spotifyHandler.dom.repeatButton.style.color = "#1DB954"; 199 | spotifyHandler.dom.repeatButton.innerHTML = ""; 200 | spotifyHandler.dom.repeatButton.className = "material-icons side-button dotted"; 201 | break; 202 | case "track": 203 | spotifyHandler.dom.repeatButton.style.color = "#1DB954"; 204 | spotifyHandler.dom.repeatButton.innerHTML = ""; 205 | spotifyHandler.dom.repeatButton.className = "material-icons side-button dotted"; 206 | break; 207 | default: 208 | case "off": 209 | spotifyHandler.dom.repeatButton.style.color = null; 210 | spotifyHandler.dom.repeatButton.innerHTML = ""; 211 | spotifyHandler.dom.repeatButton.className = "material-icons side-button"; 212 | break; 213 | } 214 | } 215 | else { 216 | console.log("No instances of Spotify found to control."); 217 | if (spotifyHandler.lastTrackId != "null2") { 218 | setTimeout(function() { 219 | spotifyHandler.refreshDevices(); 220 | }, 500); 221 | } 222 | if (pageHandler.shown != "discoverpage") { 223 | pageHandler.showPage("discoverpage"); 224 | } 225 | } 226 | }); 227 | } 228 | }, 229 | 230 | fixArtSize: function() { 231 | var maxHeight = document.getElementById("below-art-holder").offsetTop - 42 - 48; 232 | var maxWidth = window.innerWidth - 48; 233 | if (maxHeight < maxWidth) { 234 | spotifyHandler.dom.artwork.style.width = maxHeight + "px"; 235 | } 236 | else { 237 | spotifyHandler.dom.artwork.style.width = maxWidth + "px"; 238 | } 239 | }, 240 | 241 | updateTimes: function(prog, dur) { 242 | spotifyHandler.dom.playbackTime.innerHTML = formatSeconds(prog); 243 | spotifyHandler.dom.durationTime.innerHTML = formatSeconds(dur); 244 | }, 245 | 246 | refreshDevices: function() { 247 | if (!document.hidden) { 248 | spotifyHandler.api.getMyDevices(function(err, data) { 249 | if (err) { 250 | console.error(err); 251 | spotifyHandler.dom.deviceList.innerHTML = ""; 252 | } 253 | else { 254 | var tempList = ""; 255 | var tempListDis = ""; 256 | for (var i = 0; i < data.devices.length; i++) { 257 | if (data.devices[i].is_active) { 258 | spotifyHandler.dom.listeningOn.innerHTML = stripTags(data.devices[i].name); 259 | spotifyHandler.dom.listeningOnIcon.innerHTML = getDeviceIcon(data.devices[i].type.toLowerCase()); 260 | if (data.devices.length > 1) { 261 | spotifyHandler.dom.devicesButton.setAttribute("data-curdevice", stripTags(data.devices[i].name)); 262 | } 263 | else { 264 | spotifyHandler.dom.devicesButton.setAttribute("data-curdevice", ""); 265 | } 266 | } 267 | else { 268 | tempList += '
  • '+getDeviceIcon(data.devices[i].type.toLowerCase())+''+data.devices[i].name+'
  • '; 269 | } 270 | tempListDis += '
  • '+getDeviceIcon(data.devices[i].type.toLowerCase())+''+data.devices[i].name+'
  • '; 271 | } 272 | spotifyHandler.dom.deviceList.innerHTML = tempList; 273 | spotifyHandler.dom.discoverList.innerHTML = tempListDis; 274 | if (data.devices.length > 1) { 275 | spotifyHandler.dom.deviceListHolder.style.display = "block"; 276 | spotifyHandler.dom.devicesButton.className = "material-icons bar-button dotted"; 277 | } 278 | else { 279 | spotifyHandler.dom.deviceListHolder.style.display = "none"; 280 | spotifyHandler.dom.devicesButton.className = "material-icons bar-button"; 281 | } 282 | if (data.devices.length > 0) { 283 | spotifyHandler.dom.discoverSpinner.style.display = "none"; 284 | spotifyHandler.dom.discoverListHolder.style.display = null; 285 | } 286 | else { 287 | spotifyHandler.dom.discoverSpinner.style.display = null; 288 | spotifyHandler.dom.discoverListHolder.style.display = "none"; 289 | } 290 | } 291 | }); 292 | } 293 | }, 294 | 295 | setVolume: function(newVolume, volumebarOnly) { 296 | spotifyHandler.dom.volumebar.style.background = 'linear-gradient(to right, #1DB954 0%, #1DB954 '+newVolume+'%, #353942 '+newVolume+'%, #353942 100%)'; 297 | if (spotifyHandler.dom.volumebar.value != newVolume && !changingVolume) { 298 | spotifyHandler.dom.volumebar.value = newVolume; 299 | } 300 | if (!volumebarOnly) { 301 | spotifyHandler.api.setVolume(newVolume, {}); 302 | } 303 | }, 304 | 305 | transferringPlayback: false, 306 | transferPlayback: function(deviceId) { 307 | if (!spotifyHandler.transferringPlayback) { 308 | spotifyHandler.transferringPlayback = true; 309 | spotifyHandler.api.transferMyPlayback([deviceId], {}, function(err, data) { 310 | if (err) { 311 | console.error(err); 312 | spotifyHandler.transferringPlayback = false; 313 | } 314 | else { 315 | console.log("Moved playback"); 316 | setTimeout(function() { 317 | spotifyHandler.refreshDevices(); 318 | spotifyHandler.transferringPlayback = false; 319 | }, 500); 320 | } 321 | }); 322 | } 323 | }, 324 | 325 | fetchingQueue: false, 326 | queueTotal: undefined, 327 | queueOffset: 0, 328 | fillQueue: function(type, id) { 329 | if (id != null) 330 | { 331 | if (spotifyHandler.lastQueueId != id) { 332 | spotifyHandler.dom.queueButton.disabled = true; 333 | spotifyHandler.lastQueueId = id; 334 | spotifyHandler.lastQueueType = type; 335 | spotifyHandler.queueOffset = 0; 336 | spotifyHandler.queueTotal = undefined; 337 | spotifyHandler.dom.queue.innerHTML = ""; 338 | spotifyHandler.fetchQueueTracks(type, id, 0); 339 | } 340 | else { 341 | console.log("Queue already loaded for id " + id); 342 | } 343 | } 344 | else { 345 | spotifyHandler.lastQueueId = null; 346 | spotifyHandler.lastQueueType = null; 347 | spotifyHandler.dom.queue.innerHTML = ""; 348 | spotifyHandler.fetchQueueTracks(type, id, 0); 349 | } 350 | }, 351 | 352 | fetchQueueTracks: function(type, id, offset) { 353 | if (spotifyHandler.fetchingQueue != true) { 354 | if (type == "album") { 355 | spotifyHandler.fetchingQueue = true; 356 | spotifyHandler.api.getAlbumTracks(id, {offset: offset}, spotifyHandler.handleFetchedTracks); 357 | } 358 | else if (type == "playlist") { 359 | spotifyHandler.fetchingQueue = true; 360 | spotifyHandler.api.getPlaylistTracks(id, {offset: offset}, spotifyHandler.handleFetchedTracks); 361 | } 362 | else if (type == "artist") { 363 | spotifyHandler.fetchingQueue = true; 364 | spotifyHandler.api.getArtistTopTracks(id, "from_token", {}, spotifyHandler.handleFetchedTracks); 365 | } 366 | else if (type == "library" && id == "library") { 367 | spotifyHandler.fetchingQueue = true; 368 | spotifyHandler.api.getMySavedTracks({offset: offset, limit: 50, market: "from_token"}, spotifyHandler.handleFetchedTracks); 369 | } 370 | else { 371 | spotifyHandler.dom.queueButton.disabled = true; 372 | console.log("Queue cannot be retrieved for type " + type); 373 | } 374 | } 375 | else { 376 | console.warn("Already fetching queue!"); 377 | } 378 | }, 379 | 380 | handleFetchedTracks: function(err, data) { 381 | spotifyHandler.fetchingQueue = false; 382 | spotifyHandler.dom.queueButton.disabled = false; 383 | if (err) { 384 | console.error(err); 385 | } 386 | else { 387 | console.log("Queue retrieved", data); 388 | if (data.items) { 389 | spotifyHandler.addQueueTracks(data.items, false); 390 | spotifyHandler.queueOffset += data.items.length; 391 | } 392 | else if (data.tracks) { 393 | spotifyHandler.addQueueTracks(data.tracks, true); 394 | spotifyHandler.queueOffset += data.tracks.length; 395 | } 396 | spotifyHandler.queueTotal = data.total; 397 | } 398 | }, 399 | 400 | createTrackItem: function(tempTrack, doCover, inCurrentContext) { 401 | var trackElem = document.createElement("li"); 402 | var tempArtists = []; 403 | trackElem.className = "queue-item"; 404 | trackElem.setAttribute("data-uri", tempTrack.uri); 405 | if (inCurrentContext) { 406 | trackElem.setAttribute("data-context", "spotify:"+spotifyHandler.lastQueueType+":"+spotifyHandler.lastQueueId); 407 | } 408 | else { 409 | trackElem.setAttribute("data-context", tempTrack.album.uri); 410 | } 411 | trackElem.setAttribute("onclick", "spotifyHandler.playContext(this.getAttribute('data-context'), this.getAttribute('data-uri'));"); 412 | tempArtists = []; 413 | for (var j = 0; j < tempTrack.artists.length; j++) { 414 | tempArtists.push(stripTags(tempTrack.artists[j].name)); 415 | } 416 | trackElem.innerHTML = (doCover ? '
    ': '
    '+(tempTrack.disc_number > 1 ? tempTrack.disc_number+'-' : '')+tempTrack.track_number+'
    ')+''; 417 | spotifyHandler.dom.queue.appendChild(trackElem); 418 | return (trackElem); 419 | }, 420 | 421 | addQueueTracks: function(tracks, doCover) { 422 | var tempTrack = {}; 423 | for (var i = 0; i < tracks.length; i++) { 424 | 425 | tempTrack = tracks[i]; 426 | if ("track" in tempTrack) { 427 | tempTrack = tempTrack.track; 428 | doCover = true; 429 | } 430 | if (tempTrack.uri != null && tempTrack.uri.indexOf(":local:") == -1) { 431 | spotifyHandler.dom.queue.appendChild(spotifyHandler.createTrackItem(tempTrack, doCover, true)); 432 | } 433 | } 434 | }, 435 | 436 | playContext: function(contextUri, trackUri) { 437 | if (trackUri == null) { 438 | spotifyHandler.api.play({ 439 | context_uri: contextUri 440 | }); 441 | } 442 | else if (contextUri != null && contextUri != "spotify:library:library") { 443 | spotifyHandler.api.play({ 444 | context_uri: contextUri, 445 | offset: { 446 | uri: trackUri 447 | } 448 | }); 449 | } 450 | else { 451 | // workaround for missing context for user's library 452 | // only plays tracks fetched so far... but it's better than nothing 453 | var tempUris = []; 454 | for (var i = 0; i < spotifyHandler.dom.queue.children.length; i++) { 455 | tempUris.push(spotifyHandler.dom.queue.children[i].getAttribute("data-uri")); 456 | } 457 | spotifyHandler.api.play({ 458 | uris: tempUris, 459 | offset: { 460 | uri: trackUri 461 | } 462 | }); 463 | } 464 | }, 465 | 466 | startPlaySession: function(deviceId) { 467 | spotifyHandler.api.play({ 468 | device_id: deviceId 469 | }, function(err, data) { 470 | if (err) { 471 | console.error(err); 472 | alert("Could not start playback due to an error ("+err.status+"). You'll have to start it yourself, on the device you clicked on."); 473 | } 474 | }); 475 | }, 476 | 477 | fetchingPlaylists: false, 478 | playlistsTotal: undefined, 479 | playlistsOffset: 0, 480 | firstAlbumFetched: false, 481 | loadLibrary: function() { 482 | spotifyHandler.dom.library.innerHTML = ""; 483 | spotifyHandler.dom.library.appendChild(spotifyHandler.createDividerItem("Playlists")); 484 | spotifyHandler.playlistsOffset = 0; 485 | spotifyHandler.playlistsTotal = undefined; 486 | spotifyHandler.fetchPlaylists(0); 487 | }, 488 | 489 | fetchPlaylists: function(offset) { 490 | if (spotifyHandler.fetchingPlaylists != true) { 491 | spotifyHandler.fetchingPlaylists = true; 492 | if (offset < spotifyHandler.playlistsTotal || (offset == 0 && spotifyHandler.playlistsTotal == undefined)) { 493 | spotifyHandler.api.getUserPlaylists({offset: offset, limit: 50}, spotifyHandler.handleFetchedPlaylists); 494 | } 495 | else { 496 | if (!spotifyHandler.firstAlbumFetched) { 497 | spotifyHandler.dom.library.appendChild(spotifyHandler.createDividerItem("Albums")); 498 | spotifyHandler.firstAlbumFetched = true; 499 | } 500 | offset = offset - spotifyHandler.playlistsTotal; 501 | if (offset >= 0) { 502 | spotifyHandler.api.getMySavedAlbums({offset: offset, limit: 50, country: "from_token"}, spotifyHandler.handleFetchedPlaylists); 503 | } 504 | } 505 | } 506 | else { 507 | console.warn("Already fetching playlists!"); 508 | } 509 | }, 510 | 511 | handleFetchedPlaylists: function(err, data) { 512 | spotifyHandler.fetchingPlaylists = false; 513 | if (err) { 514 | console.error(err); 515 | } 516 | else { 517 | console.log("Playlists or albums fetched", data); 518 | spotifyHandler.addPlaylists(data.items); 519 | spotifyHandler.playlistsOffset += data.items.length; 520 | if (data.href.indexOf("me/albums") == -1) { 521 | spotifyHandler.playlistsTotal = data.total; 522 | } 523 | else if (data.offset == data.total) { 524 | // workaround to stop fetching albums from library once all have been fetched 525 | spotifyHandler.fetchingPlaylists = true; 526 | } 527 | } 528 | }, 529 | 530 | createPlaylistOrAlbumItem: function(tempData) { 531 | playlistElem = document.createElement("li"); 532 | playlistElem.className = "queue-item"; 533 | playlistElem.setAttribute("data-uri", tempData.uri); 534 | tempArtists = []; 535 | if ("artists" in tempData) { 536 | for (var j = 0; j < tempData.artists.length; j++) { 537 | tempArtists.push(stripTags(tempData.artists[j].name)); 538 | } 539 | } 540 | playlistElem.setAttribute("onclick", "spotifyHandler.playContext(this.getAttribute('data-uri'), null); pageHandler.showPage('playerpage');"); 541 | playlistElem.innerHTML = '
    '; 542 | return (playlistElem); 543 | }, 544 | 545 | addPlaylists: function(data) { 546 | for (var i = 0; i < data.length; i++) { 547 | tempData = data[i]; 548 | if ("album" in tempData) { 549 | tempData = tempData.album; 550 | } 551 | spotifyHandler.dom.library.appendChild(spotifyHandler.createPlaylistOrAlbumItem(tempData)); 552 | } 553 | }, 554 | 555 | createDividerItem: function(content) { 556 | divider = document.createElement("li"); 557 | divider.className = "queue-item divider"; 558 | divider.innerHTML = content; 559 | return (divider); 560 | }, 561 | 562 | searchReq: null, 563 | search: function(q) { 564 | if (spotifyHandler.searchReq != null) { 565 | spotifyHandler.searchReq.abort(); 566 | } 567 | if (q.trim() != "") 568 | { 569 | spotifyHandler.searchReq = spotifyHandler.api.search(q.trim(), ["track", "album", "playlist"], {offset: 0, limit: 12, market: "from_token"}); 570 | spotifyHandler.searchReq.then(function(data) { 571 | console.log("Search results are in", data); 572 | spotifyHandler.dom.search.innerHTML = ""; 573 | var anyResults = false; 574 | if (data.tracks.items.length > 0) { 575 | spotifyHandler.dom.search.appendChild(spotifyHandler.createDividerItem("Tracks")); 576 | for (var i = 0; i < data.tracks.items.length; i++) { 577 | spotifyHandler.dom.search.appendChild(spotifyHandler.createTrackItem(data.tracks.items[i], true, false)); 578 | } 579 | anyResults = true; 580 | } 581 | if (data.albums.items.length > 0) { 582 | spotifyHandler.dom.search.appendChild(spotifyHandler.createDividerItem("Albums")); 583 | for (var i = 0; i < data.albums.items.length; i++) { 584 | spotifyHandler.dom.search.appendChild(spotifyHandler.createPlaylistOrAlbumItem(data.albums.items[i], true)); 585 | } 586 | anyResults = true; 587 | } 588 | if (data.playlists.items.length > 0) { 589 | spotifyHandler.dom.search.appendChild(spotifyHandler.createDividerItem("Playlists")); 590 | for (var i = 0; i < data.playlists.items.length; i++) { 591 | spotifyHandler.dom.search.appendChild(spotifyHandler.createPlaylistOrAlbumItem(data.playlists.items[i], true)); 592 | } 593 | anyResults = true; 594 | } 595 | if (!anyResults) { 596 | spotifyHandler.dom.search.appendChild(spotifyHandler.createDividerItem("No results found for \""+stripTags(q.trim())+"\"")); 597 | } 598 | }, function(err) { 599 | // console.error(err); 600 | }); 601 | } 602 | else { 603 | spotifyHandler.dom.search.innerHTML = ""; 604 | } 605 | }, 606 | 607 | init: function() { 608 | document.getElementById("signinbtn").addEventListener("click", spotifyHandler.signIn); 609 | 610 | spotifyHandler.dom.playerPage = document.getElementById("playerpage"); 611 | spotifyHandler.dom.playingFrom = document.getElementById("playing-from"); 612 | spotifyHandler.dom.playingFromName = document.getElementById("playing-from-name"); 613 | spotifyHandler.dom.artwork = document.getElementById("artwork"); 614 | spotifyHandler.dom.title = document.getElementById("title"); 615 | spotifyHandler.dom.artist = document.getElementById("artist"); 616 | spotifyHandler.dom.likeButton = document.getElementById("like-button"); 617 | spotifyHandler.dom.playbackTime = document.getElementById("playback-time"); 618 | spotifyHandler.dom.durationTime = document.getElementById("duration-time"); 619 | spotifyHandler.dom.likeButton = document.getElementById("like-button"); 620 | spotifyHandler.dom.shuffleButton = document.getElementById("shuffle-button"); 621 | spotifyHandler.dom.previousButton = document.getElementById("previous-button"); 622 | spotifyHandler.dom.playPauseButton = document.getElementById("play-pause-button"); 623 | spotifyHandler.dom.nextButton = document.getElementById("next-button"); 624 | spotifyHandler.dom.repeatButton = document.getElementById("repeat-button"); 625 | spotifyHandler.dom.devicesButton = document.getElementById("devices-button"); 626 | spotifyHandler.dom.queuePage = document.getElementById("queuepage"); 627 | spotifyHandler.dom.queueButton = document.getElementById("queue-button"); 628 | spotifyHandler.dom.queue = document.getElementById("queue"); 629 | spotifyHandler.dom.contextName = document.getElementById("contextname"); 630 | spotifyHandler.dom.deviceListHolder = document.getElementById("devicelist-holder"); 631 | spotifyHandler.dom.deviceList = document.getElementById("devicelist"); 632 | spotifyHandler.dom.discoverSpinner = document.getElementById("discoverspinner"); 633 | spotifyHandler.dom.discoverListHolder = document.getElementById("discoverlist-holder"); 634 | spotifyHandler.dom.discoverList = document.getElementById("discoverlist"); 635 | spotifyHandler.dom.volumebar = document.getElementById("volumebar"); 636 | spotifyHandler.dom.listeningOn = document.getElementById("listeningon"); 637 | spotifyHandler.dom.listeningOnIcon = document.getElementById("listeningon-icon"); 638 | spotifyHandler.dom.themeColor = document.querySelector("meta[name=theme-color]"); 639 | spotifyHandler.dom.library = document.getElementById("library"); 640 | spotifyHandler.dom.libraryPage = document.getElementById("librarypage"); 641 | spotifyHandler.dom.search = document.getElementById("search"); 642 | spotifyHandler.dom.searchPage = document.getElementById("searchpage"); 643 | spotifyHandler.dom.searchBar = document.getElementById("searchbar"); 644 | window.addEventListener("resize", spotifyHandler.fixArtSize); 645 | spotifyHandler.dom.artwork.addEventListener("loadstart", function(event) { 646 | spotifyHandler.dom.playerPage.style.background = null; 647 | spotifyHandler.dom.themeColor.setAttribute("content", "#1DB954"); 648 | }); 649 | spotifyHandler.dom.artwork.addEventListener("load", function(event) { 650 | spotifyHandler.fixArtSize(); 651 | if (event.target.src.indexOf("data:image/gif;base64") != 0) { 652 | var vibrant = new Vibrant(event.target); 653 | var swatches = vibrant.swatches(); 654 | if (swatches.Vibrant != undefined) { 655 | spotifyHandler.dom.playerPage.style.background = "linear-gradient(rgba("+swatches.Vibrant.rgb.join(",")+",0.7), #15161A 75%)"; 656 | spotifyHandler.dom.themeColor.setAttribute("content", swatches.Vibrant.getHex()); 657 | } 658 | else if (swatches.Muted != undefined) { 659 | spotifyHandler.dom.playerPage.style.background = "linear-gradient(rgba("+swatches.Muted.rgb.join(",")+",0.7), #15161A 75%)"; 660 | spotifyHandler.dom.themeColor.setAttribute("content", swatches.Muted.getHex()); 661 | } 662 | else { 663 | console.log(swatches); 664 | spotifyHandler.dom.playerPage.style.background = null; 665 | spotifyHandler.dom.themeColor.setAttribute("content", "#1DB954"); 666 | } 667 | } 668 | else { 669 | spotifyHandler.dom.playerPage.style.background = null; 670 | spotifyHandler.dom.themeColor.setAttribute("content", "#1DB954"); 671 | } 672 | }); 673 | spotifyHandler.dom.playPauseButton.addEventListener("click", function(event) { 674 | spotifyHandler.dom.playPauseButton.disabled = true; 675 | if (spotifyHandler.dom.playPauseButton.title == "Pause") { 676 | spotifyHandler.api.pause({}, function() { 677 | spotifyHandler.dom.playPauseButton.disabled = false; 678 | spotifyHandler.dom.playPauseButton.innerHTML = ""; 679 | spotifyHandler.dom.playPauseButton.title = "Play"; 680 | setTimeout(function() { 681 | spotifyHandler.setCurrentlyPlaying(); 682 | }, 250); 683 | }); 684 | } 685 | else { 686 | spotifyHandler.api.play({}, function() { 687 | spotifyHandler.dom.playPauseButton.disabled = false; 688 | spotifyHandler.dom.playPauseButton.innerHTML = ""; 689 | spotifyHandler.dom.playPauseButton.title = "Pause"; 690 | setTimeout(function() { 691 | spotifyHandler.setCurrentlyPlaying(); 692 | }, 250); 693 | }); 694 | } 695 | }); 696 | spotifyHandler.dom.nextButton.addEventListener("click", function(event) { 697 | spotifyHandler.dom.nextButton.disabled = true; 698 | spotifyHandler.api.skipToNext({}, function() { 699 | spotifyHandler.dom.nextButton.disabled = false; 700 | setTimeout(function() { 701 | spotifyHandler.setCurrentlyPlaying(); 702 | }, 250); 703 | }); 704 | }); 705 | spotifyHandler.dom.previousButton.addEventListener("click", function(event) { 706 | spotifyHandler.dom.previousButton.disabled = true; 707 | spotifyHandler.api.skipToPrevious({}, function() { 708 | spotifyHandler.dom.previousButton.disabled = false; 709 | setTimeout(function() { 710 | spotifyHandler.setCurrentlyPlaying(); 711 | }, 250); 712 | }); 713 | }); 714 | spotifyHandler.dom.likeButton.addEventListener("click", function(event) { 715 | spotifyHandler.dom.likeButton.disabled = true; 716 | if (spotifyHandler.dom.likeButton.getAttribute("data-liked") == "false") { 717 | spotifyHandler.api.addToMySavedTracks([spotifyHandler.lastTrackId], {}, function(err, data) { 718 | if (err) { 719 | console.error(err); 720 | } 721 | else { 722 | spotifyHandler.dom.likeButton.disabled = false; 723 | spotifyHandler.dom.likeButton.innerHTML = ""; 724 | spotifyHandler.dom.likeButton.style.color = "#1DB954"; 725 | spotifyHandler.dom.likeButton.title = "Remove from liked songs"; 726 | spotifyHandler.dom.likeButton.setAttribute("data-liked", "true"); 727 | } 728 | }); 729 | } 730 | else { 731 | spotifyHandler.api.removeFromMySavedTracks([spotifyHandler.lastTrackId], {}, function(err, data) { 732 | if (err) { 733 | console.error(err); 734 | } 735 | else { 736 | spotifyHandler.dom.likeButton.disabled = false; 737 | spotifyHandler.dom.likeButton.innerHTML = ""; 738 | spotifyHandler.dom.likeButton.style.color = null; 739 | spotifyHandler.dom.likeButton.title = "Add to liked songs"; 740 | spotifyHandler.dom.likeButton.setAttribute("data-liked", "false"); 741 | } 742 | }); 743 | } 744 | }); 745 | spotifyHandler.dom.devicesButton.addEventListener("click", function(event) { 746 | pageHandler.showPage("devicespage"); 747 | }); 748 | spotifyHandler.dom.queueButton.addEventListener("click", function(event) { 749 | pageHandler.showPage("queuepage"); 750 | }); 751 | spotifyHandler.dom.shuffleButton.addEventListener("click", function(event) { 752 | spotifyHandler.dom.shuffleButton.disabled = true; 753 | spotifyHandler.api.setShuffle(!spotifyHandler.lastPlaybackStatus.shuffle_state, {}, function(err, data) { 754 | spotifyHandler.dom.shuffleButton.disabled = false; 755 | if (err) { 756 | console.error(err); 757 | } 758 | else { 759 | setTimeout(function() { 760 | spotifyHandler.setCurrentlyPlaying(); 761 | }, 250); 762 | } 763 | }); 764 | }); 765 | spotifyHandler.dom.repeatButton.addEventListener("click", function(event) { 766 | spotifyHandler.dom.repeatButton.disabled = true; 767 | var newState = { 768 | off: "context", 769 | context: "track", 770 | track: "off" 771 | }; 772 | spotifyHandler.api.setRepeat(newState[spotifyHandler.lastPlaybackStatus.repeat_state], {}, function(err, data) { 773 | spotifyHandler.dom.repeatButton.disabled = false; 774 | if (err) { 775 | console.error(err); 776 | } 777 | else { 778 | setTimeout(function() { 779 | spotifyHandler.setCurrentlyPlaying(); 780 | }, 250); 781 | } 782 | }); 783 | }); 784 | 785 | spotifyHandler.dom.queuePage.addEventListener("scroll", function(event) { 786 | if (event.target.offsetHeight + event.target.scrollTop + 1280 >= event.target.scrollHeight && spotifyHandler.fetchingQueue != true && spotifyHandler.queueOffset < spotifyHandler.queueTotal) { 787 | console.log("Scrolled near the end of queue, fetching more tracks"); 788 | spotifyHandler.fetchQueueTracks(spotifyHandler.lastQueueType, spotifyHandler.lastQueueId, spotifyHandler.queueOffset); 789 | } 790 | }); 791 | 792 | spotifyHandler.dom.libraryPage.addEventListener("scroll", function(event) { 793 | if (event.target.offsetHeight + event.target.scrollTop + 1280 >= event.target.scrollHeight && spotifyHandler.fetchingPlaylists != true) { 794 | console.log("Scrolled near the end of library, fetching more playlists"); 795 | spotifyHandler.fetchPlaylists(spotifyHandler.playlistsOffset); 796 | } 797 | }); 798 | 799 | spotifyHandler.dom.searchBar.addEventListener("input", function(event) { 800 | spotifyHandler.search(event.target.value); 801 | }); 802 | 803 | if ('mediaSession' in navigator) 804 | { 805 | navigator.mediaSession.metadata = new MediaMetadata({}); 806 | navigator.mediaSession.setActionHandler('play', spotifyHandler.api.play); 807 | navigator.mediaSession.setActionHandler('pause', spotifyHandler.api.pause); 808 | navigator.mediaSession.setActionHandler('nexttrack', spotifyHandler.api.skipToNext); 809 | navigator.mediaSession.setActionHandler('previoustrack', spotifyHandler.api.skipToPrevious); 810 | navigator.mediaSession.playbackState = "none"; 811 | } 812 | 813 | if (window.location.hash.length > 0) 814 | { 815 | var hash = {}; 816 | var tempHash = window.location.hash.substring(1).split("&"); 817 | window.location.hash = ""; 818 | for (var i = 0; i < tempHash.length; i++) { 819 | hash[tempHash[i].split("=")[0]] = tempHash[i].split("=")[1]; 820 | } 821 | if ("access_token" in hash && parseInt(hash["state"]) == state) { 822 | if (getCookie("spat") != hash["access_token"]) { 823 | setCookie("spat", hash["access_token"]); 824 | spotifyHandler.expires = new Date().getTime() + (parseInt(hash["expires_in"]) * 1000); 825 | setCookie("spex", spotifyHandler.expires); 826 | } 827 | else { 828 | spotifyHandler.expires = parseInt(getCookie("spex")); 829 | } 830 | setInterval(spotifyHandler.checkAccessToken, 1000); 831 | setInterval(spotifyHandler.refreshDevices, 5000); 832 | setInterval(spotifyHandler.setCurrentlyPlaying, 1000); 833 | setTimeout(function() { 834 | setInterval(function() { 835 | if (spotifyHandler.lastPlaybackStatus.is_playing) { 836 | progressBar.setValue(((spotifyHandler.lastPlaybackStatus.progress_ms + 500) / spotifyHandler.lastPlaybackStatus.item.duration_ms) * 100); 837 | } 838 | }, 1000); 839 | }, 500); 840 | spotifyHandler.api.setAccessToken(hash["access_token"]); 841 | pageHandler.showPage("playerpage"); 842 | spotifyHandler.setCurrentlyPlaying(); 843 | spotifyHandler.refreshDevices(); 844 | spotifyHandler.loadLibrary(); 845 | } 846 | else if ("error" in hash && parseInt(hash["state"]) == state) { 847 | if (hash["error"] == "access_denied") { 848 | 849 | } 850 | else { 851 | alert("An error occurred connecting to your Spotify account: " + hash["error"]); 852 | } 853 | pageHandler.showPage("signinpage"); 854 | } 855 | else { 856 | alert("Something went wrong connecting your Spotify account. Please try again."); 857 | pageHandler.showPage("signinpage"); 858 | } 859 | } 860 | else if (getCookie("spat") != null) { 861 | console.log("No hash present, but we might be able to sign in automatically, since a previous access token was found."); 862 | spotifyHandler.signIn(); 863 | } 864 | else { 865 | pageHandler.showPage('signinpage'); 866 | } 867 | } 868 | }; -------------------------------------------------------------------------------- /spotify-web-api.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Modified from JMPerez/spotify-web-api-js 3 | * https://github.com/JMPerez/spotify-web-api-js/ 4 | */ 5 | 6 | /* global module */ 7 | 'use strict'; 8 | 9 | /** 10 | * Class representing the API 11 | */ 12 | var SpotifyWebApi = (function() { 13 | var _baseUri = 'https://api.spotify.com/v1'; 14 | var _accessToken = null; 15 | var _promiseImplementation = null; 16 | 17 | var WrapPromiseWithAbort = function(promise, onAbort) { 18 | promise.abort = onAbort; 19 | return promise; 20 | }; 21 | 22 | var _promiseProvider = function(promiseFunction, onAbort) { 23 | var returnedPromise; 24 | if (_promiseImplementation !== null) { 25 | var deferred = _promiseImplementation.defer(); 26 | promiseFunction( 27 | function(resolvedResult) { 28 | deferred.resolve(resolvedResult); 29 | }, 30 | function(rejectedResult) { 31 | deferred.reject(rejectedResult); 32 | } 33 | ); 34 | returnedPromise = deferred.promise; 35 | } else { 36 | if (window.Promise) { 37 | returnedPromise = new window.Promise(promiseFunction); 38 | } 39 | } 40 | 41 | if (returnedPromise) { 42 | return new WrapPromiseWithAbort(returnedPromise, onAbort); 43 | } else { 44 | return null; 45 | } 46 | }; 47 | 48 | var _extend = function() { 49 | var args = Array.prototype.slice.call(arguments); 50 | var target = args[0]; 51 | var objects = args.slice(1); 52 | target = target || {}; 53 | objects.forEach(function(object) { 54 | for (var j in object) { 55 | if (object.hasOwnProperty(j)) { 56 | target[j] = object[j]; 57 | } 58 | } 59 | }); 60 | return target; 61 | }; 62 | 63 | var _buildUrl = function(url, parameters) { 64 | var qs = ''; 65 | for (var key in parameters) { 66 | if (parameters.hasOwnProperty(key)) { 67 | var value = parameters[key]; 68 | qs += encodeURIComponent(key) + '=' + encodeURIComponent(value) + '&'; 69 | } 70 | } 71 | if (qs.length > 0) { 72 | // chop off last '&' 73 | qs = qs.substring(0, qs.length - 1); 74 | url = url + '?' + qs; 75 | } 76 | return url; 77 | }; 78 | 79 | var _performRequest = function(requestData, callback) { 80 | var req = new XMLHttpRequest(); 81 | 82 | var promiseFunction = function(resolve, reject) { 83 | function success(data) { 84 | if (resolve) { 85 | resolve(data); 86 | } 87 | if (callback) { 88 | callback(null, data); 89 | } 90 | } 91 | 92 | function failure() { 93 | if (reject) { 94 | reject(req); 95 | } 96 | if (callback) { 97 | callback(req, null); 98 | } 99 | } 100 | 101 | var type = requestData.type || 'GET'; 102 | req.open(type, _buildUrl(requestData.url, requestData.params)); 103 | if (_accessToken) { 104 | req.setRequestHeader('Authorization', 'Bearer ' + _accessToken); 105 | } 106 | if (requestData.contentType) { 107 | req.setRequestHeader('Content-Type', requestData.contentType) 108 | } 109 | 110 | req.onreadystatechange = function() { 111 | if (req.readyState === 4) { 112 | var data = null; 113 | try { 114 | data = req.responseText ? JSON.parse(req.responseText) : ''; 115 | } catch (e) { 116 | console.error(e); 117 | } 118 | 119 | if (req.status >= 200 && req.status < 300) { 120 | success(data); 121 | } else { 122 | failure(); 123 | } 124 | } 125 | }; 126 | 127 | if (type === 'GET') { 128 | req.send(null); 129 | } else { 130 | var postData = null 131 | if (requestData.postData) { 132 | postData = requestData.contentType === 'image/jpeg' ? requestData.postData : JSON.stringify(requestData.postData) 133 | } 134 | req.send(postData); 135 | } 136 | }; 137 | 138 | if (callback) { 139 | promiseFunction(); 140 | return null; 141 | } else { 142 | return _promiseProvider(promiseFunction, function() { 143 | req.abort(); 144 | }); 145 | } 146 | }; 147 | 148 | var _checkParamsAndPerformRequest = function(requestData, options, callback, optionsAlwaysExtendParams) { 149 | var opt = {}; 150 | var cb = null; 151 | 152 | if (typeof options === 'object') { 153 | opt = options; 154 | cb = callback; 155 | } else if (typeof options === 'function') { 156 | cb = options; 157 | } 158 | 159 | // options extend postData, if any. Otherwise they extend parameters sent in the url 160 | var type = requestData.type || 'GET'; 161 | if (type !== 'GET' && requestData.postData && !optionsAlwaysExtendParams) { 162 | requestData.postData = _extend(requestData.postData, opt); 163 | } else { 164 | requestData.params = _extend(requestData.params, opt); 165 | } 166 | return _performRequest(requestData, cb); 167 | }; 168 | 169 | /** 170 | * Creates an instance of the wrapper 171 | * @constructor 172 | */ 173 | var Constr = function() {}; 174 | 175 | Constr.prototype = { 176 | constructor: SpotifyWebApi 177 | }; 178 | 179 | /** 180 | * Fetches a resource through a generic GET request. 181 | * 182 | * @param {string} url The URL to be fetched 183 | * @param {function(Object,Object)} callback An optional callback 184 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 185 | */ 186 | Constr.prototype.getGeneric = function(url, callback) { 187 | var requestData = { 188 | url: url 189 | }; 190 | return _checkParamsAndPerformRequest(requestData, callback); 191 | }; 192 | 193 | /** 194 | * Fetches information about the current user. 195 | * See [Get Current User's Profile](https://developer.spotify.com/web-api/get-current-users-profile/) on 196 | * the Spotify Developer site for more information about the endpoint. 197 | * 198 | * @param {Object} options A JSON object with options that can be passed 199 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 200 | * one is the error object (null if no error), and the second is the value if the request succeeded. 201 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 202 | */ 203 | Constr.prototype.getMe = function(options, callback) { 204 | var requestData = { 205 | url: _baseUri + '/me' 206 | }; 207 | return _checkParamsAndPerformRequest(requestData, options, callback); 208 | }; 209 | 210 | /** 211 | * Fetches current user's saved tracks. 212 | * See [Get Current User's Saved Tracks](https://developer.spotify.com/web-api/get-users-saved-tracks/) on 213 | * the Spotify Developer site for more information about the endpoint. 214 | * 215 | * @param {Object} options A JSON object with options that can be passed 216 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 217 | * one is the error object (null if no error), and the second is the value if the request succeeded. 218 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 219 | */ 220 | Constr.prototype.getMySavedTracks = function(options, callback) { 221 | var requestData = { 222 | url: _baseUri + '/me/tracks' 223 | }; 224 | return _checkParamsAndPerformRequest(requestData, options, callback); 225 | }; 226 | 227 | /** 228 | * Adds a list of tracks to the current user's saved tracks. 229 | * See [Save Tracks for Current User](https://developer.spotify.com/web-api/save-tracks-user/) on 230 | * the Spotify Developer site for more information about the endpoint. 231 | * 232 | * @param {Array} trackIds The ids of the tracks. If you know their Spotify URI it is easy 233 | * to find their track id (e.g. spotify:track:) 234 | * @param {Object} options A JSON object with options that can be passed 235 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 236 | * one is the error object (null if no error), and the second is the value if the request succeeded. 237 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 238 | */ 239 | Constr.prototype.addToMySavedTracks = function(trackIds, options, callback) { 240 | var requestData = { 241 | url: _baseUri + '/me/tracks', 242 | type: 'PUT', 243 | postData: trackIds 244 | }; 245 | return _checkParamsAndPerformRequest(requestData, options, callback); 246 | }; 247 | 248 | /** 249 | * Remove a list of tracks from the current user's saved tracks. 250 | * See [Remove Tracks for Current User](https://developer.spotify.com/web-api/remove-tracks-user/) on 251 | * the Spotify Developer site for more information about the endpoint. 252 | * 253 | * @param {Array} trackIds The ids of the tracks. If you know their Spotify URI it is easy 254 | * to find their track id (e.g. spotify:track:) 255 | * @param {Object} options A JSON object with options that can be passed 256 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 257 | * one is the error object (null if no error), and the second is the value if the request succeeded. 258 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 259 | */ 260 | Constr.prototype.removeFromMySavedTracks = function(trackIds, options, callback) { 261 | var requestData = { 262 | url: _baseUri + '/me/tracks', 263 | type: 'DELETE', 264 | postData: trackIds 265 | }; 266 | return _checkParamsAndPerformRequest(requestData, options, callback); 267 | }; 268 | 269 | /** 270 | * Checks if the current user's saved tracks contains a certain list of tracks. 271 | * See [Check Current User's Saved Tracks](https://developer.spotify.com/web-api/check-users-saved-tracks/) on 272 | * the Spotify Developer site for more information about the endpoint. 273 | * 274 | * @param {Array} trackIds The ids of the tracks. If you know their Spotify URI it is easy 275 | * to find their track id (e.g. spotify:track:) 276 | * @param {Object} options A JSON object with options that can be passed 277 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 278 | * one is the error object (null if no error), and the second is the value if the request succeeded. 279 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 280 | */ 281 | Constr.prototype.containsMySavedTracks = function(trackIds, options, callback) { 282 | var requestData = { 283 | url: _baseUri + '/me/tracks/contains', 284 | params: { ids: trackIds.join(',') } 285 | }; 286 | return _checkParamsAndPerformRequest(requestData, options, callback); 287 | }; 288 | 289 | /** 290 | * Get a list of the albums saved in the current Spotify user's "Your Music" library. 291 | * See [Get Current User's Saved Albums](https://developer.spotify.com/web-api/get-users-saved-albums/) on 292 | * the Spotify Developer site for more information about the endpoint. 293 | * 294 | * @param {Object} options A JSON object with options that can be passed 295 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 296 | * one is the error object (null if no error), and the second is the value if the request succeeded. 297 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 298 | */ 299 | Constr.prototype.getMySavedAlbums = function(options, callback) { 300 | var requestData = { 301 | url: _baseUri + '/me/albums' 302 | }; 303 | return _checkParamsAndPerformRequest(requestData, options, callback); 304 | }; 305 | 306 | /** 307 | * Save one or more albums to the current user's "Your Music" library. 308 | * See [Save Albums for Current User](https://developer.spotify.com/web-api/save-albums-user/) on 309 | * the Spotify Developer site for more information about the endpoint. 310 | * 311 | * @param {Array} albumIds The ids of the albums. If you know their Spotify URI, it is easy 312 | * to find their album id (e.g. spotify:album:) 313 | * @param {Object} options A JSON object with options that can be passed 314 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 315 | * one is the error object (null if no error), and the second is the value if the request succeeded. 316 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 317 | */ 318 | Constr.prototype.addToMySavedAlbums = function(albumIds, options, callback) { 319 | var requestData = { 320 | url: _baseUri + '/me/albums', 321 | type: 'PUT', 322 | postData: albumIds 323 | }; 324 | return _checkParamsAndPerformRequest(requestData, options, callback); 325 | }; 326 | 327 | /** 328 | * Remove one or more albums from the current user's "Your Music" library. 329 | * See [Remove Albums for Current User](https://developer.spotify.com/web-api/remove-albums-user/) on 330 | * the Spotify Developer site for more information about the endpoint. 331 | * 332 | * @param {Array} albumIds The ids of the albums. If you know their Spotify URI, it is easy 333 | * to find their album id (e.g. spotify:album:) 334 | * @param {Object} options A JSON object with options that can be passed 335 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 336 | * one is the error object (null if no error), and the second is the value if the request succeeded. 337 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 338 | */ 339 | Constr.prototype.removeFromMySavedAlbums = function(albumIds, options, callback) { 340 | var requestData = { 341 | url: _baseUri + '/me/albums', 342 | type: 'DELETE', 343 | postData: albumIds 344 | }; 345 | return _checkParamsAndPerformRequest(requestData, options, callback); 346 | }; 347 | 348 | /** 349 | * Check if one or more albums is already saved in the current Spotify user's "Your Music" library. 350 | * See [Check User's Saved Albums](https://developer.spotify.com/web-api/check-users-saved-albums/) on 351 | * the Spotify Developer site for more information about the endpoint. 352 | * 353 | * @param {Array} albumIds The ids of the albums. If you know their Spotify URI, it is easy 354 | * to find their album id (e.g. spotify:album:) 355 | * @param {Object} options A JSON object with options that can be passed 356 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 357 | * one is the error object (null if no error), and the second is the value if the request succeeded. 358 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 359 | */ 360 | Constr.prototype.containsMySavedAlbums = function(albumIds, options, callback) { 361 | var requestData = { 362 | url: _baseUri + '/me/albums/contains', 363 | params: { ids: albumIds.join(',') } 364 | }; 365 | return _checkParamsAndPerformRequest(requestData, options, callback); 366 | }; 367 | 368 | /** 369 | * Get the current user’s top artists based on calculated affinity. 370 | * See [Get a User’s Top Artists](https://developer.spotify.com/web-api/get-users-top-artists-and-tracks/) on 371 | * the Spotify Developer site for more information about the endpoint. 372 | * 373 | * @param {Object} options A JSON object with options that can be passed 374 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 375 | * one is the error object (null if no error), and the second is the value if the request succeeded. 376 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 377 | */ 378 | Constr.prototype.getMyTopArtists = function(options, callback) { 379 | var requestData = { 380 | url: _baseUri + '/me/top/artists' 381 | }; 382 | return _checkParamsAndPerformRequest(requestData, options, callback); 383 | }; 384 | 385 | /** 386 | * Get the current user’s top tracks based on calculated affinity. 387 | * See [Get a User’s Top Tracks](https://developer.spotify.com/web-api/get-users-top-artists-and-tracks/) on 388 | * the Spotify Developer site for more information about the endpoint. 389 | * 390 | * @param {Object} options A JSON object with options that can be passed 391 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 392 | * one is the error object (null if no error), and the second is the value if the request succeeded. 393 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 394 | */ 395 | Constr.prototype.getMyTopTracks = function(options, callback) { 396 | var requestData = { 397 | url: _baseUri + '/me/top/tracks' 398 | }; 399 | return _checkParamsAndPerformRequest(requestData, options, callback); 400 | }; 401 | 402 | /** 403 | * Get tracks from the current user’s recently played tracks. 404 | * See [Get Current User’s Recently Played Tracks](https://developer.spotify.com/web-api/web-api-personalization-endpoints/get-recently-played/) on 405 | * the Spotify Developer site for more information about the endpoint. 406 | * 407 | * @param {Object} options A JSON object with options that can be passed 408 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 409 | * one is the error object (null if no error), and the second is the value if the request succeeded. 410 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 411 | */ 412 | Constr.prototype.getMyRecentlyPlayedTracks = function(options, callback) { 413 | var requestData = { 414 | url: _baseUri + '/me/player/recently-played' 415 | }; 416 | return _checkParamsAndPerformRequest(requestData, options, callback); 417 | }; 418 | 419 | /** 420 | * Adds the current user as a follower of one or more other Spotify users. 421 | * See [Follow Artists or Users](https://developer.spotify.com/web-api/follow-artists-users/) on 422 | * the Spotify Developer site for more information about the endpoint. 423 | * 424 | * @param {Array} userIds The ids of the users. If you know their Spotify URI it is easy 425 | * to find their user id (e.g. spotify:user:) 426 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 427 | * one is the error object (null if no error), and the second is an empty value if the request succeeded. 428 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 429 | */ 430 | Constr.prototype.followUsers = function(userIds, callback) { 431 | var requestData = { 432 | url: _baseUri + '/me/following/', 433 | type: 'PUT', 434 | params: { 435 | ids: userIds.join(','), 436 | type: 'user' 437 | } 438 | }; 439 | return _checkParamsAndPerformRequest(requestData, callback); 440 | }; 441 | 442 | /** 443 | * Adds the current user as a follower of one or more artists. 444 | * See [Follow Artists or Users](https://developer.spotify.com/web-api/follow-artists-users/) on 445 | * the Spotify Developer site for more information about the endpoint. 446 | * 447 | * @param {Array} artistIds The ids of the artists. If you know their Spotify URI it is easy 448 | * to find their artist id (e.g. spotify:artist:) 449 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 450 | * one is the error object (null if no error), and the second is an empty value if the request succeeded. 451 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 452 | */ 453 | Constr.prototype.followArtists = function(artistIds, callback) { 454 | var requestData = { 455 | url: _baseUri + '/me/following/', 456 | type: 'PUT', 457 | params: { 458 | ids: artistIds.join(','), 459 | type: 'artist' 460 | } 461 | }; 462 | return _checkParamsAndPerformRequest(requestData, callback); 463 | }; 464 | 465 | /** 466 | * Add the current user as a follower of one playlist. 467 | * See [Follow a Playlist](https://developer.spotify.com/web-api/follow-playlist/) on 468 | * the Spotify Developer site for more information about the endpoint. 469 | * 470 | * @param {string} ownerId The id of the playlist owner. If you know the Spotify URI of 471 | * the playlist, it is easy to find the owner's user id 472 | * (e.g. spotify:user::playlist:xxxx) 473 | * @param {string} playlistId The id of the playlist. If you know the Spotify URI it is easy 474 | * to find the playlist id (e.g. spotify:user:xxxx:playlist:) 475 | * @param {Object} options A JSON object with options that can be passed. For instance, 476 | * whether you want the playlist to be followed privately ({public: false}) 477 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 478 | * one is the error object (null if no error), and the second is an empty value if the request succeeded. 479 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 480 | */ 481 | Constr.prototype.followPlaylist = function(ownerId, playlistId, options, callback) { 482 | var requestData = { 483 | url: _baseUri + '/users/' + encodeURIComponent(ownerId) + '/playlists/' + playlistId + '/followers', 484 | type: 'PUT', 485 | postData: {} 486 | }; 487 | 488 | return _checkParamsAndPerformRequest(requestData, options, callback); 489 | }; 490 | 491 | /** 492 | * Removes the current user as a follower of one or more other Spotify users. 493 | * See [Unfollow Artists or Users](https://developer.spotify.com/web-api/unfollow-artists-users/) on 494 | * the Spotify Developer site for more information about the endpoint. 495 | * 496 | * @param {Array} userIds The ids of the users. If you know their Spotify URI it is easy 497 | * to find their user id (e.g. spotify:user:) 498 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 499 | * one is the error object (null if no error), and the second is an empty value if the request succeeded. 500 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 501 | */ 502 | Constr.prototype.unfollowUsers = function(userIds, callback) { 503 | var requestData = { 504 | url: _baseUri + '/me/following/', 505 | type: 'DELETE', 506 | params: { 507 | ids: userIds.join(','), 508 | type: 'user' 509 | } 510 | }; 511 | return _checkParamsAndPerformRequest(requestData, callback); 512 | }; 513 | 514 | /** 515 | * Removes the current user as a follower of one or more artists. 516 | * See [Unfollow Artists or Users](https://developer.spotify.com/web-api/unfollow-artists-users/) on 517 | * the Spotify Developer site for more information about the endpoint. 518 | * 519 | * @param {Array} artistIds The ids of the artists. If you know their Spotify URI it is easy 520 | * to find their artist id (e.g. spotify:artist:) 521 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 522 | * one is the error object (null if no error), and the second is an empty value if the request succeeded. 523 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 524 | */ 525 | Constr.prototype.unfollowArtists = function(artistIds, callback) { 526 | var requestData = { 527 | url: _baseUri + '/me/following/', 528 | type: 'DELETE', 529 | params: { 530 | ids: artistIds.join(','), 531 | type: 'artist' 532 | } 533 | }; 534 | return _checkParamsAndPerformRequest(requestData, callback); 535 | }; 536 | 537 | /** 538 | * Remove the current user as a follower of one playlist. 539 | * See [Unfollow a Playlist](https://developer.spotify.com/web-api/unfollow-playlist/) on 540 | * the Spotify Developer site for more information about the endpoint. 541 | * 542 | * @param {string} ownerId The id of the playlist owner. If you know the Spotify URI of 543 | * the playlist, it is easy to find the owner's user id 544 | * (e.g. spotify:user::playlist:xxxx) 545 | * @param {string} playlistId The id of the playlist. If you know the Spotify URI it is easy 546 | * to find the playlist id (e.g. spotify:user:xxxx:playlist:) 547 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 548 | * one is the error object (null if no error), and the second is an empty value if the request succeeded. 549 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 550 | */ 551 | Constr.prototype.unfollowPlaylist = function(ownerId, playlistId, callback) { 552 | var requestData = { 553 | url: _baseUri + '/users/' + encodeURIComponent(ownerId) + '/playlists/' + playlistId + '/followers', 554 | type: 'DELETE' 555 | }; 556 | return _checkParamsAndPerformRequest(requestData, callback); 557 | }; 558 | 559 | /** 560 | * Checks to see if the current user is following one or more other Spotify users. 561 | * See [Check if Current User Follows Users or Artists](https://developer.spotify.com/web-api/check-current-user-follows/) on 562 | * the Spotify Developer site for more information about the endpoint. 563 | * 564 | * @param {Array} userIds The ids of the users. If you know their Spotify URI it is easy 565 | * to find their user id (e.g. spotify:user:) 566 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 567 | * one is the error object (null if no error), and the second is an array of boolean values that indicate 568 | * whether the user is following the users sent in the request. 569 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 570 | */ 571 | Constr.prototype.isFollowingUsers = function(userIds, callback) { 572 | var requestData = { 573 | url: _baseUri + '/me/following/contains', 574 | type: 'GET', 575 | params: { 576 | ids: userIds.join(','), 577 | type: 'user' 578 | } 579 | }; 580 | return _checkParamsAndPerformRequest(requestData, callback); 581 | }; 582 | 583 | /** 584 | * Checks to see if the current user is following one or more artists. 585 | * See [Check if Current User Follows](https://developer.spotify.com/web-api/check-current-user-follows/) on 586 | * the Spotify Developer site for more information about the endpoint. 587 | * 588 | * @param {Array} artistIds The ids of the artists. If you know their Spotify URI it is easy 589 | * to find their artist id (e.g. spotify:artist:) 590 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 591 | * one is the error object (null if no error), and the second is an array of boolean values that indicate 592 | * whether the user is following the artists sent in the request. 593 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 594 | */ 595 | Constr.prototype.isFollowingArtists = function(artistIds, callback) { 596 | var requestData = { 597 | url: _baseUri + '/me/following/contains', 598 | type: 'GET', 599 | params: { 600 | ids: artistIds.join(','), 601 | type: 'artist' 602 | } 603 | }; 604 | return _checkParamsAndPerformRequest(requestData, callback); 605 | }; 606 | 607 | /** 608 | * Check to see if one or more Spotify users are following a specified playlist. 609 | * See [Check if Users Follow a Playlist](https://developer.spotify.com/web-api/check-user-following-playlist/) on 610 | * the Spotify Developer site for more information about the endpoint. 611 | * 612 | * @param {string} ownerId The id of the playlist owner. If you know the Spotify URI of 613 | * the playlist, it is easy to find the owner's user id 614 | * (e.g. spotify:user::playlist:xxxx) 615 | * @param {string} playlistId The id of the playlist. If you know the Spotify URI it is easy 616 | * to find the playlist id (e.g. spotify:user:xxxx:playlist:) 617 | * @param {Array} userIds The ids of the users. If you know their Spotify URI it is easy 618 | * to find their user id (e.g. spotify:user:) 619 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 620 | * one is the error object (null if no error), and the second is an array of boolean values that indicate 621 | * whether the users are following the playlist sent in the request. 622 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 623 | */ 624 | Constr.prototype.areFollowingPlaylist = function(ownerId, playlistId, userIds, callback) { 625 | var requestData = { 626 | url: _baseUri + '/users/' + encodeURIComponent(ownerId) + '/playlists/' + playlistId + '/followers/contains', 627 | type: 'GET', 628 | params: { 629 | ids: userIds.join(',') 630 | } 631 | }; 632 | return _checkParamsAndPerformRequest(requestData, callback); 633 | }; 634 | 635 | /** 636 | * Get the current user's followed artists. 637 | * See [Get User's Followed Artists](https://developer.spotify.com/web-api/get-followed-artists/) on 638 | * the Spotify Developer site for more information about the endpoint. 639 | * 640 | * @param {Object} [options] Options, being after and limit. 641 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 642 | * one is the error object (null if no error), and the second is an object with a paged object containing 643 | * artists. 644 | * @returns {Promise|undefined} A promise that if successful, resolves to an object containing a paging object which contains 645 | * artists objects. Not returned if a callback is given. 646 | */ 647 | Constr.prototype.getFollowedArtists = function(options, callback) { 648 | var requestData = { 649 | url: _baseUri + '/me/following', 650 | type: 'GET', 651 | params: { 652 | type: 'artist' 653 | } 654 | }; 655 | return _checkParamsAndPerformRequest(requestData, options, callback); 656 | }; 657 | 658 | /** 659 | * Fetches information about a specific user. 660 | * See [Get a User's Profile](https://developer.spotify.com/web-api/get-users-profile/) on 661 | * the Spotify Developer site for more information about the endpoint. 662 | * 663 | * @param {string} userId The id of the user. If you know the Spotify URI it is easy 664 | * to find the id (e.g. spotify:user:) 665 | * @param {Object} options A JSON object with options that can be passed 666 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 667 | * one is the error object (null if no error), and the second is the value if the request succeeded. 668 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 669 | */ 670 | Constr.prototype.getUser = function(userId, options, callback) { 671 | var requestData = { 672 | url: _baseUri + '/users/' + encodeURIComponent(userId) 673 | }; 674 | return _checkParamsAndPerformRequest(requestData, options, callback); 675 | }; 676 | 677 | /** 678 | * Fetches a list of the current user's playlists. 679 | * See [Get a List of a User's Playlists](https://developer.spotify.com/web-api/get-list-users-playlists/) on 680 | * the Spotify Developer site for more information about the endpoint. 681 | * 682 | * @param {string} userId An optional id of the user. If you know the Spotify URI it is easy 683 | * to find the id (e.g. spotify:user:). If not provided, the id of the user that granted 684 | * the permissions will be used. 685 | * @param {Object} options A JSON object with options that can be passed 686 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 687 | * one is the error object (null if no error), and the second is the value if the request succeeded. 688 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 689 | */ 690 | Constr.prototype.getUserPlaylists = function(userId, options, callback) { 691 | var requestData; 692 | if (typeof userId === 'string') { 693 | requestData = { 694 | url: _baseUri + '/users/' + encodeURIComponent(userId) + '/playlists' 695 | }; 696 | } else { 697 | requestData = { 698 | url: _baseUri + '/me/playlists' 699 | }; 700 | callback = options; 701 | options = userId; 702 | } 703 | return _checkParamsAndPerformRequest(requestData, options, callback); 704 | }; 705 | 706 | /** 707 | * Fetches a specific playlist. 708 | * See [Get a Playlist](https://developer.spotify.com/web-api/get-playlist/) on 709 | * the Spotify Developer site for more information about the endpoint. 710 | * 711 | * @param {string} playlistId The id of the playlist. If you know the Spotify URI it is easy 712 | * to find the playlist id (e.g. spotify:user:xxxx:playlist:) 713 | * @param {Object} options A JSON object with options that can be passed 714 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 715 | * one is the error object (null if no error), and the second is the value if the request succeeded. 716 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 717 | */ 718 | Constr.prototype.getPlaylist = function(playlistId, options, callback) { 719 | var requestData = { 720 | url: _baseUri + '/playlists/' + playlistId 721 | }; 722 | return _checkParamsAndPerformRequest(requestData, options, callback); 723 | }; 724 | 725 | /** 726 | * Fetches the tracks from a specific playlist. 727 | * See [Get a Playlist's Tracks](https://developer.spotify.com/web-api/get-playlists-tracks/) on 728 | * the Spotify Developer site for more information about the endpoint. 729 | * 730 | * @param {string} playlistId The id of the playlist. If you know the Spotify URI it is easy 731 | * to find the playlist id (e.g. spotify:user:xxxx:playlist:) 732 | * @param {Object} options A JSON object with options that can be passed 733 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 734 | * one is the error object (null if no error), and the second is the value if the request succeeded. 735 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 736 | */ 737 | Constr.prototype.getPlaylistTracks = function(playlistId, options, callback) { 738 | var requestData = { 739 | url: _baseUri + '/playlists/' + playlistId + '/tracks' 740 | }; 741 | return _checkParamsAndPerformRequest(requestData, options, callback); 742 | }; 743 | 744 | /** 745 | * Creates a playlist and stores it in the current user's library. 746 | * See [Create a Playlist](https://developer.spotify.com/web-api/create-playlist/) on 747 | * the Spotify Developer site for more information about the endpoint. 748 | * 749 | * @param {string} userId The id of the user. You may want to user the "getMe" function to 750 | * find out the id of the current logged in user 751 | * @param {Object} options A JSON object with options that can be passed 752 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 753 | * one is the error object (null if no error), and the second is the value if the request succeeded. 754 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 755 | */ 756 | Constr.prototype.createPlaylist = function(userId, options, callback) { 757 | var requestData = { 758 | url: _baseUri + '/users/' + encodeURIComponent(userId) + '/playlists', 759 | type: 'POST', 760 | postData: options 761 | }; 762 | return _checkParamsAndPerformRequest(requestData, options, callback); 763 | }; 764 | 765 | /** 766 | * Change a playlist's name and public/private state 767 | * See [Change a Playlist's Details](https://developer.spotify.com/web-api/change-playlist-details/) on 768 | * the Spotify Developer site for more information about the endpoint. 769 | * 770 | * @param {string} userId The id of the user. You may want to user the "getMe" function to 771 | * find out the id of the current logged in user 772 | * @param {string} playlistId The id of the playlist. If you know the Spotify URI it is easy 773 | * to find the playlist id (e.g. spotify:user:xxxx:playlist:) 774 | * @param {Object} data A JSON object with the data to update. E.g. {name: 'A new name', public: true} 775 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 776 | * one is the error object (null if no error), and the second is the value if the request succeeded. 777 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 778 | */ 779 | Constr.prototype.changePlaylistDetails = function(userId, playlistId, data, callback) { 780 | var requestData = { 781 | url: _baseUri + '/users/' + encodeURIComponent(userId) + '/playlists/' + playlistId, 782 | type: 'PUT', 783 | postData: data 784 | }; 785 | return _checkParamsAndPerformRequest(requestData, data, callback); 786 | }; 787 | 788 | /** 789 | * Add tracks to a playlist. 790 | * See [Add Tracks to a Playlist](https://developer.spotify.com/web-api/add-tracks-to-playlist/) on 791 | * the Spotify Developer site for more information about the endpoint. 792 | * 793 | * @param {string} userId The id of the user. If you know the Spotify URI it is easy 794 | * to find the user id (e.g. spotify:user::playlist:xxxx) 795 | * @param {string} playlistId The id of the playlist. If you know the Spotify URI it is easy 796 | * to find the playlist id (e.g. spotify:user:xxxx:playlist:) 797 | * @param {Array} uris An array of Spotify URIs for the tracks 798 | * @param {Object} options A JSON object with options that can be passed 799 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 800 | * one is the error object (null if no error), and the second is the value if the request succeeded. 801 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 802 | */ 803 | Constr.prototype.addTracksToPlaylist = function(userId, playlistId, uris, options, callback) { 804 | var requestData = { 805 | url: _baseUri + '/users/' + encodeURIComponent(userId) + '/playlists/' + playlistId + '/tracks', 806 | type: 'POST', 807 | postData: { 808 | uris: uris 809 | } 810 | }; 811 | return _checkParamsAndPerformRequest(requestData, options, callback, true); 812 | }; 813 | 814 | /** 815 | * Replace the tracks of a playlist 816 | * See [Replace a Playlist's Tracks](https://developer.spotify.com/web-api/replace-playlists-tracks/) on 817 | * the Spotify Developer site for more information about the endpoint. 818 | * 819 | * @param {string} userId The id of the user. If you know the Spotify URI it is easy 820 | * to find the user id (e.g. spotify:user::playlist:xxxx) 821 | * @param {string} playlistId The id of the playlist. If you know the Spotify URI it is easy 822 | * to find the playlist id (e.g. spotify:user:xxxx:playlist:) 823 | * @param {Array} uris An array of Spotify URIs for the tracks 824 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 825 | * one is the error object (null if no error), and the second is the value if the request succeeded. 826 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 827 | */ 828 | Constr.prototype.replaceTracksInPlaylist = function(userId, playlistId, uris, callback) { 829 | var requestData = { 830 | url: _baseUri + '/users/' + encodeURIComponent(userId) + '/playlists/' + playlistId + '/tracks', 831 | type: 'PUT', 832 | postData: { uris: uris } 833 | }; 834 | return _checkParamsAndPerformRequest(requestData, {}, callback); 835 | }; 836 | 837 | /** 838 | * Reorder tracks in a playlist 839 | * See [Reorder a Playlist’s Tracks](https://developer.spotify.com/web-api/reorder-playlists-tracks/) on 840 | * the Spotify Developer site for more information about the endpoint. 841 | * 842 | * @param {string} userId The id of the user. If you know the Spotify URI it is easy 843 | * to find the user id (e.g. spotify:user::playlist:xxxx) 844 | * @param {string} playlistId The id of the playlist. If you know the Spotify URI it is easy 845 | * to find the playlist id (e.g. spotify:user:xxxx:playlist:) 846 | * @param {number} rangeStart The position of the first track to be reordered. 847 | * @param {number} insertBefore The position where the tracks should be inserted. To reorder the tracks to 848 | * the end of the playlist, simply set insert_before to the position after the last track. 849 | * @param {Object} options An object with optional parameters (range_length, snapshot_id) 850 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 851 | * one is the error object (null if no error), and the second is the value if the request succeeded. 852 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 853 | */ 854 | Constr.prototype.reorderTracksInPlaylist = function(userId, playlistId, rangeStart, insertBefore, options, callback) { 855 | /* eslint-disable camelcase */ 856 | var requestData = { 857 | url: _baseUri + '/users/' + encodeURIComponent(userId) + '/playlists/' + playlistId + '/tracks', 858 | type: 'PUT', 859 | postData: { 860 | range_start: rangeStart, 861 | insert_before: insertBefore 862 | } 863 | }; 864 | /* eslint-enable camelcase */ 865 | return _checkParamsAndPerformRequest(requestData, options, callback); 866 | }; 867 | 868 | /** 869 | * Remove tracks from a playlist 870 | * See [Remove Tracks from a Playlist](https://developer.spotify.com/web-api/remove-tracks-playlist/) on 871 | * the Spotify Developer site for more information about the endpoint. 872 | * 873 | * @param {string} userId The id of the user. If you know the Spotify URI it is easy 874 | * to find the user id (e.g. spotify:user::playlist:xxxx) 875 | * @param {string} playlistId The id of the playlist. If you know the Spotify URI it is easy 876 | * to find the playlist id (e.g. spotify:user:xxxx:playlist:) 877 | * @param {Array} uris An array of tracks to be removed. Each element of the array can be either a 878 | * string, in which case it is treated as a URI, or an object containing the properties `uri` (which is a 879 | * string) and `positions` (which is an array of integers). 880 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 881 | * one is the error object (null if no error), and the second is the value if the request succeeded. 882 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 883 | */ 884 | Constr.prototype.removeTracksFromPlaylist = function(userId, playlistId, uris, callback) { 885 | var dataToBeSent = uris.map(function(uri) { 886 | if (typeof uri === 'string') { 887 | return { uri: uri }; 888 | } else { 889 | return uri; 890 | } 891 | }); 892 | 893 | var requestData = { 894 | url: _baseUri + '/users/' + encodeURIComponent(userId) + '/playlists/' + playlistId + '/tracks', 895 | type: 'DELETE', 896 | postData: { tracks: dataToBeSent } 897 | }; 898 | return _checkParamsAndPerformRequest(requestData, {}, callback); 899 | }; 900 | 901 | /** 902 | * Remove tracks from a playlist, specifying a snapshot id. 903 | * See [Remove Tracks from a Playlist](https://developer.spotify.com/web-api/remove-tracks-playlist/) on 904 | * the Spotify Developer site for more information about the endpoint. 905 | * 906 | * @param {string} userId The id of the user. If you know the Spotify URI it is easy 907 | * to find the user id (e.g. spotify:user::playlist:xxxx) 908 | * @param {string} playlistId The id of the playlist. If you know the Spotify URI it is easy 909 | * to find the playlist id (e.g. spotify:user:xxxx:playlist:) 910 | * @param {Array} uris An array of tracks to be removed. Each element of the array can be either a 911 | * string, in which case it is treated as a URI, or an object containing the properties `uri` (which is a 912 | * string) and `positions` (which is an array of integers). 913 | * @param {string} snapshotId The playlist's snapshot ID against which you want to make the changes 914 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 915 | * one is the error object (null if no error), and the second is the value if the request succeeded. 916 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 917 | */ 918 | Constr.prototype.removeTracksFromPlaylistWithSnapshotId = function(userId, playlistId, uris, snapshotId, callback) { 919 | var dataToBeSent = uris.map(function(uri) { 920 | if (typeof uri === 'string') { 921 | return { uri: uri }; 922 | } else { 923 | return uri; 924 | } 925 | }); 926 | /* eslint-disable camelcase */ 927 | var requestData = { 928 | url: _baseUri + '/users/' + encodeURIComponent(userId) + '/playlists/' + playlistId + '/tracks', 929 | type: 'DELETE', 930 | postData: { 931 | tracks: dataToBeSent, 932 | snapshot_id: snapshotId 933 | } 934 | }; 935 | /* eslint-enable camelcase */ 936 | return _checkParamsAndPerformRequest(requestData, {}, callback); 937 | }; 938 | 939 | /** 940 | * Remove tracks from a playlist, specifying the positions of the tracks to be removed. 941 | * See [Remove Tracks from a Playlist](https://developer.spotify.com/web-api/remove-tracks-playlist/) on 942 | * the Spotify Developer site for more information about the endpoint. 943 | * 944 | * @param {string} userId The id of the user. If you know the Spotify URI it is easy 945 | * to find the user id (e.g. spotify:user::playlist:xxxx) 946 | * @param {string} playlistId The id of the playlist. If you know the Spotify URI it is easy 947 | * to find the playlist id (e.g. spotify:user:xxxx:playlist:) 948 | * @param {Array} positions array of integers containing the positions of the tracks to remove 949 | * from the playlist. 950 | * @param {string} snapshotId The playlist's snapshot ID against which you want to make the changes 951 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 952 | * one is the error object (null if no error), and the second is the value if the request succeeded. 953 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 954 | */ 955 | Constr.prototype.removeTracksFromPlaylistInPositions = function(userId, playlistId, positions, snapshotId, callback) { 956 | /* eslint-disable camelcase */ 957 | var requestData = { 958 | url: _baseUri + '/users/' + encodeURIComponent(userId) + '/playlists/' + playlistId + '/tracks', 959 | type: 'DELETE', 960 | postData: { 961 | positions: positions, 962 | snapshot_id: snapshotId 963 | } 964 | }; 965 | /* eslint-enable camelcase */ 966 | return _checkParamsAndPerformRequest(requestData, {}, callback); 967 | }; 968 | 969 | /** 970 | * Upload a custom playlist cover image. 971 | * See [Upload A Custom Playlist Cover Image](https://developer.spotify.com/web-api/upload-a-custom-playlist-cover-image/) on 972 | * the Spotify Developer site for more information about the endpoint. 973 | * 974 | * @param {string} userId The id of the user. If you know the Spotify URI it is easy 975 | * to find the user id (e.g. spotify:user::playlist:xxxx) 976 | * @param {string} playlistId The id of the playlist. If you know the Spotify URI it is easy 977 | * to find the playlist id (e.g. spotify:user:xxxx:playlist:) 978 | * @param {string} imageData Base64 encoded JPEG image data, maximum payload size is 256 KB. 979 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 980 | * one is the error object (null if no error), and the second is the value if the request succeeded. 981 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 982 | */ 983 | Constr.prototype.uploadCustomPlaylistCoverImage = function(userId, playlistId, imageData, callback) { 984 | var requestData = { 985 | url: _baseUri + '/users/' + encodeURIComponent(userId) + '/playlists/' + playlistId + '/images', 986 | type: 'PUT', 987 | postData: imageData.replace(/^data:image\/jpeg;base64,/, ''), 988 | contentType: 'image/jpeg' 989 | }; 990 | return _checkParamsAndPerformRequest(requestData, {}, callback); 991 | }; 992 | 993 | /** 994 | * Fetches an album from the Spotify catalog. 995 | * See [Get an Album](https://developer.spotify.com/web-api/get-album/) on 996 | * the Spotify Developer site for more information about the endpoint. 997 | * 998 | * @param {string} albumId The id of the album. If you know the Spotify URI it is easy 999 | * to find the album id (e.g. spotify:album:) 1000 | * @param {Object} options A JSON object with options that can be passed 1001 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 1002 | * one is the error object (null if no error), and the second is the value if the request succeeded. 1003 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 1004 | */ 1005 | Constr.prototype.getAlbum = function(albumId, options, callback) { 1006 | var requestData = { 1007 | url: _baseUri + '/albums/' + albumId 1008 | }; 1009 | return _checkParamsAndPerformRequest(requestData, options, callback); 1010 | }; 1011 | 1012 | /** 1013 | * Fetches the tracks of an album from the Spotify catalog. 1014 | * See [Get an Album's Tracks](https://developer.spotify.com/web-api/get-albums-tracks/) on 1015 | * the Spotify Developer site for more information about the endpoint. 1016 | * 1017 | * @param {string} albumId The id of the album. If you know the Spotify URI it is easy 1018 | * to find the album id (e.g. spotify:album:) 1019 | * @param {Object} options A JSON object with options that can be passed 1020 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 1021 | * one is the error object (null if no error), and the second is the value if the request succeeded. 1022 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 1023 | */ 1024 | Constr.prototype.getAlbumTracks = function(albumId, options, callback) { 1025 | var requestData = { 1026 | url: _baseUri + '/albums/' + albumId + '/tracks' 1027 | }; 1028 | return _checkParamsAndPerformRequest(requestData, options, callback); 1029 | }; 1030 | 1031 | /** 1032 | * Fetches multiple albums from the Spotify catalog. 1033 | * See [Get Several Albums](https://developer.spotify.com/web-api/get-several-albums/) on 1034 | * the Spotify Developer site for more information about the endpoint. 1035 | * 1036 | * @param {Array} albumIds The ids of the albums. If you know their Spotify URI it is easy 1037 | * to find their album id (e.g. spotify:album:) 1038 | * @param {Object} options A JSON object with options that can be passed 1039 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 1040 | * one is the error object (null if no error), and the second is the value if the request succeeded. 1041 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 1042 | */ 1043 | Constr.prototype.getAlbums = function(albumIds, options, callback) { 1044 | var requestData = { 1045 | url: _baseUri + '/albums/', 1046 | params: { ids: albumIds.join(',') } 1047 | }; 1048 | return _checkParamsAndPerformRequest(requestData, options, callback); 1049 | }; 1050 | 1051 | /** 1052 | * Fetches a track from the Spotify catalog. 1053 | * See [Get a Track](https://developer.spotify.com/web-api/get-track/) on 1054 | * the Spotify Developer site for more information about the endpoint. 1055 | * 1056 | * @param {string} trackId The id of the track. If you know the Spotify URI it is easy 1057 | * to find the track id (e.g. spotify:track:) 1058 | * @param {Object} options A JSON object with options that can be passed 1059 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 1060 | * one is the error object (null if no error), and the second is the value if the request succeeded. 1061 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 1062 | */ 1063 | Constr.prototype.getTrack = function(trackId, options, callback) { 1064 | var requestData = {}; 1065 | requestData.url = _baseUri + '/tracks/' + trackId; 1066 | return _checkParamsAndPerformRequest(requestData, options, callback); 1067 | }; 1068 | 1069 | /** 1070 | * Fetches multiple tracks from the Spotify catalog. 1071 | * See [Get Several Tracks](https://developer.spotify.com/web-api/get-several-tracks/) on 1072 | * the Spotify Developer site for more information about the endpoint. 1073 | * 1074 | * @param {Array} trackIds The ids of the tracks. If you know their Spotify URI it is easy 1075 | * to find their track id (e.g. spotify:track:) 1076 | * @param {Object} options A JSON object with options that can be passed 1077 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 1078 | * one is the error object (null if no error), and the second is the value if the request succeeded. 1079 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 1080 | */ 1081 | Constr.prototype.getTracks = function(trackIds, options, callback) { 1082 | var requestData = { 1083 | url: _baseUri + '/tracks/', 1084 | params: { ids: trackIds.join(',') } 1085 | }; 1086 | return _checkParamsAndPerformRequest(requestData, options, callback); 1087 | }; 1088 | 1089 | /** 1090 | * Fetches an artist from the Spotify catalog. 1091 | * See [Get an Artist](https://developer.spotify.com/web-api/get-artist/) on 1092 | * the Spotify Developer site for more information about the endpoint. 1093 | * 1094 | * @param {string} artistId The id of the artist. If you know the Spotify URI it is easy 1095 | * to find the artist id (e.g. spotify:artist:) 1096 | * @param {Object} options A JSON object with options that can be passed 1097 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 1098 | * one is the error object (null if no error), and the second is the value if the request succeeded. 1099 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 1100 | */ 1101 | Constr.prototype.getArtist = function(artistId, options, callback) { 1102 | var requestData = { 1103 | url: _baseUri + '/artists/' + artistId 1104 | }; 1105 | return _checkParamsAndPerformRequest(requestData, options, callback); 1106 | }; 1107 | 1108 | /** 1109 | * Fetches multiple artists from the Spotify catalog. 1110 | * See [Get Several Artists](https://developer.spotify.com/web-api/get-several-artists/) on 1111 | * the Spotify Developer site for more information about the endpoint. 1112 | * 1113 | * @param {Array} artistIds The ids of the artists. If you know their Spotify URI it is easy 1114 | * to find their artist id (e.g. spotify:artist:) 1115 | * @param {Object} options A JSON object with options that can be passed 1116 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 1117 | * one is the error object (null if no error), and the second is the value if the request succeeded. 1118 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 1119 | */ 1120 | Constr.prototype.getArtists = function(artistIds, options, callback) { 1121 | var requestData = { 1122 | url: _baseUri + '/artists/', 1123 | params: { ids: artistIds.join(',') } 1124 | }; 1125 | return _checkParamsAndPerformRequest(requestData, options, callback); 1126 | }; 1127 | 1128 | /** 1129 | * Fetches the albums of an artist from the Spotify catalog. 1130 | * See [Get an Artist's Albums](https://developer.spotify.com/web-api/get-artists-albums/) on 1131 | * the Spotify Developer site for more information about the endpoint. 1132 | * 1133 | * @param {string} artistId The id of the artist. If you know the Spotify URI it is easy 1134 | * to find the artist id (e.g. spotify:artist:) 1135 | * @param {Object} options A JSON object with options that can be passed 1136 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 1137 | * one is the error object (null if no error), and the second is the value if the request succeeded. 1138 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 1139 | */ 1140 | Constr.prototype.getArtistAlbums = function(artistId, options, callback) { 1141 | var requestData = { 1142 | url: _baseUri + '/artists/' + artistId + '/albums' 1143 | }; 1144 | return _checkParamsAndPerformRequest(requestData, options, callback); 1145 | }; 1146 | 1147 | /** 1148 | * Fetches a list of top tracks of an artist from the Spotify catalog, for a specific country. 1149 | * See [Get an Artist's Top Tracks](https://developer.spotify.com/web-api/get-artists-top-tracks/) on 1150 | * the Spotify Developer site for more information about the endpoint. 1151 | * 1152 | * @param {string} artistId The id of the artist. If you know the Spotify URI it is easy 1153 | * to find the artist id (e.g. spotify:artist:) 1154 | * @param {string} countryId The id of the country (e.g. ES for Spain or US for United States) 1155 | * @param {Object} options A JSON object with options that can be passed 1156 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 1157 | * one is the error object (null if no error), and the second is the value if the request succeeded. 1158 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 1159 | */ 1160 | Constr.prototype.getArtistTopTracks = function(artistId, countryId, options, callback) { 1161 | var requestData = { 1162 | url: _baseUri + '/artists/' + artistId + '/top-tracks', 1163 | params: { country: countryId } 1164 | }; 1165 | return _checkParamsAndPerformRequest(requestData, options, callback); 1166 | }; 1167 | 1168 | /** 1169 | * Fetches a list of artists related with a given one from the Spotify catalog. 1170 | * See [Get an Artist's Related Artists](https://developer.spotify.com/web-api/get-related-artists/) on 1171 | * the Spotify Developer site for more information about the endpoint. 1172 | * 1173 | * @param {string} artistId The id of the artist. If you know the Spotify URI it is easy 1174 | * to find the artist id (e.g. spotify:artist:) 1175 | * @param {Object} options A JSON object with options that can be passed 1176 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 1177 | * one is the error object (null if no error), and the second is the value if the request succeeded. 1178 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 1179 | */ 1180 | Constr.prototype.getArtistRelatedArtists = function(artistId, options, callback) { 1181 | var requestData = { 1182 | url: _baseUri + '/artists/' + artistId + '/related-artists' 1183 | }; 1184 | return _checkParamsAndPerformRequest(requestData, options, callback); 1185 | }; 1186 | 1187 | /** 1188 | * Fetches a list of Spotify featured playlists (shown, for example, on a Spotify player's "Browse" tab). 1189 | * See [Get a List of Featured Playlists](https://developer.spotify.com/web-api/get-list-featured-playlists/) on 1190 | * the Spotify Developer site for more information about the endpoint. 1191 | * 1192 | * @param {Object} options A JSON object with options that can be passed 1193 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 1194 | * one is the error object (null if no error), and the second is the value if the request succeeded. 1195 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 1196 | */ 1197 | Constr.prototype.getFeaturedPlaylists = function(options, callback) { 1198 | var requestData = { 1199 | url: _baseUri + '/browse/featured-playlists' 1200 | }; 1201 | return _checkParamsAndPerformRequest(requestData, options, callback); 1202 | }; 1203 | 1204 | /** 1205 | * Fetches a list of new album releases featured in Spotify (shown, for example, on a Spotify player's "Browse" tab). 1206 | * See [Get a List of New Releases](https://developer.spotify.com/web-api/get-list-new-releases/) on 1207 | * the Spotify Developer site for more information about the endpoint. 1208 | * 1209 | * @param {Object} options A JSON object with options that can be passed 1210 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 1211 | * one is the error object (null if no error), and the second is the value if the request succeeded. 1212 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 1213 | */ 1214 | Constr.prototype.getNewReleases = function(options, callback) { 1215 | var requestData = { 1216 | url: _baseUri + '/browse/new-releases' 1217 | }; 1218 | return _checkParamsAndPerformRequest(requestData, options, callback); 1219 | }; 1220 | 1221 | /** 1222 | * Get a list of categories used to tag items in Spotify (on, for example, the Spotify player's "Browse" tab). 1223 | * See [Get a List of Categories](https://developer.spotify.com/web-api/get-list-categories/) on 1224 | * the Spotify Developer site for more information about the endpoint. 1225 | * 1226 | * @param {Object} options A JSON object with options that can be passed 1227 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 1228 | * one is the error object (null if no error), and the second is the value if the request succeeded. 1229 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 1230 | */ 1231 | Constr.prototype.getCategories = function(options, callback) { 1232 | var requestData = { 1233 | url: _baseUri + '/browse/categories' 1234 | }; 1235 | return _checkParamsAndPerformRequest(requestData, options, callback); 1236 | }; 1237 | 1238 | /** 1239 | * Get a single category used to tag items in Spotify (on, for example, the Spotify player's "Browse" tab). 1240 | * See [Get a Category](https://developer.spotify.com/web-api/get-category/) on 1241 | * the Spotify Developer site for more information about the endpoint. 1242 | * 1243 | * @param {string} categoryId The id of the category. These can be found with the getCategories function 1244 | * @param {Object} options A JSON object with options that can be passed 1245 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 1246 | * one is the error object (null if no error), and the second is the value if the request succeeded. 1247 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 1248 | */ 1249 | Constr.prototype.getCategory = function(categoryId, options, callback) { 1250 | var requestData = { 1251 | url: _baseUri + '/browse/categories/' + categoryId 1252 | }; 1253 | return _checkParamsAndPerformRequest(requestData, options, callback); 1254 | }; 1255 | 1256 | /** 1257 | * Get a list of Spotify playlists tagged with a particular category. 1258 | * See [Get a Category's Playlists](https://developer.spotify.com/web-api/get-categorys-playlists/) on 1259 | * the Spotify Developer site for more information about the endpoint. 1260 | * 1261 | * @param {string} categoryId The id of the category. These can be found with the getCategories function 1262 | * @param {Object} options A JSON object with options that can be passed 1263 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 1264 | * one is the error object (null if no error), and the second is the value if the request succeeded. 1265 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 1266 | */ 1267 | Constr.prototype.getCategoryPlaylists = function(categoryId, options, callback) { 1268 | var requestData = { 1269 | url: _baseUri + '/browse/categories/' + categoryId + '/playlists' 1270 | }; 1271 | return _checkParamsAndPerformRequest(requestData, options, callback); 1272 | }; 1273 | 1274 | /** 1275 | * Get Spotify catalog information about artists, albums, tracks or playlists that match a keyword string. 1276 | * See [Search for an Item](https://developer.spotify.com/web-api/search-item/) on 1277 | * the Spotify Developer site for more information about the endpoint. 1278 | * 1279 | * @param {string} query The search query 1280 | * @param {Array} types An array of item types to search across. 1281 | * Valid types are: 'album', 'artist', 'playlist', and 'track'. 1282 | * @param {Object} options A JSON object with options that can be passed 1283 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 1284 | * one is the error object (null if no error), and the second is the value if the request succeeded. 1285 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 1286 | */ 1287 | Constr.prototype.search = function(query, types, options, callback) { 1288 | var requestData = { 1289 | url: _baseUri + '/search/', 1290 | params: { 1291 | q: query, 1292 | type: types.join(',') 1293 | } 1294 | }; 1295 | return _checkParamsAndPerformRequest(requestData, options, callback); 1296 | }; 1297 | 1298 | /** 1299 | * Fetches albums from the Spotify catalog according to a query. 1300 | * See [Search for an Item](https://developer.spotify.com/web-api/search-item/) on 1301 | * the Spotify Developer site for more information about the endpoint. 1302 | * 1303 | * @param {string} query The search query 1304 | * @param {Object} options A JSON object with options that can be passed 1305 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 1306 | * one is the error object (null if no error), and the second is the value if the request succeeded. 1307 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 1308 | */ 1309 | Constr.prototype.searchAlbums = function(query, options, callback) { 1310 | return this.search(query, ['album'], options, callback); 1311 | }; 1312 | 1313 | /** 1314 | * Fetches artists from the Spotify catalog according to a query. 1315 | * See [Search for an Item](https://developer.spotify.com/web-api/search-item/) on 1316 | * the Spotify Developer site for more information about the endpoint. 1317 | * 1318 | * @param {string} query The search query 1319 | * @param {Object} options A JSON object with options that can be passed 1320 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 1321 | * one is the error object (null if no error), and the second is the value if the request succeeded. 1322 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 1323 | */ 1324 | Constr.prototype.searchArtists = function(query, options, callback) { 1325 | return this.search(query, ['artist'], options, callback); 1326 | }; 1327 | 1328 | /** 1329 | * Fetches tracks from the Spotify catalog according to a query. 1330 | * See [Search for an Item](https://developer.spotify.com/web-api/search-item/) on 1331 | * the Spotify Developer site for more information about the endpoint. 1332 | * 1333 | * @param {string} query The search query 1334 | * @param {Object} options A JSON object with options that can be passed 1335 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 1336 | * one is the error object (null if no error), and the second is the value if the request succeeded. 1337 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 1338 | */ 1339 | Constr.prototype.searchTracks = function(query, options, callback) { 1340 | return this.search(query, ['track'], options, callback); 1341 | }; 1342 | 1343 | /** 1344 | * Fetches playlists from the Spotify catalog according to a query. 1345 | * See [Search for an Item](https://developer.spotify.com/web-api/search-item/) on 1346 | * the Spotify Developer site for more information about the endpoint. 1347 | * 1348 | * @param {string} query The search query 1349 | * @param {Object} options A JSON object with options that can be passed 1350 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 1351 | * one is the error object (null if no error), and the second is the value if the request succeeded. 1352 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 1353 | */ 1354 | Constr.prototype.searchPlaylists = function(query, options, callback) { 1355 | return this.search(query, ['playlist'], options, callback); 1356 | }; 1357 | 1358 | /** 1359 | * Get audio features for a single track identified by its unique Spotify ID. 1360 | * See [Get Audio Features for a Track](https://developer.spotify.com/web-api/get-audio-features/) on 1361 | * the Spotify Developer site for more information about the endpoint. 1362 | * 1363 | * @param {string} trackId The id of the track. If you know the Spotify URI it is easy 1364 | * to find the track id (e.g. spotify:track:) 1365 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 1366 | * one is the error object (null if no error), and the second is the value if the request succeeded. 1367 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 1368 | */ 1369 | Constr.prototype.getAudioFeaturesForTrack = function(trackId, callback) { 1370 | var requestData = {}; 1371 | requestData.url = _baseUri + '/audio-features/' + trackId; 1372 | return _checkParamsAndPerformRequest(requestData, {}, callback); 1373 | }; 1374 | 1375 | /** 1376 | * Get audio features for multiple tracks based on their Spotify IDs. 1377 | * See [Get Audio Features for Several Tracks](https://developer.spotify.com/web-api/get-several-audio-features/) on 1378 | * the Spotify Developer site for more information about the endpoint. 1379 | * 1380 | * @param {Array} trackIds The ids of the tracks. If you know their Spotify URI it is easy 1381 | * to find their track id (e.g. spotify:track:) 1382 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 1383 | * one is the error object (null if no error), and the second is the value if the request succeeded. 1384 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 1385 | */ 1386 | Constr.prototype.getAudioFeaturesForTracks = function(trackIds, callback) { 1387 | var requestData = { 1388 | url: _baseUri + '/audio-features', 1389 | params: { ids: trackIds } 1390 | }; 1391 | return _checkParamsAndPerformRequest(requestData, {}, callback); 1392 | }; 1393 | 1394 | /** 1395 | * Get audio analysis for a single track identified by its unique Spotify ID. 1396 | * See [Get Audio Analysis for a Track](https://developer.spotify.com/web-api/get-audio-analysis/) on 1397 | * the Spotify Developer site for more information about the endpoint. 1398 | * 1399 | * @param {string} trackId The id of the track. If you know the Spotify URI it is easy 1400 | * to find the track id (e.g. spotify:track:) 1401 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 1402 | * one is the error object (null if no error), and the second is the value if the request succeeded. 1403 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 1404 | */ 1405 | Constr.prototype.getAudioAnalysisForTrack = function(trackId, callback) { 1406 | var requestData = {}; 1407 | requestData.url = _baseUri + '/audio-analysis/' + trackId; 1408 | return _checkParamsAndPerformRequest(requestData, {}, callback); 1409 | }; 1410 | 1411 | /** 1412 | * Create a playlist-style listening experience based on seed artists, tracks and genres. 1413 | * See [Get Recommendations Based on Seeds](https://developer.spotify.com/web-api/get-recommendations/) on 1414 | * the Spotify Developer site for more information about the endpoint. 1415 | * 1416 | * @param {Object} options A JSON object with options that can be passed 1417 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 1418 | * one is the error object (null if no error), and the second is the value if the request succeeded. 1419 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 1420 | */ 1421 | Constr.prototype.getRecommendations = function(options, callback) { 1422 | var requestData = { 1423 | url: _baseUri + '/recommendations' 1424 | }; 1425 | return _checkParamsAndPerformRequest(requestData, options, callback); 1426 | }; 1427 | 1428 | /** 1429 | * Retrieve a list of available genres seed parameter values for recommendations. 1430 | * See [Available Genre Seeds](https://developer.spotify.com/web-api/get-recommendations/#available-genre-seeds) on 1431 | * the Spotify Developer site for more information about the endpoint. 1432 | * 1433 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 1434 | * one is the error object (null if no error), and the second is the value if the request succeeded. 1435 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 1436 | */ 1437 | Constr.prototype.getAvailableGenreSeeds = function(callback) { 1438 | var requestData = { 1439 | url: _baseUri + '/recommendations/available-genre-seeds' 1440 | }; 1441 | return _checkParamsAndPerformRequest(requestData, {}, callback); 1442 | }; 1443 | 1444 | /** 1445 | * Get information about a user’s available devices. 1446 | * See [Get a User’s Available Devices](https://developer.spotify.com/web-api/get-a-users-available-devices/) on 1447 | * the Spotify Developer site for more information about the endpoint. 1448 | * 1449 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 1450 | * one is the error object (null if no error), and the second is the value if the request succeeded. 1451 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 1452 | */ 1453 | Constr.prototype.getMyDevices = function(callback) { 1454 | var requestData = { 1455 | url: _baseUri + '/me/player/devices' 1456 | }; 1457 | return _checkParamsAndPerformRequest(requestData, {}, callback); 1458 | }; 1459 | 1460 | /** 1461 | * Get information about the user’s current playback state, including track, track progress, and active device. 1462 | * See [Get Information About The User’s Current Playback](https://developer.spotify.com/web-api/get-information-about-the-users-current-playback/) on 1463 | * the Spotify Developer site for more information about the endpoint. 1464 | * 1465 | * @param {Object} options A JSON object with options that can be passed. 1466 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 1467 | * one is the error object (null if no error), and the second is the value if the request succeeded. 1468 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 1469 | */ 1470 | Constr.prototype.getMyCurrentPlaybackState = function(options, callback) { 1471 | var requestData = { 1472 | url: _baseUri + '/me/player' 1473 | }; 1474 | return _checkParamsAndPerformRequest(requestData, options, callback); 1475 | }; 1476 | 1477 | /** 1478 | * Get the object currently being played on the user’s Spotify account. 1479 | * See [Get the User’s Currently Playing Track](https://developer.spotify.com/web-api/get-the-users-currently-playing-track/) on 1480 | * the Spotify Developer site for more information about the endpoint. 1481 | * 1482 | * @param {Object} options A JSON object with options that can be passed. 1483 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 1484 | * one is the error object (null if no error), and the second is the value if the request succeeded. 1485 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 1486 | */ 1487 | Constr.prototype.getMyCurrentPlayingTrack = function(options, callback) { 1488 | var requestData = { 1489 | url: _baseUri + '/me/player/currently-playing' 1490 | }; 1491 | return _checkParamsAndPerformRequest(requestData, options, callback); 1492 | }; 1493 | 1494 | /** 1495 | * Transfer playback to a new device and determine if it should start playing. 1496 | * See [Transfer a User’s Playback](https://developer.spotify.com/web-api/transfer-a-users-playback/) on 1497 | * the Spotify Developer site for more information about the endpoint. 1498 | * 1499 | * @param {Array} deviceIds A JSON array containing the ID of the device on which playback should be started/transferred. 1500 | * @param {Object} options A JSON object with options that can be passed. 1501 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 1502 | * one is the error object (null if no error), and the second is the value if the request succeeded. 1503 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 1504 | */ 1505 | Constr.prototype.transferMyPlayback = function(deviceIds, options, callback) { 1506 | var postData = options || {}; 1507 | postData.device_ids = deviceIds; 1508 | var requestData = { 1509 | type: 'PUT', 1510 | url: _baseUri + '/me/player', 1511 | postData: postData 1512 | }; 1513 | return _checkParamsAndPerformRequest(requestData, options, callback); 1514 | }; 1515 | 1516 | /** 1517 | * Start a new context or resume current playback on the user’s active device. 1518 | * See [Start/Resume a User’s Playback](https://developer.spotify.com/web-api/start-a-users-playback/) on 1519 | * the Spotify Developer site for more information about the endpoint. 1520 | * 1521 | * @param {Object} options A JSON object with options that can be passed. 1522 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 1523 | * one is the error object (null if no error), and the second is the value if the request succeeded. 1524 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 1525 | */ 1526 | Constr.prototype.play = function(options, callback) { 1527 | options = options || {}; 1528 | var params = 'device_id' in options ? {device_id: options.device_id} : null; 1529 | var postData = {}; 1530 | ['context_uri', 'uris', 'offset'].forEach(function(field) { 1531 | if (field in options) { 1532 | postData[field] = options[field]; 1533 | } 1534 | }); 1535 | var requestData = { 1536 | type: 'PUT', 1537 | url: _baseUri + '/me/player/play', 1538 | params: params, 1539 | postData: postData 1540 | }; 1541 | 1542 | // need to clear options so it doesn't add all of them to the query params 1543 | var newOptions = typeof options === 'function' ? options : {}; 1544 | return _checkParamsAndPerformRequest(requestData, newOptions, callback); 1545 | }; 1546 | 1547 | /** 1548 | * Pause playback on the user’s account. 1549 | * See [Pause a User’s Playback](https://developer.spotify.com/web-api/pause-a-users-playback/) on 1550 | * the Spotify Developer site for more information about the endpoint. 1551 | * 1552 | * @param {Object} options A JSON object with options that can be passed. 1553 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 1554 | * one is the error object (null if no error), and the second is the value if the request succeeded. 1555 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 1556 | */ 1557 | Constr.prototype.pause = function(options, callback) { 1558 | options = options || {}; 1559 | var params = 'device_id' in options ? {device_id: options.device_id} : null; 1560 | var requestData = { 1561 | type: 'PUT', 1562 | url: _baseUri + '/me/player/pause', 1563 | params: params 1564 | }; 1565 | return _checkParamsAndPerformRequest(requestData, options, callback); 1566 | }; 1567 | 1568 | /** 1569 | * Skips to next track in the user’s queue. 1570 | * See [Skip User’s Playback To Next Track](https://developer.spotify.com/web-api/skip-users-playback-to-next-track/) on 1571 | * the Spotify Developer site for more information about the endpoint. 1572 | * 1573 | * @param {Object} options A JSON object with options that can be passed. 1574 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 1575 | * one is the error object (null if no error), and the second is the value if the request succeeded. 1576 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 1577 | */ 1578 | Constr.prototype.skipToNext = function(options, callback) { 1579 | options = options || {}; 1580 | var params = 'device_id' in options ? {device_id: options.device_id} : null; 1581 | var requestData = { 1582 | type: 'POST', 1583 | url: _baseUri + '/me/player/next', 1584 | params: params 1585 | }; 1586 | return _checkParamsAndPerformRequest(requestData, options, callback); 1587 | }; 1588 | 1589 | /** 1590 | * Skips to previous track in the user’s queue. 1591 | * Note that this will ALWAYS skip to the previous track, regardless of the current track’s progress. 1592 | * Returning to the start of the current track should be performed using `.seek()` 1593 | * See [Skip User’s Playback To Previous Track](https://developer.spotify.com/web-api/skip-users-playback-to-next-track/) on 1594 | * the Spotify Developer site for more information about the endpoint. 1595 | * 1596 | * @param {Object} options A JSON object with options that can be passed. 1597 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 1598 | * one is the error object (null if no error), and the second is the value if the request succeeded. 1599 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 1600 | */ 1601 | Constr.prototype.skipToPrevious = function(options, callback) { 1602 | options = options || {}; 1603 | var params = 'device_id' in options ? {device_id: options.device_id} : null; 1604 | var requestData = { 1605 | type: 'POST', 1606 | url: _baseUri + '/me/player/previous', 1607 | params: params 1608 | }; 1609 | return _checkParamsAndPerformRequest(requestData, options, callback); 1610 | }; 1611 | 1612 | /** 1613 | * Seeks to the given position in the user’s currently playing track. 1614 | * See [Seek To Position In Currently Playing Track](https://developer.spotify.com/web-api/seek-to-position-in-currently-playing-track/) on 1615 | * the Spotify Developer site for more information about the endpoint. 1616 | * 1617 | * @param {number} position_ms The position in milliseconds to seek to. Must be a positive number. 1618 | * @param {Object} options A JSON object with options that can be passed. 1619 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 1620 | * one is the error object (null if no error), and the second is the value if the request succeeded. 1621 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 1622 | */ 1623 | Constr.prototype.seek = function(position_ms, options, callback) { 1624 | var params = { 1625 | position_ms: position_ms 1626 | }; 1627 | if ('device_id' in options) { 1628 | params.device_id = options.device_id; 1629 | } 1630 | var requestData = { 1631 | type: 'PUT', 1632 | url: _baseUri + '/me/player/seek', 1633 | params: params 1634 | }; 1635 | return _checkParamsAndPerformRequest(requestData, options, callback); 1636 | }; 1637 | 1638 | /** 1639 | * Set the repeat mode for the user’s playback. Options are repeat-track, repeat-context, and off. 1640 | * See [Set Repeat Mode On User’s Playback](https://developer.spotify.com/web-api/set-repeat-mode-on-users-playback/) on 1641 | * the Spotify Developer site for more information about the endpoint. 1642 | * 1643 | * @param {String} state A string set to 'track', 'context' or 'off'. 1644 | * @param {Object} options A JSON object with options that can be passed. 1645 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 1646 | * one is the error object (null if no error), and the second is the value if the request succeeded. 1647 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 1648 | */ 1649 | Constr.prototype.setRepeat = function(state, options, callback) { 1650 | var params = { 1651 | state: state 1652 | }; 1653 | if ('device_id' in options) { 1654 | params.device_id = options.device_id; 1655 | } 1656 | var requestData = { 1657 | type: 'PUT', 1658 | url: _baseUri + '/me/player/repeat', 1659 | params: params 1660 | }; 1661 | return _checkParamsAndPerformRequest(requestData, options, callback); 1662 | }; 1663 | 1664 | /** 1665 | * Set the volume for the user’s current playback device. 1666 | * See [Set Volume For User’s Playback](https://developer.spotify.com/web-api/set-volume-for-users-playback/) on 1667 | * the Spotify Developer site for more information about the endpoint. 1668 | * 1669 | * @param {number} volume_percent The volume to set. Must be a value from 0 to 100 inclusive. 1670 | * @param {Object} options A JSON object with options that can be passed. 1671 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 1672 | * one is the error object (null if no error), and the second is the value if the request succeeded. 1673 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 1674 | */ 1675 | Constr.prototype.setVolume = function(volume_percent, options, callback) { 1676 | var params = { 1677 | volume_percent: volume_percent 1678 | }; 1679 | if ('device_id' in options) { 1680 | params.device_id = options.device_id; 1681 | } 1682 | var requestData = { 1683 | type: 'PUT', 1684 | url: _baseUri + '/me/player/volume', 1685 | params: params 1686 | }; 1687 | return _checkParamsAndPerformRequest(requestData, options, callback); 1688 | }; 1689 | 1690 | /** 1691 | * Toggle shuffle on or off for user’s playback. 1692 | * See [Toggle Shuffle For User’s Playback](https://developer.spotify.com/web-api/toggle-shuffle-for-users-playback/) on 1693 | * the Spotify Developer site for more information about the endpoint. 1694 | * 1695 | * @param {bool} state Whether or not to shuffle user's playback. 1696 | * @param {Object} options A JSON object with options that can be passed. 1697 | * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first 1698 | * one is the error object (null if no error), and the second is the value if the request succeeded. 1699 | * @return {Object} Null if a callback is provided, a `Promise` object otherwise 1700 | */ 1701 | Constr.prototype.setShuffle = function(state, options, callback) { 1702 | var params = { 1703 | state: state 1704 | }; 1705 | if ('device_id' in options) { 1706 | params.device_id = options.device_id; 1707 | } 1708 | var requestData = { 1709 | type: 'PUT', 1710 | url: _baseUri + '/me/player/shuffle', 1711 | params: params 1712 | }; 1713 | return _checkParamsAndPerformRequest(requestData, options, callback); 1714 | }; 1715 | 1716 | /** 1717 | * Gets the access token in use. 1718 | * 1719 | * @return {string} accessToken The access token 1720 | */ 1721 | Constr.prototype.getAccessToken = function() { 1722 | return _accessToken; 1723 | }; 1724 | 1725 | /** 1726 | * Sets the access token to be used. 1727 | * See [the Authorization Guide](https://developer.spotify.com/web-api/authorization-guide/) on 1728 | * the Spotify Developer site for more information about obtaining an access token. 1729 | * 1730 | * @param {string} accessToken The access token 1731 | * @return {void} 1732 | */ 1733 | Constr.prototype.setAccessToken = function(accessToken) { 1734 | _accessToken = accessToken; 1735 | }; 1736 | 1737 | /** 1738 | * Sets an implementation of Promises/A+ to be used. E.g. Q, when. 1739 | * See [Conformant Implementations](https://github.com/promises-aplus/promises-spec/blob/master/implementations.md) 1740 | * for a list of some available options 1741 | * 1742 | * @param {Object} PromiseImplementation A Promises/A+ valid implementation 1743 | * @throws {Error} If the implementation being set doesn't conform with Promises/A+ 1744 | * @return {void} 1745 | */ 1746 | Constr.prototype.setPromiseImplementation = function(PromiseImplementation) { 1747 | var valid = false; 1748 | try { 1749 | var p = new PromiseImplementation(function(resolve) { 1750 | resolve(); 1751 | }); 1752 | if (typeof p.then === 'function' && typeof p.catch === 'function') { 1753 | valid = true; 1754 | } 1755 | } catch (e) { 1756 | console.error(e); 1757 | } 1758 | if (valid) { 1759 | _promiseImplementation = PromiseImplementation; 1760 | } else { 1761 | throw new Error('Unsupported implementation of Promises/A+'); 1762 | } 1763 | }; 1764 | 1765 | return Constr; 1766 | })(); 1767 | 1768 | if (typeof module === 'object' && typeof module.exports === 'object') { 1769 | module.exports = SpotifyWebApi; 1770 | } 1771 | --------------------------------------------------------------------------------