public function seemsArtistly($input) { $blacklist = array('various', 'artist', 'artists', 'originalmix', 'unknownartist', 'unbekannterinterpret'); if (isset($blacklist[az09($input)]) === TRUE) { return FALSE; } return TRUE; }
public static function getIdsByString($itemString) { if (trim($itemString) === '') { return array("1"); // Unknown } $app = \Slim\Slim::getInstance(); $classPath = get_called_class(); if (preg_match("/\\\\([^\\\\]*)\$/", $classPath, $m)) { $class = strtolower($m[1]); } else { $class = strtolower($classPath); } if (isset($GLOBALS['unified' . $class . 's']) === FALSE) { if (method_exists($classPath, 'unifyItemnames')) { if (isset($app->config[$class . 's'])) { $GLOBALS['unified' . $class . 's'] = $classPath::unifyItemnames($app->config[$class . 's']); } else { $GLOBALS['unified' . $class . 's'] = array(); } } else { $GLOBALS['unified' . $class . 's'] = array(); } } if (isset($GLOBALS[$class . 'Cache']) === FALSE) { $GLOBALS[$class . 'Cache'] = array(); } $itemIds = array(); $tmpGlue = "tmpGlu3"; foreach (trimExplode($tmpGlue, str_ireplace($app->config[$class . '-glue'], $tmpGlue, $itemString), TRUE) as $itemPart) { $az09 = az09($itemPart); if ($az09 === '' || preg_match("/^hash0x([a-f0-9]{7})\$/", $az09)) { // TODO: is there a chance to translate strings like HASH(0xa54fe70) to an useable string? $itemIds[1] = 1; } else { $artistArticle = ''; foreach (array('The', 'Die') as $matchArticle) { // search for prefixed article if (preg_match("/^" . $matchArticle . " (.*)\$/i", $itemPart, $m)) { $artistArticle = $matchArticle . ' '; $itemPart = $m[1]; $az09 = az09($itemPart); #var_dump($itemString); die('prefixed-article'); } // search for suffixed article if (preg_match("/^(.*)([\\ ,]+)" . $matchArticle . "/i", $itemPart, $m)) { $artistArticle = $matchArticle . ' '; $itemPart = remU($m[1]); $az09 = az09($itemPart); #var_dump($m); die('suffixed-article'); } } // unify items based on config if (array_key_exists($az09, $GLOBALS['unified' . $class . 's']) === TRUE) { $itemPart = $GLOBALS['unified' . $class . 's'][$az09]; $az09 = az09($itemPart); } // check if we alread have an id // permformance improvement ~8% if (isset($GLOBALS[$class . 'Cache'][$az09]) === TRUE) { $itemIds[$GLOBALS[$class . 'Cache'][$az09]] = $GLOBALS[$class . 'Cache'][$az09]; continue; } $query = "SELECT id FROM artist WHERE az09=\"" . $az09 . "\" LIMIT 1;"; $result = $app->db->query($query); $record = $result->fetch_assoc(); if ($record) { $itemId = $record['id']; } else { $g = new $classPath(); $g->setTitle(ucwords(strtolower($itemPart))); $g->setAz09($az09); $g->setArticle($artistArticle); $g->insert(); $itemId = $app->db->insert_id; } $itemIds[$itemId] = $itemId; $GLOBALS[$class . 'Cache'][$az09] = $itemId; } } return $itemIds; }
private static function isVA($input) { switch (az09($input)) { case 'various': case 'variousartist': case 'variousartists': case 'va': return TRUE; } if (preg_match("/(v\\.a\\.|various|various\\ artists|various\\ artist)(?:[ .\\-_]{1,4})(.*)\$/i", $input)) { return TRUE; } return FALSE; }
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; }
function genreUnifier($genreString) { // TODO: convert to tree // https://en.wikipedia.org/wiki/List_of_electronic_music_genres // https://en.wikipedia.org/wiki/List_of_rock_genres // https://en.wikipedia.org/wiki/Heavy_metal_subgenres if (trim($genreString) == '') { return 'Unknown'; } if (preg_match("/^HASH\\((.*)\\)\$/i", $genreString)) { return 'HASH(0xxxxxxxx)'; } $unified = array('Drum & Bass' => array('127', 'db', 'dnb', 'dandb', 'drumbass', 'drumnbass', 'drumandbass', 'drumampbass', 'drumandbassjungle', 'drumnbassjungle', 'rumbass', 'jungle', 'junglednb', 'jungledrumbass', 'jungledrumnbass', 'jungledrumandbass', 'liquid', 'liquiddnb', 'liquiddrumbass', 'liquiddrumnbass', 'liquiddrumandbass', 'jumpup', 'jumpupdnb', 'jumpupdrumbass', 'jumpupdrumnbass', 'jumpupdrumandbass', 'vocaldnb', 'vocaldrumbass', 'vocaldrumnbass', 'vocaldrumandbass'), 'Hip Hop' => array('hiphip'), 'Rap' => array('rap', 'hiphoprap', 'raphiphop'), 'R&B' => array('rb', 'rnb', 'hiphoprb', 'hiphoprnb', 'rnbhiphip'), 'Unknown' => array('unknown', 'genre', 'unknowngenre', 'unbekannt', 'unbekanntesgenre')); $az09 = az09($genreString); foreach ($unified as $beauty => $matches) { foreach ($matches as $match) { if ($az09 === $match) { return $beauty; } } } return ucwords(strtolower($genreString)); }
public static function cleanUpGenreStringArray($input) { $output = array(); if (count($input) == 0) { return array("unknown" => "Unknown"); } // "Unknown" is not necessary in case we have an additiopnal genre-entry if (count($input) > 1 && ($idx = array_search("Unknown", $input))) { unset($input[$idx]); } foreach ($input as $item) { if (strlen($item) < 2) { continue; } $az09 = az09($item); $output[$az09] = $item; if (strtolower($item) == $item) { $output[$az09] = ucwords($item); } if (strtoupper($item) == $item && strlen($item) > 3) { $output[$az09] = ucwords(strtolower($item)); } } // hotfix for bug in parseGenreStringAdvanced() # TODO: fix parseGenreStringAdvanced() and remove these lines if (isset($output['drum']) === TRUE && isset($output['bass']) === TRUE) { unset($output['drum']); unset($output['bass']); $output['drumandbass'] = "Drum & Bass"; } if (isset($output['deep']) === TRUE && isset($output['house']) === TRUE) { unset($output['deep']); $output['deephouse'] = "Deep House"; } return $output; }
function fetchAlbumImages($albumDir, $album_id) { global $cfg, $db, $getID3; $fallBackImage = NJB_HOME_DIR . 'image/no_image.png'; if (is_dir($albumDir) == FALSE) { return array($fallBackImage); } $musicFiles = array(); $imageFiles = array(); $flag = 0; // No image if ($cfg['image_read_embedded'] === TRUE) { // get all files music files of directory $handle = opendir($albumDir); while ($file = readdir($handle)) { $ext = strtolower(preg_replace('/^.*\\./', '', $file)); if (is_file($albumDir . $file) && in_array($ext, $cfg['media_extension']) !== FALSE) { $musicFiles[] = $albumDir . $file; } } closedir($handle); foreach ($musicFiles as $i) { $coverBinary = writeEmbeddedCoverToTempfile($i); if ($coverBinary !== FALSE) { // md5() of extracted images of same album files seems to be different - lets use filesize $imageFiles[filesize($coverBinary)] = $coverBinary; } } } if ($cfg['image_look_current_directory'] === TRUE) { $imageFiles = array_merge($imageFiles, getImages($albumDir)); } if ($cfg['image_look_cover_directory'] === TRUE) { // get all image files of album directory $handle = opendir($albumDir); while ($dirname = readdir($handle)) { if (is_dir($albumDir . $dirname)) { if (in_array(az09($dirname), $cfg['common_artwork_dir_names'])) { $imageFiles = array_merge($imageFiles, getImages($albumDir . $dirname)); } } } closedir($handle); } if ($cfg['image_look_parent_directory'] === TRUE && count($imageFiles) === 0) { $imageFiles = getImages(dirname($albumDir)); } if (count($imageFiles) === 0) { $imageFiles = array($fallBackImage); } $albumUpdated = FALSE; // insert all images into database... foreach ($imageFiles as $image) { $filesize = filesize($image); $filemtime = filemtime($image); $flag = 0; $image_front = ''; $image_back = ''; if (stripos($image, NJB_HOME_DIR) !== FALSE && $image !== $fallBackImage) { $flag = 3; $image_front = str_replace($cfg['media_dir'], '', $image); } $imagesize = @getimagesize($image); if (!$imagesize) { //TODO: logging #message(__FILE__, __LINE__, 'error', '[b]Failed to read image information from:[/b][br]' . $image); error_log('OMPD-import-image error for: ' . $image); } $image_id = $flag == 3 ? $album_id : 'no_image'; $image_id .= '_' . base_convert(NJB_IMAGE_SIZE * 100 + NJB_IMAGE_QUALITY, 10, 36) . base_convert($filemtime, 10, 36) . base_convert($filesize, 10, 36); mysql_query('INSERT INTO bitmap (image, filesize, filemtime, flag, image_front, image_back, image_front_width, image_front_height, image_id, album_id, updated) VALUES ("' . mysql_real_escape_string(resampleImage($image)) . '", ' . (int) $filesize . ', ' . (int) $filemtime . ', ' . (int) $flag . ', "' . mysql_real_escape_string($image_front) . '", "' . mysql_real_escape_string($image_back) . '", ' . ($flag == 3 ? $imagesize[0] : 0) . ', ' . ($flag == 3 ? $imagesize[1] : 0) . ', "' . mysql_real_escape_string($image_id) . '", "' . mysql_real_escape_string($album_id) . '", 1)'); if ($albumUpdated === FALSE) { mysql_query('UPDATE album SET image_id = "' . mysql_real_escape_string($image_id) . '" WHERE album_id = "' . mysql_real_escape_string($album_id) . '" LIMIT 1'); $albumUpdated = TRUE; } if (stripos($image, NJB_HOME_DIR . 'tmp/') === 0) { @unlink($image); } } }