Exemplo n.º 1
0
        /// <summary>
        /// Gets the metadata associated with the specified video.
        /// </summary>
        public async Task <Video> GetAsync(VideoId id)
        {
            var videoInfoResponse = await VideoInfoResponse.GetAsync(_httpClient, id);

            var playerResponse = videoInfoResponse.GetPlayerResponse();

            var watchPage = await WatchPage.GetAsync(_httpClient, id);

            return(new Video(
                       id,
                       playerResponse.GetVideoTitle(),
                       playerResponse.GetVideoAuthor(),
                       playerResponse.GetVideoChannelId(),
                       playerResponse.GetVideoUploadDate(),
                       playerResponse.GetVideoDescription(),
                       playerResponse.GetVideoDuration(),
                       new ThumbnailSet(id),
                       playerResponse.GetVideoKeywords(),
                       new Engagement(
                           playerResponse.TryGetVideoViewCount() ?? 0,
                           watchPage.TryGetVideoLikeCount() ?? 0,
                           watchPage.TryGetVideoDislikeCount() ?? 0
                           ),
                       Fallback.ToEmpty(watchPage.TryGetInitialData()?.GetChapters())
                       ));
        }
Exemplo n.º 2
0
        private async Task <Video> GetVideoFromWatchPageAsync(VideoId id)
        {
            var videoInfoResponse = await VideoInfoResponse.GetAsync(_httpClient, id);

            var playerResponse = videoInfoResponse.GetPlayerResponse();

            var watchPage = await WatchPage.GetAsync(_httpClient, id);

            return(new Video(
                       id,
                       playerResponse.GetVideoTitle(),
                       playerResponse.GetVideoAuthor(),
                       playerResponse.GetVideoChannelId(),
                       playerResponse.GetVideoUploadDate(),
                       playerResponse.GetVideoDescription(),
                       playerResponse.GetVideoDuration(),
                       new ThumbnailSet(id),
                       playerResponse.GetVideoKeywords(),
                       new Engagement(
                           playerResponse.TryGetVideoViewCount() ?? 0,
                           watchPage.TryGetVideoLikeCount() ?? 0,
                           watchPage.TryGetVideoDislikeCount() ?? 0
                           )
                       ));
        }
        private async Task <StreamContext> GetStreamContextFromWatchPageAsync(VideoId videoId)
        {
            var watchPage = await WatchPage.GetAsync(_httpClient, videoId);

            var playerConfig = watchPage.TryGetPlayerConfig();

            var playerResponse =
                playerConfig?.GetPlayerResponse() ??
                watchPage.TryGetPlayerResponse() ??
                throw VideoUnplayableException.Unplayable(videoId);

            var previewVideoId = playerResponse.TryGetPreviewVideoId();

            if (!string.IsNullOrWhiteSpace(previewVideoId))
            {
                throw VideoRequiresPurchaseException.Preview(videoId, previewVideoId);
            }

            var playerSourceUrl = watchPage.TryGetPlayerSourceUrl() ?? playerConfig?.GetPlayerSourceUrl();
            var playerSource    = !string.IsNullOrWhiteSpace(playerSourceUrl)
                ? await PlayerSource.GetAsync(_httpClient, playerSourceUrl)
                : null;

            var cipherOperations = playerSource?.GetCipherOperations().ToArray() ?? Array.Empty <ICipherOperation>();

            if (!playerResponse.IsVideoPlayable())
            {
                throw VideoUnplayableException.Unplayable(videoId, playerResponse.TryGetVideoPlayabilityError());
            }

            if (playerResponse.IsLive())
            {
                throw VideoUnplayableException.LiveStream(videoId);
            }

            var streamInfoProviders = new List <IStreamInfoProvider>();

            // Streams from player config
            if (playerConfig != null)
            {
                streamInfoProviders.AddRange(playerConfig.GetStreams());
            }

            // Streams from player response
            streamInfoProviders.AddRange(playerResponse.GetStreams());

            // Streams from DASH manifest
            var dashManifestUrl = playerResponse.TryGetDashManifestUrl();

            if (!string.IsNullOrWhiteSpace(dashManifestUrl))
            {
                var dashManifest = await GetDashManifestAsync(dashManifestUrl, cipherOperations);

                streamInfoProviders.AddRange(dashManifest.GetStreams());
            }

            return(new StreamContext(streamInfoProviders, cipherOperations));
        }
Exemplo n.º 4
0
        /// <summary>
        ///     Gets the metadata associated with the specified video.
        /// </summary>
        public async Task <Video> GetAsync(string id)
        {
            var videoInfoResponse = await VideoInfoResponse.GetAsync(_httpClient, id);

            var playerResponse = videoInfoResponse.GetPlayerResponse();

            var watchPage = await WatchPage.GetAsync(_httpClient, id);

            //TODO
            return(null);
        }