radio.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. /**** Last-fm API ****/
  2. (function( $ ) {
  3. $.fn.lfya = function(options){
  4. var urla = "https://ws.audioscrobbler.com/2.0/?method=user.gettopartists&user=windhamdavid&api_key=e12ea1d0253898ee9a93edfe42ffdeab&period=12month&format=json&limit=200";
  5. var artists = [];
  6. function isLoadeda (artistElement) {
  7. for (var i = 0; i < artists.length; i++){
  8. var markup = $("<li class='list-group-item'>" + artists[i].aname + "<span class='badge'>" + artists[i].played + "</span></li>");
  9. artistElement.append(markup);
  10. }
  11. }
  12. return this.each(function(){
  13. var $this = $(this);
  14. $.getJSON( urla, function(data){
  15. $(data.topartists.artist).each(function(){
  16. artists.push ({
  17. aname: this.name,
  18. played: this.playcount
  19. });
  20. });
  21. isLoadeda($this);
  22. });
  23. });
  24. };
  25. $('.artists').lfya();
  26. $.fn.lfyt = function(options){
  27. var urla = "https://ws.audioscrobbler.com/2.0/?method=user.gettoptracks&user=windhamdavid&api_key=e12ea1d0253898ee9a93edfe42ffdeab&period=12month&format=json&limit=200";
  28. var tracks = [];
  29. function isLoadedt (tracksElement) {
  30. for (var i = 0; i < tracks.length; i++){
  31. var markup = $("<li class='list-group-item'>" + tracks[i].artist + ": <span class='artist'>" + tracks[i].title + "</span><span class='badge'>" + tracks[i].played + "</span></li>");
  32. tracksElement.append(markup);
  33. }
  34. }
  35. return this.each(function(){
  36. var $this = $(this);
  37. $.getJSON( urla, function(data){
  38. $(data.toptracks.track).each(function(){
  39. tracks.push ({
  40. title: this.name,
  41. artist: this.artist.name,
  42. played: this.playcount,
  43. });
  44. });
  45. isLoadedt($this);
  46. });
  47. });
  48. };
  49. $('.tracks').lfyt();
  50. $.fn.lfm = function(options){
  51. var url = "https://ws.audioscrobbler.com/2.0/?method=user.gettopalbums&user=windhamdavid&api_key=e12ea1d0253898ee9a93edfe42ffdeab&period=12month&format=json&limit=200";
  52. var albums = [];
  53. function isLoaded (albumElement) {
  54. for (var i = 0; i < albums.length; i++){
  55. var markup = $("<li class='list-group-item'>" + albums[i].artist + ": <span class='artist'>" + albums[i].name + "</span></li>");
  56. albumElement.append(markup);
  57. }
  58. albumElement.find('.album').hover(function(){
  59. $(this).addClass('flip');
  60. },function(){
  61. $(this).removeClass('flip');
  62. });
  63. }
  64. return this.each(function(){
  65. var $this = $(this);
  66. $.getJSON( url, function(data){
  67. $(data.topalbums.album).each(function(){
  68. albums.push ({
  69. name: this.name,
  70. artist: this.artist.name,
  71. played: this.playcount,
  72. art: this.image[this.image.length-1]["#text"]
  73. });
  74. });
  75. isLoaded($this);
  76. });
  77. });
  78. };
  79. $('.albums').lfm();
  80. })( jQuery );
  81. getRecentTracks(); //call it once to avoid delay
  82. function getRecentTracks() {
  83. $.fn.lfmr = function(options){
  84. //tracksinterval = setInterval(getRecentTracks,180000); // check every 3 minutes
  85. var urla = "https://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=windhamdavid&api_key=e12ea1d0253898ee9a93edfe42ffdeab&format=json&limit=100";
  86. var tracks = [];
  87. function isLoadedr (recentElement) {
  88. for (var i = 0; i < tracks.length; i++){
  89. var markup = $("<li class='list-group-item'>" + tracks[i].artist + " - <span class='artist'>" + tracks[i].title + " : " + tracks[i].album + "</li>");
  90. recentElement.append(markup);
  91. }
  92. }
  93. return this.each(function(){
  94. var $this = $(this);
  95. $.getJSON( urla, function(data){
  96. $(data.recenttracks.track).each(function(){
  97. tracks.push ({
  98. artist: this.artist["#text"],
  99. title: this.name,
  100. album: this.album["#text"]
  101. });
  102. });
  103. isLoadedr($this);
  104. });
  105. });
  106. };
  107. $('.recent').lfmr();
  108. $('.recent').hide();
  109. $('.recent').fadeIn(1000);
  110. }( jQuery );
  111. /**** Audio Player ****/
  112. amplitude_config = {
  113. // amplitude_songs: []
  114. "amplitude_songs": [{
  115. "url": "http://stream.davidawindham.com:8008/stream",
  116. "live": true
  117. }],
  118. "amplitude_volume": 73
  119. }
  120. function get_radio_tower() {return 'img/radio.gif';}
  121. function get_radio_none() {return 'img/none.svg';}
  122. function get_radio_eq() {return 'img/eq.gif';}
  123. function get_radio_eq_none() {return 'img/1.png';}
  124. var interval = null;
  125. $(document).ready(function() {
  126. interval = setInterval(radioTitle,20000); // every 20 seconds or stop polling
  127. $('#error-reconnecting').hide();
  128. $('#connection-error-retry').on('click', function () {
  129. radioTitle();
  130. $('#error-reconnecting').show();
  131. $('#connection-error-reconnecting').attr('data-transitiongoal', 100).progressbar();
  132. })
  133. });
  134. $('#amplitude-play-pause').click(function() {
  135. radioTitle();
  136. });
  137. $('#connection-error-retry').click(function() {
  138. setTimeout(function () {
  139. $('#connection-error').modal('hide');
  140. }, 2000);
  141. setTimeout(function () {
  142. radioTitle();
  143. $('#connection-error-reconnecting').attr('data-transitiongoal', 0).progressbar();
  144. $('#error-reconnecting').hide();
  145. }, 3000);
  146. });
  147. //radioTitle(); // call it once on load to avoid 20s delay
  148. function radioTitle() {
  149. var url = 'http://stream.davidawindham.com/status2.xsl';
  150. var mountpoint = '/stream';
  151. $.ajax({ type: 'GET',
  152. url: url,
  153. async: true,
  154. jsonpCallback: 'parseMusic',
  155. contentType: "application/json",
  156. dataType: 'jsonp',
  157. success: function(json){
  158. if(json[mountpoint] == null) {
  159. $('#connection-error').modal('show');
  160. $('#radio').attr('src', get_radio_none()).fadeIn(300);
  161. $('#eq').attr('src', get_radio_eq_none()).fadeIn(300);
  162. clearInterval(interval);
  163. }
  164. else {
  165. $('#track').text(json[mountpoint].title);
  166. $('#listeners').text(json[mountpoint].listeners);
  167. $('#peak-listeners').text(json[mountpoint].peak_listeners);
  168. $('#bitrate').text(json[mountpoint].bitrate);
  169. $('#radio').attr('src', get_radio_tower()).fadeIn(300);
  170. $('#eq').attr('src', get_radio_eq()).fadeIn(300);
  171. $('#connection-error').modal('hide');
  172. }
  173. },
  174. error: function(e){
  175. $('#connection-error').modal('show');
  176. clearInterval(interval);
  177. $('#radio').attr('src', get_radio_none()).fadeIn(300);
  178. $('#eq').attr('src', get_radio_eq_none()).fadeIn(300);
  179. }
  180. });
  181. }
  182. /**** Page Features ****/
  183. $(document).ready(function() {
  184. function spectrum() {
  185. var randomColor = Math.floor(Math.random()*16777215).toString(16);
  186. $("span#user-label").css({ backgroundColor: '#' + randomColor });
  187. };
  188. $('ul.nav-tabs a').tooltip();
  189. });