feat: add paginated series inventory with bulk Emby SDK queries (1.3.0)
This commit is contained in:
1 parent
e7e690f60c
commit
208d7045f9
14 files changed
+555
-41
No files matched your search
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
// Read-only acceptance test AFTER the separately approved plugin restart.
|
||||
// Run on the Emby host. No tokens or episode paths are printed.
|
||||
$config = $argv[1] ?? '/mnt/nvme-storage/appdata/Emby/plugins/configurations/eMCPy.xml';
|
||||
$x = simplexml_load_file($config);
|
||||
if (!$x) throw new RuntimeException('Cannot read local plugin configuration');
|
||||
$calls = 0;
|
||||
function rpc($method, $params) {
|
||||
global $x, $calls;
|
||||
$calls++;
|
||||
$c = curl_init('http://127.0.0.1:'.(int)$x->McpPort.'/mcp');
|
||||
curl_setopt_array($c, [CURLOPT_RETURNTRANSFER=>true, CURLOPT_POST=>true,
|
||||
CURLOPT_HTTPHEADER=>['Content-Type: application/json','X-Api-Key: '.(string)$x->ApiKey],
|
||||
CURLOPT_POSTFIELDS=>json_encode(['jsonrpc'=>'2.0','id'=>$calls,'method'=>$method,'params'=>$params]),CURLOPT_TIMEOUT=>60]);
|
||||
$body = curl_exec($c); $code = curl_getinfo($c, CURLINFO_HTTP_CODE); curl_close($c);
|
||||
if ($code !== 200) throw new RuntimeException('MCP request failed: HTTP '.$code);
|
||||
$r = json_decode($body,true,512,JSON_THROW_ON_ERROR);
|
||||
if (isset($r['error'])) throw new RuntimeException('MCP JSON-RPC error');
|
||||
return $r['result'];
|
||||
}
|
||||
function requireTrue($ok,$message) { if (!$ok) throw new RuntimeException($message); }
|
||||
function callTool($name,$args,$expectError=false) {
|
||||
$r=rpc('tools/call',['name'=>$name,'arguments'=>$args]);
|
||||
if ($expectError) {requireTrue(!empty($r['isError']), 'Expected MCP tool error');return null;}
|
||||
requireTrue(empty($r['isError']), 'MCP tool failed: '.$name);
|
||||
return json_decode($r['content'][0]['text'],true,512,JSON_THROW_ON_ERROR);
|
||||
}
|
||||
$init=rpc('initialize',(object)[]);
|
||||
requireTrue($init['serverInfo']['version']==='1.3.0','Expected loaded eMCPy 1.3.0');
|
||||
$tools=rpc('tools/list',(object)[]);
|
||||
requireTrue(count($tools['tools'])===18,'Expected 18 tools');
|
||||
$search=callTool('emby_search',['query'=>'Proper People','type'=>'Series']);
|
||||
requireTrue(count($search['items'])===1,'Select explicit series ID; search ambiguous');
|
||||
$id=$search['items'][0]['id'];
|
||||
$results=[];
|
||||
foreach ([null,2022,2023,999999] as $season) {
|
||||
$base=['seriesId'=>$id]; if ($season!==null) $base['season']=$season;
|
||||
$seen=[];$start=0;$revision=null;$pageCount=0;$total=null;
|
||||
do {
|
||||
$a=$base+['start'=>$start,'limit'=>7];if($revision!==null)$a['expectedRevision']=$revision;
|
||||
$p=callTool('emby_series_inventory',$a);$pageCount++;
|
||||
if($total!==null)requireTrue($p['total']===$total,'Total changed');
|
||||
$total=$p['total'];$revision=$p['inventoryRevision'];
|
||||
requireTrue($p['returned']===count($p['items']),'Wrong returned count');
|
||||
foreach($p['items'] as $item) {
|
||||
requireTrue(!isset($seen[$item['id']]),'Duplicate item');$seen[$item['id']]=true;
|
||||
foreach(['id','seriesId','title','seasonNumber','episodeNumber','providerIds','tvdbId','path','mediaSources','runtimeTicks'] as $field)
|
||||
requireTrue(array_key_exists($field,$item),'Missing response field: '.$field);
|
||||
if($season===2022||$season===2023) {
|
||||
requireTrue(str_ends_with(strtolower($item['path']??''),'.mkv'),'Expected MKV');
|
||||
requireTrue($item['seasonNumber']===$season && $item['episodeNumber']!==null,'Missing numbering');
|
||||
requireTrue($item['tvdbId']!==null && !empty($item['mediaSources']) && $item['runtimeTicks']!==null,'Missing metadata');
|
||||
}
|
||||
}
|
||||
requireTrue($p['hasMore']===($start+$p['returned']<$total),'Invalid hasMore');
|
||||
if($p['hasMore']){requireTrue($p['nextStart']>$start,'Pagination stalled');$start=$p['nextStart'];}
|
||||
else requireTrue($p['nextStart']===null,'Last nextStart must be null');
|
||||
} while($p['hasMore']);
|
||||
requireTrue(count($seen)===$total,'Incomplete inventory');
|
||||
if($season===2022||$season===2023)requireTrue($total===($season===2022?18:17),'Reference count changed');
|
||||
$empty=callTool('emby_series_inventory',$base+['start'=>$total]);
|
||||
requireTrue($empty['returned']===0 && !$empty['hasMore'],'End must be empty');
|
||||
$results[]=['season'=>$season,'total'=>$total,'pagesOf7'=>$pageCount];
|
||||
}
|
||||
callTool('emby_series_inventory',['seriesId'=>'not-an-id'],true);
|
||||
callTool('emby_series_inventory',['seriesId'=>'9223372036854775807'],true);
|
||||
callTool('emby_series_inventory',['seriesId'=>$id,'limit'=>201],true);
|
||||
callTool('emby_series_inventory',['seriesId'=>$id,'expectedRevision'=>'wrong'],true);
|
||||
echo json_encode(['version'=>$init['serverInfo']['version'],'results'=>$results,'calls'=>$calls,'episodeDetailCalls'=>0],JSON_PRETTY_PRINT).PHP_EOL;
|
||||
Reference in new issue
Block a user