youtube_explode/lib/src/videos/streams/video_resolution.dart

41 lines
915 B
Dart
Raw Normal View History

import 'package:freezed_annotation/freezed_annotation.dart';
part 'video_resolution.g.dart';
2020-06-03 13:18:37 +02:00
/// Width and height of a video.
@JsonSerializable()
2021-10-04 13:00:22 +02:00
class VideoResolution implements Comparable<VideoResolution> {
2020-06-03 13:18:37 +02:00
/// Viewport width.
final int width;
/// Viewport height.
final int height;
/// Initializes an instance of [VideoResolution]
const VideoResolution(this.width, this.height);
factory VideoResolution.fromJson(Map<String, dynamic> json) =>
_$VideoResolutionFromJson(json);
Map<String, dynamic> toJson() => _$VideoResolutionToJson(this);
2020-06-03 13:18:37 +02:00
@override
String toString() => '${width}x$height';
2021-10-04 13:00:22 +02:00
@override
int compareTo(VideoResolution other) {
if (width == other.width && height == other.height) {
return 0;
}
if (width > other.width) {
return 1;
}
if (width == other.width && height > other.height) {
return 1;
}
return -1;
}
2020-06-03 13:18:37 +02:00
}