Added Progress
This commit is contained in:
parent
f61ff02693
commit
0c8297c3a8
|
@ -14,7 +14,7 @@ use Symfony\Component\Config;
|
|||
use Symfony\Component\Console\Application;
|
||||
use Sikofitt\Hathor\Command\ScannerCommand;
|
||||
|
||||
|
||||
define('BASEDIR', dirname(__FILE__));
|
||||
$app = new Application('Hathor', 'v0.0.1');
|
||||
$app->add(new ScannerCommand());
|
||||
$app->run();
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
namespace Sikofitt\Hathor\Command;
|
||||
|
||||
use Symfony\Component\Config\Definition\Exception\Exception;
|
||||
use Symfony\Component\Finder\Finder;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
@ -22,36 +23,71 @@ class ScannerCommand extends BaseCommand
|
|||
$this
|
||||
->setName('scan')
|
||||
->setDescription('Scans Music')
|
||||
->addArgument('file', InputArgument::OPTIONAL, 'the file to work on');
|
||||
->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)
|
||||
{
|
||||
$output->writeln("Please wait ...");
|
||||
$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("/home/eric/Music")
|
||||
->in($input->getOption('directory'))
|
||||
->ignoreDotFiles(true)
|
||||
->ignoreUnreadableDirs(true)
|
||||
->ignoreVCS(true)
|
||||
->sortByType()
|
||||
->name("*.mp3")
|
||||
->name("*.mp4")
|
||||
->name("*.ogg")
|
||||
->name("*.wma")
|
||||
->name("*.mp2");
|
||||
->name($extensionRegex);
|
||||
$progress = new ProgressBar($output, $finder->count());
|
||||
$progress->setFormat("debug");
|
||||
$progress->setBarWidth(50);
|
||||
$progress->setFormat(" %message%\n <fg=cyan>%current%</><fg=black;options=bold>/</><fg=cyan;options=bold>%max%</> <fg=cyan>[</>%bar%<fg=cyan>]</> %percent:3s%% %elapsed:6s%/%estimated:-6s% %memory:6s%");
|
||||
$progress->clear();
|
||||
$progress->start();
|
||||
foreach ($finder as $file) {
|
||||
$progress->setOverwrite(true);
|
||||
$progress->setMessage($file->getFilename());
|
||||
$progress->advance();
|
||||
}
|
||||
$progress->finish();
|
||||
$getID3 = new ID3;
|
||||
//$getID3->setFile($input->getArgument('file'))->getFileData()->dumpAll();
|
||||
$progress->setBarCharacter('<fg=cyan;options=bold>#</>');
|
||||
$progress->setProgressCharacter('<fg=cyan>#</>');
|
||||
$progress->setEmptyBarCharacter('<fg=cyan>#</>');
|
||||
//$progress->setRedrawFrequency(100);
|
||||
|
||||
$cols = shell_exec('tput cols');
|
||||
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 = substr($file->getFilename(), 0,$cols - 30);
|
||||
|
||||
$progress->setMessage("<fg=white;options=bold>Current File - $currentFile ...</>");
|
||||
|
||||
//$getID3->setFile($file->getRealPath());
|
||||
try {
|
||||
// $allMusicData[] = $getID3->getFileData ();
|
||||
} catch(\Exception $e) {
|
||||
$progress->setMessage('<warning>Caught RuntimeException</warning>');
|
||||
continue;
|
||||
}
|
||||
|
||||
$progress->advance();
|
||||
|
||||
}
|
||||
$progress->setMessage('Finished!');
|
||||
$progress->finish();
|
||||
$output->writeln('');
|
||||
//var_dump($allMusicData);
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue