function _parseFileListResponse($resp) { if (is_null($resp)) { return NULL; } else { $plistArray = array(); $plistLine = strtok($resp, "\n"); $plistFile = ""; $plCounter = -1; while ($plistLine) { list($element, $value) = explode(": ", $plistLine); if ($element == "file" or $element == "playlist") { $plCounter++; $plistFile = $value; $plistArray[$plCounter]["file"] = $plistFile; $plistArray[$plCounter]["fileext"] = parseFileStr($plistFile, '.'); } else { if ($element == "directory") { $plCounter++; // record directory index for further processing $dirCounter++; $plistFile = $value; $plistArray[$plCounter]["directory"] = $plistFile; } else { $plistArray[$plCounter][$element] = $value; $plistArray[$plCounter]["Time2"] = songTime($plistArray[$plCounter]["Time"]); } } $plistLine = strtok("\n"); } // reverse MPD list output if (isset($dirCounter) && isset($plistArray[0]["file"])) { $dir = array_splice($plistArray, -$dirCounter); $plistArray = $dir + $plistArray; } } return $plistArray; }
function _parseFileListResponse($resp) { if (is_null($resp)) { return NULL; } else { $plistArray = array(); $dirArray = array(); $plCounter = -1; $dirCounter = 0; $plistLine = strtok($resp, "\n"); $plistFile = ""; while ($plistLine) { list($element, $value) = explode(": ", $plistLine, 2); if ($element == "file" or $element == "playlist") { $plCounter++; $plistFile = $value; $plistArray[$plCounter]["file"] = $plistFile; $plistArray[$plCounter]["fileext"] = parseFileStr($plistFile, '.'); $plistArray[$plCounter]["Type"] = "MpdFile"; } else { if ($element == "directory") { $dirCounter++; $dirArray[$dirCounter]["directory"] = $value; $dirArray[$dirCounter]["Type"] = "MpdDirectory"; } else { $plistArray[$plCounter][$element] = $value; $plistArray[$plCounter]["Time2"] = songTime($plistArray[$plCounter]["Time"]); } } $plistLine = strtok("\n"); } } return array_merge($dirArray, $plistArray); }
/** * Parse MPD playlist */ function _parseFileListResponse($resp) { $res = array(); $item = array(); $directoryIndex = -1; foreach (explode("\n", $resp) as $line) { if (false === strpos($line, ': ')) { continue; } list($key, $val) = explode(': ', $line, 2); if (sizeof($item) && in_array($key, array('file', 'playlist', 'directory'))) { $res[] = $item; $item = array(); } switch ($key) { case 'playlist': // treat webradio playlists as files if (substr($val, 0, 8) !== "WEBRADIO") { break; } $key = 'file'; // fallthrough // fallthrough case 'file': $item["fileext"] = pathinfo($val, PATHINFO_EXTENSION); break; case 'directory': $directoryIndex = sizeof($res); break; case 'Time': $item['Time2'] = songTime($val); } $item[$key] = $val; } // add final item to array if (sizeof($item)) { $res[] = $item; } // reverse MPD list output if ($directoryIndex >= 0) { $dir = array_splice($res, $directoryIndex); $res = $dir + $res; } return $res; }
function _parseFileListResponse($resp) { if (is_null($resp)) { return null; } else { $plistArray = array(); $plistLine = strtok($resp, "\n"); // $plistFile = ""; $plCounter = -1; $browseMode = TRUE; while ($plistLine) { // list ( $element, $value ) = explode(": ",$plistLine); if (!strpos($plistLine, '@eaDir')) { list($element, $value) = explode(': ', $plistLine, 2); } if ($element === 'file' or $element === 'playlist') { $plCounter++; $browseMode = FALSE; // $plistFile = $value; $plistArray[$plCounter][$element] = $value; $plistArray[$plCounter]['fileext'] = parseFileStr($value, '.'); } elseif ($element === 'directory') { $plCounter++; // record directory index for further processing $dirCounter++; // $plistFile = $value; $plistArray[$plCounter]['directory'] = $value; } else { if ($browseMode) { if ($element === 'Album') { $plCounter++; $plistArray[$plCounter]['album'] = $value; } else { if ($element === 'Artist') { $plCounter++; $plistArray[$plCounter]['artist'] = $value; } else { if ($element === 'Genre') { $plCounter++; $plistArray[$plCounter]['genre'] = $value; } } } } else { $plistArray[$plCounter][$element] = $value; $plistArray[$plCounter]['Time2'] = songTime($plistArray[$plCounter]['Time']); } } $plistLine = strtok("\n"); } } return $plistArray; }