Skip to content

Commit

Permalink
Merge pull request #8 from Rpsl/7-preserve-sorting-of-queue
Browse files Browse the repository at this point in the history
#7 Preserve sorting of queue
  • Loading branch information
Rpsl authored Jan 26, 2020
2 parents 86a202b + 95cdfe9 commit 752543a
Show file tree
Hide file tree
Showing 5 changed files with 233 additions and 11 deletions.
10 changes: 9 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,16 @@ phpstan:
test:
php ./vendor/bin/phpunit -c phpunit.xml ./tests/

test-coverage:
docker run --rm -it --name soap4me -v $(shell pwd):/app/ --entrypoint /usr/local/bin/phpdbg soap4me-dev:latest -qrr -d memory_limit=-1 vendor/bin/phpunit --configuration phpunit.xml --coverage-html /app/coverage/ && \
rm -rf /app/build

docker-build:
docker build -t soap4me:latest .

docker-build-dev:
docker build -t soap4me-dev:latest . && \
docker run --rm -it --name soap4me-dev -v $(shell pwd):/app/ --entrypoint /usr/local/bin/composer soap4me-dev:latest install --prefer-dist

docker-attach:
docker run --rm -it --name soap4me -v $(shell pwd):/app/ --entrypoint /bin/bash soap4me:latest
docker run --rm -it --name soap4me -v $(shell pwd):/app/ --entrypoint /bin/bash soap4me-dev:latest
23 changes: 16 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# soap4.me downloader
# Soap4.me downloader

**Для работы необходим премиум аккаунт**

Это форкнутый и переписанный, на скорую руку, скрипт [TurboLoader](https://github.com/Rpsl/turboload), который, как можно догадаться из названия, автоматически скачивает сериалы с сервиса [soap4.me](http://soap4.me)

## Зачем?

Мне удобно когда все серии скачиваются на сетевой хранилище
Expand Down Expand Up @@ -32,14 +30,25 @@ SOAP_PASSWORD=""
NOTIFY_EMAIL="[email protected]"
MAILGUN_DOMAIN="domain.mailgun.org"
MAILGUN_FROM="Turboloader <turboload@domain.mailgun.org>"
MAILGUN_FROM="Soap4me downloader <soap4me@domain.mailgun.org>"
MAILGUN_KEY=""
```


### Docker
# Docker

Build image from sources
```bash
$ docker build -t soap4me:latest .
```

Pull image from github
```bash
docker pull docker.pkg.github.com/rpsl/soap4me/soap4me:latest
```


Run downloader (not daemon mode)
```bash
docker build -t soap4me:latest .
docker run --rm -it --name soap4me -v $(pwd)/downloads:/app/downloads/ -v $(pwd)/.env:/app/.env -v $(pwd)/cookie.json:/app/cookie.json soap4me:latest
$ docker run --rm -it --name soap4me -v $(pwd)/downloads:/app/downloads/ -v $(pwd)/.env:/app/.env -v $(pwd)/cookie.json:/app/cookie.json soap4me:latest
```
14 changes: 14 additions & 0 deletions src/Soap4me/Downloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,18 @@ public function download(): void
});
}

/**
* Return filterd queue
*
* @return Episode[]
*/
public function getQueue()
{
$this->filter();

return $this->queue;
}

/**
* Filter Queue. Leavel only best quality episodes
*/
Expand Down Expand Up @@ -127,8 +139,10 @@ private function filter(): void

// @todo look as shit, but we have only one episode after filtering
foreach ($tmpQueue as $show) {
ksort($show);
foreach ($show as $season) {
$season = array_reverse($season, true);
ksort($season);
foreach ($season as $episode) {
$this->add($episode);
}
Expand Down
189 changes: 189 additions & 0 deletions tests/Soap4me/DownloaderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
<?php declare(strict_types=1);

namespace Tests\Soap4me;

use PHPUnit\Framework\TestCase;
use Psr\Log\AbstractLogger;
use Soap4me\Downloader;
use Soap4me\DownloaderTransport\AbstractTransport;
use Soap4me\Episode;

class DownloaderTest extends TestCase
{
/** @var \PHPUnit\Framework\MockObject\MockObject|Downloader|Downloader */
private $downloader;

private $queue;

protected function setUp(): void
{
/**
* @var AbstractLogger $logger
*/
$logger = $this->getMockBuilder(AbstractLogger::class)
->disableOriginalConstructor()
->getMockForAbstractClass();

/**
* @var AbstractTransport $transport
*/
$transport = $this->getMockBuilder(AbstractTransport::class)
->disableOriginalConstructor()
->getMockForAbstractClass();

$this->downloader = new Downloader($logger, $transport);

$this->queue = null;
}

protected function tearDown(): void
{
$this->queue = null;
}

public function testAdd()
{
$episode = new Episode(
'The Simpsons',
'The Winter of Our Monetized Content',
31,
1,
'fullHD',
'ru',
'some-hash-string',
12345,
6789,
'token-poken'
);

$this->downloader->add($episode);

$queue = $this->downloader->getQueue();

$this->assertSame(
1,
count($queue)
);
}

public function testAddBatch()
{
$episodes = [];

$episodes[] = new Episode(
'The Simpsons',
'The Winter of Our Monetized Content',
31,
1,
'fullHD',
'ru',
'some-hash-string',
12345,
6789,
'token-poken'
);

$episodes[] = new Episode(
'The Simpsons',
'The Winter of Our Monetized Content',
31,
2,
'fullHD',
'ru',
'some-hash-string',
12345,
6789,
'token-poken'
);

$episodes[] = new Episode(
'The Simpsons',
'The Winter of Our Monetized Content',
31,
3,
'fullHD',
'ru',
'some-hash-string',
12345,
6789,
'token-poken'
);

$this->downloader->addBatch($episodes);

$queue = $this->downloader->getQueue();

$this->assertSame(
3,
count($queue)
);
}

public function testFilter_Sorting()
{
$episodes = [];

$episodes[] = new Episode(
'The Simpsons',
'The Winter of Our Monetized Content',
31,
4,
'fullHD',
'ru',
'some-hash-string',
12345,
6789,
'token-poken'
);

$episodes[] = new Episode(
'The Simpsons',
'The Winter of Our Monetized Content',
31,
2,
'fullHD',
'ru',
'some-hash-string',
12345,
6789,
'token-poken'
);

$episodes[] = new Episode(
'The Simpsons',
'The Winter of Our Monetized Content',
31,
3,
'fullHD',
'ru',
'some-hash-string',
12345,
6789,
'token-poken'
);

$episodes[] = new Episode(
'The Simpsons',
'The Winter of Our Monetized Content',
31,
1,
'fullHD',
'ru',
'some-hash-string',
12345,
6789,
'token-poken'
);

$this->downloader->addBatch($episodes);

$queue = $this->downloader->getQueue();

$var = 1;

foreach ($queue as $ep) {
$this->assertSame($var, $ep->getNumber());
$var++;
}
}
}
8 changes: 5 additions & 3 deletions tests/Soap4me/EpisodeTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?php
<?php declare(strict_types=1);

namespace Soap4me;
namespace Tests\Soap4me;

use Soap4me\Episode;
use Soap4me\Exception\QualityException;

use GuzzleHttp\Client;
use GuzzleHttp\Handler\MockHandler;
Expand All @@ -9,7 +12,6 @@
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;
use PHPUnit\Framework\TestCase;
use Soap4me\Exception\QualityException;

class EpisodeTest extends TestCase
{
Expand Down

0 comments on commit 752543a

Please sign in to comment.