Exemple #1
0
 /**
  * in case we find ranges without gaps add aditional score
  * 
  */
 private function addChronologyScore()
 {
     if (count($this->extractedTrackNumbers) === 0) {
         return;
     }
     $orderedByRelevance = uniqueArrayOrderedByRelevance($this->extractedTrackNumbers);
     if (count($orderedByRelevance) < 2) {
         return;
     }
     $sorted = $this->extractedTrackNumbers;
     sort($sorted);
     $joined = join("", $sorted);
     if (preg_match("/^([0-9]+)\$/", $joined) === 0) {
         # TODO: does it make sense to guess a valid range of A1, AA1,...
         # some labels does not use A,B,... as letteHashrs
         # for now ignore any range but score in case really all extracted tracknumbers are vinyl-schemed
         $isVinylPattern = TRUE;
         foreach ($this->extractedTrackNumbers as $i) {
             if ($this->getNumberScheme($i) !== 'vinyl') {
                 $isVinylPattern = FALSE;
             }
         }
         if ($isVinylPattern === TRUE) {
             $this->handleAsAlbumScore += 3 * count($this->extractedTrackNumbers);
         }
         return;
     }
     $rangeNess = $this->extractNumericRangeness($sorted);
     if (count($rangeNess) === 1) {
         $this->handleAsAlbumScore += 5;
         return;
     }
     // multiple disc releases often has more ranges
     // 101 - 1XX, 201 - 20X
     $discRange = TRUE;
     foreach ($rangeNess as $range) {
         if (preg_match("/^(\\d{1})01-/", $range, $m) === 0) {
             $discRange = FALSE;
         }
     }
     if ($discRange === TRUE) {
         $this->handleAsAlbumScore += 5 * count($this->extractedTrackNumbers);
         return;
     }
     return;
 }
Exemple #2
0
 public function setDefaultLabels($forceAllAlbums = FALSE)
 {
     $app = \Slim\Slim::getInstance();
     $this->jobPhase = 7;
     // check config
     if (isset($app->config['label-parent-directories']) === FALSE) {
         cliLog('aborting setDefaultLabels() no label directories configured', 2);
         return;
     }
     // validate config
     $foundValidDirectories = FALSE;
     foreach ($app->config['label-parent-directories'] as $dir) {
         if (is_dir($app->config['mpd']['musicdir'] . $dir) === FALSE) {
             cliLog('WARNING: label-parent-directory ' . $dir . ' does not exist', 2, 'yellow', 2);
         } else {
             $foundValidDirectories = TRUE;
         }
     }
     if ($foundValidDirectories === FALSE) {
         cliLog('aborting setDefaultLabels() no valid label directories configured', 2, 'red');
         return;
     }
     $this->beginJob(array('currentItem' => "fetching all track-labels for inserting into table:album ..."), __FUNCTION__);
     foreach ($app->config['label-parent-directories'] as $labelDir) {
         if (substr($labelDir, -1) !== DS) {
             $labelDir .= DS;
         }
         // append trailingSlash
         $query = "SELECT count(id) as itemCountTotal FROM track WHERE relativePath LIKE \"" . $labelDir . "%\" ";
         $this->itemCountTotal += $app->db->query($query)->fetch_assoc()['itemCountTotal'];
         $msg = "found " . $this->itemCountTotal . " to check";
         cliLog($msg, 2);
     }
     $updatedTracks = 0;
     foreach ($app->config['label-parent-directories'] as $labelDir) {
         if (substr($labelDir, -1) !== DS) {
             $labelDir .= DS;
         }
         // append trailingSlash
         $query = "SELECT id, labelId, relativePath FROM track WHERE relativePath LIKE \"" . $labelDir . "%\"";
         $result = $app->db->query($query);
         $counter = 0;
         $previousLabelString = "";
         $existingLabelIdsInDir = array();
         $updateTrackIds = array();
         while ($t = $result->fetch_assoc()) {
             $labelDirname = explode(DS, substr($t['relativePath'], strlen($labelDir)), 2);
             $labelDirname = $labelDirname[0];
             $counter++;
             $this->itemCountChecked++;
             if ($t['labelId'] == '' || $t['labelId'] == '1') {
                 $updateTrackIds[] = $t['id'];
                 $updatedTracks++;
             }
             if ($counter === 1) {
                 $previousLabelString = $labelDirname;
                 $existingLabelIdsInDir = array_merge($existingLabelIdsInDir, trimExplode(",", $t['labelId'], TRUE));
                 continue;
             }
             if ($labelDirname != $previousLabelString) {
                 // extract the most used label-id
                 $existingLabelIdsInDir = uniqueArrayOrderedByRelevance($existingLabelIdsInDir);
                 $foundMatchingDatabaseLabelId = FALSE;
                 // remove "Unknown Label (id=1)"
                 if (($key = array_search('1', $existingLabelIdsInDir)) !== false) {
                     unset($existingLabelIdsInDir[$key]);
                 }
                 if (count($existingLabelIdsInDir) > 0) {
                     $existingLabelId = array_shift($existingLabelIdsInDir);
                     $databaseLabel = \Slimpd\Label::getInstanceByAttributes(array('id' => $existingLabelId));
                     if (az09($previousLabelString) == $databaseLabel->getAz09()) {
                         $foundMatchingDatabaseLabelId = $databaseLabel->getId();
                         // everything is fine - we already have a label id
                         #$msg = "GOOD: directory: " . $previousLabelString . " matches database-label:" . $databaseLabel->getTitle();
                         #echo $msg . "\n";
                     } else {
                         // try to replace common substitutions
                         $teststring = str_replace(array("_", " and ", " point "), array(" ", " & ", " . "), $previousLabelString);
                         if (az09($teststring) == $databaseLabel->getAz09()) {
                             $foundMatchingDatabaseLabelId = $databaseLabel->getId();
                             #$msg = "GOOD: directory: " . $previousLabelString . " matches database-label:" . $databaseLabel->getTitle();
                         } else {
                             #$msg = "BAD: directory: " . $previousLabelString . " does NOT match database-label:" . $databaseLabel->getTitle();
                             #echo $msg . "\n";
                             #print_r($existingLabelIdsInDir);
                         }
                     }
                 }
                 if ($foundMatchingDatabaseLabelId === FALSE) {
                     $newLabelString = ucwords(str_replace("_", " ", $previousLabelString));
                     $msg = "generating labelstring from dirname: " . $newLabelString;
                     $foundMatchingDatabaseLabelId = join(",", \Slimpd\Label::getIdsByString($newLabelString));
                 } else {
                     $msg = "updating with ID: " . $foundMatchingDatabaseLabelId;
                 }
                 cliLog($msg, 3);
                 // update all tracks with labelId's
                 if (count($updateTrackIds) > 0) {
                     $query = "UPDATE track SET labelId=\"" . $foundMatchingDatabaseLabelId . "\"\n\t\t\t\t\t\t\tWHERE id IN (" . join(",", $updateTrackIds) . ")";
                     $app->db->query($query);
                 }
                 $this->updateJob(array('updatedTracks' => $updatedTracks, 'currentItem' => 'directory: ' . $t['relativePath'] . ' ' . $msg));
                 $previousLabelString = $labelDirname;
                 $existingLabelIdsInDir = trimExplode(",", $t['labelId'], TRUE);
                 $updateTrackIds = array();
             }
             $this->itemCountProcessed++;
         }
     }
     $this->finishJob(array('updatedTracks' => $updatedTracks), __FUNCTION__);
     return;
 }