private async Task _handleYoutubePacket(SessionEventArgs session) { // check if the packet in session is Audio or Video YoutubeMediaPacketType PacketType = _parseMediaPacketType(session.HttpClient.Response.Headers.Headers["Content-Type"].Value); // if content type is not video nor audio cancel it if (PacketType == YoutubeMediaPacketType.Unknown) { return; } var requestURL = requestURLFromSession(session); // making sure that the packet is valid to parse if (!YoutubeMediaPacket.IsValidYoutubeRequestURL(requestURL)) { return; } byte[] bodyBytes = await session.GetResponseBody(); var newPacket = new YoutubeMediaPacket(PacketType, requestURL, bodyBytes); // if videos list contains a video with the same fingerprint append the packet to it // otherwise create another video and add new packet to bool isVideoAddedBefore = this.VideosManagers.Any(x => x.Video.VideoFingerPrint == newPacket.VideoFingerPrint); if (!isVideoAddedBefore) { var newVideo = new YoutubeVideo(newPacket.VideoFingerPrint); var newVideoManager = new YoutubeVideoManager(newVideo, _client); VideosManagers.Add(newVideoManager); newVideoManager.OnYoutubeLastPacketRecieved += videoLastPacketRecieved; newVideoManager.OnYoutubeStored += NewVideoManager_OnYoutubeStored; newVideoManager.AddPacketFile(newPacket); } else { var packetVideo = VideosManagers.Where(x => x.Video.VideoFingerPrint == newPacket.VideoFingerPrint).FirstOrDefault(); packetVideo.AddPacketFile(newPacket); } }
private void videoLastPacketRecieved(object sender, YoutubeMediaPacket lastPacket) { YoutubeVideoManager videoManager = sender as YoutubeVideoManager; OnNewVideoLastPacketRecieved?.Invoke(videoManager); }