Fix fetching quality from itag (Removed entirely).

This commit is contained in:
Mattia 2021-09-01 18:39:09 +02:00
parent c70ac16007
commit bba4ba97b6
8 changed files with 24 additions and 121 deletions

View File

@ -37,10 +37,7 @@ class EmbeddedPlayerClient {
const [];
///
late final Iterable<_StreamInfo> streams = [
...muxedStreams,
...adaptiveStreams
];
late final List<_StreamInfo> streams = [...muxedStreams, ...adaptiveStreams];
///
EmbeddedPlayerClient(this.root);
@ -56,8 +53,9 @@ class EmbeddedPlayerClient {
'context': const {
'client': {
'hl': 'en',
'clientName': 'ANDROID_EMBEDDED_PLAYER',
'clientVersion': '16.05'
'clientName': 'WEB',
'clientVersion': '2.20210721.00.00',
"clientScreen": "EMBED"
}
},
'videoId': videoId
@ -121,7 +119,8 @@ class _StreamInfo extends StreamInfoProvider {
late final bool isAudioOnly = mimeType.type == 'audio';
@override
late final String? videoQualityLabel = root['quality_label'];
late final String videoQualityLabel =
root['qualityLabel'] ?? root['quality_label'];
@override
late final int? videoWidth = root['width'];

View File

@ -89,4 +89,8 @@ class _StreamInfo extends StreamInfoProvider {
@override
late final int framerate = int.parse(root.getAttribute('framerate')!);
// TODO: Implement this
@override
late final String? videoQualityLabel = null;
}

View File

@ -2,93 +2,6 @@ import '../extensions/helpers_extension.dart';
import '../videos/streams/video_quality.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>{
VideoQuality.low144: VideoResolution(256, 144),
VideoQuality.low240: VideoResolution(426, 240),
@ -105,19 +18,12 @@ const _resolutionMap = <VideoQuality, VideoResolution>{
/// Utilities for [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]
/// 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();
if (label.startsWith('144')) {
@ -182,12 +88,6 @@ extension VideoQualityUtil on VideoQuality {
return '${getLabel()}$framerateRounded';
}
///
static String getLabelFromTagWithFramerate(int itag, double framerate) {
var videoQuality = fromTag(itag);
return videoQuality.getLabelWithFramerate(framerate);
}
/// Returns a [VideoResolution] from its [VideoQuality]
VideoResolution toVideoResolution() {
var r = _resolutionMap[this];

View File

@ -36,7 +36,7 @@ abstract class StreamInfoProvider {
String? get videoCodec => null;
///
String? get videoQualityLabel => null;
String? get videoQualityLabel;
///
int? get videoWidth => null;

View File

@ -53,5 +53,6 @@ class Bitrate with Comparable<Bitrate>, _$Bitrate {
}
@override
String toString() => '${_getLargestValue()} ${_getLargestSymbol()}';
String toString() =>
'${_getLargestValue().toStringAsFixed(2)} ${_getLargestSymbol()}';
}

View File

@ -53,5 +53,6 @@ class FileSize with Comparable<FileSize>, _$FileSize {
}
@override
String toString() => '${_getLargestValue()} ${_getLargestSymbol()}';
String toString() =>
'${_getLargestValue().toStringAsFixed(2)} ${_getLargestSymbol()}';
}

View File

@ -156,10 +156,6 @@ class StreamsClient {
await _httpClient.getContentLength(url, validate: false) ??
0;
// if (contentLength <= 0) {
// continue;
// }
// Common
var container = StreamContainer.parse(streamInfo.container!);
var fileSize = FileSize(contentLength);
@ -171,9 +167,7 @@ class StreamsClient {
// Muxed or Video-only
if (!videoCodec.isNullOrWhiteSpace) {
var framerate = Framerate(streamInfo.framerate ?? 24);
var videoQualityLabel = streamInfo.videoQualityLabel ??
VideoQualityUtil.getLabelFromTagWithFramerate(
tag, framerate.framesPerSecond.toDouble());
var videoQualityLabel = streamInfo.videoQualityLabel!;
var videoQuality = VideoQualityUtil.fromLabel(videoQualityLabel);

View File

@ -1,5 +1,9 @@
/// Video quality.
enum VideoQuality {
/// Unknown video quality.
/// (This should be reported to the project's repo.)
unknown,
/// Low quality (144p).
low144,