Beispiel #1
0
function process_file($filedata)
{
    global $numtracks, $totaltime, $prefs, $dbterms, $collection, $putinplaylistarray, $trackbytrack;
    global $db_time, $coll_time, $rtime;
    // Pre-process the file data
    $mytime = microtime(true);
    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']) == false) {
            return false;
        }
    }
    if ($prefs['ignore_unplayable'] && strpos($filedata['Title'], "[unplayable]") === 0) {
        debuglog("Ignoring unplayable track " . $filedata['file'], "COLLECTION", 9);
        return false;
    }
    if (strpos($filedata['Title'], "[loading]") === 0) {
        debuglog("Ignoring unloaded track " . $filedata['file'], "COLLECTION", 9);
        return false;
    }
    $filedata['domain'] = getDomain($filedata['file']);
    $unmopfile = preg_replace('/^.+?:(track|album|artist):/', '', $filedata['file']);
    check_is_stream($filedata);
    if ($filedata['type'] != 'stream') {
        if ($filedata['Title'] == null) {
            $filedata['Title'] = rawurldecode(basename($filedata['file']));
        }
        if ($filedata['Album'] == null) {
            $filedata['Album'] = album_from_path($unmopfile);
        }
        if ($filedata['Artist'] == null) {
            $filedata['Artist'] = artist_from_path($unmopfile, $filedata['file']);
        }
    }
    if ($filedata['Track'] == null) {
        $filedata['Track'] = format_tracknum(basename(rawurldecode($filedata['file'])));
    } else {
        $filedata['Track'] = format_tracknum(ltrim($filedata['Track'], '0'));
    }
    // External Album URI (mopidy only)
    // OR cue sheet link (mpd only). We're only doing CUE sheets, not M3U
    if ($filedata['X-AlbumUri'] === null && strtolower(pathinfo($filedata['playlist'], PATHINFO_EXTENSION)) == "cue") {
        $filedata['X-AlbumUri'] = $filedata['playlist'];
        debuglog("Found CUE sheet for album " . $filedata['Album'], "COLLECTION");
    }
    // Disc Number
    if ($filedata['Disc'] != null) {
        $filedata['Disc'] = format_tracknum(ltrim($filedata['Disc'], '0'));
    }
    if (strpos($filedata['file'], ':artist:') !== false) {
        $filedata['X-AlbumUri'] = $filedata['file'];
        $filedata['Album'] = get_int_text("label_allartist") . concatenate_artist_names($filedata['Artist']);
        if ($filedata['X-AlbumImage'] == null) {
            $filedata['X-AlbumImage'] = "newimages/artist-icon.png";
        }
        $filedata['Disc'] = 0;
        $filedata['Track'] = 0;
    } else {
        if (strpos($filedata['file'], ':album:') !== false) {
            $filedata['X-AlbumUri'] = $filedata['file'];
            $filedata['Disc'] = 0;
            $filedata['Track'] = 0;
        }
    }
    // Sometimes the file domain can be http but the album domain is correct
    // this is true eg for bassdrive
    if ($filedata['X-AlbumUri'] !== null && getDomain($filedata['X-AlbumUri']) != getDomain($filedata['file'])) {
        $filedata['domain'] = getDomain($filedata['X-AlbumUri']);
    }
    if (strpos($filedata['file'], 'archives.bassdrivearchive.com') !== false) {
        // Slightly annoyingly, bassdrive archive tracks come back with http uris.
        $filedata['domain'] = "bassdrive";
    }
    switch ($filedata['domain']) {
        // Some domain-specific fixups for mpd's soundcloud playlist plugin and various unhelpful
        // mopidy backends. There's no consistency of behaviour in the Mopidy backends
        // so to provide some kind of consistency of display we have to do a lot of work.
        case "soundcloud":
            if ($prefs['player_backend'] == "mpd") {
                if ($filedata['Name'] != null) {
                    $filedata['Title'] = $filedata['Name'];
                    $filedata['Album'] = "SoundCloud";
                    $arse = explode(' - ', $filedata['Name']);
                    $filedata['Artist'] = $arse[0];
                } else {
                    $filedata['Artist'] = "Unknown Artist";
                    $filedata['Title'] = "Unknown Track";
                    $filedata['Album'] = "SoundCloud";
                }
            } else {
                $filedata['folder'] = concatenate_artist_names($filedata['Artist']);
                $filedata['AlbumArtist'] = $filedata['Artist'];
            }
            break;
        case "youtube":
            $filedata['folder'] = $filedata['file'];
            $filedata['Artist'] = munge_youtube_track_into_artist($filedata['Title']);
            $filedata['Album'] = munge_youtube_track_into_album($filedata['Title']);
            $filedata['Title'] = munge_youtube_track_into_title($filedata['Title']);
            $filedata['AlbumArtist'] = $filedata['Artist'];
            break;
        case "spotify":
            $filedata['folder'] = $filedata['X-AlbumUri'];
            break;
        case "internetarchive":
            $filedata['X-AlbumUri'] = $filedata['file'];
            $filedata['folder'] = $filedata['file'];
            $filedata['AlbumArtist'] = "Internet Archive";
            break;
        case "podcast http":
        case "podcast https":
        case "podcast ftp":
        case "podcast file":
            $filedata['folder'] = dirname($file);
            $matches = array();
            $a = preg_match('/podcast\\+http:\\/\\/(.*?)\\//', $filedata['file'], $matches);
            if ($a == 1) {
                $filedata['AlbumArtist'] = $matches[1];
                $filedata['Album'] = $filedata['Title'];
                $filedata['Album'] = preg_replace('/^Album\\:\\s*/', '', $filedata['Album']);
                $albumuri = $file;
            } else {
                $filedata['AlbumArtist'] = "Podcasts";
            }
            if ($filedata['Artist'] == "http" || $filedata['Artist'] == "https" || $filedata['Artist'] == "ftp" || $filedata['Artist'] == "file" || substr($filedata['Artist'], 0, 7) == "podcast") {
                $filedata['Artist'] = $filedata['AlbumArtist'];
            }
            break;
        default:
            $filedata['folder'] = dirname($unmopfile);
            break;
    }
    $rtime += microtime(true) - $mytime;
    if ($trackbytrack && $filedata['AlbumArtist'] && $filedata['Disc'] !== null) {
        $tstart = microtime(true);
        do_track_by_track(new track($filedata));
        $db_time += microtime(true) - $tstart;
    } else {
        $cstart = microtime(true);
        if ($filedata['Disc'] === null) {
            $filedata['Disc'] = 1;
        }
        $collection->newTrack(new track($filedata));
        $coll_time += microtime(true) - $cstart;
    }
    $numtracks++;
    $totaltime += $filedata['Time'];
}
Beispiel #2
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);
}