/// <summary> /// Initializes an instance of <see cref="VideoOnlyStreamInfo"/>. /// </summary> public VideoOnlyStreamInfo( string url, Container container, FileSize size, Bitrate bitrate, string videoCodec, VideoQuality videoQuality, Resolution videoResolution) { Url = url; Container = container; Size = size; Bitrate = bitrate; VideoCodec = videoCodec; VideoQuality = videoQuality; VideoResolution = videoResolution; }
/// <summary> /// Initializes an instance of <see cref="MuxedStreamInfo"/>. /// </summary> public MuxedStreamInfo( string url, Container container, FileSize size, Bitrate bitrate, string audioCodec, string videoCodec, VideoQuality videoQuality, Resolution resolution) { Url = url; Container = container; Size = size; Bitrate = bitrate; AudioCodec = audioCodec; VideoCodec = videoCodec; VideoQuality = videoQuality; VideoResolution = resolution; }
private async ValueTask PopulateStreamInfosAsync( ICollection <IStreamInfo> streamInfos, IEnumerable <IStreamInfoExtractor> streamInfoExtractors, SignatureScrambler signatureScrambler, CancellationToken cancellationToken = default) { foreach (var streamInfoExtractor in streamInfoExtractors) { var itag = streamInfoExtractor.TryGetItag() ?? throw new YoutubeExplodeException("Could not extract stream itag."); var urlRaw = streamInfoExtractor.TryGetUrl() ?? throw new YoutubeExplodeException("Could not extract stream URL."); // Unscramble URL var signature = streamInfoExtractor.TryGetSignature(); var signatureParameter = streamInfoExtractor.TryGetSignatureParameter(); var url = UnscrambleStreamUrl(signatureScrambler, urlRaw, signature, signatureParameter); // Get content length var contentLength = streamInfoExtractor.TryGetContentLength() ?? await _httpClient.TryGetContentLengthAsync(url, false, cancellationToken) ?? 0; if (contentLength <= 0) { continue; // broken stream URL? } var fileSize = new FileSize(contentLength); var container = streamInfoExtractor.TryGetContainer()?.Pipe(s => new Container(s)) ?? throw new YoutubeExplodeException("Could not extract stream container."); var bitrate = streamInfoExtractor.TryGetBitrate()?.Pipe(s => new Bitrate(s)) ?? throw new YoutubeExplodeException("Could not extract stream bitrate."); var audioCodec = streamInfoExtractor.TryGetAudioCodec(); var videoCodec = streamInfoExtractor.TryGetVideoCodec(); // Muxed or video-only stream if (!string.IsNullOrWhiteSpace(videoCodec)) { var framerate = streamInfoExtractor.TryGetFramerate() ?? 24; var videoQualityLabel = streamInfoExtractor.TryGetVideoQualityLabel(); var videoQuality = !string.IsNullOrWhiteSpace(videoQualityLabel) ? VideoQuality.FromLabel(videoQualityLabel, framerate) : VideoQuality.FromItag(itag, framerate); var videoWidth = streamInfoExtractor.TryGetVideoWidth(); var videoHeight = streamInfoExtractor.TryGetVideoHeight(); var videoResolution = videoWidth is not null && videoHeight is not null ? new Resolution(videoWidth.Value, videoHeight.Value) : videoQuality.GetDefaultVideoResolution(); // Muxed if (!string.IsNullOrWhiteSpace(audioCodec)) { var streamInfo = new MuxedStreamInfo( url, container, fileSize, bitrate, audioCodec, videoCodec, videoQuality, videoResolution ); streamInfos.Add(streamInfo); } // Video-only else { var streamInfo = new VideoOnlyStreamInfo( url, container, fileSize, bitrate, videoCodec, videoQuality, videoResolution ); streamInfos.Add(streamInfo); } } // Audio-only else if (!string.IsNullOrWhiteSpace(audioCodec)) { var streamInfo = new AudioOnlyStreamInfo( url, container, fileSize, bitrate, audioCodec ); streamInfos.Add(streamInfo); } else { Debug.Fail("Stream doesn't contain neither audio nor video codec information."); } } }