mirror of
				https://github.com/SuperBFG7/ympd
				synced 2025-10-30 05:13:00 +00:00 
			
		
		
		
	Merge branch 'master' into notandy-master
This commit is contained in:
		| @@ -43,6 +43,7 @@ file(GLOB RESOURCES | |||||||
|     htdocs/css/*.css |     htdocs/css/*.css | ||||||
|     htdocs/fonts/* |     htdocs/fonts/* | ||||||
|     htdocs/index.html |     htdocs/index.html | ||||||
|  |     htdocs/player.html | ||||||
| ) | ) | ||||||
|  |  | ||||||
| set(SOURCES | set(SOURCES | ||||||
|   | |||||||
| @@ -29,6 +29,8 @@ Run flags | |||||||
| ``` | ``` | ||||||
| Usage: ./ympd [OPTION]... | 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] |  -h, --host <host>             connect to mpd at host [localhost] | ||||||
|  -p, --port <port>             connect to mpd at port [6600] |  -p, --port <port>             connect to mpd at port [6600] | ||||||
|  -w, --webport [ip:]<port>     listen interface/port for webserver [8080] |  -w, --webport [ip:]<port>     listen interface/port for webserver [8080] | ||||||
| @@ -52,6 +54,12 @@ To run ympd with SSL support: | |||||||
| # ./ympd -w "ssl://8081:/path/to/ssl.pem" | # ./ympd -w "ssl://8081:/path/to/ssl.pem" | ||||||
| ``` | ``` | ||||||
|  |  | ||||||
|  | Dirble support | ||||||
|  | -------------- | ||||||
|  |  | ||||||
|  | 1. Get an API-key from http://dirble.com | ||||||
|  | 2. Add the key at ```var TOKEN = "";```, in ```mpd.js```. | ||||||
|  |  | ||||||
| Copyright | Copyright | ||||||
| --------- | --------- | ||||||
|  |  | ||||||
|   | |||||||
| @@ -25,6 +25,7 @@ MPD_HOST=localhost | |||||||
| MPD_PORT=6600 | MPD_PORT=6600 | ||||||
| WEB_PORT=8080 | WEB_PORT=8080 | ||||||
| DIRBLE_API_TOKEN=2e223c9909593b94fc6577361a | DIRBLE_API_TOKEN=2e223c9909593b94fc6577361a | ||||||
|  | #DIGEST=--digest /path/to/htdigest | ||||||
|  |  | ||||||
|  |  | ||||||
| # Exit if the package is not installed | # Exit if the package is not installed | ||||||
| @@ -36,7 +37,7 @@ DIRBLE_API_TOKEN=2e223c9909593b94fc6577361a | |||||||
| # Load the VERBOSE setting and other rcS variables | # Load the VERBOSE setting and other rcS variables | ||||||
| [ -f /etc/default/rcS ] && . /etc/default/rcS | [ -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 --mpdpass '$MPD_PASSWORD' --webport $WEB_PORT --host $MPD_HOST --port $MPD_PORT --dirbletoken $DIRBLE_API_TOKEN $DIGEST" | ||||||
|  |  | ||||||
| do_start() | do_start() | ||||||
| { | { | ||||||
|   | |||||||
| @@ -4,3 +4,4 @@ MPD_PASSWORD= | |||||||
| WEB_PORT=8080 | WEB_PORT=8080 | ||||||
| YMPD_USER=nobody | YMPD_USER=nobody | ||||||
| DIRBLE_API_TOKEN=2e223c9909593b94fc6577361a | DIRBLE_API_TOKEN=2e223c9909593b94fc6577361a | ||||||
|  | #DIGEST=--digest /path/to/htdigest | ||||||
|   | |||||||
| @@ -9,8 +9,9 @@ Environment=MPD_PASSWORD= | |||||||
| Environment=WEB_PORT=8080 | Environment=WEB_PORT=8080 | ||||||
| Environment=YMPD_USER=nobody | Environment=YMPD_USER=nobody | ||||||
| Environment=DIRBLE_API_TOKEN=2e223c9909593b94fc6577361a | Environment=DIRBLE_API_TOKEN=2e223c9909593b94fc6577361a | ||||||
|  | Environment=DIGEST= | ||||||
| EnvironmentFile=/etc/default/ympd | 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 --mpdpass "$MPD_PASSWORD" --webport $WEB_PORT --host $MPD_HOST --port $MPD_PORT --dirbletoken $DIRBLE_API_TOKE $DIGEST | ||||||
| Type=simple | Type=simple | ||||||
|  |  | ||||||
| [Install] | [Install] | ||||||
|   | |||||||
| @@ -15,6 +15,12 @@ body { | |||||||
|   margin-bottom: 0; |   margin-bottom: 0; | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
|  | button { | ||||||
|  |   overflow: hidden; | ||||||
|  | } | ||||||
|  |  | ||||||
|  |  | ||||||
| #volume-icon { | #volume-icon { | ||||||
|   float: left; |   float: left; | ||||||
|   margin-right: 10px; |   margin-right: 10px; | ||||||
|   | |||||||
| @@ -34,7 +34,7 @@ | |||||||
|  |  | ||||||
|         <ul id="nav_links" class="nav navbar-nav"> |         <ul id="nav_links" class="nav navbar-nav"> | ||||||
|           <li id="queue"><a href="#/">Queue</a></li> |           <li id="queue"><a href="#/">Queue</a></li> | ||||||
|           <li id="browse"><a href="#/browse/0/">Browse database</a></li> |           <li id="browse"><a href="#/browse/0/">Browse</a></li> | ||||||
|           <li id="dirble"><a href="#/dirble/">Dirble</a></li> |           <li id="dirble"><a href="#/dirble/">Dirble</a></li> | ||||||
|           <li><a href="#" data-toggle="modal" data-target="#addstream">Add Stream</a></li> |           <li><a href="#" data-toggle="modal" data-target="#addstream">Add Stream</a></li> | ||||||
|           <li><a href="#" data-toggle="modal" data-target="#settings" onclick="getHost();">Settings</a></li> |           <li><a href="#" data-toggle="modal" data-target="#settings" onclick="getHost();">Settings</a></li> | ||||||
| @@ -60,13 +60,25 @@ | |||||||
|               <span class="glyphicon glyphicon-heart"></span> |               <span class="glyphicon glyphicon-heart"></span> | ||||||
|             </button> |             </button> | ||||||
|           </div> |           </div> | ||||||
|  | <!--           | ||||||
|           <div class="btn-group"> |           <div class="btn-group"> | ||||||
|             <div class="btn btn-toolbar btn-default"> |             <div class="btn btn-toolbar btn-default"> | ||||||
|               <span id="volume-icon" class="glyphicon glyphicon-volume-up"></span> |               <span id="volume-icon" class="glyphicon glyphicon-volume-up"></span> | ||||||
|               <div id="volumeslider"></div> |               <div id="volumeslider"></div> | ||||||
|             </div> |             </div> | ||||||
|           </div> |           </div> | ||||||
|  | --> | ||||||
|  |            <div class="btn-group" role="group"> | ||||||
|  |             <audio id="player" preload="none"></audio> | ||||||
|  |             <button type="button" class="btn btn-default" onclick="clickLocalPlay()"> | ||||||
|  |               <span id="localplay-icon" class="glyphicon glyphicon-play"></span> | ||||||
|  |             </button> | ||||||
|  |             <button type="button" class="btn btn-default" onclick="window.open('/player.html');"> | ||||||
|  |               <span id="localplay-icon" class="glyphicon glyphicon-new-window"></span> | ||||||
|  |             </button> | ||||||
|           </div> |           </div> | ||||||
|  |        </div> | ||||||
|  |            | ||||||
|         <form id="search" class="navbar-form navbar-right" role="search"> |         <form id="search" class="navbar-form navbar-right" role="search"> | ||||||
|           <div class="form-group"> |           <div class="form-group"> | ||||||
|             <input type="text" class="form-control" placeholder="Search"> |             <input type="text" class="form-control" placeholder="Search"> | ||||||
| @@ -115,6 +127,8 @@ | |||||||
|               <tr> |               <tr> | ||||||
|                 <th>#</th> |                 <th>#</th> | ||||||
|                 <th>Title</th> |                 <th>Title</th> | ||||||
|  |                 <th>Album</th> | ||||||
|  |                 <th>Artist</th> | ||||||
|                 <th>Duration</th> |                 <th>Duration</th> | ||||||
|                 <th></th> |                 <th></th> | ||||||
|               </tr> |               </tr> | ||||||
| @@ -252,7 +266,12 @@ | |||||||
|                   MPD Password is set |                   MPD Password is set | ||||||
|                 </div> |                 </div> | ||||||
|               </div> |               </div> | ||||||
|  |             </div> | ||||||
|  |             <div class="row"> | ||||||
|  |               <div class="form-group col-md-12"> | ||||||
|  |                 <label class="control-label" for="mpdstream">MPD Stream URL</label> | ||||||
|  |                 <input type="text" class="form-control" id="mpdstream" /> | ||||||
|  |               </div> | ||||||
|             </div> |             </div> | ||||||
|             <div class="row"> |             <div class="row"> | ||||||
|               <div class="form-group col-md-12"> |               <div class="form-group col-md-12"> | ||||||
|   | |||||||
							
								
								
									
										133
									
								
								htdocs/js/mpd.js
									
									
									
									
									
								
							
							
						
						
									
										133
									
								
								htdocs/js/mpd.js
									
									
									
									
									
								
							| @@ -16,6 +16,8 @@ | |||||||
|    Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |    Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||||||
| */ | */ | ||||||
|  |  | ||||||
|  | var TOKEN = ""; | ||||||
|  |  | ||||||
| var socket; | var socket; | ||||||
| var last_state; | var last_state; | ||||||
| var last_outputs; | var last_outputs; | ||||||
| @@ -112,6 +114,9 @@ var app = $.sammy(function() { | |||||||
|  |  | ||||||
|  |  | ||||||
|     this.get(/\#\/dirble\/(\d+)\/(\d+)/, function() { |     this.get(/\#\/dirble\/(\d+)\/(\d+)/, function() { | ||||||
|  |          | ||||||
|  |         if (TOKEN === "") context.redirect("#/0"); | ||||||
|  |          | ||||||
|         prepare(); |         prepare(); | ||||||
|         current_app = 'dirble'; |         current_app = 'dirble'; | ||||||
|         $('#breadcrump').removeClass('hide').empty().append("<li><a href=\"#/dirble/\">Categories</a></li><li>"+dirble_selected_cat+"</li>"); |         $('#breadcrump').removeClass('hide').empty().append("<li><a href=\"#/dirble/\">Categories</a></li><li>"+dirble_selected_cat+"</li>"); | ||||||
| @@ -143,6 +148,9 @@ var app = $.sammy(function() { | |||||||
|  |  | ||||||
|  |  | ||||||
|     this.get(/\#\/dirble\//, function() { |     this.get(/\#\/dirble\//, function() { | ||||||
|  |          | ||||||
|  |         if (TOKEN === "") context.redirect("#/0"); | ||||||
|  |          | ||||||
|         prepare(); |         prepare(); | ||||||
|         current_app = 'dirble'; |         current_app = 'dirble'; | ||||||
|         $('#breadcrump').removeClass('hide').empty().append("<li>Categories</li>"); |         $('#breadcrump').removeClass('hide').empty().append("<li>Categories</li>"); | ||||||
| @@ -197,6 +205,67 @@ $(document).ready(function(){ | |||||||
|             $('#btnnotify').addClass("active") |             $('#btnnotify').addClass("active") | ||||||
|  |  | ||||||
|     add_filter(); |     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'); | ||||||
| }); | }); | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -226,6 +295,7 @@ function webSocketConnect() { | |||||||
|  |  | ||||||
|             var obj = JSON.parse(msg.data); |             var obj = JSON.parse(msg.data); | ||||||
|              |              | ||||||
|  |  | ||||||
|             switch (obj.type) { |             switch (obj.type) { | ||||||
|                 case "queue": |                 case "queue": | ||||||
|                     if(current_app !== 'queue') |                     if(current_app !== 'queue') | ||||||
| @@ -239,6 +309,8 @@ function webSocketConnect() { | |||||||
|                         $('#salamisandwich > tbody').append( |                         $('#salamisandwich > tbody').append( | ||||||
|                             "<tr trackid=\"" + obj.data[song].id + "\"><td>" + (obj.data[song].pos + 1) + "</td>" + |                             "<tr trackid=\"" + obj.data[song].id + "\"><td>" + (obj.data[song].pos + 1) + "</td>" + | ||||||
|                                 "<td>"+ obj.data[song].title +"</td>" + |                                 "<td>"+ obj.data[song].title +"</td>" + | ||||||
|  |                                 "<td>"+ obj.data[song].album +"</td>" + | ||||||
|  |                                 "<td>"+ obj.data[song].artist +"</td>" +  | ||||||
|                                 "<td>"+ minutes + ":" + (seconds < 10 ? '0' : '') + seconds + |                                 "<td>"+ minutes + ":" + (seconds < 10 ? '0' : '') + seconds + | ||||||
|                         "</td><td></td></tr>"); |                         "</td><td></td></tr>"); | ||||||
|                     } |                     } | ||||||
| @@ -357,8 +429,10 @@ function webSocketConnect() { | |||||||
|                                 $('#salamisandwich > tbody').append( |                                 $('#salamisandwich > tbody').append( | ||||||
|                                     "<tr uri=\"" + encodeURI(obj.data[item].uri) + "\" class=\"song\">" + |                                     "<tr uri=\"" + encodeURI(obj.data[item].uri) + "\" class=\"song\">" + | ||||||
|                                     "<td><span class=\"glyphicon glyphicon-music\"></span></td>" +  |                                     "<td><span class=\"glyphicon glyphicon-music\"></span></td>" +  | ||||||
|                                     "<td>" + obj.data[item].title +"</td>" + |                                     "<td>" + obj.data[item].title  + "</td>" + | ||||||
|                                     "<td>"+ minutes + ":" + (seconds < 10 ? '0' : '') + seconds + |                                     "<td>" + obj.data[item].album  + "</td>" + | ||||||
|  |                                     "<td>" + obj.data[item].artist + "</td>" +  | ||||||
|  |                                     "<td>" + minutes + ":" + (seconds < 10 ? '0' : '') + seconds + | ||||||
|                                     "</td><td></td></tr>" |                                     "</td><td></td></tr>" | ||||||
|                                 ); |                                 ); | ||||||
|                                 break; |                                 break; | ||||||
| @@ -556,6 +630,7 @@ function webSocketConnect() { | |||||||
|                     break; |                     break; | ||||||
|                 case "mpdhost": |                 case "mpdhost": | ||||||
|                     $('#mpdhost').val(obj.data.host); |                     $('#mpdhost').val(obj.data.host); | ||||||
|  |                     setLocalStream(obj.data.host); | ||||||
|                     $('#mpdport').val(obj.data.port); |                     $('#mpdport').val(obj.data.port); | ||||||
|                     if(obj.data.passwort_set) |                     if(obj.data.passwort_set) | ||||||
|                         $('#mpd_password_set').removeClass('hide'); |                         $('#mpd_password_set').removeClass('hide'); | ||||||
| @@ -654,12 +729,14 @@ var updatePlayIcon = function(state) | |||||||
|     if(state == 1) { // stop |     if(state == 1) { // stop | ||||||
|         $("#play-icon").addClass("glyphicon-play"); |         $("#play-icon").addClass("glyphicon-play"); | ||||||
|         $('#track-icon').addClass("glyphicon-stop"); |         $('#track-icon').addClass("glyphicon-stop"); | ||||||
|     } else if(state == 2) { // pause | 		document.getElementById('player').pause(); | ||||||
|  |     } else if(state == 2) { // play | ||||||
|         $("#play-icon").addClass("glyphicon-pause"); |         $("#play-icon").addClass("glyphicon-pause"); | ||||||
|         $('#track-icon').addClass("glyphicon-play"); |         $('#track-icon').addClass("glyphicon-play"); | ||||||
|     } else { // play |     } else { // pause | ||||||
|         $("#play-icon").addClass("glyphicon-play"); |         $("#play-icon").addClass("glyphicon-play"); | ||||||
|         $('#track-icon').addClass("glyphicon-pause"); |         $('#track-icon').addClass("glyphicon-pause"); | ||||||
|  | 		document.getElementById('player').pause(); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -677,6 +754,52 @@ function clickPlay() { | |||||||
|         socket.send('MPD_API_SET_PAUSE'); |         socket.send('MPD_API_SET_PAUSE'); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | 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) { | function trash(tr) { | ||||||
|     if ( $('#btntrashmodeup').hasClass('active') ) { |     if ( $('#btntrashmodeup').hasClass('active') ) { | ||||||
|         socket.send('MPD_API_RM_RANGE,0,' + (tr.index() + 1)); |         socket.send('MPD_API_RM_RANGE,0,' + (tr.index() + 1)); | ||||||
| @@ -767,6 +890,7 @@ function getHost() { | |||||||
|  |  | ||||||
|     $('#mpdhost').keypress(onEnter); |     $('#mpdhost').keypress(onEnter); | ||||||
|     $('#mpdport').keypress(onEnter); |     $('#mpdport').keypress(onEnter); | ||||||
|  |     $('#mpdstream').keypress(onEnter); | ||||||
|     $('#mpd_pw').keypress(onEnter); |     $('#mpd_pw').keypress(onEnter); | ||||||
|     $('#mpd_pw_con').keypress(onEnter); |     $('#mpd_pw_con').keypress(onEnter); | ||||||
| } | } | ||||||
| @@ -843,6 +967,7 @@ function confirmSettings() { | |||||||
|             socket.send('MPD_API_SET_MPDPASS,'+$('#mpd_pw').val()); |             socket.send('MPD_API_SET_MPDPASS,'+$('#mpd_pw').val()); | ||||||
|     } |     } | ||||||
|     socket.send('MPD_API_SET_MPDHOST,'+$('#mpdport').val()+','+$('#mpdhost').val()); |     socket.send('MPD_API_SET_MPDHOST,'+$('#mpdport').val()+','+$('#mpdhost').val()); | ||||||
|  |     $.cookie("mpdstream", $("#mpdstream").val(), { expires: 424242 }); | ||||||
|     $('#settings').modal('hide'); |     $('#settings').modal('hide'); | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										126
									
								
								htdocs/player.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										126
									
								
								htdocs/player.html
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,126 @@ | |||||||
|  | <!DOCTYPE html> | ||||||
|  | <html lang="en"> | ||||||
|  | <head> | ||||||
|  |   <meta charset="utf-8"> | ||||||
|  |   <meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||||||
|  | <!--  <meta name="viewport" content="width=device-width, initial-scale=1.0">--> | ||||||
|  |   <meta name="viewport" content="width=320"> | ||||||
|  |   <meta name="description" content="ympd - fast and lightweight MPD webclient"> | ||||||
|  |   <meta name="author" content="andy@ndyk.de"> | ||||||
|  |  | ||||||
|  |   <title>ympd player</title> | ||||||
|  |  | ||||||
|  |   <!-- Bootstrap core CSS --> | ||||||
|  |   <link href="css/bootstrap.css" rel="stylesheet"> | ||||||
|  |   <link href="css/bootstrap-theme.css" rel="stylesheet"> | ||||||
|  |  | ||||||
|  |   <!-- Custom styles for this template --> | ||||||
|  |   <link href="css/mpd.css" rel="stylesheet"> | ||||||
|  |   <link href="assets/favicon.ico" rel="shortcut icon" type="image/vnd.microsoft.icon"> | ||||||
|  |   <script src="js/jquery-1.10.2.min.js"></script> | ||||||
|  |   <script src="js/jquery.cookie.js"></script> | ||||||
|  |   <script src="js/bootstrap.min.js"></script> | ||||||
|  |   <script src="js/bootstrap-notify.js"></script> | ||||||
|  | <script type="text/javascript"> | ||||||
|  | function clickLocalPlay() { | ||||||
|  |     var player = document.getElementById('player'); | ||||||
|  |     $("#localplay-icon").removeClass("glyphicon-play").removeClass("glyphicon-pause"); | ||||||
|  |  | ||||||
|  |  | ||||||
|  |     if ( player.paused ) { | ||||||
|  |         var mpdstream = $.cookie("mpdstream"); | ||||||
|  |         player.src = mpdstream; | ||||||
|  |         console.log("playing mpd stream: " + player.src); | ||||||
|  |         player.load(); | ||||||
|  |         player.play(); | ||||||
|  |         $("#localplay-icon").addClass("glyphicon-pause"); | ||||||
|  |     } else { | ||||||
|  |         player.pause(); | ||||||
|  |         player.src=''; | ||||||
|  |         player.removeAttribute("src"); | ||||||
|  |         $("#localplay-icon").addClass("glyphicon-play"); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | $(document).ready(function(){ | ||||||
|  | 	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); | ||||||
|  | }); | ||||||
|  | </script> | ||||||
|  | </head> | ||||||
|  | <body> | ||||||
|  |   <div class="navbar navbar-inverse navbar-fixed-top" role="navigation"> | ||||||
|  |     <div class="container"> | ||||||
|  |         <a class="navbar-brand" href="/" target="_blank"><span class="glyphicon glyphicon-play-circle"></span> ympd</a> | ||||||
|  |     </div> | ||||||
|  |   </div> | ||||||
|  |  | ||||||
|  |   <div class="container starter-template"> | ||||||
|  |     <div class="row"> | ||||||
|  |       <div class="col-md-10 col-xs-12"> | ||||||
|  |             <audio id="player" preload="none"></audio> | ||||||
|  |             <button type="button" class="btn btn-default btn-lg center-block" onclick="clickLocalPlay()"> | ||||||
|  |               <span id="localplay-icon" class="glyphicon glyphicon-play"></span> | ||||||
|  |             </button> | ||||||
|  |         <div class="notifications top-right"></div> | ||||||
|  |       </div> | ||||||
|  |     </div> | ||||||
|  |   </div> | ||||||
|  | </body> | ||||||
|  | </html> | ||||||
| @@ -475,6 +475,42 @@ char* mpd_get_title(struct mpd_song const *song) | |||||||
|     return str; |     return str; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | char* mpd_get_album(struct mpd_song const *song) | ||||||
|  | { | ||||||
|  |     char *str; | ||||||
|  |  | ||||||
|  |     str = (char *)mpd_song_get_tag(song, MPD_TAG_ALBUM, 0); | ||||||
|  |     if(str == NULL){ | ||||||
|  |         str = "-"; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     return str; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | char* mpd_get_artist(struct mpd_song const *song) | ||||||
|  | { | ||||||
|  |     char *str; | ||||||
|  |  | ||||||
|  |     str = (char *)mpd_song_get_tag(song, MPD_TAG_ARTIST, 0); | ||||||
|  |     if(str == NULL){ | ||||||
|  |         str = "-"; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     return str; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | char* mpd_get_year(struct mpd_song const *song) | ||||||
|  | { | ||||||
|  |     char *str; | ||||||
|  |  | ||||||
|  |     str = (char *)mpd_song_get_tag(song, MPD_TAG_DATE, 0); | ||||||
|  |     if(str == NULL){ | ||||||
|  |         str = "-"; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     return str; | ||||||
|  | } | ||||||
|  |  | ||||||
| int mpd_put_state(char *buffer, int *current_song_id, unsigned *queue_version) | int mpd_put_state(char *buffer, int *current_song_id, unsigned *queue_version) | ||||||
| { | { | ||||||
|     struct mpd_status *status; |     struct mpd_status *status; | ||||||
| @@ -602,6 +638,10 @@ int mpd_put_queue(char *buffer, unsigned int offset) | |||||||
|             cur += json_emit_int(cur, end - cur, mpd_song_get_pos(song)); |             cur += json_emit_int(cur, end - cur, mpd_song_get_pos(song)); | ||||||
|             cur += json_emit_raw_str(cur, end - cur, ",\"duration\":"); |             cur += json_emit_raw_str(cur, end - cur, ",\"duration\":"); | ||||||
|             cur += json_emit_int(cur, end - cur, mpd_song_get_duration(song)); |             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_raw_str(cur, end - cur, ",\"title\":"); | ||||||
|             cur += json_emit_quoted_str(cur, end - cur, mpd_get_title(song)); |             cur += json_emit_quoted_str(cur, end - cur, mpd_get_title(song)); | ||||||
|             cur += json_emit_raw_str(cur, end - cur, "},"); |             cur += json_emit_raw_str(cur, end - cur, "},"); | ||||||
| @@ -656,6 +696,10 @@ int mpd_put_browse(char *buffer, char *path, unsigned int offset) | |||||||
|                 song = mpd_entity_get_song(entity); |                 song = mpd_entity_get_song(entity); | ||||||
|                 cur += json_emit_raw_str(cur, end - cur, "{\"type\":\"song\",\"uri\":"); |                 cur += json_emit_raw_str(cur, end - cur, "{\"type\":\"song\",\"uri\":"); | ||||||
|                 cur += json_emit_quoted_str(cur, end - cur, mpd_song_get_uri(song)); |                 cur += json_emit_quoted_str(cur, end - cur, mpd_song_get_uri(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, ",\"artist\":"); | ||||||
|  |                 cur += json_emit_quoted_str(cur, end - cur, mpd_get_artist(song)); | ||||||
|                 cur += json_emit_raw_str(cur, end - cur, ",\"duration\":"); |                 cur += json_emit_raw_str(cur, end - cur, ",\"duration\":"); | ||||||
|                 cur += json_emit_int(cur, end - cur, mpd_song_get_duration(song)); |                 cur += json_emit_int(cur, end - cur, mpd_song_get_duration(song)); | ||||||
|                 cur += json_emit_raw_str(cur, end - cur, ",\"title\":"); |                 cur += json_emit_raw_str(cur, end - cur, ",\"title\":"); | ||||||
| @@ -714,6 +758,10 @@ int mpd_search(char *buffer, char *searchstr) | |||||||
|         while((song = mpd_recv_song(mpd.conn)) != NULL) { |         while((song = mpd_recv_song(mpd.conn)) != NULL) { | ||||||
|             cur += json_emit_raw_str(cur, end - cur, "{\"type\":\"song\",\"uri\":"); |             cur += json_emit_raw_str(cur, end - cur, "{\"type\":\"song\",\"uri\":"); | ||||||
|             cur += json_emit_quoted_str(cur, end - cur, mpd_song_get_uri(song)); |             cur += json_emit_quoted_str(cur, end - cur, mpd_song_get_uri(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, ",\"artist\":"); | ||||||
|  |             cur += json_emit_quoted_str(cur, end - cur, mpd_get_artist(song)); | ||||||
|             cur += json_emit_raw_str(cur, end - cur, ",\"duration\":"); |             cur += json_emit_raw_str(cur, end - cur, ",\"duration\":"); | ||||||
|             cur += json_emit_int(cur, end - cur, mpd_song_get_duration(song)); |             cur += json_emit_int(cur, end - cur, mpd_song_get_duration(song)); | ||||||
|             cur += json_emit_raw_str(cur, end - cur, ",\"title\":"); |             cur += json_emit_raw_str(cur, end - cur, ",\"title\":"); | ||||||
|   | |||||||
							
								
								
									
										25
									
								
								src/ympd.c
									
									
									
									
									
								
							
							
						
						
									
										25
									
								
								src/ympd.c
									
									
									
									
									
								
							| @@ -38,7 +38,12 @@ void bye() | |||||||
|     force_exit = 1; |     force_exit = 1; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | char *gpass = NULL; | ||||||
|  |  | ||||||
| static int server_callback(struct mg_connection *c, enum mg_event ev) { | static int server_callback(struct mg_connection *c, enum mg_event ev) { | ||||||
|  |     int result = MG_FALSE; | ||||||
|  |     FILE *fp = NULL; | ||||||
|  |  | ||||||
|     switch(ev) { |     switch(ev) { | ||||||
|         case MG_CLOSE: |         case MG_CLOSE: | ||||||
|             mpd_close_handler(c); |             mpd_close_handler(c); | ||||||
| @@ -57,7 +62,16 @@ static int server_callback(struct mg_connection *c, enum mg_event ev) { | |||||||
|                 return callback_http(c); |                 return callback_http(c); | ||||||
| #endif | #endif | ||||||
|         case MG_AUTH: |         case MG_AUTH: | ||||||
|  |             // no auth for websockets since mobile safari does not support it | ||||||
|  |             if ( (gpass == NULL) || (c->is_websocket) ) | ||||||
|                 return MG_TRUE; |                 return MG_TRUE; | ||||||
|  |             else { | ||||||
|  |                 if ( (fp = fopen(gpass, "r")) != NULL ) { | ||||||
|  |                     result = mg_authorize_digest(c, fp); | ||||||
|  |                     fclose(fp); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |             return result; | ||||||
|         default: |         default: | ||||||
|             return MG_FALSE; |             return MG_FALSE; | ||||||
|     } |     } | ||||||
| @@ -77,12 +91,14 @@ int main(int argc, char **argv) | |||||||
|     mg_set_option(server, "document_root", SRC_PATH); |     mg_set_option(server, "document_root", SRC_PATH); | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
|  |     mg_set_option(server, "auth_domain", "ympd"); | ||||||
|     mpd.port = 6600; |     mpd.port = 6600; | ||||||
|     strcpy(mpd.host, "127.0.0.1"); |     strcpy(mpd.host, "127.0.0.1"); | ||||||
|  |  | ||||||
|     strcpy(dirble_api_token, "2e223c9909593b94fc6577361a"); |     strcpy(dirble_api_token, "2e223c9909593b94fc6577361a"); | ||||||
|  |  | ||||||
|     static struct option long_options[] = { |     static struct option long_options[] = { | ||||||
|  |         {"digest",       required_argument, 0, 'D'}, | ||||||
|         {"host",         required_argument, 0, 'h'}, |         {"host",         required_argument, 0, 'h'}, | ||||||
|         {"port",         required_argument, 0, 'p'}, |         {"port",         required_argument, 0, 'p'}, | ||||||
|         {"webport",      required_argument, 0, 'w'}, |         {"webport",      required_argument, 0, 'w'}, | ||||||
| @@ -94,9 +110,12 @@ int main(int argc, char **argv) | |||||||
|         {0,              0,                 0,  0 } |         {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:d:v:m", | ||||||
|                 long_options, &option_index)) != -1) { |                 long_options, &option_index)) != -1) { | ||||||
|         switch (n) { |         switch (n) { | ||||||
|  |             case 'D': | ||||||
|  |                 gpass = strdup(optarg); | ||||||
|  |                 break; | ||||||
|             case 'h': |             case 'h': | ||||||
|                 strncpy(mpd.host, optarg, sizeof(mpd.host)); |                 strncpy(mpd.host, optarg, sizeof(mpd.host)); | ||||||
|                 break; |                 break; | ||||||
| @@ -124,12 +143,14 @@ int main(int argc, char **argv) | |||||||
|                 break; |                 break; | ||||||
|             default: |             default: | ||||||
|                 fprintf(stderr, "Usage: %s [OPTION]...\n\n" |                 fprintf(stderr, "Usage: %s [OPTION]...\n\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" |                         " -h, --host <host>\t\tconnect to mpd at host [localhost]\n" | ||||||
|                         " -p, --port <port>\t\tconnect to mpd at port [6600]\n" |                         " -p, --port <port>\t\tconnect to mpd at port [6600]\n" | ||||||
|                         " -w, --webport [ip:]<port>\tlisten interface/port for webserver [8080]\n" |                         " -w, --webport [ip:]<port>\tlisten interface/port for webserver [8080]\n" | ||||||
|                         " -u, --user <username>\t\tdrop priviliges to user after socket bind\n" |                         " -u, --user <username>\t\tdrop priviliges to user after socket bind\n" | ||||||
|                         " -d, --dirbletoken <apitoken>\tDirble API token\n" |                         " -d, --dirbletoken <apitoken>\tDirble API token\n" | ||||||
|                         " -V, --version\t\t\tget version\n" |                         " -v, --version\t\t\tget version\n" | ||||||
|                         " -m, --mpdpass <password>\tspecifies the password to use when connecting to mpd\n" |                         " -m, --mpdpass <password>\tspecifies the password to use when connecting to mpd\n" | ||||||
|                         " --help\t\t\t\tthis help\n" |                         " --help\t\t\t\tthis help\n" | ||||||
|                         , argv[0]); |                         , argv[0]); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 SuperBFG7
					SuperBFG7