public PreparePlayVideoResult(VideoId contentId, NiconicoSession niconicoSession, NicoVideoSessionOwnershipManager ownershipManager, DmcWatchApiData dmcWatchData) : this(contentId, niconicoSession) { _ownershipManager = ownershipManager; _dmcWatchData = dmcWatchData; IsSuccess = _dmcWatchData != null; if (_dmcWatchData?.Media.Delivery is not null and var delivery) { AvailableQualities = delivery.Movie.Videos .Select(x => new NicoVideoQualityEntity(x.IsAvailable, QualityIdToNicoVideoQuality(x.Id), x.Id, (int)x.Metadata.Bitrate, (int)x.Metadata.Resolution.Width, (int)x.Metadata.Resolution.Height)) .ToImmutableArray(); }
public YoutubeMedia(IVideo video) : this() { this._videoId = video.Id; this.Author = video.Author.Title; this.Title = video.Title; this.Duration = video.Duration.Value; var thumbnailUrl = video.Thumbnails.OrderByDescending(t => t.Resolution.Area).First().Url; this.SetBitmapImage(uri: new Uri(thumbnailUrl)); }
public VideoListItemControlViewModel( VideoId videoId, string title, string thumbnailUrl, TimeSpan videoLength, DateTime postedAt ) : base(videoId, title, thumbnailUrl, videoLength, postedAt) { UpdateIsHidenVideoOwner(this); if (VideoId != VideoId && VideoId != null) { SubscribeAll(VideoId); } }
private async Task <StreamContext> GetSteamContextFromVideoInfoAsync(VideoId videoId) { var embedPage = await EmbedPage.GetAsync(_httpClient, videoId); var playerConfig = embedPage.TryGetPlayerConfig() ?? throw VideoUnplayableException.Unplayable(videoId); var playerSource = await PlayerSource.GetAsync(_httpClient, playerConfig.GetPlayerSourceUrl()); var cipherOperations = playerSource.GetCipherOperations().ToArray(); var videoInfoResponse = await VideoInfoResponse.GetAsync(_httpClient, videoId, playerSource.GetSts()); var playerResponse = videoInfoResponse.GetPlayerResponse(); var previewVideoId = playerResponse.TryGetPreviewVideoId(); if (!string.IsNullOrWhiteSpace(previewVideoId)) { throw VideoRequiresPurchaseException.Preview(videoId, previewVideoId); } if (!playerResponse.IsVideoPlayable()) { throw VideoUnplayableException.Unplayable(videoId, playerResponse.TryGetVideoPlayabilityError()); } if (playerResponse.IsLive()) { throw VideoUnplayableException.LiveStream(videoId); } var streamInfoProviders = new List <IStreamInfoProvider>(); // Streams from video info streamInfoProviders.AddRange(videoInfoResponse.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)); }
//public Stream GetFileData() //{ //} public async Task <Stream> GetYoutubeData(string url) { var youtube = new YoutubeClient(); var memoryStream = new MemoryStream(); var videoId = new VideoId(url); var streams = await youtube.Videos.Streams.GetManifestAsync(videoId); var streamInfo = streams.GetAudioOnly(); var mp4Stream = streamInfo.SingleOrDefault(x => x.Container.Name == "mp4"); return(await youtube.Videos.Streams.GetAsync(mp4Stream)); }
public void VideoId_ToNiconicoId() { var idA = new VideoId(123456); NiconicoId idB = new VideoId("123456"); Assert.AreEqual(NiconicoIdType.VideoAlias, idB.IdType); Assert.AreEqual(idA, idB); VideoId converted = (VideoId)idB; Assert.AreEqual(VideoIdType.VideoAlias, converted.IdType); }
public async Task DownloadVideo(string folder, string videoIdOrUrl, IProgress <double> progress, CancellationToken token = default) { var videoId = new VideoId(videoIdOrUrl); var videoInfo = await _videoClient.GetAsync(videoId); var streamManifest = await _streamClient.GetManifestAsync(videoId).ConfigureAwait(false); var streamInfo = streamManifest.GetAudioOnly().WithHighestBitrate(); string filePath = $"{folder}\\{videoInfo.Title}.{streamInfo.Container.Name}"; await _streamClient.DownloadAsync(streamInfo, filePath, progress, token).ConfigureAwait(false); }
/// <summary> /// Initializes an instance of <see cref="PlaylistVideo"/>. /// </summary> public PlaylistVideo( VideoId id, string title, Author author, TimeSpan?duration, IReadOnlyList <Thumbnail> thumbnails) { Id = id; Title = title; Author = author; Duration = duration; Thumbnails = thumbnails; }
private void cleartextboxes() { FirstName.Clear(); LastName.Clear(); Address.Clear(); PhoneNumber.Clear(); CustomerID.Clear(); VideoId.Clear(); RentedCost.Clear(); Year.Clear(); Title.Clear(); Genre.Clear(); }
public async Task <ContentManageResult> RemoveMylistItem(MylistId mylistId, VideoId videoId) { var itemId = _loginUserMylistItemIdRepository.GetItemId(mylistId, videoId); if (mylistId.IsWatchAfterMylist) { return(await _niconicoSession.ToolkitContext.Mylist.LoginUser.RemoveWatchAfterItemsAsync(new[] { itemId })); } else { return(await _niconicoSession.ToolkitContext.Mylist.LoginUser.RemoveMylistItemsAsync(mylistId, new[] { itemId })); } }
public override int GetHashCode() { int hash = 1; if (videoId_ != null) { hash ^= VideoId.GetHashCode(); } if (userId_ != null) { hash ^= UserId.GetHashCode(); } return(hash); }
private Utils.VideoSettings GetVideoSettings(VideoId videoId) { StreamManifest manifest = client.Videos.Streams.GetManifestAsync(videoId).Result; Utils.VideoSettings videoSettings = new Utils.VideoSettings() { StreamManifest = manifest, MuxedStreamInfo = manifest.GetMuxedStreams().ToList(), VideoOnlyStreamInfo = manifest.GetVideoOnlyStreams().ToList(), AudioOnlyStreamInfo = manifest.GetAudioOnlyStreams().ToList() }; return(videoSettings); }
public override int GetHashCode() { int hash = 1; if (videoId_ != null) { hash ^= VideoId.GetHashCode(); } if (Views != 0L) { hash ^= Views.GetHashCode(); } return(hash); }
public override int GetHashCode() { int hash = 1; if (videoId_ != null) { hash ^= VideoId.GetHashCode(); } if (timestamp_ != null) { hash ^= Timestamp.GetHashCode(); } return(hash); }
/// <summary> /// Gets the HTTP Live Stream (HLS) manifest URL for the specified video (if it's a live video stream). /// </summary> public async Task <string> GetHttpLiveStreamUrlAsync(VideoId videoId) { var videoInfoResponse = await VideoInfoResponse.GetAsync(_httpClient, videoId); var playerResponse = videoInfoResponse.GetPlayerResponse(); if (!playerResponse.IsVideoPlayable()) { throw VideoUnplayableException.Unplayable(videoId, playerResponse.TryGetVideoPlayabilityError()); } return(playerResponse.TryGetHlsManifestUrl() ?? throw VideoUnplayableException.NotLiveStream(videoId)); }
private Video( VideoId id, VideoTitle title, VideoDescription description, VideoAuthor author, VideoCreatedAT createdAt ) { this.id = id; this.title = title; this.description = description; this.author = author; this.createdAt = createdAt; }
public void VideoId() { var idA = new VideoId("sm12345"); Assert.AreEqual(VideoIdType.Video, idA.IdType); var idB = new VideoId("so012345"); Assert.AreEqual(VideoIdType.Video, idB.IdType); var idC = new VideoId("nm012345"); Assert.AreEqual(VideoIdType.Video, idC.IdType); }
private async Task <InAppNotificationPayload> SubmitVideoContentSuggestion(VideoId videoId) { var(res, nicoVideo) = await NicoVideoProvider.GetVideoInfoAsync(videoId); if (res.Video.IsDeleted || string.IsNullOrEmpty(nicoVideo.Title)) { return(null); } return(new InAppNotificationPayload() { Content = "InAppNotification_ContentDetectedFromClipboard".Translate(nicoVideo.Title), ShowDuration = DefaultNotificationShowDuration, IsShowDismissButton = true, Commands = { new InAppNotificationCommand() { Label = "Play".Translate(), Command = new RelayCommand(() => { _messenger.Send(VideoPlayRequestMessage.PlayVideo(videoId)); NotificationService.DismissInAppNotification(); }) }, new InAppNotificationCommand() { Label = "@view".Translate(), Command = new RelayCommand(() => { _queuePlaylist.Add(nicoVideo); NotificationService.DismissInAppNotification(); }) }, new InAppNotificationCommand() { Label = HohoemaPageType.VideoInfomation.Translate(), Command = new RelayCommand(() => { PageManager.OpenPageWithId(HohoemaPageType.VideoInfomation, videoId); NotificationService.DismissInAppNotification(); }) }, } }); }
/// <summary> /// Gets the manifest containing information about available streams on the specified video. /// </summary> public async ValueTask <StreamManifest> GetManifestAsync( VideoId videoId, CancellationToken cancellationToken = default) { var streamInfos = new List <IStreamInfo>(); var playerResponse = await _controller.GetPlayerResponseAsync(videoId, cancellationToken); if (!playerResponse.IsVideoPlayable()) { // Try the embedded variant if this player response comes back unplayable playerResponse = await _controller.GetPlayerResponseAsync(videoId, true, cancellationToken); } var purchasePreviewVideoId = playerResponse.TryGetPreviewVideoId(); if (!string.IsNullOrWhiteSpace(purchasePreviewVideoId)) { throw new VideoRequiresPurchaseException( $"Video '{videoId}' requires purchase and cannot be played.", purchasePreviewVideoId ); } if (playerResponse.IsVideoPlayable()) { // Extract streams from player response await PopulateStreamInfosAsync(streamInfos, playerResponse.GetStreams(), cancellationToken); // Extract streams from DASH manifest var dashManifestUrl = playerResponse.TryGetDashManifestUrl(); if (!string.IsNullOrWhiteSpace(dashManifestUrl)) { var dashManifest = await _controller.GetDashManifestAsync(dashManifestUrl, cancellationToken); await PopulateStreamInfosAsync(streamInfos, dashManifest.GetStreams(), cancellationToken); } } // Couldn't extract any streams if (!streamInfos.Any()) { var reason = playerResponse.TryGetVideoPlayabilityError(); throw new VideoUnplayableException( $"Video '{videoId}' does not contain any playable streams. Reason: '{reason}'." ); } return(new StreamManifest(streamInfos)); }
/// <summary> /// Converts most fitting streams for the specified video ID. /// </summary> public async Task ConvertStreamsAsync( VideoId videoId, string outputFilePath, IProgress <double>?progress = null, CancellationToken cancellationToken = default) { var options = new ConversionOptionsBuilder(outputFilePath).Build(); await ConvertStreamsAsync( videoId, options, progress, cancellationToken ); }
public override int GetHashCode() { int hash = 1; if (videoId_ != null) { hash ^= VideoId.GetHashCode(); } hash ^= videos_.GetHashCode(); if (PagingState.Length != 0) { hash ^= PagingState.GetHashCode(); } return(hash); }
/// <summary> /// Selects best media streams for the specified video, downloads them, and processes into a single file. /// Conversion format is derived from file extension, unless explicitly specified. /// </summary> public static async Task DownloadAsync( this VideoClient videoClient, VideoId videoId, string outputFilePath, Action <ConversionRequestBuilder> configure, IProgress <double>?progress = null, CancellationToken cancellationToken = default) { var requestBuilder = new ConversionRequestBuilder(outputFilePath); configure(requestBuilder); var request = requestBuilder.Build(); await videoClient.DownloadAsync(videoId, request, progress, cancellationToken); }
public async Task GetAudioStreamDataAsync() { var youtube = new YoutubeClient(); var url = "https://www.youtube.com/watch?v=vyuHCcI4Q-g"; // Read the video ID var videoId = new VideoId(url); // Get media streams & choose the best muxed stream var streams = await youtube.Videos.Streams.GetManifestAsync(videoId); var streamInfo = streams.GetAudioOnly(); var mp4Stream = streamInfo.SingleOrDefault(x => x.Container.Name == "mp4"); var stream = await youtube.Videos.Streams.GetAsync(mp4Stream); Assert.IsNotNull(stream); }
public static PlayAnimationEvent Serdes(PlayAnimationEvent e, AssetMapping mapping, ISerializer s) { if (s == null) { throw new ArgumentNullException(nameof(s)); } e ??= new PlayAnimationEvent(); e.VideoId = VideoId.SerdesU8(nameof(VideoId), e.VideoId, mapping, s); e.X = s.UInt8(nameof(X), e.X); e.Y = s.UInt8(nameof(Y), e.Y); e.Unk4 = s.UInt8(nameof(Unk4), e.Unk4); e.Unk5 = s.UInt8(nameof(Unk5), e.Unk5); e.Unk6 = s.UInt16(nameof(Unk6), e.Unk6); e.Unk8 = s.UInt16(nameof(Unk8), e.Unk8); return(e); }
/// <summary> /// Converts most fitting streams for the specified video ID. /// </summary> public async Task ConvertStreamsAsync( VideoId videoId, ConversionOptions options, IProgress <double>?progress = null, CancellationToken cancellationToken = default) { var streamManifest = await _client.GetManifestAsync(videoId); var streamInfos = GetBestMediaStreamInfos(streamManifest, options.Format).ToArray(); await ConvertStreamsAsync( streamInfos, options, progress, cancellationToken ); }
public async Task <PlayerResponseExtractor> GetPlayerResponseAsync( VideoId videoId, bool isEmbedded, CancellationToken cancellationToken = default) { const string url = $"https://www.youtube.com/youtubei/v1/player?key={ApiKey}"; var payload = new { videoId = videoId.Value, contentCheckOk = true, racyCheckOk = true, context = new { client = new { clientName = "ANDROID", clientScreen = isEmbedded ? "EMBED" : null, clientVersion = "16.46.37", hl = "en", gl = "US", utcOffsetMinutes = 0 }, thirdParty = new { embedUrl = "https://www.youtube.com" } } }; using var request = new HttpRequestMessage(HttpMethod.Post, url) { Content = Json.SerializeToHttpContent(payload) }; var raw = await SendHttpRequestAsync(request, cancellationToken); var playerResponse = PlayerResponseExtractor.Create(raw); if (!playerResponse.IsVideoAvailable()) { throw new VideoUnavailableException($"Video '{videoId}' is not available."); } return(playerResponse); }
private async Task <bool> DownloadVideo(VideoId videoId, string info = "") { try { YoutubeClient client = new YoutubeClient(); Video video = await client.Videos.GetAsync(videoId); this.lblVideo.Text = video.Title; var streams = await client.Videos.Streams.GetManifestAsync(videoId); var streamInfoSet = streams.GetMuxed().WithHighestVideoQuality(); string filePath = video.Title + "." + streamInfoSet.Container.Name; filePath = filePath.Replace("/", ""); string invalid = new string(Path.GetInvalidFileNameChars()) + new string(Path.GetInvalidPathChars()); foreach (char c in invalid) { filePath = filePath.Replace(c.ToString(), ""); } string oldFileName = Path.Combine(downloadedPath, filePath); string indexFileName = Path.Combine(downloadedPath, (string.IsNullOrEmpty(info) ? "" : (info + "_")) + filePath); if (File.Exists(oldFileName)) { File.Move(oldFileName, indexFileName); return(true); } picBox.Load(video.Thumbnails.LowResUrl); await client.Videos.Streams.DownloadAsync(streamInfoSet, indexFileName, this); return(true); } catch (Exception ex) { MessageBox.Show(ex.Message); return(false); } }
/// <summary> /// Gets the manifest that contains information about available streams in the specified video. /// </summary> public async Task <StreamManifest> GetManifestAsync(VideoId videoId) { // We can try to extract the manifest from two sources: get_video_info and the video watch page. // In some cases one works, in some cases another does. try { var streamInfoSource = await GetSteamContextFromVideoInfoAsync(videoId); return(await GetManifestAsync(streamInfoSource)); } catch (YoutubeExplodeException) { var streamInfoSource = await GetStreamContextFromWatchPageAsync(videoId); return(await GetManifestAsync(streamInfoSource)); } }
public static PlayAnimationEvent Serdes(PlayAnimationEvent e, AssetMapping mapping, ISerializer s) { if (s == null) { throw new ArgumentNullException(nameof(s)); } e ??= new PlayAnimationEvent(); e.VideoId = VideoId.SerdesU8(nameof(VideoId), e.VideoId, mapping, s); e.X = s.UInt8(nameof(X), e.X); e.Y = s.UInt8(nameof(Y), e.Y); e.Unk4 = s.UInt8(nameof(Unk4), e.Unk4); e.Unk5 = s.UInt8(nameof(Unk5), e.Unk5); int zeroes = s.UInt16(null, 0); zeroes += s.UInt16(null, 0); s.Assert(zeroes == 0, "PlayAnimation: Expected fields 6, 8 to be 0"); return(e); }
public Video(VideoId id, bool looping) { On <IdleClockEvent>(_ => { if (!_looping && _player.Frame == _player.FrameCount - 1) { Complete?.Invoke(); Remove(); } else { _player.NextFrame(); _texture.GetMutableLayerBuffer(0); } }); _id = id; _looping = looping; }