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

37 lines
977 B
Dart
Raw Normal View History

2020-06-03 13:18:37 +02:00
import 'bitrate.dart';
import 'filesize.dart';
import 'stream_container.dart';
2020-06-03 13:18:37 +02:00
/// Generic YouTube media stream.
abstract class StreamInfo {
/// Stream tag.
/// Uniquely identifies a stream inside a manifest.
final int tag;
/// Stream URL.
final Uri url;
/// Stream container.
final StreamContainer container;
2020-06-03 13:18:37 +02:00
/// Stream size.
final FileSize size;
/// Stream bitrate.
final Bitrate bitrate;
2020-06-05 20:08:04 +02:00
/// Initialize an instance of [StreamInfo].
2020-06-03 13:18:37 +02:00
StreamInfo(this.tag, this.url, this.container, this.size, this.bitrate);
}
2020-06-16 21:49:30 +02:00
/// Extension for Iterables of StreamInfo.
extension StreamInfoIterableExt<T extends StreamInfo> on Iterable<T> {
/// Gets the stream with highest bitrate.
T withHighestBitrate() => sortByBitrate().last;
/// Gets the video streams sorted by bitrate in ascending order.
/// This returns new list without editing the original list.
List<T> sortByBitrate() =>
toList()..sort((a, b) => a.bitrate.compareTo(b.bitrate));
}