@@ -243,6 +243,12 @@ protected function getLibraries(Context $context, Closure $handle, Closure $erro
243243
244244 $ limitLibraryId = ag ($ opts , Options::ONLY_LIBRARY_ID , null );
245245
246+ $ selectLibraryList = null ;
247+ $ inverseLibrarySelect = true === (bool ) ag ($ context ->options , Options::LIBRARY_INVERSE , false );
248+ if (null !== ($ selectLibraryIds = ag ($ context ->options , Options::LIBRARY_SELECT , null ))) {
249+ $ selectLibraryList = array_map (static fn ($ value ) => (string ) $ value , $ selectLibraryIds );
250+ }
251+
246252 $ requests = $ total = [];
247253 $ ignored = $ unsupported = 0 ;
248254
@@ -259,11 +265,15 @@ protected function getLibraries(Context $context, Closure $handle, Closure $erro
259265 ],
260266 ];
261267
262- if (null !== $ limitLibraryId && $ libraryId !== (string ) $ limitLibraryId ) {
268+ if ($ limitLibraryId && $ libraryId !== (string ) $ limitLibraryId ) {
269+ continue ;
270+ }
271+
272+ if (true === in_array ($ libraryId , $ ignoreIds ?? [], true )) {
263273 continue ;
264274 }
265275
266- if (true === in_array (ag ( $ logContext , ' library.id ' ), $ ignoreIds ?? [] , true )) {
276+ if ($ selectLibraryList && $ inverseLibrarySelect === in_array ($ libraryId , $ selectLibraryList , true )) {
267277 continue ;
268278 }
269279
@@ -280,7 +290,7 @@ protected function getLibraries(Context $context, Closure $handle, Closure $erro
280290 http_build_query ([
281291 'sortBy ' => 'DateCreated ' ,
282292 'sortOrder ' => 'Ascending ' ,
283- 'parentId ' => ag ( $ logContext , ' library.id ' ) ,
293+ 'parentId ' => $ libraryId ,
284294 'recursive ' => 'true ' ,
285295 'collapseBoxSetItems ' => 'false ' ,
286296 'excludeLocationTypes ' => 'Virtual ' ,
@@ -384,10 +394,11 @@ protected function getLibraries(Context $context, Closure $handle, Closure $erro
384394
385395 // -- Episodes Parent external ids.
386396 foreach ($ listDirs as $ section ) {
397+ $ libraryId = (string ) ag ($ section , 'Id ' );
387398 $ logContext = [
388399 ...$ rContext ,
389400 'library ' => [
390- 'id ' => ( string ) ag ( $ section , ' Id ' ) ,
401+ 'id ' => $ libraryId ,
391402 'title ' => ag ($ section , 'Name ' , '?? ' ),
392403 'type ' => ag ($ section , ['CollectionType ' , 'Type ' ], 'unknown ' ),
393404 ],
@@ -397,7 +408,11 @@ protected function getLibraries(Context $context, Closure $handle, Closure $erro
397408 ],
398409 ];
399410
400- if (true === in_array (ag ($ logContext , 'library.id ' ), $ ignoreIds ?? [], true )) {
411+ if (true === in_array ($ libraryId , $ ignoreIds ?? [], true )) {
412+ continue ;
413+ }
414+
415+ if ($ selectLibraryList && $ inverseLibrarySelect === in_array ($ libraryId , $ selectLibraryList , true )) {
401416 continue ;
402417 }
403418
@@ -409,8 +424,8 @@ protected function getLibraries(Context $context, Closure $handle, Closure $erro
409424 continue ;
410425 }
411426
412- if (true === array_key_exists (ag ( $ logContext , ' library.id ' ) , $ total )) {
413- $ logContext ['library ' ]['totalRecords ' ] = $ total [ag ( $ logContext , ' library.id ' ) ];
427+ if (true === array_key_exists ($ libraryId , $ total )) {
428+ $ logContext ['library ' ]['totalRecords ' ] = $ total [$ libraryId ];
414429 }
415430
416431 $ url = $ context
@@ -422,7 +437,7 @@ protected function getLibraries(Context $context, Closure $handle, Closure $erro
422437 )
423438 ->withQuery (
424439 http_build_query ([
425- 'parentId ' => ag ( $ logContext , ' library.id ' ) ,
440+ 'parentId ' => $ libraryId ,
426441 'recursive ' => 'false ' ,
427442 'enableUserData ' => 'false ' ,
428443 'enableImages ' => 'false ' ,
@@ -462,16 +477,17 @@ protected function getLibraries(Context $context, Closure $handle, Closure $erro
462477
463478 // -- get paginated movies/episodes.
464479 foreach ($ listDirs as $ section ) {
480+ $ libraryId = (string ) ag ($ section , 'Id ' );
465481 $ logContext = [
466482 ...$ rContext ,
467483 'library ' => [
468- 'id ' => ( string ) ag ( $ section , ' Id ' ) ,
484+ 'id ' => $ libraryId ,
469485 'title ' => ag ($ section , 'Name ' , '?? ' ),
470486 'type ' => ag ($ section , ['CollectionType ' , 'Type ' ], 'unknown ' ),
471487 ],
472488 ];
473489
474- if (true === in_array (ag ( $ logContext , ' library.id ' ) , $ ignoreIds ?? [], true )) {
490+ if (true === in_array ($ libraryId , $ ignoreIds ?? [], true )) {
475491 $ ignored ++;
476492 $ this ->logger ->info (
477493 message: "{action}: Ignoring '{client}: {user}@{backend}' - '{library.title}'. Requested by user. " ,
@@ -480,6 +496,14 @@ protected function getLibraries(Context $context, Closure $handle, Closure $erro
480496 continue ;
481497 }
482498
499+ if ($ selectLibraryList && $ inverseLibrarySelect === in_array ($ libraryId , $ selectLibraryList , true )) {
500+ $ this ->logger ->info (
501+ message: "{action}: Excluding '{client}: {user}@{backend}' - '{library.title}'. Requested by user. " ,
502+ context: $ logContext ,
503+ );
504+ continue ;
505+ }
506+
483507 if (!in_array (ag ($ logContext , 'library.type ' ), $ types , true )) {
484508 $ unsupported ++;
485509 $ this ->logger ->info (
@@ -489,7 +513,7 @@ protected function getLibraries(Context $context, Closure $handle, Closure $erro
489513 continue ;
490514 }
491515
492- if (false === array_key_exists (ag ( $ logContext , ' library.id ' ) , $ total )) {
516+ if (false === array_key_exists ($ libraryId , $ total )) {
493517 $ ignored ++;
494518 $ this ->logger ->warning (
495519 message: "{action}: Ignoring '{client}: {user}@{backend}' - '{library.title}'. No items count was found. " ,
@@ -498,9 +522,9 @@ protected function getLibraries(Context $context, Closure $handle, Closure $erro
498522 continue ;
499523 }
500524
501- $ logContext ['library ' ]['totalRecords ' ] = $ total [ag ( $ logContext , ' library.id ' ) ];
525+ $ logContext ['library ' ]['totalRecords ' ] = $ total [$ libraryId ];
502526
503- $ segmentTotal = (int ) $ total [ag ( $ logContext , ' library.id ' ) ];
527+ $ segmentTotal = (int ) $ total [$ libraryId ];
504528 $ segmentSize = (int ) ag ($ context ->options , Options::LIBRARY_SEGMENT , 1000 );
505529 $ segmented = ceil ($ segmentTotal / $ segmentSize );
506530
0 commit comments