Exemplo n.º 1
0
function do_track_by_track($trackobject)
{
    // The difference between this and the above function is that this one takes tracks as they come in direct
    // from the backend - without being collectionised. This is faster and uses less RAM but does rely on the tags
    // being correct - they're filtered before being sent here.
    // Tracks must have disc and albumartist tags to be handled by this method.
    // The collectionizer was designed to sort tracks without those tags so if those tags exist they don't need
    // to be collectionized.
    global $mysqlc, $find_track, $update_track, $prefs;
    static $current_albumartist = null;
    static $current_album = null;
    static $current_domain = null;
    static $current_albumlink = null;
    static $albumobj = null;
    static $albumindex = null;
    static $albumartistindex = null;
    $artistname = $trackobject->get_sort_artist();
    if ($current_albumartist != $artistname) {
        $albumartistindex = check_artist($artistname, false);
    }
    if ($albumartistindex == null) {
        debuglog("ERROR! Checked artist " . $artistname . " and index is still null!", "MYSQL_TBT", 1);
        return false;
    }
    if ($current_albumartist != $artistname || $current_album != $trackobject->tags['Album'] || $current_domain != $trackobject->tags['domain'] || $trackobject->tags['X-AlbumUri'] != null && $trackobject->tags['X-AlbumUri'] != $current_albumlink) {
        $albumobj = new album($trackobject->tags['Album'], $artistname, $trackobject->tags['domain']);
        $albumobj->newTrack($trackobject);
        $albumindex = check_album($albumobj->name, $albumartistindex, $albumobj->uri, $albumobj->getImage('small'), $albumobj->getDate(), "0", $albumobj->getKey(), $albumobj->musicbrainz_albumid, $albumobj->domain, false);
        if ($albumindex == null) {
            debuglog("ERROR! Album index for " . $albumobj->name . " is still null!", "MYSQL_TBT", 1);
            return false;
        }
    } else {
        $albumobj->newTrack($trackobject, true);
    }
    $current_albumartist = $artistname;
    $current_album = $albumobj->name;
    $current_domain = $albumobj->domain;
    $current_albumlink = $albumobj->uri;
    foreach ($albumobj->tracks as $trackobj) {
        // The album we've just created must only have one track, but this makes sure we use the track object
        // that is part of the album. This MAY be important due to various assumptions and the fact that PHP
        // insists on copying variables rather than passing by reference.
        check_and_update_track($trackobj, $albumindex, $albumartistindex, $artistname);
    }
}
Exemplo n.º 2
0
function check_wishlist_doodads($ttids)
{
    global $uri, $albumartist, $album, $albumuri, $image, $date;
    $donesomething = false;
    if ($stmt = sql_prepare_query("SELECT Uri, Albumindex FROM Tracktable WHERE TTindex = ?", $ttids[0])) {
        while ($ttidobj = $stmt->fetch(PDO::FETCH_OBJ)) {
            if ($ttidobj->Uri == null) {
                if ($up1 = sql_prepare_query("UPDATE Tracktable SET Uri = ? WHERE TTindex = ?", $uri, $ttids[0])) {
                    debuglog("  .. Updated track URI for ex-wishlist item", "USERRATINGS", 5);
                    $donesomething = true;
                } else {
                    debuglog("  .. FAILED to update Track URI!", "USERRATINGS", 2);
                }
                if ($ttidobj->Albumindex == null) {
                    $albumai = check_artist($albumartist, true);
                    $albumindex = check_album($album, $albumai, $albumuri, $image, $date, "no", md5($albumartist . " " . $album), null, getDomain($uri), true);
                    if ($up2 = sql_prepare_query("UPDATE Tracktable SET Albumindex = ? WHERE TTindex = ?", $albumindex, $ttids[0])) {
                        debuglog("  .. Updated track album index for wishlist item", "USERRATINGS", 5);
                        $donesomething = true;
                    } else {
                        debuglog("  .. FAILED to update Track Album Index!", "USERRATINGS", 2);
                    }
                }
            }
        }
    }
    return $donesomething;
}