Skip to content

Commit dbae8dd

Browse files
committed
fix: save stream selection per media for audio and subtitles (not just language pref)
1 parent 0d0388f commit dbae8dd

File tree

3 files changed

+296
-35
lines changed

3 files changed

+296
-35
lines changed

lib/client/plex_client.dart

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

lib/models/plex_media_info.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@ class PlexMediaInfo {
33
final List<PlexAudioTrack> audioTracks;
44
final List<PlexSubtitleTrack> subtitleTracks;
55
final List<PlexChapter> chapters;
6+
final int? partId;
67

78
PlexMediaInfo({
89
required this.videoUrl,
910
required this.audioTracks,
1011
required this.subtitleTracks,
1112
required this.chapters,
13+
this.partId,
1214
});
15+
int? getPartId() => partId;
1316
}
1417

1518
/// Mixin for building track labels with a consistent pattern

0 commit comments

Comments
 (0)