Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/media/media_version.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ class MediaVersion {
final List<MediaPart> parts;

/// Human-readable name for this version (e.g. "Director's Cut").
/// Plex doesn't surface a name on `Media` entries, so this is null on the
/// Plex path and set from `MediaSource.Name` on the Jellyfin path when the
/// names differ across sources.
/// Set from `Media.title` on the Plex path when the server names the
/// version (Plex optimized versions, servers exposing several releases),
/// and from `MediaSource.Name` on the Jellyfin path.
final String? name;

const MediaVersion({
Expand Down
7 changes: 7 additions & 0 deletions lib/services/plex_mappers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,11 @@ class PlexMediaVersionDto {
final int? height;
@JsonKey(readValue: readStringField)
final String? container;

/// Version name some servers set on `Media` (e.g. Plex optimized versions,
/// or servers exposing several releases of one title).
@JsonKey(readValue: readStringField)
final String? title;
@JsonKey(readValue: _readPartKey)
final String partKey;
@JsonKey(readValue: _readPartAccessible)
Expand All @@ -347,6 +352,7 @@ class PlexMediaVersionDto {
this.width,
this.height,
this.container,
this.title,
required this.partKey,
this.accessible,
this.exists,
Expand Down Expand Up @@ -1219,6 +1225,7 @@ class PlexMappers {
bitrate: dto.bitrate,
container: dto.container,
parts: parts,
name: _stringOrNull(dto.title),
);
}

Expand Down
1 change: 1 addition & 0 deletions lib/services/plex_mappers.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions test/models/plex_media_version_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,33 @@ void main() {
});
});

group('Plex media version name', () {
test('Media title becomes the version name and prefixes the label', () {
final v = PlexMappers.mediaVersionFromJson({..._media(), 'title': 'Auto · 1080p WEB-DL · DD+ 5.1 · GROUP'});
expect(v.name, 'Auto · 1080p WEB-DL · DD+ 5.1 · GROUP');
final technical = PlexMappers.mediaVersionFromJson(_media()).displayLabel;
expect(v.displayLabel, 'Auto · 1080p WEB-DL · DD+ 5.1 · GROUP · $technical');
});

test('versions with identical specs stay distinguishable by name', () {
final a = PlexMappers.mediaVersionFromJson({..._media(id: 1), 'title': 'WEB-DL · GROUP-A'});
final b = PlexMappers.mediaVersionFromJson({..._media(id: 2), 'title': 'WEB-DL · GROUP-B'});
expect(a.displayLabel, isNot(b.displayLabel));
});

test('missing or blank Media title keeps the technical label', () {
for (final media in [
_media(),
{..._media(), 'title': ''},
{..._media(), 'title': ' '},
]) {
final v = PlexMappers.mediaVersionFromJson(media);
expect(v.name, isNull);
expect(v.displayLabel, startsWith('1080p '));
}
});
});

group('MediaVersion displayLabel', () {
test('formats Plex videoResolution for display', () {
String displayLabel(String resolution) =>
Expand Down