diff --git a/src/Deblan/Command/ListCommand.php b/src/Deblan/Command/ListCommand.php
index d5ad385..3289519 100644
--- a/src/Deblan/Command/ListCommand.php
+++ b/src/Deblan/Command/ListCommand.php
@@ -15,16 +15,34 @@ class ListCommand extends Command
$this
->setName('streams')
->setDescription('List available streams.')
- ->addOption('category', null, InputOption::VALUE_REQUIRED, '')
+ ->addOption('language', null, InputOption::VALUE_REQUIRED, '')
+ ->addOption('difficulty', null, InputOption::VALUE_REQUIRED, '')
->setHelp("The %command.name% 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();
+ $streams = $liveCoding->getStreams($language, $difficulty);
foreach ($streams as $stream) {
$output->writeln(sprintf(
@@ -47,8 +65,8 @@ class ListCommand extends Command
'Languages: %s',
implode(', ', $stream->getLanguages())
));
-
- $output->writeln(sprintf(
+
+ $output->writeln(sprintf(
'Difficulty: %s',
$stream->getDifficulty()
));
diff --git a/src/Deblan/Helper/LiveCoding.php b/src/Deblan/Helper/LiveCoding.php
index 84334f7..dbdd437 100644
--- a/src/Deblan/Helper/LiveCoding.php
+++ b/src/Deblan/Helper/LiveCoding.php
@@ -18,9 +18,41 @@ class LiveCoding
$this->app = $app;
}
- public function getStreams($category = null)
+ public function getLanguages()
{
- $content = file_get_contents($this->app->buildUrl('livestreams/'));
+ return [
+ 'objc-swift-ios' => 'Obj-C/Swift (iOS)',
+ 'java' => 'Java',
+ 'android' => 'Android',
+ 'c-cplusplus' => 'C/C++',
+ 'csharp-dotnet' => 'C#/.NET',
+ 'python' => 'Python',
+ 'javascript' => 'JavaScript',
+ 'php' => 'PHP',
+ 'ruby"' => 'Ruby',
+ 'sql"' => 'SQL',
+ 'html-css' => 'HTML/CSS',
+ 'others' => 'Others',
+ ];
+ }
+
+ public function getDifficulties()
+ {
+ return [
+ 1 => 'beginner',
+ 2 => 'intermediate',
+ 3 => 'expert',
+ ];
+ }
+
+ public function getStreams($language = null, $difficulty = null)
+ {
+
+ $content = file_get_contents($this->app->buildUrl(sprintf(
+ 'livestreams/%s%s',
+ $language !== null ? $language.'/' : 'all',
+ $difficulty !== null ? $difficulty.'/' : null
+ )));
preg_match_all(
'`
(.+)\s+
`isU',
@@ -57,8 +89,8 @@ class LiveCoding
if (!empty($languages)) {
$difficulty = trim(array_pop($languages), '()');
} else {
- $difficulty = null;
- }
+ $difficulty = null;
+ }
$stream = new Stream();
$stream
@@ -67,7 +99,7 @@ class LiveCoding
->setCountry($countryMatch[1])
->setAuthor($authorMatch[1])
->setLanguages($languages)
- ->setDifficulty($difficulty)
+ ->setDifficulty($difficulty)
->setUrl($this->app->buildUrl($urlMatch[1]));
$streams[] = $stream;