From 9c6a5fc5787109a0dfe47caf9a3df9c72a2ff1fc Mon Sep 17 00:00:00 2001 From: Andrew McMillan Date: Sat, 5 Jun 2010 14:46:52 +1200 Subject: [PATCH] Nicely working now with several small javascript widgets. --- inc/album-list.php | 29 +++++++ inc/artist-list.php | 29 +++++++ inc/daemonInterface.php | 13 ++- inc/header.php | 28 +------ inc/home-header.php | 94 ++++++++++++++++++++++ inc/menu.php | 183 +++++++++++++++++++++++++++++++++++++------ inc/mpdPlayer.php | 6 +- inc/show-album.php | 103 ++++++++++++++++++++++++ inc/show-artist.php | 101 ++++++++++++++++++++++++ inc/stream-list.php | 31 ++++++++ inc/vlcPlayer.php | 6 +- inc/xmms2Player.php | 5 +- scripts/add_subtree.pl | 2 +- scripts/xmmsosd.pl | 156 ++++++++++++++++++++++++++++++++++++ www/action.php | 58 ++++++++++++++ www/adorno.css | 100 ++++++++++++++++++----- www/always.php | 25 +++++- www/current.php | 20 +++++ www/img/stop.png | Bin 0 -> 923 bytes www/index.php | 24 +++--- www/js/adorno.js | 175 +++++++++++++++++++++++++++++++++++------ www/{index.php => queue.php} | 39 ++++----- 22 files changed, 1086 insertions(+), 141 deletions(-) create mode 100644 inc/album-list.php create mode 100644 inc/artist-list.php create mode 100644 inc/home-header.php create mode 100644 inc/show-album.php create mode 100644 inc/show-artist.php create mode 100644 inc/stream-list.php create mode 100755 scripts/xmmsosd.pl create mode 100644 www/action.php create mode 100644 www/current.php create mode 100644 www/img/stop.png rewrite www/js/adorno.js (97%) copy www/{index.php => queue.php} (70%) diff --git a/inc/album-list.php b/inc/album-list.php new file mode 100644 index 0000000..0f88a5a --- /dev/null +++ b/inc/album-list.php @@ -0,0 +1,29 @@ +Albums\n

"; +$where = ''; +$params = array(); +if ( isset($search) ) { + $where = "(artist ~* :search OR album ~* :search OR title ~* :search OR path_name ~* :search) "; + $params[':search'] = $search; +} +if ( isset($altr) ) { + $altr = trim($altr); + $where .= ($where == ''? '' : ' AND '); + $where .= '(album ~ :album_match)'; + $params[':album_match'] = '^'.$altr; +} +if ( $where != '' ) $where = 'WHERE '. $where; +$sql = 'SELECT distinct ON (lower(album)) album FROM tracks '.$where.' ORDER BY lower(album)'; +$qry = new AwlQuery( $sql, $params ); + +if ( $qry->Exec('album') && $qry->rows() > 0 ) { + while ( $album = $qry->Fetch() ) { + $display = htmlspecialchars($album->album); + if ( trim($display) == "" ) $display = "«unknown»"; + echo " album) . "$letter_get\" class=\"album\">$display\n"; + } +} + diff --git a/inc/artist-list.php b/inc/artist-list.php new file mode 100644 index 0000000..d483e92 --- /dev/null +++ b/inc/artist-list.php @@ -0,0 +1,29 @@ +Artists\n

"; +$where = ''; +$params = array(); +if ( isset($search) ) { + $where = "(artist ~* :search OR album ~* :search OR title ~* :search OR path_name ~* :search) "; + $params[':search'] = $search; +} +if ( isset($altr) ) { + $altr = trim($altr); + $where .= ($where == ''? '' : ' AND '); + $where .= '(artist ~ :artist_match)'; + $params[':artist_match'] = '^'.$altr; +} +if ( $where != '' ) $where = 'WHERE '. $where; +$sql = 'SELECT distinct ON (lower(artist)) artist FROM tracks '.$where.' ORDER BY lower(artist)'; +$qry = new AwlQuery( $sql, $params ); + +if ( $qry->Exec('artist') && $qry->rows() > 0 ) { + while ( $artist = $qry->Fetch() ) { + $display = htmlspecialchars($artist->artist); + if ( trim($display) == "" ) $display = "«unknown»"; + echo " artist) . "$letter_get\" class=\"artist\">$display\n"; + } +} + diff --git a/inc/daemonInterface.php b/inc/daemonInterface.php index 30176b0..c284946 100644 --- a/inc/daemonInterface.php +++ b/inc/daemonInterface.php @@ -43,6 +43,7 @@ function current_track() { $qry = new AwlQuery( $query, $current_track->track ); if ( $qry->Exec('current_track') && $qry->rows() > 0 ) { $track = $qry->Fetch(); + $track->state = $current_track->state; return $track; } return; @@ -73,20 +74,22 @@ function current_queue() { $queue_pos = array(); $position = 0; - $in_list = ""; + $in_list = ''; + $params = array(); foreach( $queue AS $k => $track ) { - $in_list .= ($position == 0 ? "" : ", ") . qpg($track); + $in_list .= ($position == 0 ? '' : ', ') . ':t'.$position; + $params[':t'.$position] = $track; $queue_pos[$track] = $position++; } $queue = array(); - if ( $in_list == "" ) return $queue; + if ( $in_list == '' ) return $queue; /** * Select the track information from the database */ $sql = sprintf("SELECT *, EXTRACT( 'epoch' FROM duration ) AS dur_secs FROM tracks WHERE path_name IN ( %s );", $in_list ); - $qry = new AwlQuery( $sql ); + $qry = new AwlQuery( $sql, $params ); if ( $qry->Exec("current_queue",__LINE__,__FILE__) && $qry->rows() ) { while( $track = $qry->Fetch() ) { $position = $queue_pos[$track->path_name]; @@ -96,3 +99,5 @@ function current_queue() { return $queue; } + + diff --git a/inc/header.php b/inc/header.php index 72fd33d..93712ab 100644 --- a/inc/header.php +++ b/inc/header.php @@ -3,40 +3,16 @@ ///////////////////////////////////////////////////////// // Work out our page title ///////////////////////////////////////////////////////// - $refresh_time = 90; if ( !isset($page_title) || $page_title == "" ) { $current_track = current_track(); if ( is_object($current_track) ) { $page_title = "$current_track->title : $current_track->album : $current_track->artist "; $refresh_time = ( $current_track->finishing - time() ) + 5; - if ( $refresh_time < 0 ) $refresh_time = 180; - if ( $refresh_time < 90 && $refresh_time > 30 ) $refresh_time = 90; - error_log( "$sysabbr: DBG: Title >>$page_title<< Finish >>$current_track->finishing >>".time()." >>$refresh_time"); } } - $refresh_url = $letter_get; - if ( isset($a) ) - $refresh_url .= "&a=".urlencode($a); - else if ( isset($l) ) - $refresh_url .= "&l=".urlencode($l); - $refresh_url = sprintf( 'http://%s%s?act=no', $_SERVER['HTTP_HOST'], $_SERVER['PHP_SELF'], $refresh_url ); + if ( isset($action) ) daemon_other_command($action,$track); - if ( isset($refresh) && ! $refresh) { - // Don't add a refresh header - error_log("Refresh forced off"); - $meta_refresh = ""; - } - else if ( "$submit" != "" ) { - daemon_other_command($action,$track); - $meta_refresh = "$refresh_time;URL=$refresh_url" ; - header("Refresh: ".$meta_refresh); - } - else { - $meta_refresh = "$refresh_time; URL=$refresh_url" ; - header("Refresh: ".$meta_refresh); - } - error_log("Refresh header was : $meta_refresh"); if ( !isset($stylesheet) ) $stylesheet = "adorno.css"; echo << $page_title - - diff --git a/inc/home-header.php b/inc/home-header.php new file mode 100644 index 0000000..b247bd8 --- /dev/null +++ b/inc/home-header.php @@ -0,0 +1,94 @@ +'."\n"; + $controls = ""; + + $controls .= sprintf( $url, 'pause', 'pause.png', 'Pause the playback'); + $controls .= sprintf( $url, 'resume','resume.png','Resume the paused playback'); + $controls .= sprintf( $url, 'next', 'next.png', 'Skip ahead to the next track'); + $controls .= sprintf( $url, 'stop', 'stop.png', 'Stop playing tracks'); + $controls .= sprintf( $url, 'clear', 'clear.png', 'Clear the currently queued tracks'); + $controls .= sprintf( $url, 'off', 'off.png', 'Shut music server down and turn off'); + + return $controls; +} + + + +function build_menubar() { + global $ltrtype, $a, $l, $lltr, $altr, $search; + + if ( !isset($ltrtype) ) $ltrtype = 'artist'; + $url = $_SERVER['PHP_SELF'] . build_url_params( array('altr' => '--altr--') ); + $ls = new LinkSet( '%s', 'alphabetica' ); + + $sf = new EntryForm( '', $GLOBALS, true ); + $sf->SimpleForm(); + $menubar = $sf->StartForm(array('method' => 'get', 'id' => 'search_form')); + if ( isset($ltrtype) ) $menubar .= $sf->HiddenField( 'type', $ltrtype ); + if ( isset($lltr) ) $menubar .= $sf->HiddenField( 'lltr', $lltr ); + if ( isset($altr) ) $menubar .= $sf->HiddenField( 'altr', $altr ); + if ( isset($a) ) $menubar .= $sf->HiddenField( 'a', $a ); + else if ( isset($l) ) $menubar .= $sf->HiddenField( 'l', $l ); + + $menubar .= ''; + + $f = new EntryField( 'text', 'search', + array( 'title' => 'Enter a regular expression to search for artists / albums that match that', + 'size' => '15', 'class' => 'search_field'), + "$search" ); + $menubar .= ''; + $menubar .= ''; + + $menubar .= '
'.ucfirst($ltrtype).'s:'; + $qry = new AwlQuery("SELECT letter, pattern, $ltrtype"."_count AS count FROM letter_groups ORDER BY 1;"); + if ( $qry->Exec("artist") && $qry->rows() > 0 ) { + while ( $letter = $qry->Fetch() ) { + $help = "Display $letter->count $ltrtype"."s beginning with the letter '$letter->letter'."; + $display = $letter->letter; + if ( trim($letter->letter) == "#" ) { + $help = 'List all '."$letter->count $ltrtype".'s not beginning with an alphabetic character.'; + } + $menubar .= $ls->Link( str_replace('--altr--', rawurlencode($letter->pattern), $url), $display, $help ); + } + } + $menubar .= ''.$f->Render().''.$sf->SubmitButton("submit","Search").'
'; + + $menubar .= $sf->EndForm(); + + return $menubar; +} + +$controls = build_controls(); +$menubar = build_menubar(); +if ( !isset($stylesheet) ) $stylesheet = "adorno.css"; + + echo << + + +Adorno Music Server + + + + + + + + + + +

+
+
+
+
+ +EOHTML; diff --git a/inc/menu.php b/inc/menu.php index c434e02..6a19c32 100644 --- a/inc/menu.php +++ b/inc/menu.php @@ -2,41 +2,43 @@ require_once("LinkClass.php"); require_once("DataEntry.php"); - // Here's a bit of misdirection that ensures the URL always has a ?var=value at the beginning. - if ( ! strpos( $refresh_url, '?' ) ) $refresh_url .= "?s=" . substr( md5(rand(1,50000)), 1, 3 ); - - $url = ' '; - $url .= ''."\n"; + $url = ''."\n"; $controls = ""; - $controls .= sprintf( $url, "pause", "pause.png", "Pause the playback"); - $controls .= sprintf( $url, "resume", "resume.png", "Resume the paused playback"); - $controls .= sprintf( $url, "next", "next.png", "Skip ahead to the next track"); - $controls .= sprintf( $url, "clear", "clear.png", "Clear the currently queued tracks"); - $controls .= sprintf( $url, "off", "off.png", "Shut music server down and turn off"); + $controls .= sprintf( $url, 'pause', 'pause.png', 'Pause the playback'); + $controls .= sprintf( $url, 'resume','resume.png','Resume the paused playback'); + $controls .= sprintf( $url, 'next', 'next.png', 'Skip ahead to the next track'); + $controls .= sprintf( $url, 'stop', 'stop.png', 'Stop playing tracks'); + $controls .= sprintf( $url, 'clear', 'clear.png', 'Clear the currently queued tracks'); + $controls .= sprintf( $url, 'off', 'off.png', 'Shut music server down and turn off'); $url = ""; - if ( "$lltr" <> "" ) $url .= "&lltr=" . urlencode($lltr); - if ( "$a" <> "" ) $url .= "&a=" . urlencode($a); - elseif ( "$l" <> "" ) $url .= "&l=" . urlencode($l); - $ltrtype = "artist"; - if ( preg_match( '/album.php/', $REQUEST_URI) ) $ltrtype = "album"; + if ( "$lltr" <> "" ) $url .= "&lltr=" . rawurlencode($lltr); + elseif ( "$altr" <> "" ) $url .= "&altr=" . rawurlencode($altr); + if ( "$a" <> "" ) $url .= "&a=" . rawurlencode($a); + elseif ( "$l" <> "" ) $url .= "&l=" . rawurlencode($l); + + if ( !isset($ltrtype) ) { + $ltrtype = 'artist'; + if ( preg_match( '/album.php/', $_SERVER['REQUEST_URI']) ) $ltrtype = 'album'; + } - $url = $PHP_SELF . preg_replace( '/^&/', '?', $url . '&' ); + $url = $_SERVER['PHP_SELF'] . preg_replace( '/^&/', '?', $url . '&' ); if ( !preg_match( '{/(artist|album)\.php}', $url) ) { error_log( "$sysabbr: DBG: >>$url<< " . (preg_match('{/(artist|album)\.php}', $url)? 'true':'false') ); - $url = preg_replace( '{/[a-z0-9_-]+\.php}i', '/artist.php', $url ); + // $url = preg_replace( '{/[a-z0-9_-]+\.php}i', '/artist.php', $url ); + $url .= sprintf('type=%s&', $ltrtype); } $ls = new LinkSet( '%s', 'alphabetica' ); error_log( "$sysabbr: DBG: >>$ls->template<<" ); - $menubar = '
'.ucfirst($ltrtype).'s:'; + $menubar = ''; // $menubar .= ''; $sf = new EntryForm( $refresh_url, $GLOBALS, true ); - $sf->TrivialForm(); + $sf->SimpleForm(); $menubar .= $sf->StartForm(array('method' => 'get')); if ( isset($lltr) ) $menubar .= $sf->HiddenField( 'lltr', $lltr ); if ( isset($altr) ) $menubar .= $sf->HiddenField( 'altr', $altr ); @@ -74,13 +76,141 @@ echo << +
'.ucfirst($ltrtype).'s:'; $qry = new AwlQuery("SELECT letter, pattern, $ltrtype"."_count AS count FROM letter_groups ORDER BY 1;"); if ( $qry->Exec("artist") && $qry->rows() > 0 ) { while ( $letter = $qry->Fetch() ) { $help = "Display $letter->count $ltrtype"."s beginning with the letter '$letter->letter'."; $display = $letter->letter; - if ( trim("$letter->letter") == "#" ) { + if ( trim($letter->letter) == "#" ) { $help = 'List all '."$letter->count $ltrtype".'s not beginning with an alphabetic character.'; } $menubar .= $ls->Link( urlencode($letter->pattern), $display, $help ); @@ -45,7 +47,7 @@ $menubar .= 'Search:
- + @@ -91,6 +221,9 @@ $controls
+
EOHTML; diff --git a/inc/mpdPlayer.php b/inc/mpdPlayer.php index ce30e09..ab7c9bb 100644 --- a/inc/mpdPlayer.php +++ b/inc/mpdPlayer.php @@ -185,6 +185,9 @@ function daemon_current_track() { function daemon_other_command( $action, $track ) { global $mpd; switch( $action ) { + case 'resume': + $mpd->Daemon('play'); + break; case 'pause': $mpd->Daemon($action); break; @@ -192,7 +195,8 @@ function daemon_other_command( $action, $track ) { $mpd->Daemon($action); break; default: - error_log("adorno: ERROR: Unsupported command '$action'" ); + error_log("adorno: WARNING: Unsupported command '$action'" ); + $mpd->Daemon($action); } return true; diff --git a/inc/show-album.php b/inc/show-album.php new file mode 100644 index 0000000..1c4d73b --- /dev/null +++ b/inc/show-album.php @@ -0,0 +1,103 @@ + +album), urlencode($trk->artist), urlencode($trk->title) ); + $safe_title = htmlspecialchars($link_title); + $duration = preg_replace( "/^[0:]{1,4}/", "", $trk->duration ); + $enqueue = sprintf( "enqueue('%s','%s','%s')", rawurlencode($trk->artist), + rawurlencode($trk->album), rawurlencode($trk->title) ); + $link = <<$safe_title + +
+ + + EOHTML; -$artist_link_fmt = '%s'; -$album_link_fmt = '%s'; +$artist_link_fmt = '%s'; +$album_link_fmt = '%s'; $track_fmt = << + - + @@ -57,7 +49,9 @@ EOHTML; $current_track = current_track(); $tracks = current_queue(); -echo ''; + +// print_r( $tracks ); + $last_artist = ""; $last_album = ""; $when = $current_track->finishing; @@ -67,6 +61,7 @@ for( $k=0; isset($tracks[$k]); $k++ ) { $escape_artist = urlencode($v->artist); $escape_album = urlencode($v->album); + if ( $escape_artist != $last_artist || $escape_album != $last_album ) { if ( $escape_artist != $last_artist && $escape_album != $last_album ) { $links = sprintf( $album_link_fmt, $escape_album, $v->album); @@ -82,12 +77,8 @@ for( $k=0; isset($tracks[$k]); $k++ ) { $last_artist = $escape_artist; $last_album = $escape_album; } - printf( $track_fmt, $position, $v->tracknum, $v->title, date('H:i:s', $when ), $position, $position ); + printf( $track_fmt, ($position %2), $position, $v->tracknum, + $v->title, date('H:i:s', $when ), $position, $position ); $when += $v->dur_secs; } -echo "
\n"; -?> - - - -- 2.11.4.GIT