Completed
Push — master ( 2515f9...556e6f )
by Stanislav
03:05
created

WeburgSeriesAdd::configure()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 24
rs 8.9713
cc 1
eloc 10
nc 1
nop 0
1
<?php
2
3
namespace Popstas\Transmission\Console\Command;
4
5
use Symfony\Component\Console\Input\InputInterface;
6
use Symfony\Component\Console\Output\OutputInterface;
7
8
class WeburgSeriesAdd extends Command
9
{
10
11
    protected function configure()
12
    {
13
        parent::configure();
14
        $this
15
            ->setName('weburg-series-add')
16
            ->setAliases(['wsa'])
17
            ->setDescription('Add series to monitoring list')
18
            ->addArgument('series-id', null, 'series id or series url')
19
            ->setHelp(<<<EOT
20
## Add series to download list
21
22
You can automatically download new series. To do this, you should add series to download list:
23
```
24
transmission-cli weburg-series-add http://weburg.net/series/info/12345
25
```
26
27
After that command `weburg-download` also will download series from list for last day.
28
If you don't want to download popular torrents, but only new series, use command:
29
```
30
transmission-cli weburg-download --series
31
```
32
EOT
33
            );
34
    }
35
36
    protected function execute(InputInterface $input, OutputInterface $output)
37
    {
38
        $config = $this->getApplication()->getConfig();
39
40
        $weburgClient = $this->getApplication()->getWeburgClient();
41
42
        $seriesArgument = $input->getArgument('series-id');
43
        $seriesId = $weburgClient->cleanMovieId($seriesArgument);
44
45
        if (!$seriesId) {
46
            $output->writeln($seriesArgument . ' seems not weburg series url');
47
            return 1;
48
        }
49
50
        $seriesList = $config->get('weburg-series-list');
51
        if (in_array($seriesId, $seriesList)) {
52
            $output->writeln($seriesId . ' already in list');
53
            return 0;
54
        }
55
56
        $seriesList[] = $seriesId;
57
        $config->set('weburg-series-list', $seriesList);
58
        $config->saveConfigFile();
59
60
        $output->writeln('Series ' . $seriesId . ' added to list');
61
        return 0;
62
    }
63
}
64