@@ -462,6 +462,42 @@ class PlexClient {
462462 }
463463 }
464464
465+ /// Select specific audio and subtitle streams for playback
466+ /// This updates which streams are "selected" in the media metadata
467+ /// Uses the part ID from media info for accurate stream selection
468+ Future <bool > selectStreams (
469+ int partId, {
470+ int ? audioStreamID,
471+ int ? subtitleStreamID,
472+ bool allParts = true ,
473+ }) async {
474+ try {
475+ final queryParams = < String , dynamic > {};
476+ if (audioStreamID != null ) {
477+ queryParams['audioStreamID' ] = audioStreamID;
478+ }
479+ if (subtitleStreamID != null ) {
480+ queryParams['subtitleStreamID' ] = subtitleStreamID;
481+ }
482+ if (allParts) {
483+ // If no streams to select, return early
484+ if (queryParams.isEmpty) {
485+ return true ;
486+ }
487+
488+ // Use PUT request on /library/parts/{partId}
489+ final response = await _dio.put (
490+ '/library/parts/$partId ' ,
491+ queryParameters: queryParams,
492+ );
493+
494+ return response.statusCode == 200 ;
495+ } catch (e) {
496+ appLogger.e ('Failed to select streams' , error: e);
497+ return false ;
498+ }
499+ }
500+
465501 /// Search across all libraries using the hub search endpoint
466502 /// Only returns movies and shows, filtering out seasons and episodes
467503 Future <List <PlexMetadata >> search (String query, {int limit = 10 }) async {
@@ -923,6 +959,7 @@ class PlexClient {
923959 audioTracks: audioTracks,
924960 subtitleTracks: subtitleTracks,
925961 chapters: chapters,
962+ partId: part['id' ] as int ? ,
926963 );
927964 }
928965 }
0 commit comments