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

44 lines
1.4 KiB
Dart
Raw Normal View History

2020-06-05 16:17:08 +02:00
import 'streams.dart';
2020-06-03 13:18:37 +02:00
/// YouTube media stream that contains video.
mixin VideoStreamInfo on StreamInfo {
2020-06-03 13:18:37 +02:00
/// Video codec.
String get videoCodec;
2020-06-03 13:18:37 +02:00
/// Video quality label, as seen on YouTube.
2021-10-04 13:00:22 +02:00
@Deprecated('Use qualityLabel')
String get videoQualityLabel;
2020-06-03 13:18:37 +02:00
/// Video quality.
VideoQuality get videoQuality;
2020-06-03 13:18:37 +02:00
/// Video resolution.
VideoResolution get videoResolution;
2020-06-03 13:18:37 +02:00
/// Video framerate.
Framerate get framerate;
2020-06-03 13:18:37 +02:00
}
/// Extensions for Iterables of [VideoStreamInfo]
2020-06-16 21:49:30 +02:00
extension VideoStreamInfoExtension<T extends VideoStreamInfo> on Iterable<T> {
/// Gets all video qualities available in a collection of video streams.
Set<VideoQuality> getAllVideoQualities() =>
map((e) => e.videoQuality).toSet();
/// Gets video quality labels of all streams available in
/// a collection of video streams.
/// This could be longer than [getAllVideoQualities] since this gives also all
2020-06-16 21:49:30 +02:00
/// the different framerate values.
2021-10-04 13:02:13 +02:00
Set<String> getAllVideoQualitiesLabel() => map((e) => e.qualityLabel).toSet();
2020-06-16 21:49:30 +02:00
/// Gets the stream with best video quality.
T get bestQuality => sortByVideoQuality().first;
2020-06-16 21:49:30 +02:00
/// Gets the video streams sorted by highest video quality
/// (then by framerate) in ascending order.
/// This returns new list without editing the original list.
List<T> sortByVideoQuality() => toList()
..sort((a, b) => b.framerate.compareTo(a.framerate))
2021-10-04 13:00:22 +02:00
..sort((a, b) => b.videoResolution.compareTo(a.videoResolution));
}