92 lines
2.9 KiB
PHP
92 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace Deblan\Command;
|
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
use Symfony\Component\Console\Input\InputOption;
|
|
use Symfony\Component\Console\Command\Command;
|
|
use Exception;
|
|
|
|
class ListCommand extends Command
|
|
{
|
|
protected function configure()
|
|
{
|
|
$this
|
|
->setName('streams')
|
|
->setDescription('List available streams.')
|
|
->addOption('language', null, InputOption::VALUE_REQUIRED, '')
|
|
->addOption('difficulty', null, InputOption::VALUE_REQUIRED, '')
|
|
->setHelp("The <info>%command.name%</info> lists live streams");
|
|
}
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output)
|
|
{
|
|
$liveCoding = $this->getApplication()->getContainer()['livecoding'];
|
|
$languages = $liveCoding->getLanguages();
|
|
$difficulties = $liveCoding->getDifficulties();
|
|
|
|
$language = $input->getOption('language');
|
|
$difficulty = $input->getOption('difficulty');
|
|
|
|
if (in_array($language, $languages)) {
|
|
$language = array_keys($languages, $language)[0];
|
|
} elseif (!in_array($language, array_keys($languages))) {
|
|
$language = null;
|
|
}
|
|
|
|
if (in_array($difficulty, array_keys($difficulties))) {
|
|
$difficulty = $difficulties[$difficulty];
|
|
} elseif (!in_array($difficulty, $difficulties)) {
|
|
$difficulty = null;
|
|
}
|
|
|
|
try {
|
|
$streams = $liveCoding->getStreams($language, $difficulty);
|
|
|
|
foreach ($streams as $stream) {
|
|
$output->writeln(sprintf(
|
|
'<comment>%s</comment>',
|
|
$stream->getTitle()
|
|
));
|
|
|
|
$output->writeln(sprintf(
|
|
'<comment>%s</comment>',
|
|
str_repeat('-', mb_strlen($stream->getTitle()))
|
|
));
|
|
|
|
$output->writeln(sprintf(
|
|
'<info>Author:</info> %s',
|
|
$stream->getAuthor()
|
|
));
|
|
|
|
if (count($stream->getLanguages())) {
|
|
$output->writeln(sprintf(
|
|
'<info>Languages:</info> %s',
|
|
implode(', ', $stream->getLanguages())
|
|
));
|
|
|
|
$output->writeln(sprintf(
|
|
'<info>Difficulty:</info> %s',
|
|
$stream->getDifficulty()
|
|
));
|
|
}
|
|
|
|
$output->writeln(sprintf(
|
|
'<info>URL:</info> %s',
|
|
$stream->getUrl()
|
|
));
|
|
|
|
$output->writeln(sprintf(
|
|
'<info>Views:</info> %d',
|
|
$stream->getViews()
|
|
));
|
|
|
|
$output->writeln('');
|
|
}
|
|
} catch (Exception $e) {
|
|
$output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
|
|
}
|
|
}
|
|
}
|