Merge remote-tracking branch 'upstream/master'
authorSuperBFG7 <daniel@despite.ch>
Sun, 22 Apr 2018 16:33:10 +0000 (18:33 +0200)
committerSuperBFG7 <daniel@despite.ch>
Sun, 22 Apr 2018 16:33:10 +0000 (18:33 +0200)
1  2 
htdocs/css/mpd.css
htdocs/index.html
htdocs/js/mpd.js
src/mpd_client.c
src/ympd.c

Simple merge
Simple merge
@@@ -112,11 -110,7 +112,10 @@@ var app = $.sammy(function() 
          $('#panel-heading').text("Search: "+searchstr);
      });
  
      this.get(/\#\/dirble\/(\d+)\/(\d+)/, function() {
 +        
 +        if (TOKEN === "") context.redirect("#/0");
 +        
          prepare();
          current_app = 'dirble';
          $('#breadcrump').removeClass('hide').empty().append("<li><a href=\"#/dirble/\">Categories</a></li><li>"+dirble_selected_cat+"</li>");
  
          dirble_stations = true;
  
-         if(dirble_api_token) {
-             dirble_load_stations();
-         } else {
-             getDirbleApiToken();
-         }
+         if (dirble_api_token) { dirble_load_stations(); }
      });
  
      this.get(/\#\/dirble\//, function() {
 +        
 +        if (TOKEN === "") context.redirect("#/0");
 +        
          prepare();
          current_app = 'dirble';
          $('#breadcrump').removeClass('hide').empty().append("<li>Categories</li>");
@@@ -205,70 -187,8 +195,69 @@@ $(document).ready(function()
              $('#btnnotify').addClass("active")
  
      add_filter();
 +      
 +    document.getElementById('player').addEventListener('stalled', function() {
 +                                              if ( !document.getElementById('player').paused ) {
 +                                                      this.pause();
 +                                                      clickLocalPlay();
 +                                                      $('.top-right').notify({
 +                                                              message:{text:"music stream stalled - trying to recover..."},
 +                                                              type: "danger",
 +                                                              fadeOut: { enabled: true, delay: 1000 },
 +                                                      }).show();
 +                                              }
 +    });
 +
 +    document.getElementById('player').addEventListener('pause', function() {
 +        this.src='';
 +        this.removeAttribute("src");
 +      $("#localplay-icon").removeClass("glyphicon-pause").addClass("glyphicon-play");
 +    });
 +
 +      document.getElementById('player').addEventListener('error', function failed(e) {
 +              this.pause();
 +              switch (e.target.error.code) {
 +                      case e.target.error.MEDIA_ERR_ABORTED:
 +                              $('.top-right').notify({
 +                                      message:{text:"Audio playback aborted by user."},
 +                                      type: "info",
 +                                      fadeOut: { enabled: true, delay: 1000 },
 +                              }).show();
 +                              break;
 +                      case e.target.error.MEDIA_ERR_NETWORK:
 +                              $('.top-right').notify({
 +                                      message:{text:"Network error while playing audio."},
 +                                      type: "danger",
 +                                      fadeOut: { enabled: true, delay: 1000 },
 +                              }).show();
 +                              break;
 +                      case e.target.error.MEDIA_ERR_DECODE:
 +                              $('.top-right').notify({
 +                                      message:{text:"Audio playback aborted. Did you unplug your headphones?"},
 +                                      type: "danger",
 +                                      fadeOut: { enabled: true, delay: 1000 },
 +                              }).show();
 +                              break;
 +                      case e.target.error.MEDIA_ERR_SRC_NOT_SUPPORTED:
 +                              $('.top-right').notify({
 +                                      message:{text:"Error while loading audio (server, network or format error)."},
 +                                      type: "danger",
 +                                      fadeOut: { enabled: true, delay: 1000 },
 +                              }).show();
 +                              break;
 +                      default:
 +                              $('.top-right').notify({
 +                                      message:{text:"Unknown error while playing audio."},
 +                                      type: "danger",
 +                                      fadeOut: { enabled: true, delay: 1000 },
 +                              }).show();
 +                              break;
 +              }
 +      }, true);
 +            
 +    if (TOKEN === "") $('#dirble').addClass('hide');
  });
  
  function webSocketConnect() {
      if (typeof MozWebSocket != "undefined") {
          socket = new MozWebSocket(get_appropriate_ws_url());
                  return;
  
              var obj = JSON.parse(msg.data);
 +            
  
              switch (obj.type) {
-                 case "queue":
+                 case 'queue':
                      if(current_app !== 'queue')
                          break;
  
                                  $('#salamisandwich > tbody').append(
                                      "<tr uri=\"" + encodeURI(obj.data[item].dir) + "\" class=\"" + clazz + "\">" +
                                      "<td><span class=\"glyphicon glyphicon-folder-open\"></span></td>" +
-                                     "<td><a>" + basename(obj.data[item].dir) + "</a></td>" +
-                                     "<td></td><td></td>" +
 -                                    "<td colspan=\"2\"><a>" + basename(obj.data[item].dir) + "</a></td>" +
++                                    "<td colspan=\"3\"><a>" + basename(obj.data[item].dir) + "</a></td>" +
                                      "<td></td><td></td></tr>"
                                  );
                                  break;
                                  $('#salamisandwich > tbody').append(
                                      "<tr uri=\"" + encodeURI(obj.data[item].plist) + "\" class=\"" + clazz + "\">" +
                                      "<td><span class=\"glyphicon glyphicon-list\"></span></td>" +
-                                     "<td><a>" + basename(obj.data[item].plist) + "</a></td>" +
-                                     "<td></td><td></td>" +
 -                                    "<td colspan=\"2\"><a>" + basename(obj.data[item].plist) + "</a></td>" +
++                                    "<td colspan=\"3\"><a>" + basename(obj.data[item].plist) + "</a></td>" +
                                      "<td></td><td></td></tr>"
                                  );
                                  break;
                                  var minutes = Math.floor(obj.data[item].duration / 60);
                                  var seconds = obj.data[item].duration - minutes * 60;
  
-                                 $('#salamisandwich > tbody').append(
+                                 if (typeof obj.data[item].artist === 'undefined') {
+                                     var details = "<td colspan=\"2\">" + obj.data[item].title + "</td>";
+                                 } else {
+                                     var details = "<td>" + obj.data[item].artist + "<br /><span>" + obj.data[item].album + "</span></td><td>" + obj.data[item].title + "</td>";
+                                 }
+                               $('#salamisandwich > tbody').append(
                                      "<tr uri=\"" + encodeURI(obj.data[item].uri) + "\" class=\"song\">" +
 -                                    "<td><span class=\"glyphicon glyphicon-music\"></span></td>" + details +
 +                                    "<td><span class=\"glyphicon glyphicon-music\"></span></td>" + 
 +                                    "<td>" + obj.data[item].title  + "</td>" +
 +                                    "<td>" + obj.data[item].album  + "</td>" +
 +                                    "<td>" + obj.data[item].artist + "</td>" + 
                                      "<td>" + minutes + ":" + (seconds < 10 ? '0' : '') + seconds +
                                      "</td><td></td></tr>"
                                  );
                                      $('#next').removeClass('hide');
                                  } else {
                                      $('#salamisandwich > tbody').append(
-                                         "<tr><td><span class=\"glyphicon glyphicon-remove\"></span></td>" + 
-                                         "<td>Too many results, please refine your search!</td>" + 
-                                         "<td></td><td></td>" +
+                                         "<tr><td><span class=\"glyphicon glyphicon-remove\"></span></td>" +
 -                                        "<td colspan=\"2\">Too many results, please refine your search!</td>" +
++                                        "<td colspan=\"3\">Too many results, please refine your search!</td>" +
                                          "<td></td><td></td></tr>"
                                      );
                                  }
                          }).show();
                          
                      break;
-                 case "mpdhost":
+                 case 'mpdhost':
                      $('#mpdhost').val(obj.data.host);
 +                    setLocalStream(obj.data.host);
                      $('#mpdport').val(obj.data.port);
                      if(obj.data.passwort_set)
                          $('#mpd_password_set').removeClass('hide');
@@@ -638,12 -618,12 +630,16 @@@ int mpd_put_queue(char *buffer, unsigne
              cur += json_emit_int(cur, end - cur, mpd_song_get_pos(song));
              cur += json_emit_raw_str(cur, end - cur, ",\"duration\":");
              cur += json_emit_int(cur, end - cur, mpd_song_get_duration(song));
 +            cur += json_emit_raw_str(cur, end - cur, ",\"artist\":");
 +            cur += json_emit_quoted_str(cur, end - cur, mpd_get_artist(song));
 +            cur += json_emit_raw_str(cur, end - cur, ",\"album\":");
 +            cur += json_emit_quoted_str(cur, end - cur, mpd_get_album(song));
              cur += json_emit_raw_str(cur, end - cur, ",\"title\":");
              cur += json_emit_quoted_str(cur, end - cur, mpd_get_title(song));
+             cur += json_emit_raw_str(cur, end - cur, ",\"artist\":");
+             cur += json_emit_quoted_str(cur, end - cur, mpd_get_artist(song));
+             cur += json_emit_raw_str(cur, end - cur, ",\"album\":");
+             cur += json_emit_quoted_str(cur, end - cur, mpd_get_album(song));
              cur += json_emit_raw_str(cur, end - cur, "},");
          }
          mpd_entity_free(entity);
diff --cc src/ympd.c
@@@ -89,19 -77,12 +89,17 @@@ int main(int argc, char **argv
      mg_set_option(server, "document_root", SRC_PATH);
  #endif
  
 +    mg_set_option(server, "auth_domain", "ympd");
      mpd.port = 6600;
 +    mpd.local_port = 0;
 +      mpd.gpass = NULL;
      strcpy(mpd.host, "127.0.0.1");
  
-     strcpy(dirble_api_token, "2e223c9909593b94fc6577361a");
      static struct option long_options[] = {
 +        {"digest",       required_argument, 0, 'D'},
          {"host",         required_argument, 0, 'h'},
          {"port",         required_argument, 0, 'p'},
 +        {"localport",    required_argument, 0, 'l'},
          {"webport",      required_argument, 0, 'w'},
          {"dirbletoken",  required_argument, 0, 'd'},
          {"user",         required_argument, 0, 'u'},