コード例 #1
0
ファイル: backend.php プロジェクト: cyrilix/rompr
function check_and_update_track($trackobj, $albumindex, $artistindex, $artistname)
{
    global $find_track, $update_track, $numdone, $prefs, $doing_search;
    static $current_trackartist = null;
    static $trackartistindex = null;
    $ttid = null;
    $lastmodified = null;
    $hidden = 0;
    $disc = 0;
    $uri = null;
    $issearchresult = 0;
    // Why are we not checking by URI? That should be unique, right?
    // Well, er. no. They're not.
    // Especially Spotify returns the same URI multiple times if it's in mutliple playlists
    // We CANNOT HANDLE that. Nor do we want to.
    // The other advantage of this is that we can put an INDEX on Albumindex, TrackNo, and Title,
    // which we can't do with Uri cos it's too long - this speeds the whole process up by a factor
    // of about 32 (9 minutes when checking by URI vs 15 seconds this way, on my collection)
    // Also, URIs might change if the user moves his music collection.
    if ($prefs['collection_type'] == "sqlite") {
        // Lord knows why, but we have to re-prepare these every single bloody time!
        prepare_findtracks();
    }
    if ($find_track->execute(array($trackobj->tags['Title'], $albumindex, $trackobj->tags['Track'], $trackobj->tags['Disc'], $artistindex))) {
        $obj = $find_track->fetch(PDO::FETCH_OBJ);
        if ($obj) {
            $ttid = $obj->TTindex;
            $lastmodified = $obj->LastModified;
            $hidden = $obj->Hidden;
            $disc = $obj->Disc;
            $issearchresult = $obj->isSearchResult;
        }
    } else {
        show_sql_error();
        return false;
    }
    // NOTE: It is imperative that the search results have been tidied up -
    // i.e. there are no 1s or 2s in the database before we do a collection update
    // When doing a search, we MUST NOT change lastmodified of any track, because this will cause
    // user-added tracks to get a lastmodified date, and lastmodified == NULL
    // is how we detect user-added tracks and prevent them being deleted on collection updates
    if ($ttid) {
        if (!$doing_search && $trackobj->tags['Last-Modified'] != $lastmodified || $doing_search && $issearchresult == 0 || $trackobj->tags['Disc'] != $disc && $trackobj->tags['Disc'] !== '' || $hidden != 0) {
            if ($prefs['debug_enabled'] > 6) {
                # Don't bother doing all these string comparisons if debugging is disabled. It's slow.
                debuglog("  Updating track with ttid {$ttid} because :", "MYSQL", 7);
                if (!$doing_search && $lastmodified === null) {
                    debuglog("    LastModified is not set in the database", "MYSQL", 7);
                }
                if (!$doing_search && $trackobj->tags['Last-Modified'] === null) {
                    debuglog("    TrackObj LastModified is NULL too!", "MYSQL", 7);
                }
                if (!$doing_search && $lastmodified != $trackobj->tags['Last-Modified']) {
                    debuglog("    LastModified has changed: We have " . $lastmodified . " but track has " . $trackobj->tags['Last-Modified'], "MYSQL", 7);
                }
                if ($disc != $trackobj->tags['Disc']) {
                    debuglog("    Disc Number has changed: We have " . $disc . " but track has " . $trackobj->tags['Disc'], "MYSQL", 7);
                }
                if ($hidden != 0) {
                    debuglog("    It is hidden", "MYSQL", 7);
                }
            }
            $newsearchresult = 0;
            $newlastmodified = $trackobj->tags['Last-Modified'];
            if ($issearchresult == 0 && $doing_search) {
                $newsearchresult = $hidden != 0 ? 3 : 1;
                debuglog("    It needs to be marked as a search result : Value " . $newsearchresult, "MYSQL", 7);
                $newlastmodified = $lastmodified;
            }
            if ($update_track->execute(array($trackobj->tags['Track'], $trackobj->tags['Time'], $trackobj->tags['Disc'], $newlastmodified, $trackobj->tags['file'], $albumindex, $newsearchresult, $ttid))) {
                $numdone++;
                check_transaction();
            } else {
                show_sql_error();
            }
        }
    } else {
        $a = $trackobj->get_artist_string();
        if ($a != $current_trackartist || $trackartistindex == null) {
            if ($artistname != $a && $a != null) {
                $trackartistindex = check_artist($a, false);
            } else {
                $trackartistindex = $artistindex;
            }
        }
        if ($trackartistindex == null) {
            debuglog("ERROR! Trackartistindex is still null!", "MYSQL_TBT", 1);
            return false;
        }
        $current_trackartist = $a;
        $sflag = $doing_search ? 2 : 0;
        $ttid = create_new_track($trackobj->tags['Title'], null, $trackobj->tags['Track'], $trackobj->tags['Time'], null, null, null, null, null, $trackobj->tags['file'], $trackartistindex, $artistindex, $albumindex, null, null, $trackobj->tags['Last-Modified'], $trackobj->tags['Disc'], null, null, 0, $trackobj->getImage(), $sflag);
        $numdone++;
        check_transaction();
    }
    if ($ttid == null) {
        debuglog("ERROR! No ttid for track " . $trackobj->tags['file'], "MYSQL", 1);
    } else {
        if (!$doing_search) {
            generic_sql_query("INSERT INTO Foundtracks (TTindex) VALUES (" . $ttid . ")", false, false);
        }
    }
}
コード例 #2
0
ファイル: userRatings.php プロジェクト: cyrilix/rompr
     }
     break;
 case 'set':
     if ($artist === null || $title === null || $attributes == null) {
         debuglog("Something is not set", "USERRATING", 1);
         header('HTTP/1.1 400 Bad Request');
         exit(0);
     }
     $ttids = find_item(forcedUriOnly($urionly, getDomain($uri)) ? $uri : null, $title, $artist, $album, $albumartist, forcedUriOnly($urionly, getDomain($uri)));
     if (count($ttids) == 0) {
         // NOTE: This is adding new tracks without putting them through the collectioniser.
         // This is probably OK, since the collectioniser was designed for coping with
         // local files that had bad or partial tags. Stuff coming from online sources
         // is usually OK. I hope.
         check_album_image();
         $ttids[0] = create_new_track($title, $artist, $trackno, $duration, $albumartist, $albumuri, $image, $album, $date, $uri, null, null, null, null, md5($albumartist . " " . $album), null, $disc, null, $uri === null ? "local" : getDomain($uri), 0, $trackimage, 0);
         debuglog("Created New Track with TTindex " . $ttids[0], "USERRATINGS", 5);
     } else {
         if (count($ttids) == 1) {
             // Check to see if the track we've returned is a wishlist track, and update its info
             if ($uri && $album) {
                 check_wishlist_doodads($ttids);
             }
         }
     }
     if (count($ttids) > 0) {
         foreach ($ttids as $ttid) {
             foreach ($attributes as $pair) {
                 $dbg = $pair["value"];
                 if (is_array($pair["value"])) {
                     $dbg = implode($pair["value"], ", ");