Merge branch 'master' into notandy-master
authorSuperBFG7 <daniel@despite.ch>
Fri, 26 Jan 2018 12:51:20 +0000 (13:51 +0100)
committerSuperBFG7 <daniel@despite.ch>
Fri, 26 Jan 2018 12:51:20 +0000 (13:51 +0100)
1  2 
CMakeLists.txt
README.md
contrib/init.debian
contrib/ympd.default
contrib/ympd.service
htdocs/index.html
htdocs/js/mpd.js
src/mpd_client.c
src/ympd.c

diff --cc CMakeLists.txt
Simple merge
diff --cc README.md
+++ b/README.md
@@@ -29,13 -28,14 +29,15 @@@ Run flag
  ```
  Usage: ./ympd [OPTION]...
  
 - -d, --digest <htdigest>    path to htdigest file for authorization
 -                            (realm ympd) [no authorization]
 - -h, --host <host>          connect to mpd at host [localhost]
 - -p, --port <port>          connect to mpd at port [6600]
 - -w, --webport [ip:]<port>  listen interface/port for webserver [8080]
 - -u, --user <username>      drop priviliges to user after socket bind
 - -V, --version              get version
 - --help                     this help
++ -D, --digest <htdigest>       path to htdigest file for authorization
++                               (realm ympd) [no authorization]
 + -h, --host <host>             connect to mpd at host [localhost]
 + -p, --port <port>             connect to mpd at port [6600]
 + -w, --webport [ip:]<port>     listen interface/port for webserver [8080]
 + -d, --dirbletoken <apitoken>  Dirble API token
 + -u, --user <username>         drop priviliges to user after socket bind
 + -V, --version                 get version
 + --help                        this help
  ```
  
  SSL Support
@@@ -24,7 -24,7 +24,8 @@@ YMPD_USER=nobod
  MPD_HOST=localhost
  MPD_PORT=6600
  WEB_PORT=8080
 +DIRBLE_API_TOKEN=2e223c9909593b94fc6577361a
+ #DIGEST=--digest /path/to/htdigest
  
  
  # Exit if the package is not installed
@@@ -36,7 -36,7 +37,7 @@@
  # Load the VERBOSE setting and other rcS variables
  [ -f /etc/default/rcS ] && . /etc/default/rcS
  
- DAEMON_OPT="--user $YMPD_USER --mpdpass '$MPD_PASSWORD' --webport $WEB_PORT --host $MPD_HOST --port $MPD_PORT --dirbletoken $DIRBLE_API_TOKEN"
 -DAEMON_OPT="--user $YMPD_USER --webport $WEB_PORT --host $MPD_HOST --port $MPD_PORT $DIGEST"
++DAEMON_OPT="--user $YMPD_USER --mpdpass '$MPD_PASSWORD' --webport $WEB_PORT --host $MPD_HOST --port $MPD_PORT --dirbletoken $DIRBLE_API_TOKEN $DIGEST"
  
  do_start()
  {
@@@ -1,6 -1,5 +1,7 @@@
  MPD_HOST=localhost
  MPD_PORT=6600
 +MPD_PASSWORD=
  WEB_PORT=8080
  YMPD_USER=nobody
 +DIRBLE_API_TOKEN=2e223c9909593b94fc6577361a
+ #DIGEST=--digest /path/to/htdigest
@@@ -5,12 -5,11 +5,13 @@@ Requires=network.target local-fs.targe
  [Service]
  Environment=MPD_HOST=localhost
  Environment=MPD_PORT=6600
 +Environment=MPD_PASSWORD=
  Environment=WEB_PORT=8080
  Environment=YMPD_USER=nobody
 +Environment=DIRBLE_API_TOKEN=2e223c9909593b94fc6577361a
+ Environment=DIGEST=
  EnvironmentFile=/etc/default/ympd
- ExecStart=/usr/bin/ympd --user $YMPD_USER --mpdpass "$MPD_PASSWORD" --webport $WEB_PORT --host $MPD_HOST --port $MPD_PORT --dirbletoken $DIRBLE_API_TOKE
 -ExecStart=/usr/bin/ympd --user $YMPD_USER --webport $WEB_PORT --host $MPD_HOST --port $MPD_PORT $DIGEST
++ExecStart=/usr/bin/ympd --user $YMPD_USER --mpdpass "$MPD_PASSWORD" --webport $WEB_PORT --host $MPD_HOST --port $MPD_PORT --dirbletoken $DIRBLE_API_TOKE $DIGEST
  Type=simple
  
  [Install]
Simple merge
@@@ -195,8 -186,67 +203,69 @@@ $(document).ready(function()
      else
          if ($.cookie("notification") === "true")
              $('#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');
  });
  
  
@@@ -677,6 -713,62 +754,52 @@@ function clickPlay() 
          socket.send('MPD_API_SET_PAUSE');
  }
  
 -function renumber_table(tableID,item) {
 -    was = item.children("td").first().text();//Check if first item exists!
 -    is = item.index() + 1;//maybe add pagination
 -
 -    if (was != is) {
 -        socket.send("MPD_API_MOVE_TRACK," + was + "," + is);
 -        socket.send('MPD_API_GET_QUEUE,'+pagination);
 -    }
 -}
 -
+ function clickLocalPlay() {
+     var player = document.getElementById('player');
+     $("#localplay-icon").removeClass("glyphicon-play").removeClass("glyphicon-pause");
+       
+     if ( !$('#track-icon').hasClass('glyphicon-play') ) {
+               clickPlay();
+       }
+     if ( player.paused ) {
+         var mpdstream = $.cookie("mpdstream");
+         if ( mpdstream ) {
+             player.src = mpdstream;
+             console.log("playing mpd stream: " + player.src);
+             player.load();
+             player.play();
+             $("#localplay-icon").addClass("glyphicon-pause");
+         } else {
+             $("#mpdstream").change(function(){ clickLocalPlay(); $(this).unbind("change"); });
+             $("#localplay-icon").addClass("glyphicon-play");
+             getHost();
+         }
+     } else {
+         player.pause();
+     }
+ }
+ function setLocalStream(mpdhost) {
+     var mpdstream = $.cookie("mpdstream");
+     if ( !mpdstream ) {
+         mpdstream = "http://";
+         if ( mpdhost == "127.0.0.1" )
+             mpdstream += window.location.hostname;
+         else
+             mpdstream += mpdhost;
+         mpdstream += ":8000/";
+         $.cookie("mpdstream", mpdstream, { expires: 424242 });
+     }
+     $("#mpdstream").val(mpdstream);
+     $("#mpdstream").change();
+ }
  function trash(tr) {
      if ( $('#btntrashmodeup').hasClass('active') ) {
          socket.send('MPD_API_RM_RANGE,0,' + (tr.index() + 1));
Simple merge
diff --cc src/ympd.c
@@@ -80,9 -95,8 +95,10 @@@ int main(int argc, char **argv
      mpd.port = 6600;
      strcpy(mpd.host, "127.0.0.1");
  
 +    strcpy(dirble_api_token, "2e223c9909593b94fc6577361a");
 +
      static struct option long_options[] = {
 -        {"digest",       required_argument, 0, 'd'},
++        {"digest",       required_argument, 0, 'D'},
          {"host",         required_argument, 0, 'h'},
          {"port",         required_argument, 0, 'p'},
          {"webport",      required_argument, 0, 'w'},
          {0,              0,                 0,  0 }
      };
  
-     while((n = getopt_long(argc, argv, "h:p:w:u:vm:",
 -    while((n = getopt_long(argc, argv, "d:h:p:w:u:v",
++    while((n = getopt_long(argc, argv, "D:h:p:w:u:d:v:m",
                  long_options, &option_index)) != -1) {
          switch (n) {
 -            case 'd':
++            case 'D':
+                 gpass = strdup(optarg);
+                 break;
              case 'h':
                  strncpy(mpd.host, optarg, sizeof(mpd.host));
                  break;
                  break;
              default:
                  fprintf(stderr, "Usage: %s [OPTION]...\n\n"
 -                        " -d, --digest <htdigest>\tpath to htdigest file for authorization\n"
++                        " -D, --digest <htdigest>\tpath to htdigest file for authorization\n"
+                         "                        \t(realm ympd) [no authorization]\n"
                          " -h, --host <host>\t\tconnect to mpd at host [localhost]\n"
                          " -p, --port <port>\t\tconnect to mpd at port [6600]\n"
                          " -w, --webport [ip:]<port>\tlisten interface/port for webserver [8080]\n"
                          " -u, --user <username>\t\tdrop priviliges to user after socket bind\n"
-                         " -V, --version\t\t\tget version\n"
 +                        " -d, --dirbletoken <apitoken>\tDirble API token\n"
+                         " -v, --version\t\t\tget version\n"
 +                        " -m, --mpdpass <password>\tspecifies the password to use when connecting to mpd\n"
                          " --help\t\t\t\tthis help\n"
                          , argv[0]);
                  return EXIT_FAILURE;