Stream command helper

This commit is contained in:
Simon Vieille 2015-07-14 01:09:51 +02:00
parent 497ef179af
commit 019f8a81e4
2 changed files with 31 additions and 3 deletions

View file

@ -17,7 +17,7 @@ class ListCommand extends Command
->setDescription('List available streams.') ->setDescription('List available streams.')
->addOption('language', null, InputOption::VALUE_REQUIRED, '') ->addOption('language', null, InputOption::VALUE_REQUIRED, '')
->addOption('difficulty', null, InputOption::VALUE_REQUIRED, '') ->addOption('difficulty', null, InputOption::VALUE_REQUIRED, '')
->setHelp("The <info>%command.name%</info> lists live streams"); ->setHelp('The <info>%command.name%</info> lists live streams');
} }
protected function execute(InputInterface $input, OutputInterface $output) protected function execute(InputInterface $input, OutputInterface $output)
@ -32,12 +32,40 @@ class ListCommand extends Command
if (in_array($language, $languages)) { if (in_array($language, $languages)) {
$language = array_keys($languages, $language)[0]; $language = array_keys($languages, $language)[0];
} elseif (!in_array($language, array_keys($languages))) { } elseif (!in_array($language, array_keys($languages))) {
if ($language !== null) {
$output->writeln('<info>language</info> available values:');
foreach ($liveCoding->getLanguages() as $key => $value) {
$output->writeln(sprintf(
' <comment>%s</comment> or <comment>%s</comment>',
$key,
$value
));
}
$output->writeln('');
}
$language = null; $language = null;
} }
if (in_array($difficulty, array_keys($difficulties))) { if (in_array($difficulty, array_keys($difficulties))) {
$difficulty = $difficulties[$difficulty]; $difficulty = $difficulties[$difficulty];
} elseif (!in_array($difficulty, $difficulties)) { } elseif (!in_array($difficulty, $difficulties)) {
if ($difficulty !== null) {
$output->writeln('<info>difficulty</info> available values:');
foreach ($liveCoding->getDifficulties() as $key => $value) {
$output->writeln(sprintf(
' <comment>%s</comment> or <comment>%s</comment>',
$key,
$value
));
}
$output->writeln('');
}
$difficulty = null; $difficulty = null;
} }

View file

@ -51,7 +51,7 @@ class LiveCoding
$content = file_get_contents($this->app->buildUrl(sprintf( $content = file_get_contents($this->app->buildUrl(sprintf(
'livestreams/%s%s', 'livestreams/%s%s',
$language !== null ? $language.'/' : 'all', $language !== null ? $language.'/' : 'all',
$difficulty !== null ? $difficulty.'/' : null $difficulty !== null ? '/'.$difficulty.'/' : null
))); )));
preg_match_all( preg_match_all(
@ -94,7 +94,7 @@ class LiveCoding
$stream = new Stream(); $stream = new Stream();
$stream $stream
->setTitle(trim($titleMatch[1])) ->setTitle(html_entity_decode(trim($titleMatch[1])))
->setViews($viewsMatch[1]) ->setViews($viewsMatch[1])
->setCountry($countryMatch[1]) ->setCountry($countryMatch[1])
->setAuthor($authorMatch[1]) ->setAuthor($authorMatch[1])