Пример #1
0
function doFileSearch($cmd, $domains = null)
{
    global $connection, $dbterms, $array_params;
    $tree = new mpdlistthing(null);
    $parts = true;
    $fcount = 0;
    $filedata = array();
    $foundfile = false;
    if (count($domains) == 0) {
        $domains = null;
    }
    fputs($connection, $cmd . "\n");
    while (!feof($connection) && $parts) {
        $parts = getline($connection);
        if (is_array($parts)) {
            switch ($parts[0]) {
                case "file":
                    if (!$foundfile) {
                        $foundfile = true;
                    } else {
                        if ($dbterms['tags'] !== null || $dbterms['rating'] !== null) {
                            // If this is a search and we have tags or ratings to search for, check them here.
                            if (check_url_against_database($filedata['file'], $dbterms['tags'], $dbterms['rating']) == true) {
                                if (!is_array($domains) || in_array(getDomain($filedata['file']), $domains)) {
                                    $tree->newItem($filedata);
                                    $fcount++;
                                }
                            }
                        } else {
                            if (!is_array($domains) || in_array(getDomain($filedata['file']), $domains)) {
                                $tree->newItem($filedata);
                                $fcount++;
                            }
                        }
                        $filedata = array();
                    }
                    $filedata[$parts[0]] = trim($parts[1]);
                    break;
                case "playlist":
                    $filedata[$parts[0]] = trim($parts[1]);
                    if ($dbterms['tags'] === null && $dbterms['rating'] === null) {
                        $tree->newItem($filedata);
                        $fcount++;
                    }
                    $filedata = array();
                    break;
                case "Title":
                case "Time":
                case "AlbumArtist":
                case "Album":
                case "Artist":
                    if (in_array($parts[0], $array_params)) {
                        $filedata[$parts[0]] = array_unique(explode(';', trim($parts[1])));
                    } else {
                        $filedata[$parts[0]] = explode(';', trim($parts[1]))[0];
                    }
                    break;
            }
        }
    }
    if (array_key_exists('file', $filedata)) {
        if (!is_array($domains) || in_array(getDomain($filedata['file']), $domains)) {
            $tree->newItem($filedata);
            $fcount++;
        }
    }
    printFileSearch($tree, $fcount);
}
Пример #2
0
 if (array_key_exists('terms', $_REQUEST)) {
     // SQL database search request
     $domains = checkDomains($_REQUEST);
     include "player/mpd/connection.php";
     include "collection/collection.php";
     include "collection/dbsearch.php";
     $doing_search = true;
     if ($_REQUEST['resultstype'] == "tree") {
         $tree = new mpdlistthing(null);
     } else {
         cleanSearchTables();
         open_transaction();
     }
     $fcount = doDbCollection($_REQUEST['terms'], $domains, $_REQUEST['resultstype']);
     if ($_REQUEST['resultstype'] == "tree") {
         printFileSearch($tree, $fcount);
     } else {
         close_transaction();
         dumpAlbums($_REQUEST['dump']);
     }
     close_mpd();
 } else {
     if (array_key_exists('wishlist', $_REQUEST)) {
         include "collection/collection.php";
         include "collection/dbsearch.php";
         getWishlist();
     } else {
         if (array_key_exists('rebuild', $_REQUEST)) {
             // This is a request to rebuild the music collection coming from either
             // the mpd or mopidy controller
             debuglog("======================================================================", "TIMINGS", 4);