Example #1
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;
 }
Example #2
0
 private function getFilenameScheme($value, $idx)
 {
     #$value = "B2-Aaron_Dilloway-Untitled-sour.mp3";
     if ($value == '') {
         return 'missing';
     }
     $rx = new \Slimpd\RegexHelper();
     // maybe we have a year in filename -> add little score
     if (preg_match_all("/" . $rx->mayBracket . $rx->year . $rx->mayBracket . "/", $value, $m)) {
         foreach ($m as $i) {
             foreach ($i as $x) {
                 $this->scoreAttribute($idx, 'year', $x, 0.5);
             }
         }
     }
     // maybe we have a catNr in filename  -> add little score
     if (preg_match_all("/" . $rx->catNr . "/", $value, $m)) {
         foreach ($m as $i) {
             foreach ($i as $x) {
                 $this->scoreAttribute($idx, 'catalogNr', $x, 0.5);
             }
         }
     }
     $iHateRegex = array('classic' => $rx->dStart . $rx->num . $rx->glue . $rx->noMinus . "-" . $rx->noMinus . $rx->ext . $rx->dEnd, 'classic-vinyl' => $rx->dStart . $rx->vinyl . $rx->glue . $rx->noMinus . "-" . $rx->noMinus . $rx->ext . $rx->dEnd, 'classicscene' => $rx->dStart . $rx->num . $rx->glue . $rx->noMinus . "-" . $rx->noMinus . $rx->scene . $rx->ext . $rx->dEnd, 'classicscene-vinyl' => $rx->dStart . $rx->vinyl . $rx->glue . $rx->noMinus . "-" . $rx->noMinus . $rx->scene . $rx->ext . $rx->dEnd, 'album-number-artist-title' => $rx->dStart . $rx->noMinus . $rx->glue . $rx->num . $rx->glue . $rx->noMinus . $rx->glue . $rx->noMinus . $rx->ext . $rx->dEnd, 'album-vinyl-artist-title' => $rx->dStart . $rx->noMinus . $rx->glue . $rx->vinyl . $rx->glue . $rx->noMinus . $rx->glue . $rx->noMinus . $rx->ext . $rx->dEnd, 'noartist' => $rx->dStart . $rx->num . $rx->glue . $rx->noMinus . $rx->ext . $rx->dEnd, 'noartist-vinyl' => $rx->dStart . $rx->vinyl . $rx->glue . $rx->noMinus . $rx->ext . $rx->dEnd, 'nonumber' => $rx->dStart . $rx->noMinus . "-" . $rx->noMinus . $rx->ext . $rx->dEnd, 'nonumber-noartist' => $rx->dStart . $rx->noMinus . $rx->ext . $rx->dEnd, 'anything' => $rx->dStart . $rx->anything . $rx->ext . $rx->dEnd);
     foreach ($iHateRegex as $result => $pattern) {
         #cliLog($pattern);
         if (preg_match($pattern, $value, $m)) {
             if ($result !== 'nonumber' && $result !== 'nonumber-noartist') {
                 if (is_numeric($m[1])) {
                     $this->extractedTrackNumbers[$idx] = intval($m[1]);
                 } else {
                     // vinyl schemed tracknumer
                     $this->extractedTrackNumbers[$idx] = strtoupper($m[1]);
                 }
             }
             switch ($result) {
                 // make recommendations for expected track-attributes
                 case 'classic':
                 case 'classicscene':
                 case 'classic-vinyl':
                 case 'classicscene-vinyl':
                     $this->recommend($idx, array('number' => remU($m[1]), 'artist' => remU($m[2]), 'title' => remU($m[3])));
                     break;
                 case 'noartist':
                 case 'noartist-vinyl':
                     $this->recommend($idx, array('number' => remU($m[1]), 'title' => remU($m[2])));
                     break;
                 case 'nonumber':
                     $this->recommend($idx, array('artist' => remU($m[1]), 'title' => remU($m[2])));
                     break;
                 case 'album-number-artist-title':
                 case 'album-vinyl-artist-title':
                     $this->recommend($idx, array('album' => remU($m[1]), 'number' => remU($m[2]), 'artist' => remU($m[3]), 'title' => remU($m[4])));
                     $this->recommend('album', array('title' => remU($m[1])));
                 case 'nonumber-noartist':
                 case 'anything':
                     $this->recommend($idx, array('title' => remU($m[1])));
                     break;
             }
             if (stripos($result, 'vinyl') !== FALSE) {
                 $this->recommend($idx, array('source' => 'Vinyl'));
             }
             cliLog(__FUNCTION__ . " " . $result . ": " . $value, 6, 'green');
             return $result;
             // 01-Aaron_Dilloway-Untitled.mp3
         }
     }
     $result = "nomatch";
     cliLog(__FUNCTION__ . " " . $result . ": " . $value, 6, 'red');
     return $result;
 }