"; break; } $el = strtok( $got, ":" ); $ret[$el] = strtok( "\0" ); $ret[$el] = ltrim( $ret[$el] ); } if( ! isset( $ret )) { $ret = array(); } return $ret; } function getCommandInfo( $conn, $MPDVersion ) { fputs( $conn, "commands\n" ); while( ! feof( $conn )) { $got = fgets( $conn, "1024" ); $got = str_replace( "\n", "", $got ); if( strncmp( "OK", $got, strlen( "OK" )) == "0") { break; } if( strncmp( "ACK", $got, strlen( "ACK" )) == "0") { $ret = array(); if(strncmp($MPDVersion,"0.11.",strlen("0.11.") == 0 )) { $ret = array( // 0.11.x "clearerror" => 1, "deleteid" => 1, "move" => 1, "moveid" => 1, "playid" => 1, "playlistid" => 1, "plchanges" => 1, "seekid" => 1, "swapid" => 1, "update" => 1 ); }; // 0.10.x $ret = $ret + array( "add" => true, "clear" => true, "close" => true, "crossfade" => true, "close" => true, "crossfade" => true, "currentsong" => true, "delete" => true, "find" => true, "list" => true, "listall" => true, "listallinfo" => true, "load" => true, "lsinfo" => true, "next" => true, "pause" => true, "password" => true, "ping" => true, "play" => true, "playlist" => true, "playlistinfo" => true, "previous" => true, "random" => true, "repeat" => true, "rm" => true, "save" => true, "search" => true, "seek" => true, "setvol" => true, "shuffle" => true, "stats" => true, "status" => true, "stop" => true, "swap" => true, "volume" => true ); return $ret; } $el = str_replace( "command: ", "", $got); $ret[$el] = true; } fputs( $conn, "notcommands\n" ); while( ! feof( $conn )) { $got = fgets( $conn,1024 ); $got = str_replace( "\n", "", $got ); if( strncmp( "OK", $got, strlen( "OK" )) == "0" ) { break; } if( strncmp( "ACK", $got, strlen( "ACK" )) == "0" ) { echo "$got
"; break; } if( $el = str_replace( "command: ", "", $got )) { $ret["all"] = false; $ret[$el] = false; } } if( ! isset ( $ret["all"] )) { $ret["all"] = true; } return $ret; } function setNotSetSongFields( $song, $display_fields ) { if( isset( $song["Title"] )) { for( $i = "0"; $i < count( $display_fields ); $i++ ) { if( ! isset( $song[ $display_fields[$i] ] )) { $song[ $display_fields[$i] ] = ""; } } } return $song; } function getPlaylistInfo( $conn, $song, $display_fields ) { fputs( $conn, "playlistinfo $song\n" ); $count = -1; while ( ! feof( $conn )) { $got = fgets( $conn, "1024" ); $got = str_replace( "\n", "", $got ); if( strncmp( "OK", $got, strlen( "OK" )) == "0") { break; } if( strncmp( "ACK" , $got, strlen( "ACK" )) == "0") { break; } $el = strtok( $got, ":"); if( strcmp( $el, "file" ) == "0" ) { if( $count >= "0" ) { $ret[$count] = setNotSetSongFields( $ret[$count], $display_fields ); } $count++; } $ret[$count][$el] = strtok( "\0" ); $ret[$count][$el] = ltrim( $ret[$count][$el] ); } if ( ! isset( $ret )) { $ret = array(); } return $ret; } function printPlaylistInfo( $conn, $num, $hide, $show_options, $length, $commands, $arg, $color, $server, $config ) { function local( $count, $start, $filenames_only, $ret, $num, $color, $server, $hide, $show_options, $commands, $config, $length ) { $goto = $count > $start ? $count - 1 : $count; $time = time(); if( $filenames_only !== true && isset($ret["Name"]) && $ret["Name"] > "0") { $display = $ret["Name"]; } else { $display = songInfo2Display( $ret, $config["playlist_display_conf"], $config["playlist_display_conf_separator"], $config["filenames_only"], $config["regex"], $config["wordwrap"] ); } $id = $ret["Id"]; if( isset( $num ) && ( $num == $count )) { echo ""; } else { echo ""; } if( $config["enable_swap"] === true ) { echo ""; } else { echo ""; } if( $commands["move"] === false || ($config["enable_swap"] === true && $ret["Pos"] == "0" )) { echo "^
"; } else if( $config["enable_swap"] === true ) { echo "^
"; } if( $commands["delete"] === false ) { echo "d"; } else { echo ""; echo "d"; } if( ( $commands["swap"] === false || $length == ( $ret["Pos"] + 1 )) && $config["enable_swap"] === true ) { echo "
v"; } else if( $config["enable_swap"] === true ) { echo "
"; echo "v"; } if( $commands["play"] === false ) { echo "$display"; } else { echo "$display"; } echo ""; } /* $count => $start-1 $num => The actual MPD playlist number */ $spread = $config["hide_threshold"]; $filenames_only = $config["filenames_only"]; $start = "0"; $end = ( $length - 1 ); $spread *= "2"; echo ""; if ( $hide == "1" ) { // $start is playlist length minus the spread divided by two $start = $num - $spread / 2; // $end is just the length-1 $end = $num + $spread / 2; /* If $start is less than 0 go ahead and make it 0 and the $end will be $end - start, we don't need to show the beginning hide marks */ if( $start < "0" ) { $end -= $start; $start = "0"; } /* Else if $end>=$length we don't need to worry about the ending ... */ if( $end >= $length ) { $start -= $end - $length+1; if( $start < 0 ) { $start = 0; $end = $length-1; } } // Else show the beginning ... string if( $start > "0" ) { echo ""; echo ""; echo "..."; echo ""; } $str = "command_list_begin\n"; for( ($i = $start); ($i <= $end); $i++) { $str .= "playlistinfo $i\n"; } fputs( $conn, $str . "command_list_end\n" ); } else { if( $length > ( $spread + 1 )) { echo ""; echo ""; echo "(condense)"; echo ""; } fputs( $conn, "playlistinfo -1\n" ); } $count = $start-1; while( ! feof( $conn )) { $got = fgets( $conn, "1024" ); $got = str_replace( "\n", "", $got ); if( strncmp( "OK", $got, strlen( "OK" )) == "0" ) { break; } else if( strncmp( "ACK", $got, strlen( "ACK" )) == "0" ) { break; } $el = strtok( $got, ":" ); if ( strcmp( $el, "file" ) == "0" ) { if ( $count >= $start ) { local( $count, $start, $filenames_only, $ret, $num, $color, $server, $hide, $show_options, $commands, $config, $length ); unset ( $ret ); } $count++; } $ret[$el] = strtok( "\0" ); $ret[$el] = ltrim( $ret[$el] ); } if ( $count >= $start ) { local( $count, $start, $filenames_only, $ret, $num, $color, $server, $hide, $show_options, $commands, $config, $length ); } if ( $hide > 0 && $end < ( $length - 1) ) { echo ""; echo ""; echo "..."; echo ""; } echo ""; } function getLsInfo( $conn, $command, $display_fields ) { $dir = array(); $music = array(); $playlist = array(); $mcount = -1; $dcount = -1; $pcount = -1; $type = ""; fputs( $conn, $command ); while( ! feof( $conn )) { $got = fgets( $conn, "1024" ); $got = str_replace( "\n", "", $got ); if( strncmp( "OK", $got, strlen( "OK" )) == "0" ) { break; } if( strncmp( "ACK", $got, strlen("ACK")) == "0" ) { echo "$got
"; break; } $el = strtok( $got, ":" ); switch ($el){ // add a new entry depending on the element type case "directory": $type = "directory"; $dcount++; $dir[$dcount] = str_replace( "$el: " , "", $got ); break; case "playlist": $type = "playlist"; $pcount++; $playlist[$pcount] = str_replace( "$el: " , "", $got ); break; case "file": $type = "file"; $mcount++; $music[$mcount]["$el"] = str_replace( "$el: ", "", $got); //$music[$mcount] = setNotSetSongFields( $filename, $display_fields ); break; default: // add additional information depending on last item type switch ($type){ case "directory": $dir[$dcount]["$el"] = str_replace( "$el: ", "", $got); break; case "playlist": //$playlist[$pcount]["$el"] = str_replace( "$el: ", "", $got); break; case "file": // $music[$mcount]["$el"] = str_replace( "$el: ", "", $got); break; } } /* if( strcmp( $el, "directory" ) == "0" ) { $dir[$dcount] = str_replace( "$el: " , "", $got ); $dcount++; continue; } if( strcmp( $el, "playlist" ) == "0" ) { $playlist[$pcount] = str_replace( "$el: " , "", $got ); $pcount++; continue; } if( strcmp( $el, "file" ) == "0" ) { if ( $mcount >= 0 ) { $music[$mcount] = setNotSetSongFields( $music[$mcount], $display_fields ); } $mcount++; } This crashes when playlists/directories come with additional information: $music[$mcount]["$el"] = str_replace( "$el: ", "", $got); */ } // end while $ret["dir"] = $dir; $ret["music"] = $music; $ret["playlist"] = $playlist; return $ret; } ?>