refactor: deduplicate shared patterns, replace hardcoded colors
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import '../utils/app_logger.dart';
|
||||
import '../utils/codec_utils.dart';
|
||||
import '../utils/track_label_builder.dart' show buildTrackLabel;
|
||||
|
||||
class PlexMediaInfo {
|
||||
final String videoUrl;
|
||||
@@ -23,9 +24,9 @@ class PlexMediaInfo {
|
||||
static PlexMediaInfo? fromMetadataJson(Map<String, dynamic> metadata) {
|
||||
final media = metadata['Media'] as List<dynamic>?;
|
||||
if (media == null || media.isEmpty) return null;
|
||||
final parts = media[0]['Part'] as List<dynamic>?;
|
||||
final parts = media.first['Part'] as List<dynamic>?;
|
||||
if (parts == null || parts.isEmpty) return null;
|
||||
final streams = parts[0]['Stream'] as List<dynamic>?;
|
||||
final streams = parts.first['Stream'] as List<dynamic>?;
|
||||
|
||||
final audioTracks = <PlexAudioTrack>[];
|
||||
final subtitleTracks = <PlexSubtitleTrack>[];
|
||||
@@ -75,27 +76,11 @@ class PlexMediaInfo {
|
||||
}
|
||||
}
|
||||
|
||||
/// Builds a track label from parts with the standard `' · '` joiner pattern.
|
||||
/// Mixin for building track labels with a consistent pattern.
|
||||
///
|
||||
/// Shared by both Plex track models and MPV track label utilities.
|
||||
/// If [title] is non-empty it is added first, then [language], then [extraParts].
|
||||
/// Falls back to `'$fallbackPrefix ${index + 1}'` when no parts are available.
|
||||
String buildTrackLabel({
|
||||
String? title,
|
||||
String? language,
|
||||
List<String> extraParts = const [],
|
||||
required int index,
|
||||
String fallbackPrefix = 'Track',
|
||||
}) {
|
||||
final parts = <String>[];
|
||||
if (title != null && title.isNotEmpty) parts.add(title);
|
||||
if (language != null && language.isNotEmpty) parts.add(language);
|
||||
parts.addAll(extraParts);
|
||||
return parts.isEmpty ? '$fallbackPrefix ${index + 1}' : parts.join(' · ');
|
||||
}
|
||||
|
||||
/// Mixin for building track labels with a consistent pattern
|
||||
mixin TrackLabelBuilder {
|
||||
/// Used by [PlexAudioTrack] and [PlexSubtitleTrack] to provide a [buildLabel]
|
||||
/// method that delegates to the shared [buildTrackLabel] function.
|
||||
mixin _TrackLabelMixin {
|
||||
int get id;
|
||||
int? get index;
|
||||
String? get displayTitle;
|
||||
@@ -112,7 +97,7 @@ mixin TrackLabelBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
class PlexAudioTrack with TrackLabelBuilder {
|
||||
class PlexAudioTrack with _TrackLabelMixin {
|
||||
@override
|
||||
final int id;
|
||||
@override
|
||||
@@ -147,7 +132,7 @@ class PlexAudioTrack with TrackLabelBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
class PlexSubtitleTrack with TrackLabelBuilder {
|
||||
class PlexSubtitleTrack with _TrackLabelMixin {
|
||||
@override
|
||||
final int id;
|
||||
@override
|
||||
|
||||
Reference in New Issue
Block a user