diff --git a/scripts/homeaudio_utils.php b/scripts/homeaudio_utils.php new file mode 100644 index 0000000..789a82b --- /dev/null +++ b/scripts/homeaudio_utils.php @@ -0,0 +1,89 @@ + 'jpg', + 'image/jpeg' => 'jpg', + 'image/png' => 'png', + 'image/gif' => 'gif' +); + +function search() { + global $globaldbh, $argv; + + $target = $argv[2]; + switch ($target) { + case "song": + case "songs": + $terms = array(); + for ( $i=3; $i 2 ) $terms[] = $argv[$i]; + } + if ( count($terms) == 0 ) { + echo "Searching requires search terms as command line parameters\n\n"; + exit(); + } + $query = "SELECT id, path, song, artist, album, title FROM songs WHERE (PATH LIKE :term1"; + for ( $i=1; $iprepare($query); + for ( $i=0; $ibindValue(":term".($i+1), "%".$terms[$i]."%", PDO::PARAM_STR); + } + $sth->execute(); + if ( $sth->rowCount() > 0 ) { + echo " ID | Path | Song | Title | Artist\n"; + echo "-------|----------------------------------------|------------------------------|---------------------------|----------------------\n"; + } + while ( $row = $sth->fetch(PDO::FETCH_ASSOC) ) { + echo str_pad(strval($row['id']), 7) . "|"; + echo " " . str_pad(substr($row['path'], 0, 37), 39) . "|"; + echo " " . str_pad(substr($row['song'], 0, 27), 29) . "|"; + echo " " . str_pad(substr($row['title'], 0, 24), 26) . "|"; + echo " " . substr($row['artist'], 0, 25) . "\n"; + } + break; + } +} + +switch ($argv[1]) { + case "search": + search(); + break; + default: + echo "Nothing to do\n"; +} +echo "\n"; + +// vim: ts=3:sw=3