private function addSongMetadata(Song $song) { $songReader = new \SongReader($this->getSongPath($song->getId())); $song->loadMetadata($songReader); preg_match('~(?P<artist>.+)-[\\d]+-(?P<title>.+)\\.mp3~', $song->getName(), $matches); $artist = null; $title = null; if (isset($matches['artist']) && isset($matches['title'])) { $artist = $matches['artist']; $title = $matches['title']; } if (!$artist && !$title) { preg_match('~(?P<artist>.+)-(?P<title>.+)\\.mp3~', $song->getName(), $matches2); if (isset($matches2['artist']) && isset($matches2['title'])) { $artist = $matches2['artist']; $title = $matches2['title']; } } if ($artist && $title && !$song->getArtist() && !$song->getTitle()) { $song->setArtist($artist); $song->setTitle($title); } }