2026-04-25 12:52:43 +02:00
|
|
|
import 'package:json_annotation/json_annotation.dart';
|
|
|
|
|
|
2026-04-26 02:34:09 +02:00
|
|
|
import '../../media/media_server_user_profile.dart';
|
2026-07-05 06:23:34 +02:00
|
|
|
import '../../utils/json_utils.dart';
|
2026-04-26 02:34:09 +02:00
|
|
|
|
2026-04-25 12:52:43 +02:00
|
|
|
part 'plex_user_profile.g.dart';
|
|
|
|
|
|
2025-10-18 00:05:20 +02:00
|
|
|
/// Represents a Plex user's profile preferences
|
|
|
|
|
/// Fetched from https://clients.plex.tv/api/v2/user
|
2026-07-05 06:23:34 +02:00
|
|
|
///
|
|
|
|
|
/// Every field parses tolerantly: the account API drifts (~July 2026 the
|
|
|
|
|
/// language-list fields switched from arrays to CSV strings, #1488), and a
|
2026-07-26 05:30:32 +02:00
|
|
|
/// single drifted field must never sink the whole profile.
|
2026-04-25 12:52:43 +02:00
|
|
|
@JsonSerializable()
|
2026-04-26 02:34:09 +02:00
|
|
|
class PlexUserProfile implements MediaServerUserProfile {
|
2026-07-05 06:23:34 +02:00
|
|
|
@JsonKey(fromJson: _boolOrTrue)
|
2026-04-26 02:34:09 +02:00
|
|
|
@override
|
2025-10-18 00:05:20 +02:00
|
|
|
final bool autoSelectAudio;
|
2026-07-05 06:23:34 +02:00
|
|
|
@JsonKey(fromJson: _flexibleLanguage)
|
2026-04-26 02:34:09 +02:00
|
|
|
@override
|
2025-10-18 00:05:20 +02:00
|
|
|
final String? defaultAudioLanguage;
|
2026-07-05 06:23:34 +02:00
|
|
|
@JsonKey(fromJson: flexibleCsvStringList)
|
2026-04-26 02:34:09 +02:00
|
|
|
@override
|
2025-10-18 00:05:20 +02:00
|
|
|
final List<String>? defaultAudioLanguages;
|
2026-07-05 06:23:34 +02:00
|
|
|
@JsonKey(fromJson: _flexibleLanguage)
|
2026-04-26 02:34:09 +02:00
|
|
|
@override
|
2025-10-18 00:05:20 +02:00
|
|
|
final String? defaultSubtitleLanguage;
|
2026-07-05 06:23:34 +02:00
|
|
|
@JsonKey(fromJson: flexibleCsvStringList)
|
2026-04-26 02:34:09 +02:00
|
|
|
@override
|
2025-10-18 00:05:20 +02:00
|
|
|
final List<String>? defaultSubtitleLanguages;
|
|
|
|
|
|
2026-04-26 02:34:09 +02:00
|
|
|
@override
|
|
|
|
|
SubtitlePlaybackMode? get subtitleMode => null;
|
|
|
|
|
|
2025-10-18 00:05:20 +02:00
|
|
|
PlexUserProfile({
|
|
|
|
|
required this.autoSelectAudio,
|
|
|
|
|
this.defaultAudioLanguage,
|
|
|
|
|
this.defaultAudioLanguages,
|
|
|
|
|
this.defaultSubtitleLanguage,
|
|
|
|
|
this.defaultSubtitleLanguages,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
factory PlexUserProfile.fromJson(Map<String, dynamic> json) {
|
2026-07-05 06:23:34 +02:00
|
|
|
final envelope = json['profile'];
|
|
|
|
|
final profile = envelope is Map<String, dynamic> ? envelope : json;
|
2026-04-25 12:52:43 +02:00
|
|
|
return _$PlexUserProfileFromJson(profile);
|
2025-10-18 00:05:20 +02:00
|
|
|
}
|
|
|
|
|
|
2026-04-25 12:52:43 +02:00
|
|
|
Map<String, dynamic> toJson() => {'profile': _$PlexUserProfileToJson(this)};
|
2025-10-18 00:05:20 +02:00
|
|
|
}
|
2026-07-05 06:23:34 +02:00
|
|
|
|
|
|
|
|
/// Singular language fields tolerate the inverse drift (array/CSV → first entry).
|
|
|
|
|
String? _flexibleLanguage(Object? v) => flexibleCsvStringList(v)?.first;
|
|
|
|
|
|
|
|
|
|
bool _boolOrTrue(Object? v) => flexibleBoolNullable(v) ?? true;
|