Current live config.
[adorno.git] / inc / daemonInterface.php
blobe71b4af099e2f414618e9757a97a7507adf08549
1 <?php
3 switch ( $c->daemon_type ) {
4 case 'mpd': include("mpdPlayer.php"); break;
5 case 'vlc': include("vlcPlayer.php"); break;
6 default: include("adornoPlayer.php");
9 /**
10 * High level function to play a track
12 function PlayTrack( $path, $hash ) {
13 if ( isset($_GET['act']) && $_GET['act'] == 'no' && ( !isset($_POST['act']) || $_POST['act'] == 'no') ) {
14 error_log( sprintf("DBG: PlayTrack: *NOT* Queueing '%s' for playing", $path) );
15 return;
18 error_log( sprintf("DBG: PlayTrack: Queueing '%s' for playing", $path) );
20 if ( daemon_play_track($path) ) {
21 $qry = new PgQuery( "SELECT track_played(?) ", $hash );
22 $qry->Exec("PlayTrack");
27 /**
28 * High level function to get the current track as a database object
30 function current_track() {
32 $current_track = daemon_current_track();
34 $query = "SELECT *, extract( EPOCH FROM duration)::int AS secs ";
35 if ( ereg( '[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}', $current_track->started ) ) {
36 $query .= ", extract( EPOCH FROM ('".$current_track->started."'::timestamp + duration))::int AS finishing ";
38 $query .= "FROM tracks WHERE path_name = '" . str_replace("'","''", str_replace("\\", "\\\\", $current_track->track)) . "' ; ";
40 $qry = new PgQuery( $query );
41 if ( $qry->Exec('current_track') && $qry->rows > 0 ) {
42 $track = $qry->Fetch();
43 return $track;
45 return;
49 /**
50 * High level function to crudely display the current track
52 function show_queue() {
54 $queue = daemon_get_queue();
56 echo "<h3>Coming up...</h3>\n<p class=\"track_queue\">";
57 foreach( $queue AS $k => $v ) {
58 echo nice_track_name($v) . "<br>\n";
60 echo "</p>";
64 /**
65 * High level function to return an array of $track objects
67 function current_queue() {
69 $queue = daemon_get_queue();
71 $queue_pos = array();
72 $position = 0;
73 $in_list = "";
74 foreach( $queue AS $k => $track ) {
75 $in_list .= ($position == 0 ? "" : ", ") . qpg($track);
76 $queue_pos[$track] = $position++;
79 $queue = array();
80 if ( $in_list == "" ) return $queue;
82 /**
83 * Select the track information from the database
85 $sql = sprintf("SELECT *, EXTRACT( 'epoch' FROM duration ) AS dur_secs FROM tracks WHERE path_name IN ( %s );", $in_list );
86 $qry = new PgQuery( $sql );
87 if ( $qry->Exec("current_queue",__LINE__,__FILE__) && $qry->rows ) {
88 while( $track = $qry->Fetch() ) {
89 $position = $queue_pos[$track->path_name];
90 $queue[$position] = $track;
94 return $queue;