// ignore_for_file: constant_identifier_names import 'package:fladder/jellyfin/jellyfin_open_api.swagger.dart'; import 'package:fladder/util/size_formatting.dart'; class InformationModel { final Map baseInformation; final List> videoStreams; final List> audioStreams; final List> subStreams; InformationModel({ required this.baseInformation, required this.videoStreams, required this.audioStreams, required this.subStreams, }); static InformationModel? fromResponse(BaseItemDto? item) { if (item == null) return null; var videoStreams = item.mediaStreams?.where((element) => element.type == MediaStreamType.video).toList() ?? []; var audioStreams = item.mediaStreams?.where((element) => element.type == MediaStreamType.audio).toList() ?? []; var subStreams = item.mediaStreams?.where((element) => element.type == MediaStreamType.subtitle).toList() ?? []; return InformationModel( baseInformation: { "Title": item.name, "Container": item.container, "Path": item.path, "Size": item.mediaSources?.firstOrNull?.size.byteFormat, }, videoStreams: videoStreams .map( (e) => { "Title": e.displayTitle, "Codec": e.codec, "Profile": e.profile, "Level": e.level, "Resolution": "${e.width}x${e.height}", "Aspect Ration": e.aspectRatio, "Interlaced": e.isInterlaced, "FrameRate": e.realFrameRate, "Bitrate": "${e.bitRate} kbps", "Bit depth": e.bitDepth, "Video range": e.videoRange, "Video range type": e.videoRangeType, "Ref frames": e.refFrames, }, ) .toList(), audioStreams: audioStreams .map( (e) => { "Title": e.displayTitle, "Language": e.language, "Codec": e.codec, "Layout": e.channelLayout, "Bitrate": "${e.bitRate} kbps", "Sample Rate": "${e.sampleRate} Hz", "Default": e.isDefault, "Forced": e.isForced, "External": e.isExternal, }, ) .toList(), subStreams: subStreams .map( (e) => { "Title": e.displayTitle, "Language": e.language, "Codec": e.codec, "Profile": e.profile, "Default": e.isDefault, "Forced": e.isForced, "External": e.isExternal, }, ) .toList(), ); } InformationModel copyWith({ Map? baseInformation, List>? videoStreams, List>? audioStreams, List>? subStreams, }) { return InformationModel( baseInformation: baseInformation ?? this.baseInformation, videoStreams: videoStreams ?? this.videoStreams, audioStreams: audioStreams ?? this.audioStreams, subStreams: subStreams ?? this.subStreams, ); } static String mapToString(Map map) { return map.entries.map((e) => "${e.key}: ${e.value}").join("\n"); } static String streamsToString(List> streams) { return streams.map((e) => mapToString(e)).join("\n"); } @override String toString() => "${mapToString(baseInformation)}\n\n" "${streamsToString(videoStreams)}\n\n" "${streamsToString(audioStreams)}\n\n" "${streamsToString(subStreams)}\n\n"; }