diff --git a/config/config.inc.php b/config/config.inc.php index a699209..3b45065 100644 --- a/config/config.inc.php +++ b/config/config.inc.php @@ -4,6 +4,11 @@ ** NeoMPC Config File **************************************/ + /* Server details */ + $_CONFIG['server'] = 'localhost'; + $_CONFIG['password'] = ''; + $_CONFIG['port'] = '6600'; + /* Config relating to the display of CD covers */ /* music_directory must match you MPD music_directory config */ $_CONFIG['music_directory'] = '/home/danbee/Music'; @@ -14,6 +19,7 @@ /* Browse mode can be 'filesystem' or 'metadata' */ $_CONFIG['browse_mode'] = 'metadata'; + //$_CONFIG['browse_mode'] = 'filesystem'; $_CONFIG['sort_by_tracknumber'] = true; diff --git a/lib/actions.php b/lib/actions.php index c51ce9f..02d14cb 100644 --- a/lib/actions.php +++ b/lib/actions.php @@ -75,7 +75,7 @@ global $_CONFIG, $mympd; - if ($browse == '/') { + if ($browse == $_CONFIG['separator']) { $browse = ''; } @@ -107,8 +107,8 @@ case 'metadata': - $browse_bits = split('/', $browse); - + $browse_bits = explode($_CONFIG['separator'], $browse); + if (is_array($browse_bits)) { if ($browse_bits[1]) { diff --git a/lib/global.php b/lib/global.php index 1943251..f15823a 100644 --- a/lib/global.php +++ b/lib/global.php @@ -11,7 +11,16 @@ $_COOKIE = array_map('stripslashes', $_COOKIE); } - require('config/config.inc.php'); + require('config/config.inc.php'); + + switch ($_CONFIG['browse_mode']) { + case 'filesystem': + $_CONFIG['separator'] = '/'; + break; + case 'metadata': + $_CONFIG['separator'] = '|'; + break; + } define('SMARTY_DIR', 'lib/smarty/libs/'); require(SMARTY_DIR . 'Smarty.class.php'); @@ -26,8 +35,13 @@ require("templates/${_CONFIG['template']}/config.inc.php"); - include('lib/mpd.class.php'); - $mympd = new mpd('localhost',6600); + include('lib/mpd.class.php'); + if ($_CONFIG['password'] != '') { + $mympd = new mpd($_CONFIG['server'], $_CONFIG['port'], $_CONFIG['password']); + } + else { + $mympd = new mpd($_CONFIG['server'], $_CONFIG['port']); + } if (!$mympd->connected) { echo "

Problem connecting to MPD!

"; diff --git a/lib/page.php b/lib/page.php index 34ae41d..3da7d62 100644 --- a/lib/page.php +++ b/lib/page.php @@ -14,7 +14,12 @@ $smarty->assign('show_extra_track_info', $_CONFIG['playlist_extra_track_info']); - $smarty->assign('playlist', $mympd->playlist); + $playlist = $mympd->playlist; + foreach ($playlist as $key => $playlist_item) { + $playlist[$key]['file_name'] = substr($playlist_item['file'], strrpos($playlist_item['file'], '/') + 1); + } + + $smarty->assign('playlist', $playlist); $smarty->assign('playing', $mympd->current_track_id); break; case "control": @@ -25,6 +30,7 @@ $smarty->assign('current_album', $current_track['Album']); $smarty->assign('current_artist', $current_track['Artist']); $smarty->assign('current_file', $current_track['file']); + $smarty->assign('current_filename', substr($current_track['file'], strrpos($current_track['file'], '/') + 1)); $smarty->assign('song_length', $mympd->current_track_length); $smarty->assign('song_position', $mympd->current_track_position); $smarty->assign('mpd_state', $mympd->state); @@ -64,15 +70,17 @@ switch ($_CONFIG['browse_mode']) { case 'metadata': /* metadata based browsing. this will list artists->albums->tracks */ + + $home_link = 'index.php?browse=|'; /* split the browse get var if present */ if ($_GET['browse']) { setcookie('browse', $_GET['browse']); - if ($_GET['browse'] == '/') { + if ($_GET['browse'] == '|') { $meta_level = 'artists'; } else { - $browse_bits = split('/', $_GET['browse']); + $browse_bits = explode('|', $_GET['browse']); if ($browse_bits[0]) { $artist = $browse_bits[0]; $meta_level = 'albums'; @@ -84,11 +92,11 @@ } } elseif ($_COOKIE['browse']) { - if ($_COOKIE['browse'] == '/') { + if ($_COOKIE['browse'] == '|') { $meta_level = 'artists'; } else { - $browse_bits = split('/', $_COOKIE['browse']); + $browse_bits = explode('|', $_COOKIE['md_browse']); if ($browse_bits[0]) { $artist = $browse_bits[0]; $meta_level = 'albums'; @@ -121,7 +129,7 @@ $albums = $mympd->GetAlbums($artist); foreach ($albums as $the_album) { - $browselist[] = array('metaAlbum' => $the_album, 'path' => $artist . '/' . $the_album); + $browselist[] = array('metaAlbum' => $the_album, 'path' => $artist . '|' . $the_album); } $dir_list = array(array('name' => stripslashes($artist), 'path' => urlencode($artist))); @@ -148,18 +156,21 @@ usort($browselist, "track_sort"); } - $dir_list = array(array('name' => $artist, 'path' => urlencode($artist)), array('name' => $album, 'path' => urlencode($artist . '/' . $album))); + $dir_list = array(array('name' => $artist, 'path' => urlencode($artist)), array('name' => $album, 'path' => urlencode($artist . '|' . $album))); break; } $smarty->assign('dir_list', $dir_list); $smarty->assign('browselist', $browselist); + $smarty->assign('home_link', $home_link); break; case 'filesystem': /* filesystem based browsing. this will follow the filesystem tree */ + $home_link = 'index.php?browse=/'; + /* get the browse position from the cookie or from get */ if ($_GET['browse']) { $browse = $_GET['browse']; @@ -169,7 +180,8 @@ $browse = $_COOKIE['browse']; } - $browse = $browse; + //$browse = $browse; + // ^ wtf?!? /* make the path array */ @@ -207,8 +219,7 @@ //*/ foreach ($browselist as $key => $browselist_item) { - - + if ($browselist_item['directory']) { $lastpos = strrpos($browselist_item['directory'], '/'); if ($lastpos !== false) { @@ -222,7 +233,11 @@ /* add a token for files currently on the playlist */ foreach($mympd->playlist as $playlist_item) { + $lastpos = strrpos($browselist_item['file'], '/'); + $browselist[$key]['file_name'] = substr($browselist_item['file'], $lastpos + 1); + if ($browselist_item['file'] == $playlist_item['file']) { + $browselist[$key]['in_playlist'] = "1"; } } @@ -231,6 +246,7 @@ //print_r($browselist); $smarty->assign('browselist', $browselist); + $smarty->assign('home_link', $home_link); break; } diff --git a/templates/default/browse.html b/templates/default/browse.html index 245db68..63ff128 100644 --- a/templates/default/browse.html +++ b/templates/default/browse.html @@ -1,6 +1,6 @@