예제 #1
0
 function getSubpart($template, $part)
 {
     //		debug($template, $part);
     $parts = trimExplode($part, $template);
     $templatePart = ifsetor($parts[1]);
     return $templatePart;
 }
예제 #2
0
 public function getDirectoryContent($d)
 {
     $app = \Slim\Slim::getInstance();
     // append trailing slash if missing
     $d .= substr($d, -1) !== DS ? DS : '';
     $base = $app->config['mpd']['musicdir'];
     $d = $d === $base ? '' : $d;
     if (is_dir($base . $d) === FALSE) {
         //} || $this->checkAccess($d, $baseDirs) === FALSE) {
         \Slim\Slim::getInstance()->notFound();
     }
     // avoid path disclosure outside relevant directories
     $realpath = realpath($base . $d) . DS;
     if (stripos($realpath, $app->config['mpd']['musicdir']) !== 0 && stripos($realpath, $app->config['mpd']['alternative_musicdir']) !== 0) {
         var_dump($realpath);
         die;
         \Slim\Slim::getInstance()->notFound();
     }
     $this->directory = $d;
     $bread = trimExplode(DS, $d, TRUE);
     $breadgrow = "";
     foreach ($bread as $part) {
         $breadgrow .= DS . $part;
         $this->breadcrumb[] = new _Directory($breadgrow);
     }
     //if($this->checkAccess($d) === FALSE) {
     //	die('sorry, you are not allowed to view this directory 8==========D');
     //}
     $files = scandir($base . $d);
     natcasesort($files);
     if (count($files) > 2) {
         /* The 2 accounts for . and .. */
         foreach ($files as $file) {
             if (file_exists($base . $d . $file) && $file != '.' && $file != '..' && substr($file, 0, 1) !== '.') {
                 if (is_dir($base . $d . $file) === TRUE) {
                     $this->subDirectories[] = new _Directory($d . $file);
                 } else {
                     $this->files[] = new File($d . $file);
                 }
             }
         }
     }
     #echo "<pre>" . print_r($this,1); die();
     #echo json_encode($data);
     return;
 }
예제 #3
0
 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;
 }
예제 #4
0
 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();
 }
예제 #5
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;
 }
예제 #6
0
 public function setFeaturedArtistsAndRemixers()
 {
     $artistBlacklist = \Slimpd\Artist::getArtistBlacklist();
     $inputArtistString = $this->getArtistId();
     $inputTitleString = $this->getTitle();
     $regexFeat = "/([\\ \\(\\[])featuring\\ |([\\ \\(\\[])ft(.?)\\ |([\\ \\(\\[])feat(.?)\\ |([\\ \\(\\[])ft\\.|([\\ \\(\\[])feat\\./i";
     $regexArtist = "/,|&amp;|\\ &\\ |\\ and\\ |&|\\ n\\'\\ |\\ vs(.?)\\ |\\ versus\\ |\\ with\\ |\\ meets\\ |\\  w\\/|\\.and\\.|\\ aka\\ |\\ b2b\\ |\\//i";
     $regexRemix = "/(.*)\\((.*)(\\ remix|\\ mix|\\ rework|\\ rmx|\\ re-edit|\\ re-lick|\\ vip|\\ remake)/i";
     $regexRemix2 = "/(.*)\\((remix\\ by\\ |remixed\\ by\\ |remixedby\\ )(.*)?\\)/i";
     #$regexRemix = "/(.*)\(((.*)(\ remix|\ mix|\ rework|\ rmx))|(remixed\ by\ (.*))/i";
     $regularArtists = array();
     $featuredArtists = array();
     $remixerArtists = array();
     $titlePattern = '';
     #$artistString = "Ed Rush & Optical (Featuring Tali";
     #$artistString = "Swell Session & Berti Feat. Yukimi Nagano AND Adolf)";
     #$artistString = "Ed Rush & Optical ft Tali";
     #$titleString = "The Allenko Brotherhood Ensemble Tony Allen Vs Son Of Scientists (Featuring Eska) - The Drum";
     #$titleString = "Don't Die Just Yet (The Holiday Girl-Arab Strap Remix)";
     #$titleString = "Something About Love (Original Mix)";
     #$titleString = "Channel 7 (Sutekh 233 Channels Remix)";
     #$titleString = "Levels (Cazzette`s NYC Mode Radio Mix)";
     #$titleString = "fory one ways (david j & dj k bass bomber remix)";
     #$titleString = "Music For Bagpipes (V & Z Remix)";
     #$titleString = "Ballerino _Original Mix";
     #$titleString = "to ardent feat. nancy sinatra (horse meat disco remix)";
     #$titleString = "Crushed Ice (Remix)";
     #$titleString = "Hells Bells (Gino's & Snake Remix)";
     #$titleString = "Hot Love (DJ Koze 12 Inch Mix)";
     #$titleString = "Skeleton keys (Omni Trio remix";
     #$titleString = "A Perfect Lie (Theme Song)(Gabriel & Dresden Remix)";
     #$titleString = "Princess Of The Night (Meyerdierks Digital Exclusiv Remix)";
     #$titleString = "Hello Piano (DJ Chus And Sharp & Smooth Remix)";
     #$titleString = "De-Phazz feat. Pat Appleton / Mambo Craze [Extended Version]";
     #$titleString = "Toller titel (ft ftartist a) (RemixerA & RemixerB Remix)";
     #$titleString = "Toller titel (RemixerA & RemixerB Remix) (ft ftartist a)";
     #$titleString = "Been a Long Time (Axwell Unreleased Remix)";
     #$titleString = "Feel 2009 (Deepside Deejays Rework)";
     #$titleString = "Jeff And Jane Hudson - Los Alamos";
     #TODO: $titleString = "Movement (Remixed By Lapsed & Nonnon";
     #TODO: $artistString = "Lionel Richie With Little Big Town";
     #TODO: $artistString = "B-Tight Und Sido";
     #TODO: $artistString = "James Morrison (feat. Jessie J)" // check why featArt had not been extracted
     #TODO: $titleString = "Moving Higher (Muffler VIP Mix)"
     #TODO: $titleString = "Time To Remember - MAZTEK Remix"
     # common errors in extracted artists
     # Rob Mello No Ears Vocal
     # Robin Dubstep
     # Rob Hayes Club
     # Robert Owens Full Version
     # Robert Owens - Marcus Intalex remix
     # Robert Rivera Instrumental
     # Robert Owens Radio Edit
     # Rocky Nti - Chords Remix
     # Roc Slanga Album Versio
     # Rosanna Rocci with Michael Morgan
     # Bob Marley with Mc Lyte
     # AK1200 with MC Navigator
     # Marcus Intalex w/ MC Skibadee
     # Mixed By Krafty Kuts
     # Mixed by London Elektricity
     # VA Mixed By Juju
     # Va - Mixed By DJ Friction
     # Written By Patrick Neate
     # Charles Webster Main Vocal
     # Various
     # 01 - Bryan Gee
     # 03 - DJ Hazard
     # Andy C presents Ram Raiders
     # London Elektricity/Landslide
     # Brockie B2B Mampi Swift
     # Matty Bwoy (Sta remix)
     # Va - Womc - Disc 2
     # LTJ Bukem Presents
     # V.A.(Mixed By Nu:Tone f.SP MC)
     # 6Blocc_VS._R.A.W.
     # Goldie (VIP Mix)
     # Top Buzz Present Jungle Techno
     # VA (mixed by The Green Man)
     # VA (mixed by Tomkin
     # VA - Knowledge presents
     # VA - Subliminal Volume 1
     # Special Extended
     # Original 12-Inch Disco
     # Actually Extended
     # El Bosso meets the Skadiolas
     # Desmond Dekker/The Specials
     # Flora Paar - Yapacc rework - bonus track version
     # feat Flora Paar - Yapacc
     # Helena Majdeaniec i Czerwono Czarni
     # Maciej Kossowski i Czerwono Czarni
     # DJ Sinner - Original DJ
     # Victor Simonelli Presents Solution
     # Full Continous DJ
     # Robag Wruhme Mit Wighnomy Brothers Und Delhia
     # Sound W/ Paul St. Hilaire
     # (Thomas Krome Remix)
     # (Holy Ghost Remix)
     # D-Region Full Vocal
     #######################################################
     # special remixer Strings - currently ignored at all
     # TODO: try to extract relevant data
     #######################################################
     # Prins Thomas, Lindstrom
     # WWW.TRANCEDL.COM
     # James Zabiela/Guy J
     # With - D. Mark
     # Featuring - Kate's Propellers
     # Vocals - Mike Donovan
     # Recorded By [Field Recording] - David Franzke
     # Guitar - D. Meteo *
     # Remix - Burnt Friedman *
     # Double Bass - Akira Ando Saxophone - Elliott Levin
     # Piano - Kiwi Menrath
     # Featuring - MC Soom-T
     # Featuring - MC Soom-T Remix - Dabrye
     # Featuring - Lady Dragon, Sach
     # Electric Piano - Kiwi Menrath
     # Co-producer - Thomas Fehlmann
     # Producer - Steb Sly Vocals - Shawna Sulek
     # Edited By - Dixon
     # Producer [Additional] - Oren Gerlitz, Robot Koch Producer [Additional], Lyrics By [Additional] - Sasha Perera Remix - Jahcoozi
     # Bass [2nd] - Matt Saunderson
     # Producer [Additional], Remix - Glimmers, The
     # Remix, Producer [Additional] - Âme
     # Keyboards [Psyche Keys] - Daves W.
     # Co-producer - Usual Suspects, The (2)
     # Fancy Guitar Solo - Tobi Neumann
     # 4DJsonline.com
     # [WWW.HOUSESLBEAT.COM]
     # Backing Vocals - Clara Hill, Nadir Mansouri Mixed By - Axel Reinemer
     # Edited By - Dixon, Phonique Remix - DJ Spinna
     # Bass - Magic Number Clarinet [Bass], Flugelhorn, Flute, Trumpet, Arranged By [Horns] - Pete Wraight Remix - Atjazz Saxophone [Soprano] - Dave O'Higgins
     # Remix - Slapped Eyeballers, The Vocals - Kink Artifishul
     # Vocals [Featuring], Written By [Lyrics] - Rich Medina
     # RemixedBy: PTH Projects
     # AdditionalProductionBy: Simon Green
     # Simple Jack Remix, Amine Edge & DANCE Edit
     # http://toque-musicall.blogspot.com
     # Vocals [Featuring] - Laura Darlington
     # Mohammed Yousuf (Arranged By); Salim Akhtar (Bass); Salim Jaffery (Drums); Arif Bharoocha (Guitar); Mohammed Ali Rashid (Organ)
     # Eric Fernandes (Bass); Ahsan Sajjad (Drums, Lead Vocals); Norman Braganza (Lead Guitar); Fasahat Hussein Syed (Sitar, Keyboards, Tabla)
     # RemixedBy: Parov Stelar & Raul Irie/AdditionalProductionBy: Parov Stelar & Raul Irie
     # RemixedBy: Roland Schwarz & Parov Stelar
     # Engineer [Additional], Mixed By [Additional] - Tobi Neumann Vocals - Dinky
     # Vocals, Guitar - Stan Eknatz
     #$artistString = "Ed Rush & Optical (Featuring Tali";
     #$artistString = "Swell Session & Berti Feat. Yukimi Nagano AND Adolf)";
     #$artistString = "Ed Rush & Optical ft Tali";
     #$titleString = "The Allenko Brotherhood Ensemble Tony Allen Vs Son Of Scientists (Featuring Eska) - The Drum";
     #$titleString = "Don't Die Just Yet (The Holiday Girl-Arab Strap Remix)";
     #$titleString = "Something About Love (Original Mix)";
     #$titleString = "Channel 7 (Sutekh 233 Channels Remix)";
     #$titleString = "Levels (Cazzette`s NYC Mode Radio Mix)";
     #$titleString = "fory one ways (david j & dj k bass bomber remix)";
     #$titleString = "Music For Bagpipes (V & Z Remix)";
     #$titleString = "Ballerino _Original Mix";
     #$titleString = "to ardent feat. nancy sinatra (horse meat disco remix)";
     #$titleString = "Crushed Ice (Remix)";
     #$titleString = "Hells Bells (Gino's & Snake Remix)";
     #$titleString = "Hot Love (DJ Koze 12 Inch Mix)";
     #$titleString = "Skeleton keys (Omni Trio remix";
     #$titleString = "A Perfect Lie (Theme Song)(Gabriel & Dresden Remix)";
     #$titleString = "Princess Of The Night (Meyerdierks Digital Exclusiv Remix)";
     #$titleString = "Hello Piano (DJ Chus And Sharp & Smooth Remix)";
     #$titleString = "De-Phazz feat. Pat Appleton / Mambo Craze [Extended Version]";
     #$titleString = "Toller titel (ft ftartist a) (RemixerA & RemixerB Remix)";
     #$titleString = "Toller titel (RemixerA & RemixerB Remix) (ft ftartist a)";
     #$titleString = "Been a Long Time (Axwell Unreleased Remix)";
     #$titleString = "Feel 2009 (Deepside Deejays Rework)";
     #$titleString = "Jeff And Jane Hudson - Los Alamos";
     #TODO: $titleString = "Movement (Remixed By Lapsed & Nonnon";
     #TODO: $artistString = "Lionel Richie With Little Big Town";
     #TODO: $artistString = "B-Tight Und Sido";
     #TODO: $artistString = "James Morrison (feat. Jessie J)" // check why featArt had not been extracted
     #TODO: $titleString = "Moving Higher (Muffler VIP Mix)"
     #TODO: $titleString = "Time To Remember - MAZTEK Remix"
     $tests = array(array("placeholder index 0"), array("Stel", "Your Parents Are Here (Ian F. Remix)", "Stel_-_Your_Parents_Are_Here-(JLYLTD015)-WEB-2009-WiTF"), array("Shotgun Club", "Fake Fake", "08_shotgun_club-fake_fake.mp3", "Shotgun_Club-Love_Under_The_Gun-2011-FWYH"), array("Friction", "Long Gone Memory (Ft. Arlissa) (Ulterior Motive Remix)"), array("Friction", "Long Gone Memory Ft Arlissa & Gandalf Stein (Extended Mix)"), array("Friction", "Long Gone Memory with Arlissa & Gandalf Stein (Extended Mix"), array("Friction", "Long Gone Memory (Ulterior Motive Remix) [feat. Arlissa]"), array("Friction", "Long Gone Memory [feat. Arlissa] (Ulterior Motive Remix)"), array("Friction", "fory one ways (david j & dj k bass bomber remix)"), array("Ed Rush & Optical (Featuring Tali", "Hells Bells (Gino's & Snake Remix)"), array("James Morrison (feat. Jessie J)", "Hot Love (DJ Koze 12 Inch Mix)"), array("Swell Session & Berti Feat. Yukimi Nagano AND Adolf)", "Feel 2009 (Deepside Deejays Rework)"), array("DJ Hidden", "The Devil's Instant (DJ Hidden's Other Side Remix)"), array("DJ Hidden", "Movement (Remixed By Lapsed & Nonnon"), array("The Prototypes", "Rage Within (ft.Takura) (Instrumental Mix)"), array("Bebel Gilberto", "So Nice (DJ Marky Radio Edit)"), array("High Contrast", "Basement Track (High Contrasts Upstairs Downstairs Remix)"), array("Shy FX & T-Power", "Don't Wanna Know (Feat Di & Skibadee Dillinja Remix)"), array("L'Aventure Imaginaire", "L'Aventure Imaginaire - Athen"), array("", "", "Apache_Indian-Chudi_jo_Khanki_Hath_o_Meri.mp3", "Apache_Indian"), array("My mega artistname ft. Hansbert", "Time To Remember - MAZTEK Remix"), array("", "", "05-Woody_Allen-Martha_(Aka_Mazie).mp3", "Woody_Allen_and_His_New_Orleans_Jazz_Band-Wild_Man_Blues_(1998_Film)"), array("Cutty Ranks", "Eye For An Eye f Wayne Marshal"), array("Henrik Schwarz / Ame / Dixon", "where we at (version 3)"), array("Henrik Schwarz /wDixon", "where we at (version 3)"), array("Jo-S", "Snicker - Original Mix"), array("SECT, The", "Tyrant"), array("Machine Code", "Milk Plus (vs Broken Note)"), array("Torqux", "Blazin' (feat. Lady Leshurr) (Extended Club Mix)"), array("", "", "01_El_Todopoderoso.mp3", "FANIA_MASTERWORKS-HECTOR_LAVOE____LA_VOZ____(USA2009)___(320k)"), array("fela kuti", "03. gentleman - edit version", "03._gentleman-edit_version.mp3", "cd_1_(128k)"), array("Various", "John Beltran featuring Sol Set / Aztec Girl", "03-John_Beltran_featuring_Sol_Set___Aztec_Girl.mp3", "earthcd004--va-earth_vol_4-2000"), array("T Power", "The Mutant Remix - Rollers Instinct (DJ Trace remix)"), array("The Vision", "Back In The Days (ft.Buggsy & Shadz & Scarz & Double KHK-SP)"), array("Crystal Clear", "No Sell Out (Xample & Sol Remi", "a_crystal_clear-no_sell_out_(xample_and_sol_remix).mp3", "iap001--industry_artists-crystal_clear_vs_xample_and_sol-iap001-vinyl-2005-obc"), array("Infuze", "Black Out (with TADT)"));
     $performTest = 0;
     if ($performTest > 0) {
         $inputArtistString = $tests[$performTest][0];
         $inputTitleString = $tests[$performTest][1];
         if (isset($tests[$performTest][2])) {
             $inputFileName = $tests[$performTest][2];
         }
         if (isset($tests[$performTest][3])) {
             $inputDirectoryName = $tests[$performTest][3];
         }
     }
     $artistString = $inputArtistString;
     $titleString = $inputTitleString;
     // in case we dont have artist nor title string take the filename as a basis
     if ($artistString == "" && $titleString == "") {
         if ($this->getRelativePath() !== "") {
             $titleString = preg_replace('/\\.[^.\\s]{3,4}$/', '', basename($this->getRelativePath()));
             $titleString = str_replace("_", " ", $titleString);
         }
     }
     // in case artist string is missing try to get it from title string
     if ($artistString == "" && $titleString != "") {
         $tmp = trimExplode(" - ", $titleString, TRUE, 2);
         if (count($tmp) == 2) {
             $artistString = $tmp[0];
             $titleString = $tmp[1];
         }
     }
     // in case title string is missing try to get it from artist string
     if ($artistString != "" && $titleString == "") {
         $tmp = trimExplode(" - ", $artistString, TRUE, 2);
         if (count($tmp) == 2) {
             $artistString = $tmp[0];
             $titleString = $tmp[1];
         }
     }
     $artistString = str_replace(array("[", "]"), array("(", ")"), $artistString);
     $titleString = str_replace(array("[", "]"), array("(", ")"), $titleString);
     // replace multiple whitespace with a single whitespace
     $artistString = preg_replace('!\\s+!', ' ', $artistString);
     $titleString = preg_replace('!\\s+!', ' ', $titleString);
     // assign all string-parts to category
     $groupFeat = "([\\ \\(])(featuring|ft(?:.?)|feat(?:.?))\\ ";
     $groupFeat2 = "([\\ \\(\\.])(feat\\.|ft\\.|f\\.)";
     // without trailing whitespace
     $groupGlue = "/&amp;|\\ &\\ |\\ and\\ |&|\\ n\\'\\ |\\ vs(.?)\\ |\\ versus\\ |\\ with\\ |\\ meets\\ |\\  w\\/\\ /i";
     if ($artistString == "") {
         $regularArtists[] = "Unknown Artist";
     }
     // parse ARTIST string for featured artists REGEX 1
     if (preg_match("/(.*)" . $groupFeat . "([^\\(]*)(.*)\$/i", $artistString, $m)) {
         $sFeat = trim($m[4]);
         if (substr($sFeat, -1) == ')') {
             $sFeat = substr($sFeat, 0, -1);
         }
         $artistString = str_replace($m[2] . $m[3] . ' ' . $m[4], " ", $artistString);
         $featuredArtists = array_merge($featuredArtists, preg_split($regexArtist, $sFeat));
     }
     // parse ARTIST string for featured artists REGEX 2
     if (preg_match("/(.*)" . $groupFeat2 . "([^\\(]*)(.*)\$/i", $artistString, $m)) {
         $sFeat = trim($m[4]);
         if (substr($sFeat, -1) == ')') {
             $sFeat = substr($sFeat, 0, -1);
         }
         $artistString = str_replace($m[2] . $m[3] . $m[4], " ", $artistString);
         $featuredArtists = array_merge($featuredArtists, preg_split($regexArtist, $sFeat));
     }
     $regularArtists = array_merge($regularArtists, preg_split($regexArtist, $artistString));
     // parse TITLE string for featured artists REGEX 1
     if (preg_match("/(.*)" . $groupFeat . "([^\\(]*)(.*)\$/i", $titleString, $m)) {
         $sFeat = trim($m[4]);
         if (substr($sFeat, -1) == ')') {
             $sFeat = substr($sFeat, 0, -1);
         }
         if (isset($artistBlacklist[strtolower($sFeat)]) === FALSE) {
             $titleString = str_replace($m[2] . $m[3] . ' ' . $m[4], " ", $titleString);
             $featuredArtists = array_merge($featuredArtists, preg_split($regexArtist, $sFeat));
         }
     }
     // parse TITLE string for featured artists REGEX 2
     if (preg_match("/(.*)" . $groupFeat2 . "([^\\(]*)(.*)\$/i", $titleString, $m)) {
         #print_r($m); die();
         $sFeat = trim($m[4]);
         if (substr($sFeat, -1) == ')') {
             $sFeat = substr($sFeat, 0, -1);
         }
         if (isset($artistBlacklist[strtolower($sFeat)]) === FALSE) {
             $titleString = str_replace($m[2] . $m[3] . $m[4], " ", $titleString);
             $featuredArtists = array_merge($featuredArtists, preg_split($regexArtist, $sFeat));
         }
     }
     // parse title string for remixer regex 1
     if (preg_match($regexRemix, $titleString, $m)) {
         $remixerArtists = array_merge($remixerArtists, preg_split($regexArtist, $m[2]));
     }
     // parse title string for remixer regex 1
     if (preg_match($regexRemix2, $titleString, $m)) {
         #print_r($m); die();
         $remixerArtists = array_merge($remixerArtists, preg_split($regexArtist, $m[3]));
     }
     // clean up extracted remixer-names with common strings
     $tmp = array();
     foreach ($remixerArtists as $remixerArtist) {
         if (isset($artistBlacklist[strtolower($remixerArtist)]) === TRUE) {
             continue;
         }
         $tmp[] = str_ireplace($artistBlacklist, "", $remixerArtist);
     }
     $remixerArtists = $tmp;
     // clean up extracted featuring-names with common strings
     $tmp = array();
     foreach ($featuredArtists as $featuredArtist) {
         if (isset($artistBlacklist[strtolower($featuredArtist)]) === TRUE) {
             continue;
         }
         $tmp[] = str_ireplace($artistBlacklist, "", $featuredArtist);
     }
     $featuredArtists = $tmp;
     $regularArtists = array_unique(array_filter($regularArtists));
     $featuredArtists = array_unique($featuredArtists);
     $remixerArtists = array_unique($remixerArtists);
     // to avoid incomplete substitution caused by partly artistname-matches sort array by length DESC
     $allArtists = array_merge($regularArtists, $featuredArtists, $remixerArtists);
     usort($allArtists, 'sortHelper');
     $titlePattern = str_ireplace($allArtists, "%s", $titleString);
     // remove possible brackets from featuredArtists
     #$tmp = array();
     #foreach($featuredArtists as $featuredArtist) {
     #	$tmp[] = str_replace(array("(", ")"), "", $featuredArtist);
     #}
     #$featuredArtists = $tmp;
     if (substr_count($titlePattern, "%s") !== count($remixerArtists)) {
         // oh no - we have a problem
         // reset extracted remixers
         $titlePattern = $titleString;
         $remixerArtists = array();
     }
     /* TODO: do we need this?
     		// remove " (" from titlepattern in case that are the last 2 chars
     		if(preg_match("/(.*)\ \($/", $titlePattern, $m)) {
     			$titlePattern = $m[1];
     		}
     		*/
     // clean up artist names
     // unfortunately there are artist names like "45 Thieves"
     $regularArtists = $this->removeLeadingNumbers($regularArtists);
     $featuredArtists = $this->removeLeadingNumbers($featuredArtists);
     $remixerArtists = $this->removeLeadingNumbers($remixerArtists);
     $this->setArtistId(join(",", Artist::getIdsByString(join(" & ", $regularArtists))));
     if (count($featuredArtists) > 0) {
         $this->setFeaturingId(join(",", Artist::getIdsByString(join(" & ", $featuredArtists))));
     } else {
         # TODO: currently empty values are ignored in AbstractModel::update()
         # this is relevant for old exisiting database-items which already have an invalid featuringId-value
         $this->setFeaturingId('');
     }
     if (count($remixerArtists) > 0) {
         $this->setRemixerId(join(",", Artist::getIdsByString(join(" & ", $remixerArtists))));
     } else {
         # TODO: currently empty values are ignored in AbstractModel::update()
         # this is relevant for old exisiting database-items which already have an invalid remixerId-value
         $this->setRemixerId('');
     }
     // replace multiple whitespace with a single whitespace
     $titlePattern = preg_replace('!\\s+!', ' ', $titlePattern);
     // remove whitespace before bracket
     $titlePattern = str_replace(' )', ')', $titlePattern);
     $this->setTitle($titlePattern);
     return;
     echo "inputArtist: " . $inputArtistString . "\n";
     echo "inputTitle: " . $inputTitleString . "\n";
     echo "regular: " . print_r($regularArtists, 1);
     echo "feat: " . print_r($featuredArtists, 1);
     echo "remixer: " . print_r($remixerArtists, 1);
     echo "titlePattern: " . $titlePattern . "\n";
     die;
 }
예제 #7
0
 public static function parseGenreStringAdvanced($itemString)
 {
     $app = \Slim\Slim::getInstance();
     $finalGenres = array();
     if (trim($itemString) === '') {
         $finalGenres['unknown'] = "Unknown";
         debugLog("Phase 0: nothing to do with an emty string. result: " . join(", ", $finalGenres));
         return $finalGenres;
     }
     if (preg_match("/^hash0x([a-f0-9]{7})\$/", az09($itemString))) {
         // TODO: is there a chance to translate strings like HASH(0xa54fe70) to an useable string?
         $finalGenres['unknown'] = "Unknown";
         debugLog("Phase 0: nothing to do with an useleass hassh string. result: " . join(", ", $finalGenres));
         return $finalGenres;
     }
     $originalItemString = $itemString;
     // TODO: lets see if we need it anymore...
     $itemString = str_replace(array("(", ")", "[", "]", "{", "}", "<", ">"), " ", $itemString);
     // phase 1: check if we already have a common genre
     debugLog("----------");
     debugLog("Phase 1: with genreString: {$originalItemString}");
     $az09 = az09($itemString);
     if (isset($GLOBALS['unifiedCommonGenres'][$az09])) {
         $finalGenres[] = $GLOBALS['unifiedCommonGenres'][$az09];
         debugLog("exiting in phase 1 with result: " . join(", ", $finalGenres));
         return $finalGenres;
     }
     // phase 2: check if we have multiple common genres
     $tmpGlue = "tmpGlu3";
     $badChunk = FALSE;
     debugLog("Phase 2");
     $chunks = trimExplode($tmpGlue, str_ireplace($app->config['genre-glue'], $tmpGlue, $itemString), TRUE);
     foreach ($chunks as $chunk) {
         $az09 = az09($chunk);
         if (isset($GLOBALS['unifiedCommonGenres'][$az09])) {
             $finalGenres[$az09] = $GLOBALS['unifiedCommonGenres'][$az09];
             $itemString = str_ireplace($chunk, "", $itemString);
             debugLog("FINAL-CHUNK: {$chunk} = " . $finalGenres[$az09]);
         } else {
             // very fuzzy check if we have an url
             if (preg_match("/^(http|www)([a-z0-9\\.\\/\\:]*)\\.[a-z]{2,4}\$/i", $chunk)) {
                 $itemString = str_ireplace($chunk, "", $itemString);
                 debugLog("TRASHING url-chunk: {$chunk}");
                 continue;
             }
             // very fuzzy check if we have an url
             if (preg_match("/(myspace|blogspot).com\$/i", $chunk)) {
                 $itemString = str_ireplace($chunk, "", $itemString);
                 debugLog("TRASHING: trash url-chunk: {$chunk}");
                 continue;
             }
             debugLog("BAD-CHUNK: {$chunk} - entering phase 3...");
             $badChunk = TRUE;
         }
     }
     if ($badChunk === FALSE) {
         debugLog("exiting in phase 2 with result: " . join(", ", $finalGenres));
         return $finalGenres;
     }
     #print_r($app->config['genre-replace-chunks']); die();
     // phase 3: tiny chunks
     # TODO: would camel-case splitting make sense?
     debugLog("Phase 3");
     $splitBy = array_merge($app->config['genre-glue'], array(" ", "-", ".", "_", ""));
     $badChunk = FALSE;
     $chunks = trimExplode($tmpGlue, str_ireplace($splitBy, $tmpGlue, $itemString), TRUE);
     foreach ($chunks as $chunk) {
         $az09 = az09($chunk);
         if (isset($app->config['genre-replace-chunks'][$az09])) {
             $itemString = str_ireplace($chunk, $app->config['genre-replace-chunks'][$az09], $itemString);
             debugLog("REPLACING {$chunk} with: " . $app->config['genre-replace-chunks'][$az09]);
         }
         if (isset($app->config['genre-remove-chunks'][$az09])) {
             $itemString = str_ireplace($chunk, "", $itemString);
             debugLog("REMOVING: trash url-chunk: {$chunk}");
             continue;
         }
         if (isset($GLOBALS['unifiedCommonGenres'][$az09])) {
             $finalGenres[$az09] = $GLOBALS['unifiedCommonGenres'][$az09];
             $itemString = str_ireplace($chunk, "", $itemString);
             debugLog("FINAL-CHUNK: {$chunk} = " . $finalGenres[$az09]);
         } else {
             if (trim(az09($chunk)) !== '' && trim(az09($chunk)) !== 'and') {
                 debugLog("BAD-CHUNK: {$chunk} - entering phase 4...");
                 $badChunk = TRUE;
             }
         }
     }
     if ($badChunk === FALSE) {
         debugLog("exiting in phase 3 with result: " . join(", ", $finalGenres));
         return $finalGenres;
     }
     // phase 4: remaining tiny chunks
     debugLog("Phase 4");
     $splitBy = array_merge($app->config['genre-glue'], array(" ", "-", ".", "_", ""));
     $badChunk = FALSE;
     $chunks = trimExplode($tmpGlue, str_ireplace($splitBy, $tmpGlue, $itemString), TRUE);
     if (count($chunks) === 1) {
         $az09 = az09($chunks[0]);
         $finalGenres[$az09] = $chunks[0];
         debugLog("exiting phase 4 with result: " . join(", ", $finalGenres));
         return $finalGenres;
     }
     $joinedRemainingChunks = strtolower(join(".", $chunks));
     if (isset($GLOBALS['preserveGenreChunks'][$joinedRemainingChunks]) === TRUE) {
         $finalGenres[az09($joinedRemainingChunks)] = $GLOBALS['preserveGenreChunks'][$joinedRemainingChunks];
         debugLog("found genre based on full preserved pattern: {$joinedRemainingChunks} = " . $GLOBALS['preserveGenreChunks'][$joinedRemainingChunks]);
         debugLog("exiting in phase 4 with result: " . join(", ", $finalGenres));
         return $finalGenres;
     }
     debugLog("REMAINING CHUNKWURST:" . $joinedRemainingChunks);
     $foundPreservedMatch = FALSE;
     foreach ($GLOBALS['preserveGenreChunks'] as $preserve => $genreString) {
         if (preg_match("/" . str_replace(".", "\\.", $preserve) . "/", $joinedRemainingChunks, $m)) {
             $finalGenres[az09($preserve)] = $genreString;
             $foundPreservedMatch = TRUE;
             debugLog("found genre based on partly preserved pattern: {$preserve} = " . $genreString);
             $removeChunks = explode('.', $preserve);
             $az09Chunks = array_map('az09', $chunks);
             foreach ($removeChunks as $removeChunk) {
                 if (array_search($removeChunk, $az09Chunks) !== FALSE) {
                     unset($chunks[array_search($removeChunk, $az09Chunks)]);
                 }
             }
         }
     }
     // TODO check
     // Coast Hip-Hop, Hardcore Hip-Hop, Gangsta
     // give up and create new genre for each chunk
     foreach ($chunks as $chunk) {
         $az09 = az09($chunk);
         $finalGenres[$az09] = $chunk;
         debugLog("giving up and creating new genre: {$az09} = " . $chunk);
     }
     debugLog("exiting phase 4 with result: " . join(", ", $finalGenres));
     return $finalGenres;
 }
예제 #8
0
 } elseif (removeLabel($setting, 'shuffle') !== false) {
     $unlabeled = removeLabel($setting, 'shuffle');
     if (removeLabel($unlabeled, 'button') !== false) {
         $setting = $unlabeled;
         $theseAreButtons = true;
     } else {
         shuffle($buttons);
     }
 } elseif (removeLabel($setting, 'share') !== false) {
     $share = removeLabel($setting, 'share');
 } else {
     $theseAreButtons = true;
 }
 if ($theseAreButtons) {
     $theseButtons = removeLabel($setting, 'button');
     $theseButtons = trimExplode(';', $theseButtons);
     $newButtons = array();
     foreach ($theseButtons as $thisButton) {
         if ($thisButton === '') {
             continue;
         }
         if ($thisButton[0] === '$') {
             $sep = strrpos($thisButton, '[');
             if ($sep === false) {
                 $col = substr($thisButton, 1);
                 $index = $item;
             } else {
                 $col = substr($thisButton, 1, $sep - 1);
                 $index = substr($thisButton, $sep + 1, strrpos($thisButton, ']') - $sep - 1);
             }
             $col = strtolower(trim($col));