Skip to content

Commit cf4cc3d

Browse files
authored
Merge pull request #201 from ArabCoders/dev
Remove old Server classes
2 parents 7d5f467 + 185cacc commit cf4cc3d

22 files changed

+966
-825
lines changed

FAQ.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# FAQ
22

3+
**All commands have help document attached to them. So, please read them.**
4+
35
### Q: How to sync play state to a new backend without overwriting current play state?
46

57
Add the backend and when asked, answer `no` for `Enable Importing metadata and play state from this backend?`. when you

config/config.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22

33
declare(strict_types=1);
44

5+
use App\Backends\Emby\EmbyClient;
6+
use App\Backends\Jellyfin\JellyfinClient;
7+
use App\Backends\Plex\PlexClient;
58
use App\Commands\State\BackupCommand;
69
use App\Commands\State\ExportCommand;
710
use App\Commands\State\ImportCommand;
811
use App\Commands\State\PushCommand;
912
use App\Commands\System\IndexCommand;
1013
use App\Commands\System\PruneCommand;
1114
use App\Libs\Mappers\Import\MemoryMapper;
12-
use App\Libs\Servers\EmbyServer;
13-
use App\Libs\Servers\JellyfinServer;
14-
use App\Libs\Servers\PlexServer;
1515
use Monolog\Logger;
1616

1717
return (function () {
@@ -140,9 +140,9 @@
140140
];
141141

142142
$config['supported'] = [
143-
'plex' => PlexServer::class,
144-
'emby' => EmbyServer::class,
145-
'jellyfin' => JellyfinServer::class,
143+
'plex' => PlexClient::class,
144+
'emby' => EmbyClient::class,
145+
'jellyfin' => JellyfinClient::class,
146146
];
147147

148148
$config['servers'] = [];

src/Libs/Servers/ServerInterface.php renamed to src/Backends/Common/ClientInterface.php

+30-37
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,36 @@
22

33
declare(strict_types=1);
44

5-
namespace App\Libs\Servers;
5+
namespace App\Backends\Common;
66

77
use App\Libs\Entity\StateInterface;
88
use App\Libs\Mappers\ImportInterface as iImport;
99
use App\Libs\QueueRequests;
1010
use DateTimeInterface as iDate;
1111
use JsonException;
1212
use Psr\Http\Message\ServerRequestInterface;
13-
use Psr\Http\Message\UriInterface;
1413
use Psr\Log\LoggerInterface;
1514
use SplFileObject;
1615
use Symfony\Contracts\HttpClient\Exception\ExceptionInterface;
1716
use Symfony\Contracts\HttpClient\ResponseInterface;
1817

19-
interface ServerInterface
18+
interface ClientInterface
2019
{
2120
/**
22-
* Initiate server. It should return **NEW OBJECT**
21+
* Initiate Client with context. It **MUST** return new instance.
2322
*
24-
* @param string $name Server name
25-
* @param UriInterface $url Server url
26-
* @param null|int|string $token Server Token
27-
* @param null|int|string $userId Server user Id
28-
* @param string|int|null $uuid
29-
* @param array $options array of options.
23+
* @param Context $context
3024
*
31-
* @return self
25+
* @return ClientInterface
3226
*/
33-
public function setUp(
34-
string $name,
35-
UriInterface $url,
36-
null|string|int $token = null,
37-
null|string|int $userId = null,
38-
null|string|int $uuid = null,
39-
array $options = []
40-
): self;
27+
public function withContext(Context $context): ClientInterface;
28+
29+
/**
30+
* Return client context.
31+
*
32+
* @return Context
33+
*/
34+
public function getContext(): Context;
4135

4236
/**
4337
* Get Backend name.
@@ -51,9 +45,9 @@ public function getName(): string;
5145
*
5246
* @param LoggerInterface $logger
5347
*
54-
* @return ServerInterface
48+
* @return ClientInterface
5549
*/
56-
public function setLogger(LoggerInterface $logger): ServerInterface;
50+
public function setLogger(LoggerInterface $logger): ClientInterface;
5751

5852
/**
5953
* Process The request For attributes extraction.
@@ -66,15 +60,15 @@ public function setLogger(LoggerInterface $logger): ServerInterface;
6660
public function processRequest(ServerRequestInterface $request, array $opts = []): ServerRequestInterface;
6761

6862
/**
69-
* Parse server specific webhook event. for play/un-played event.
63+
* Parse backend webhook event.
7064
*
7165
* @param ServerRequestInterface $request
7266
* @return StateInterface
7367
*/
7468
public function parseWebhook(ServerRequestInterface $request): StateInterface;
7569

7670
/**
77-
* Import watch state.
71+
* Import metadata & play state.
7872
*
7973
* @param iImport $mapper
8074
* @param iDate|null $after
@@ -84,16 +78,18 @@ public function parseWebhook(ServerRequestInterface $request): StateInterface;
8478
public function pull(iImport $mapper, iDate|null $after = null): array;
8579

8680
/**
87-
* Backup watch state.
81+
* Backup play state.
8882
*
8983
* @param iImport $mapper
84+
* @param SplFileObject|null $writer
85+
* @param array $opts
9086
*
9187
* @return array<array-key,ResponseInterface>
9288
*/
93-
public function backup(iImport $mapper, SplFileObject $writer, array $opts = []): array;
89+
public function backup(iImport $mapper, SplFileObject|null $writer = null, array $opts = []): array;
9490

9591
/**
96-
* Export watch state to server.
92+
* Compare play state and export.
9793
*
9894
* @param iImport $mapper
9995
* @param QueueRequests $queue
@@ -104,7 +100,7 @@ public function backup(iImport $mapper, SplFileObject $writer, array $opts = [])
104100
public function export(iImport $mapper, QueueRequests $queue, iDate|null $after = null): array;
105101

106102
/**
107-
* Push webhook queued states.
103+
* Compare webhook queued events and push.
108104
*
109105
* @param array<StateInterface> $entities
110106
* @param QueueRequests $queue
@@ -115,7 +111,7 @@ public function export(iImport $mapper, QueueRequests $queue, iDate|null $after
115111
public function push(array $entities, QueueRequests $queue, iDate|null $after = null): array;
116112

117113
/**
118-
* Search server libraries.
114+
* Search backend libraries.
119115
*
120116
* @param string $query
121117
* @param int $limit
@@ -126,7 +122,7 @@ public function push(array $entities, QueueRequests $queue, iDate|null $after =
126122
public function search(string $query, int $limit = 25, array $opts = []): array;
127123

128124
/**
129-
* Server Backend id.
125+
* Search backend for item id.
130126
*
131127
* @param string|int $id
132128
* @param array $opts
@@ -156,19 +152,16 @@ public function getMetadata(string|int $id, array $opts = []): array;
156152
public function getLibrary(string|int $id, array $opts = []): array;
157153

158154
/**
159-
* Get Server Unique ID.
155+
* Get backend unique id.
160156
*
161-
* @param bool $forceRefresh force read uuid from server.
157+
* @param bool $forceRefresh force reload from backend.
162158
*
163159
* @return int|string|null
164-
*
165-
* @throws JsonException May throw if json decoding fails.
166-
* @throws ExceptionInterface May be thrown if there is HTTP request errors.
167160
*/
168-
public function getServerUUID(bool $forceRefresh = false): int|string|null;
161+
public function getIdentifier(bool $forceRefresh = false): int|string|null;
169162

170163
/**
171-
* Return List of users from server.
164+
* Return list of backend users.
172165
*
173166
* @param array $opts
174167
*
@@ -180,7 +173,7 @@ public function getServerUUID(bool $forceRefresh = false): int|string|null;
180173
public function getUsersList(array $opts = []): array;
181174

182175
/**
183-
* Return list of server libraries.
176+
* Return list of backend libraries.
184177
*
185178
* @param array $opts
186179
*

src/Backends/Emby/Action/Backup.php

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Backends\Emby\Action;
6+
7+
class Backup extends \App\Backends\Jellyfin\Action\Backup
8+
{
9+
}

src/Backends/Emby/EmbyActionTrait.php

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
namespace App\Backends\Emby;
66

7+
use App\Backends\Jellyfin\JellyfinActionTrait;
8+
79
trait EmbyActionTrait
810
{
11+
use JellyfinActionTrait;
912
}

0 commit comments

Comments
 (0)