-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsoap4me.php
63 lines (50 loc) · 1.42 KB
/
soap4me.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
use League\Flysystem\Adapter\Local;
use League\Flysystem\Filesystem;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
use Symfony\Component\Dotenv\Dotenv;
use Soap4me\Parser;
use Soap4me\Downloader;
use Soap4me\DownloaderTransport\Aria2;
use Soap4me\Notify\MailgunNotify;
setlocale(LC_CTYPE, 'en_US.UTF-8');
date_default_timezone_set('Europe/Moscow');
include_once 'vendor/autoload.php';
// @todo pid ?
$dotenv = new Dotenv();
$dotenv->load(__DIR__ . '/.env');
try {
$log = new Logger('logger');
// @todo log level to params
$log->pushHandler(new StreamHandler($_ENV['LOG_FILE'], Logger::DEBUG));
} catch (Exception $e) {
}
try {
$log->info('Start processing');
// @todo need DI
$parser = new Parser(
$log,
$_ENV['SOAP_LOGIN'],
$_ENV['SOAP_PASSWORD']
);
$transport = new Aria2(
$log,
new Filesystem(new Local(realpath(dirname($_ENV['DOWNLOAD_DIR']))))
);
$notify = new MailgunNotify($log, [
'from' => $_ENV['MAILGUN_FROM'],
'to' => $_ENV['NOTIFY_EMAIL'],
'domain' => $_ENV['MAILGUN_DOMAIN'],
'key' => $_ENV['MAILGUN_KEY'],
]);
(new Downloader($log, $transport))
->addBatch($parser->findUnwatched())
->setNotify($notify)
->setMaxQuality($_ENV['MAX_QUALITY'])
->download();
$log->info('Finish');
} catch (Exception $e) {
$log->error($e->getMessage());
throw new $e;
}