public function searchImagesInFilesystem() { # TODO: in case an image gets replaced with same filename, the database record should get updated $this->jobPhase = 5; $this->beginJob(array('msg' => 'collecting directories to scan from table:albums'), __FUNCTION__); $app = \Slim\Slim::getInstance(); $phpThumb = Bitmap::getPhpThumb(); // make sure that a single directory will not be scanned twice $scannedDirectories = array(); if ($app->config['images']['look_cover_directory'] == TRUE) { $this->pluralizeCommonArtworkDirectoryNames($app->config['images']['common_artwork_dir_names']); } $query = "SELECT count(id) AS itemCountTotal FROM album WHERE lastScan <= filemtime;"; $this->itemCountTotal = (int) $app->db->query($query)->fetch_assoc()['itemCountTotal']; $query = "SELECT id, relativePath, relativePathHash, filemtime FROM album WHERE lastScan <= filemtime;"; $result = $app->db->query($query); $insertedImages = 0; while ($record = $result->fetch_assoc()) { $this->itemCountChecked++; cliLog($record['id'] . ' ' . $record['relativePath'], 2); $this->updateJob(array('msg' => 'processed ' . $this->itemCountChecked . ' files', 'currentItem' => $record['relativePath'], 'insertedImages' => $insertedImages)); $a = new Album(); $a->setId($record['id']); $a->setLastScan(time()); $a->setImportStatus(2); $foundAlbumImages = array(); if ($app->config['images']['look_current_directory']) { // check if have scanned the directory already $images = array_key_exists($record['relativePathHash'], $scannedDirectories) === TRUE ? $scannedDirectories[$record['relativePathHash']] : getDirectoryFiles($app->config['mpd']['musicdir'] . $record['relativePath']); $scannedDirectories[$record['relativePathHash']] = $images; if (count($images) > 0) { $foundAlbumImages = array_merge($foundAlbumImages, $images); } } if ($app->config['images']['look_cover_directory']) { // search for specific named subdirectories if (is_dir($app->config['mpd']['musicdir'] . $record['relativePath']) === TRUE) { $handle = opendir($app->config['mpd']['musicdir'] . $record['relativePath']); while ($dirname = readdir($handle)) { if (is_dir($app->config['mpd']['musicdir'] . $record['relativePath'] . $dirname)) { if (in_array(az09($dirname), $this->commonArtworkDirectoryNames)) { $foundAlbumImages = array_merge($foundAlbumImages, getDirectoryFiles($app->config['mpd']['musicdir'] . $record['relativePath'] . $dirname)); } } } closedir($handle); } } if ($app->config['images']['look_parent_directory'] && count($foundAlbumImages) === 0) { $parentDir = dirname($record['relativePath']) . DS; $parentDirHash = getFilePathHash($parentDir); // check if have scanned the directory already $images = array_key_exists($parentDirHash, $scannedDirectories) === TRUE ? $scannedDirectories[$parentDirHash] : getDirectoryFiles($app->config['mpd']['musicdir'] . $parentDir); $scannedDirectories[$parentDirHash] = $images; if (count($images) > 0) { $foundAlbumImages = array_merge($foundAlbumImages, $images); } } foreach ($foundAlbumImages as $imagePath) { $relativePath = str_replace($app->config['mpd']['musicdir'], '', $imagePath); $relativePathHash = getFilePathHash($relativePath); $imageSize = GetImageSize($app->config['mpd']['musicdir'] . $relativePath); $bitmap = new Bitmap(); $bitmap->setRelativePath($relativePath); $bitmap->setRelativePathHash($relativePathHash); $bitmap->setFilemtime(filemtime($imagePath)); $bitmap->setFilesize(filesize($imagePath)); $bitmap->setAlbumId($record['id']); if ($imageSize !== FALSE) { $bitmap->setWidth($imageSize[0]); $bitmap->setHeight($imageSize[1]); $bitmap->setMimeType($imageSize['mime']); } else { $bitmap->setError(1); } $bitmap->update(); $insertedImages++; } $a->update(); } $this->finishJob(array('msg' => 'processed ' . $this->itemCountChecked . ' directories', 'insertedImages' => $insertedImages), __FUNCTION__); unset($scannedDirectories); return; }
public function run() { // first of all - try to guess if this dir should be // treated as an album or as a bunch of loose tracks // further this method is adding score to several attributes which will be migrated to production db-table $this->setHandleAsAlbum(); #print_r($this->r); cliLog("handleAsAlbumScore " . $this->handleAsAlbumScore, 3, 'purple'); #die(); #if($this->tracks[0]['relativePath'] == 'newroot/crse002cd--Calibre-Musique_Concrete-2CD-CRSE002CD-2001-sour/101-calibre-deep_everytime.mp3') { #print_r($this->r); die(); #} // extract some attributes from tracks // those will be used for album stuff $mergedFromTracks = array('artist' => array(), 'genre' => array(), 'label' => array(), 'catalogNr' => array()); foreach (array_keys($mergedFromTracks) as $what) { foreach ($this->tracks as $idx => $rawTagData) { $mergedFromTracks[$what][] = $this->getMostScored($idx, $what); } $mergedFromTracks[$what][] = $this->getMostScored('album', $what); $mergedFromTracks[$what] = join(',', array_unique($mergedFromTracks[$what])); } $albumArtists = count(trimExplode(",", $mergedFromTracks['artist'])) > 3 ? 'Various Artists' : $mergedFromTracks['artist']; $a = new Album(); $a->setArtistId(join(",", Artist::getIdsByString($albumArtists))); $a->setGenreId(join(",", Genre::getIdsByString($mergedFromTracks['genre']))); #$a->setLabelId(join(",", Label::getIdsByString($mergedFromTracks['label']))); $a->setCatalogNr($this->mostScored['album']['catalogNr']); $a->setRelativePath($this->getRelativeDirectoryPath()); $a->setRelativePathHash($this->getRelativeDirectoryPathHash()); $a->setAdded($this->getDirectoryMtime()); $a->setFilemtime($this->getDirectoryMtime()); $a->setTitle($this->mostScored['album']['title']); $a->setYear($this->mostScored['album']['year']); $a->setIsJumble($this->handleAsAlbum === TRUE ? 0 : 1); $a->setTrackCount(count($this->tracks)); #print_r($a); die(); $a->update(); $albumId = $a->getId(); // add the whole bunch of valid and indvalid attributes to albumindex table $this->updateAlbumIndex($albumId); foreach ($this->tracks as $idx => $rawTagData) { $t = $this->migrateNonGuessableData($rawTagData); $t->setArtistId($this->mostScored[$idx]['artist']); // currently the string insted of an artistId $t->setTitle($this->mostScored[$idx]['title']); $t->setFeaturedArtistsAndRemixers(); # setFeaturedArtistsAndRemixers() is processing: # $t->setArtistId(); # $t->setFeaturingId(); # $t->setRemixerId(); $t->setGenreId(join(",", Genre::getIdsByString($this->getMostScored($idx, 'genre')))); $t->setLabelId(join(",", Label::getIdsByString($this->getMostScored($idx, 'label')))); $t->setCatalogNr($this->mostScored[$idx]['catalogNr']); $t->setDisc($this->mostScored[$idx]['disc']); $t->setNumber($this->mostScored[$idx]['number']); $t->setComment($this->mostScored[$idx]['comment']); $t->setYear($this->mostScored[$idx]['year']); $t->setAlbumId($albumId); // make sure to use identical ids in table:rawtagdata and table:track \Slimpd\Track::ensureRecordIdExists($t->getId()); $t->update(); // make sure extracted images will be referenced to an album \Slimpd\Bitmap::addAlbumIdToTrackId($t->getId(), $albumId); # // add the whole bunch of valid and indvalid attributes to trackindex table $this->updateTrackIndex($t->getId(), $idx); } unset($this->r['album']); if ($this->handleAsAlbum === TRUE) { // try to guess if all tracks of this album has obviously invalid fixable attributes } return; print_r($this->r); #die(); }
$image->dump($imagesize); exit; }); $app->get('/image-' . $imagesize . '/id/:itemId', function ($itemId) use($app, $config, $imagesize) { $image = \Slimpd\Bitmap::getInstanceByAttributes(array('id' => $itemId), 'filesize DESC'); $image = $image === NULL ? \Slimpd\Bitmap::getFallbackImage() : $image; $image->dump($imagesize); }); // missing track or album paramter caused by items that are not imported in slimpd yet # TODO: maybe use another fallback image for those items... $app->get('/image-' . $imagesize . '/album/', function () use($app, $config, $imagesize) { $image = \Slimpd\Bitmap::getFallbackImage(); $image->dump($imagesize); }); $app->get('/image-' . $imagesize . '/track/', function () use($app, $config, $imagesize) { $image = \Slimpd\Bitmap::getFallbackImage(); $image->dump($imagesize); }); } $app->get('/importer(/)', function () use($app, $config) { $config['action'] = 'importer'; $config['servertime'] = time(); $query = "SELECT * FROM importer ORDER BY jobStart DESC,id DESC LIMIT 30;"; $result = $app->db->query($query); while ($record = $result->fetch_assoc()) { $record['jobStatistics'] = unserialize($record['jobStatistics']); $config['itemlist'][] = $record; } $app->render('surrounding.twig', $config); }); $app->get('/importer/triggerUpdate', function () use($app, $config) {