setName('scan') ->setDescription('Scans Music') ->addOption('directory', 'd', InputOption::VALUE_OPTIONAL, 'Directory to scan for music.',BASEDIR) ->addArgument('extensions',InputArgument::IS_ARRAY, 'Extensions to scan for separated by a space',['mp2','mp3','mp4','wma','ogg']); } protected function execute(InputInterface $input, OutputInterface $output) { $extensions = $input->getArgument('extensions'); // \b(\.mp2|\.mp3|\.mp4|\.wma|\.ogg)\b$ $extensionRegex = '/\b('; foreach($extensions as $extension) { $extensionRegex .= sprintf('\.%s|',$extension); } $extensionRegex[strlen($extensionRegex)-1] = ')'; $extensionRegex .= '\b$/i'; $output->writeln("\n Please wait ... finding files.\n"); $finder = new Finder(); $finder ->files() ->in($input->getOption('directory')) ->ignoreDotFiles(true) ->ignoreUnreadableDirs(true) ->name($extensionRegex); $progress = new ProgressBar($output, $finder->count()); $progress->setBarWidth(50); $progress->setFormat(" %message%\n %current%/%max% [%bar%] %percent:3s%% %elapsed:6s%/%estimated:-6s% %memory:6s%"); $progress->clear(); $progress->start(); $getID3 = new ID3; $progress->setBarCharacter('#'); $progress->setProgressCharacter('#'); $progress->setEmptyBarCharacter('#'); //$progress->setRedrawFrequency(100); $cols = shell_exec('tput cols') - 20; foreach ($finder as $file) { $progress->setMessage(str_repeat('-', $cols - 5)); //$currentDir = explode(DIRECTORY_SEPARATOR, $file->getRelativePath()); //$currentDir = $currentDir[count($currentDir)-1]; //$currentDir = substr($currentDir[count($currentDir)-1],0,60); $currentFile = str_pad(substr($file->getFilename(), 0, $cols) . ' ...', $cols, ' '); $progress->setMessage("Current File - $currentFile "); $getID3->setFile($file->getRealPath()); try { $allMusicData[] = $getID3->getFileData (); } catch(\Exception $e) { $progress->setMessage('Caught RuntimeException'); continue; } $progress->advance(); } $progress->setMessage('Finished!'); $progress->finish(); $output->writeln(''); //var_dump($allMusicData); } }