Fix fetching quality from itag (Removed entirely).
This commit is contained in:
parent
c70ac16007
commit
bba4ba97b6
|
@ -37,10 +37,7 @@ class EmbeddedPlayerClient {
|
||||||
const [];
|
const [];
|
||||||
|
|
||||||
///
|
///
|
||||||
late final Iterable<_StreamInfo> streams = [
|
late final List<_StreamInfo> streams = [...muxedStreams, ...adaptiveStreams];
|
||||||
...muxedStreams,
|
|
||||||
...adaptiveStreams
|
|
||||||
];
|
|
||||||
|
|
||||||
///
|
///
|
||||||
EmbeddedPlayerClient(this.root);
|
EmbeddedPlayerClient(this.root);
|
||||||
|
@ -56,8 +53,9 @@ class EmbeddedPlayerClient {
|
||||||
'context': const {
|
'context': const {
|
||||||
'client': {
|
'client': {
|
||||||
'hl': 'en',
|
'hl': 'en',
|
||||||
'clientName': 'ANDROID_EMBEDDED_PLAYER',
|
'clientName': 'WEB',
|
||||||
'clientVersion': '16.05'
|
'clientVersion': '2.20210721.00.00',
|
||||||
|
"clientScreen": "EMBED"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'videoId': videoId
|
'videoId': videoId
|
||||||
|
@ -121,7 +119,8 @@ class _StreamInfo extends StreamInfoProvider {
|
||||||
late final bool isAudioOnly = mimeType.type == 'audio';
|
late final bool isAudioOnly = mimeType.type == 'audio';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
late final String? videoQualityLabel = root['quality_label'];
|
late final String videoQualityLabel =
|
||||||
|
root['qualityLabel'] ?? root['quality_label'];
|
||||||
|
|
||||||
@override
|
@override
|
||||||
late final int? videoWidth = root['width'];
|
late final int? videoWidth = root['width'];
|
||||||
|
|
|
@ -89,4 +89,8 @@ class _StreamInfo extends StreamInfoProvider {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
late final int framerate = int.parse(root.getAttribute('framerate')!);
|
late final int framerate = int.parse(root.getAttribute('framerate')!);
|
||||||
|
|
||||||
|
// TODO: Implement this
|
||||||
|
@override
|
||||||
|
late final String? videoQualityLabel = null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,93 +2,6 @@ import '../extensions/helpers_extension.dart';
|
||||||
import '../videos/streams/video_quality.dart';
|
import '../videos/streams/video_quality.dart';
|
||||||
import '../videos/streams/video_resolution.dart';
|
import '../videos/streams/video_resolution.dart';
|
||||||
|
|
||||||
const _qualityMap = <int, VideoQuality>{
|
|
||||||
5: VideoQuality.low144,
|
|
||||||
6: VideoQuality.low240,
|
|
||||||
13: VideoQuality.low144,
|
|
||||||
17: VideoQuality.low144,
|
|
||||||
18: VideoQuality.medium360,
|
|
||||||
22: VideoQuality.high720,
|
|
||||||
34: VideoQuality.medium360,
|
|
||||||
35: VideoQuality.medium480,
|
|
||||||
36: VideoQuality.low240,
|
|
||||||
37: VideoQuality.high1080,
|
|
||||||
38: VideoQuality.high3072,
|
|
||||||
43: VideoQuality.medium360,
|
|
||||||
44: VideoQuality.medium480,
|
|
||||||
45: VideoQuality.high720,
|
|
||||||
46: VideoQuality.high1080,
|
|
||||||
59: VideoQuality.medium480,
|
|
||||||
78: VideoQuality.medium480,
|
|
||||||
82: VideoQuality.medium360,
|
|
||||||
83: VideoQuality.medium480,
|
|
||||||
84: VideoQuality.high720,
|
|
||||||
85: VideoQuality.high1080,
|
|
||||||
91: VideoQuality.low144,
|
|
||||||
92: VideoQuality.low240,
|
|
||||||
93: VideoQuality.medium360,
|
|
||||||
94: VideoQuality.medium480,
|
|
||||||
95: VideoQuality.high720,
|
|
||||||
96: VideoQuality.high1080,
|
|
||||||
100: VideoQuality.medium360,
|
|
||||||
101: VideoQuality.medium480,
|
|
||||||
102: VideoQuality.high720,
|
|
||||||
132: VideoQuality.low240,
|
|
||||||
151: VideoQuality.low144,
|
|
||||||
133: VideoQuality.low240,
|
|
||||||
134: VideoQuality.medium360,
|
|
||||||
135: VideoQuality.medium480,
|
|
||||||
136: VideoQuality.high720,
|
|
||||||
137: VideoQuality.high1080,
|
|
||||||
138: VideoQuality.high4320,
|
|
||||||
160: VideoQuality.low144,
|
|
||||||
212: VideoQuality.medium480,
|
|
||||||
213: VideoQuality.medium480,
|
|
||||||
214: VideoQuality.high720,
|
|
||||||
215: VideoQuality.high720,
|
|
||||||
216: VideoQuality.high1080,
|
|
||||||
217: VideoQuality.high1080,
|
|
||||||
264: VideoQuality.high1440,
|
|
||||||
266: VideoQuality.high2160,
|
|
||||||
298: VideoQuality.high720,
|
|
||||||
299: VideoQuality.high1080,
|
|
||||||
399: VideoQuality.high1080,
|
|
||||||
398: VideoQuality.high720,
|
|
||||||
397: VideoQuality.medium480,
|
|
||||||
396: VideoQuality.medium360,
|
|
||||||
395: VideoQuality.low240,
|
|
||||||
394: VideoQuality.low144,
|
|
||||||
167: VideoQuality.medium360,
|
|
||||||
168: VideoQuality.medium480,
|
|
||||||
169: VideoQuality.high720,
|
|
||||||
170: VideoQuality.high1080,
|
|
||||||
218: VideoQuality.medium480,
|
|
||||||
219: VideoQuality.medium480,
|
|
||||||
242: VideoQuality.low240,
|
|
||||||
243: VideoQuality.medium360,
|
|
||||||
244: VideoQuality.medium480,
|
|
||||||
245: VideoQuality.medium480,
|
|
||||||
246: VideoQuality.medium480,
|
|
||||||
247: VideoQuality.high720,
|
|
||||||
248: VideoQuality.high1080,
|
|
||||||
271: VideoQuality.high1440,
|
|
||||||
272: VideoQuality.high2160,
|
|
||||||
278: VideoQuality.low144,
|
|
||||||
302: VideoQuality.high720,
|
|
||||||
303: VideoQuality.high1080,
|
|
||||||
308: VideoQuality.high1440,
|
|
||||||
313: VideoQuality.high2160,
|
|
||||||
315: VideoQuality.high2160,
|
|
||||||
330: VideoQuality.low144,
|
|
||||||
331: VideoQuality.low240,
|
|
||||||
332: VideoQuality.medium360,
|
|
||||||
333: VideoQuality.medium480,
|
|
||||||
334: VideoQuality.high720,
|
|
||||||
335: VideoQuality.high1080,
|
|
||||||
336: VideoQuality.high1440,
|
|
||||||
337: VideoQuality.high2160,
|
|
||||||
};
|
|
||||||
|
|
||||||
const _resolutionMap = <VideoQuality, VideoResolution>{
|
const _resolutionMap = <VideoQuality, VideoResolution>{
|
||||||
VideoQuality.low144: VideoResolution(256, 144),
|
VideoQuality.low144: VideoResolution(256, 144),
|
||||||
VideoQuality.low240: VideoResolution(426, 240),
|
VideoQuality.low240: VideoResolution(426, 240),
|
||||||
|
@ -105,19 +18,12 @@ const _resolutionMap = <VideoQuality, VideoResolution>{
|
||||||
|
|
||||||
/// Utilities for [VideoQuality]
|
/// Utilities for [VideoQuality]
|
||||||
extension VideoQualityUtil on VideoQuality {
|
extension VideoQualityUtil on VideoQuality {
|
||||||
/// Parses the itag as [VideoQuality]
|
|
||||||
/// Throws an [ArgumentError] if the itag matches no video quality.
|
|
||||||
static VideoQuality fromTag(int itag) {
|
|
||||||
var q = _qualityMap[itag];
|
|
||||||
if (q == null) {
|
|
||||||
throw ArgumentError.value(itag, 'itag', 'Unrecognized itag');
|
|
||||||
}
|
|
||||||
return q;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Parses the label as [VideoQuality]
|
/// Parses the label as [VideoQuality]
|
||||||
/// Throws an [ArgumentError] if the string matches no video quality.
|
/// Throws an [ArgumentError] if the string matches no video quality.
|
||||||
static VideoQuality fromLabel(String label) {
|
static VideoQuality fromLabel(String? label) {
|
||||||
|
if (label == null) {
|
||||||
|
return VideoQuality.unknown;
|
||||||
|
}
|
||||||
label = label.toLowerCase();
|
label = label.toLowerCase();
|
||||||
|
|
||||||
if (label.startsWith('144')) {
|
if (label.startsWith('144')) {
|
||||||
|
@ -182,12 +88,6 @@ extension VideoQualityUtil on VideoQuality {
|
||||||
return '${getLabel()}$framerateRounded';
|
return '${getLabel()}$framerateRounded';
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
|
||||||
static String getLabelFromTagWithFramerate(int itag, double framerate) {
|
|
||||||
var videoQuality = fromTag(itag);
|
|
||||||
return videoQuality.getLabelWithFramerate(framerate);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns a [VideoResolution] from its [VideoQuality]
|
/// Returns a [VideoResolution] from its [VideoQuality]
|
||||||
VideoResolution toVideoResolution() {
|
VideoResolution toVideoResolution() {
|
||||||
var r = _resolutionMap[this];
|
var r = _resolutionMap[this];
|
||||||
|
|
|
@ -36,7 +36,7 @@ abstract class StreamInfoProvider {
|
||||||
String? get videoCodec => null;
|
String? get videoCodec => null;
|
||||||
|
|
||||||
///
|
///
|
||||||
String? get videoQualityLabel => null;
|
String? get videoQualityLabel;
|
||||||
|
|
||||||
///
|
///
|
||||||
int? get videoWidth => null;
|
int? get videoWidth => null;
|
||||||
|
|
|
@ -53,5 +53,6 @@ class Bitrate with Comparable<Bitrate>, _$Bitrate {
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() => '${_getLargestValue()} ${_getLargestSymbol()}';
|
String toString() =>
|
||||||
|
'${_getLargestValue().toStringAsFixed(2)} ${_getLargestSymbol()}';
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,5 +53,6 @@ class FileSize with Comparable<FileSize>, _$FileSize {
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() => '${_getLargestValue()} ${_getLargestSymbol()}';
|
String toString() =>
|
||||||
|
'${_getLargestValue().toStringAsFixed(2)} ${_getLargestSymbol()}';
|
||||||
}
|
}
|
||||||
|
|
|
@ -156,10 +156,6 @@ class StreamsClient {
|
||||||
await _httpClient.getContentLength(url, validate: false) ??
|
await _httpClient.getContentLength(url, validate: false) ??
|
||||||
0;
|
0;
|
||||||
|
|
||||||
// if (contentLength <= 0) {
|
|
||||||
// continue;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// Common
|
// Common
|
||||||
var container = StreamContainer.parse(streamInfo.container!);
|
var container = StreamContainer.parse(streamInfo.container!);
|
||||||
var fileSize = FileSize(contentLength);
|
var fileSize = FileSize(contentLength);
|
||||||
|
@ -171,9 +167,7 @@ class StreamsClient {
|
||||||
// Muxed or Video-only
|
// Muxed or Video-only
|
||||||
if (!videoCodec.isNullOrWhiteSpace) {
|
if (!videoCodec.isNullOrWhiteSpace) {
|
||||||
var framerate = Framerate(streamInfo.framerate ?? 24);
|
var framerate = Framerate(streamInfo.framerate ?? 24);
|
||||||
var videoQualityLabel = streamInfo.videoQualityLabel ??
|
var videoQualityLabel = streamInfo.videoQualityLabel!;
|
||||||
VideoQualityUtil.getLabelFromTagWithFramerate(
|
|
||||||
tag, framerate.framesPerSecond.toDouble());
|
|
||||||
|
|
||||||
var videoQuality = VideoQualityUtil.fromLabel(videoQualityLabel);
|
var videoQuality = VideoQualityUtil.fromLabel(videoQualityLabel);
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
/// Video quality.
|
/// Video quality.
|
||||||
enum VideoQuality {
|
enum VideoQuality {
|
||||||
|
/// Unknown video quality.
|
||||||
|
/// (This should be reported to the project's repo.)
|
||||||
|
unknown,
|
||||||
|
|
||||||
/// Low quality (144p).
|
/// Low quality (144p).
|
||||||
low144,
|
low144,
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue