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

38 lines
945 B
Dart
Raw Normal View History

2020-06-03 13:18:37 +02:00
import 'bitrate.dart';
import 'container.dart';
import 'filesize.dart';
/// 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 Container container;
/// 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);
}
/// Extensions for [StreamInfo]
extension StreamInfoExt on StreamInfo {
static final _exp = RegExp('ratebypass[=/]yes');
2020-06-05 20:08:04 +02:00
/// Returns true if this video is rate limited.
2020-06-05 16:17:08 +02:00
bool isRateLimited() => _exp.hasMatch(url.toString());
2020-06-03 13:18:37 +02:00
/// Gets the stream with highest bitrate.
static StreamInfo getHighestBitrate(List<StreamInfo> streams) =>
(streams..sort((a, b) => a.bitrate.compareTo(b.bitrate))).last;
}