/// <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()) )); }
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 ) )); }
/// <summary>>動画の詳細情報を取得するストリームを取得する、情報は0番目の配列に格納される</summary> /// <param name="IsHtml">合わせてHtmlから情報を取得するか、現在動画説明文のみ</param> public Streams <VideoInfoResponse> OpenVideoInfoDownloadStreams(bool IsHtml = true) { var streamDataList = new List <StreamData>(); VideoInfoResponse result = null; #region APIアクセス streamDataList.Add( new StreamData() { StreamType = StreamType.Read, GetStream = () => { try { return(context.Client.OpenDownloadStream(string.Format(ApiUrls.GetVideoInfo, target.ID))); } catch (WebException e) { throw new WebException("動画情報取得APIにアクセス出来ませんでした", e); } }, SetReadData = (data) => { var serialize = new XmlSerializer(typeof(Serial.GetInfo.NicovideoThumbResponse)); var serial = (Serial.GetInfo.NicovideoThumbResponse)serialize.Deserialize( new MemoryStream(data)); result = converter.ConvertVideoInfoResponse(serial); } }); #endregion #region HTMLアクセス if (IsHtml)//HTMLから取得する { var videoPageStreamData = OpenVideoPageStreamData(); if (videoPageStreamData != null) { var super = videoPageStreamData.SetReadData; videoPageStreamData.SetReadData = (data) => { if (result.Status != Status.OK) { return; } super(data); result.VideoInfos[0].Description = HtmlTextRegex.VideoDescription.Match(htmlCache).Groups["value"].Value; }; streamDataList.Add(videoPageStreamData); } } #endregion return(new Streams <VideoInfoResponse>( streamDataList.ToArray(), () => result)); }
/// <summary> /// Gets the metadata associated with the channel that uploaded the specified video. /// </summary> public async Task <Channel> GetByVideoAsync(VideoId videoId) { var videoInfoResponse = await VideoInfoResponse.GetAsync(_httpClient, videoId); var playerResponse = videoInfoResponse.GetPlayerResponse(); var channelId = playerResponse.GetVideoChannelId(); return(await GetAsync(channelId)); }
private async Task <StreamContext> GetSteamContextFromVideoInfoAsync(VideoId videoId) { var embedPage = await EmbedPage.GetAsync(_httpClient, videoId); var playerConfig = embedPage.TryGetPlayerConfig() ?? throw VideoUnplayableException.Unplayable(videoId); var playerSourceUrl = embedPage.TryGetPlayerSourceUrl() ?? playerConfig.GetPlayerSourceUrl(); var playerSource = await PlayerSource.GetAsync(_httpClient, playerSourceUrl); 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)); }
/// <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); }
/// <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)); }
/// <summary> /// Gets the manifest that contains information about available closed caption tracks in the specified video. /// </summary> public async Task <ClosedCaptionManifest> GetManifestAsync(VideoId videoId) { var videoInfoResponse = await VideoInfoResponse.GetAsync(_httpClient, videoId); var playerResponse = videoInfoResponse.GetPlayerResponse(); var tracks = playerResponse .GetClosedCaptionTracks() .Select(track => new ClosedCaptionTrackInfo( track.GetUrl(), new Language( track.GetLanguageCode(), track.GetLanguageName() ), track.IsAutoGenerated() )).ToArray(); return(new ClosedCaptionManifest(tracks)); }
/// <summary> /// Get Video Info /// </summary> /// <param name="videoKey"> video key</param> /// <returns></returns> public VideoInfoResponse GetVideoInfo(string videoKey) { VideoInfoResponse vi = new VideoInfoResponse(); try { NameValueCollection nvc = new NameValueCollection(); nvc.Add("video_key", videoKey); string response = Call("/videos/show", nvc); vi = JsonConvert.DeserializeObject <VideoInfoResponse>(response); } catch (Exception ex) { vi.Status = CallExecutionStatus.Error; vi.ErrorMessage = ex.Message + Environment.NewLine + ex.StackTrace; } return(vi); }
public void GetVideo(string url, Action <VideoInfoResponse, Exception> callback) { try { var startInfo = new ProcessStartInfo(YoutubeDlFilename) { Arguments = $"--ignore-errors --ignore-config --flat-playlist --dump-single-json {url}", CreateNoWindow = true, UseShellExecute = false, RedirectStandardOutput = true }; var response = new VideoInfoResponse(); var videos = new List <Video>(); var playlists = new List <Playlist>(); using (var ydlProcess = Process.Start(startInfo)) { if (ydlProcess == null) { callback(null, new Exception("Cannot start info fetching process.")); return; } var output = ydlProcess.StandardOutput; while (!output.EndOfStream) { var json = output.ReadLine(); if (json == "null") { continue; } var jsonObject = JsonConvert.DeserializeObject <JObject>(json); var jsonProperties = jsonObject.Children <JProperty>(); if (jsonProperties.All(x => x.Name != "_type")) { // TODO: check if no error videos.Add(JsonConvert.DeserializeObject <Video>(json)); } else { var modelType = ((dynamic)jsonObject)._type.ToString(); if (modelType == "playlist") { playlists.Add(JsonConvert.DeserializeObject <Playlist>(json)); } } //if (typeProperty == null) //{ // videos.Add(JsonConvert.DeserializeObject<Video>(json)); //} //else if (typeProperty.Value.ToString() == "playlist") //{ // //} } ydlProcess.Close(); } response.Videos = videos.ToArray(); response.Playlists = playlists.ToArray(); callback(response, null); } catch (Exception ex) { callback(null, ex); } }