public async Task downloadBaru(IStreamInfo streamInfo, attributeVideo attr) { if (streamInfo == null) { Console.Error.WriteLine("This videos has no streams"); } // Compose file name, based on metadata string fileName = attr.namaFile; string folder = Path.Combine(rootDirectory, attr.Chanel); Console.WriteLine("nama filenya " + folder + " dan " + fileName); string lokasi = Path.Combine(folder, fileName); cekDirectory(folder); Console.WriteLine(lokasi); Console.Write("sedang mengunduh - "); using (var progress = new ProgressBar()) await yt.Videos.Streams.DownloadAsync(streamInfo, lokasi, progress); Console.WriteLine($"video disimipan di '{lokasi}'"); }
// private Process CreateStream() // { // return Process.Start(new ProcessStartInfo // { // FileName = "ffmpeg", // Arguments = "-v verbose -report -probesize 2147483647 -i test -ac 2 -ar 48000 -f s16le pipe:1", // UseShellExecute = false, // RedirectStandardOutput = true, // RedirectStandardInput = true, // RedirectStandardError = true, // }); // } private async Task SendAsync(IAudioClient client, Video video) { var a = await GetManifestAsync(video); IStreamInfo info = a.GetAudioOnly().WithHighestBitrate(); await youtube.Videos.Streams.DownloadAsync(info, "test"); //using (var ytVideo = await youtube.Videos.Streams.GetAsync(streamInfo)) using (var ffmpeg = FFmpegUtils.CreateFFmpeg(fFmpegArguments)) using (var output = ffmpeg.StandardOutput.BaseStream) //using (var input = ffmpeg.StandardInput.BaseStream) using (var discord = client.CreatePCMStream(AudioApplication.Mixed)) { try { await output.CopyToAsync(discord); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } finally { await discord.FlushAsync(); } } }
public static void DownloadVideo(IStreamInfo streamInfo, string fileName) { var youtube = new YoutubeClient(); var stream = youtube.Videos.Streams.GetAsync(streamInfo); youtube.Videos.Streams.DownloadAsync(streamInfo, $"video.{streamInfo.Container}"); }
/// <summary> /// Gets the stream identified by the specified metadata. /// </summary> public async ValueTask <Stream> GetAsync( IStreamInfo streamInfo, CancellationToken cancellationToken = default) { // For most streams, YouTube limits transfer speed to match the video playback rate. // This helps them avoid unnecessary bandwidth, but for us it's a hindrance because // we want to download the stream as fast as possible. // To solve this, we divide the logical stream up into multiple segments and download // them all separately. var isThrottled = !Regex.IsMatch(streamInfo.Url, "ratebypass[=/]yes"); var segmentSize = isThrottled ? 9_898_989 // breakpoint after which the throttling kicks in : (long?)null; // no segmentation for non-throttled streams var stream = new SegmentedHttpStream( _httpClient, streamInfo.Url, streamInfo.Size.Bytes, segmentSize ); // Pre-resolve inner stream eagerly await stream.PreloadAsync(cancellationToken); return(stream); }
private void Dispose(bool disposing) { if (this.disposed) { return; } if (disposing) { this.source = null; this.streamInfo = null; this.graph = null; this.videoRender = null; this.audioRender = null; this.videoGrabber = null; this.audioGrabber = null; if (this.sampleHandler != null) { this.sampleHandler.Dispose(); this.sampleHandler = null; } this.isConfigured = false; } this.disposed = true; }
/// <summary> /// get stream info from http response /// </summary> /// <returns></returns> public T GetStream <T>() where T : IStreamInfo { IStreamInfo streamInfo = (IStreamInfo)Activator.CreateInstance(typeof(T), Stream); streamInfo.Status = Status; if (ResponseHeaders.ContainsKey("Content-Length")) { streamInfo.Length = long.Parse(ResponseHeaders["Content-Length"]); } if (ResponseHeaders.ContainsKey("Content-Type")) { streamInfo.ContentType = ResponseHeaders["Content-Type"]; } if (ResponseHeaders.ContainsKey("Content-Disposition")) { try { CustomContentDisposition customContentDisposition = new CustomContentDisposition(ResponseHeaders["Content-Disposition"]); streamInfo.FileName = customContentDisposition.FileName; } catch { } } return((T)streamInfo); }
/// <summary> /// Downloads an already multiplexed or audio/video-only stream. /// </summary> /// <param name="video">The video to download.</param> /// <param name="streamInfo">Multiplexed or audio/video-only stream information.</param> /// <param name="cancellationToken">Used to cancel asynchronous operations.</param> public static async Task DownloadSingleStreamAsync(IVideo video, IStreamInfo streamInfo, CancellationToken cancellationToken) { await Youtube.Client.Videos.Streams.DownloadAsync( streamInfo, $@"{App.VideoFolderPath}/{video.Id.Value}.{streamInfo.Container.Name}", cancellationToken : cancellationToken); }
private static async Task <string> DownloadMedia(IStreamInfo mediaInfo, Video generalInfo, CancellationToken cancellationToken) { var fileExtension = mediaInfo.Container.Name; var fileName = $"{generalInfo.Title}.{fileExtension}"; fileName = Path.GetInvalidFileNameChars().Aggregate(fileName, (current, c) => current.Replace(c, '-')); if (!string.IsNullOrEmpty(ApplicationConfiguration.DownloadPathOverride)) { fileName = Path.Combine(ApplicationConfiguration.DownloadPathOverride, fileName); } Console.Write("Downloading... "); Console.ForegroundColor = ConsoleColor.Cyan; using (var progress = new ConsoleProgressBar()) { await Client.Videos.Streams.DownloadAsync(mediaInfo, fileName, progress, cancellationToken); } Console.ResetColor(); Console.WriteLine(); return(fileName); }
/// <summary> /// Copies the actual stream which is identified by the specified metadata to the specified stream. /// </summary> public async Task CopyToAsync(IStreamInfo streamInfo, Stream destination, IProgress <double>?progress = null, CancellationToken cancellationToken = default) { using var input = await GetAsync(streamInfo); await input.CopyToAsync(destination, progress, cancellationToken); }
public async Task <VideoViewModel> DownloadMp3(VideoViewModel model, string basePath) { try { //var converter = new YoutubeConverter(_youtubeDownloader, Path.Combine(basePath, "ffmpeg.exe")); //await converter.DownloadVideoAsync("4Bs2wOqFFck", $"video_{Guid.NewGuid()}.mp4"); var streamManifest = await _youtubeDownloader.Videos.Streams.GetManifestAsync(model.VideoId); var streamInfo = streamManifest.GetAudioOnlyStreams().GetWithHighestBitrate(); // Combine them into a collection var streamInfos = new IStreamInfo[] { streamInfo }; var fileName = $"{model.Author} - {model.Title}_{Guid.NewGuid()}.{streamInfo.Container}"; model.OriginalFileName = ReplaceInvalidChars(fileName); var filepath = Path.Combine(basePath, model.OriginalFileName); //await converter.DownloadAndProcessMediaStreamsAsync(streamInfos, filepath, "mp3"); await _youtubeDownloader.Videos.Streams.DownloadAsync(streamInfo, filepath); //await _youtubeDownloader.Videos.DownloadAsync((streamInfos, new ConversionRequestBuilder("audio.mp3").Build()); //var proc = new Process(); //proc.StartInfo.FileName = Path.Combine(basePath, "ffmpeg.exe"); ////proc.StartInfo.Arguments = $"-i {filepath} -vn -f mp3 -ab 192k {Path.Combine(basePath, "output.mp3")}"; //proc.StartInfo.Arguments = $"-i {filepath} -vn -ar 44100 -ac 2 -ab 192k -f mp3 {Path.Combine(basePath, "output.mp3")}"; //proc.StartInfo.RedirectStandardError = true; //proc.StartInfo.UseShellExecute = false; //if (!proc.Start()) //{ // Console.WriteLine("Error starting"); //} //StreamReader reader = proc.StandardError; //string line; //while ((line = reader.ReadLine()) != null) //{ // Console.WriteLine(line); //} //proc.Close(); using (Process p = new Process()) { p.StartInfo.UseShellExecute = false; p.StartInfo.CreateNoWindow = true; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.FileName = Path.Combine(basePath, "ffmpeg.exe"); var mp3fileName = $"{model.Author} - {model.Title}_{Guid.NewGuid()}.mp3"; p.StartInfo.Arguments = $"-i \"{filepath}\" -vn -ar 44100 -ac 2 -ab 192k -f mp3 \"{Path.Combine(basePath, mp3fileName)}\""; p.Start(); p.WaitForExit(); model.MP3FileName = mp3fileName; var result = p.StandardOutput.ReadToEnd(); } return(model); } catch (Exception ex) { throw ex; } }
/// <summary> /// Downloads the stream identified by the specified metadata to the specified file. /// </summary> public async ValueTask DownloadAsync( IStreamInfo streamInfo, string filePath, IProgress <double>?progress = null, CancellationToken cancellationToken = default) { using var destination = File.Create(filePath); await CopyToAsync(streamInfo, destination, progress, cancellationToken); }
private async Task <Stream> GetAudioStreamAsync(Video video) { StreamManifest manifest = await GetManifestAsync(video); IStreamInfo streamInfo = manifest.GetAudioOnly().WithHighestBitrate(); System.Console.WriteLine(streamInfo.Bitrate); return(await youtube.Videos.Streams.GetAsync(streamInfo)); }
private async Task downloadYouTubeMedia(YoutubeClient client, IStreamInfo streamInfo, string downloadPath) { var progress = new Progress <double>(p => { indicator.updateProgress("Downloading Media: ", (int)((p - (int)p) * 100)); }); await client.Videos.Streams.DownloadAsync(streamInfo, downloadPath, progress); indicator.updateProgress("Media Download Done! ", 100); }
private async Task FetchStreamInfo() { var youtube = new YoutubeClient(); Video = await youtube.Videos.GetAsync(_videoId); var streamManifest = await youtube.Videos.Streams.GetManifestAsync(_videoId); StreamInfo = streamManifest.GetAudioOnlyStreams().GetWithHighestBitrate(); }
/// <summary> /// Erzeugt eine neue Zugriffsinstanz. /// </summary> /// <param name="main">Die zugehörige Anwendung.</param> /// <param name="replayPath">Pfad zu einer VCR.NET Aufzeichnungsdatei.</param> public VCRAdaptor(IViewerSite main, string replayPath) : base(main) { // Connect to alternate interfaces ChannelInfo = (IChannelInfo)main; StreamInfo = (IStreamInfo)main; // Remember m_Profile = RemoteInfo.VCRProfile; // Use default if (string.IsNullOrEmpty(m_Profile)) { m_Profile = "*"; } // Construct Url Uri uri = RemoteInfo.ServerUri; // Connect to stream Connect(StreamInfo.BroadcastIP, StreamInfo.BroadcastPort, uri.Host); // Check startup mode if (string.IsNullOrEmpty(replayPath)) { // Special if LIVE is active var current = VCRNETRestProxy.GetFirstActivityForProfile(EndPoint, Profile); if (current != null) { if (!current.IsActive) { current = null; } else if ("LIVE".Equals(current.name)) { current = null; } } // Start correct access module if (current == null) { StartLIVE(true); } else { StartWatch(null, true); } } else { // Start remote file replay StartReplay(replayPath, null, null, true); } }
private static void DownloadMediaStream(IStreamInfo streamInfo, string filename, Settings settings) { var tempFileName = Path.Combine(settings.TempDirectory, Guid.NewGuid().ToString()); Directory.CreateDirectory(Path.GetDirectoryName(tempFileName)); Directory.CreateDirectory(Path.GetDirectoryName(filename)); Console.WriteLine($"Downloading Media to {filename}..."); _youtube.Videos.Streams.DownloadAsync(streamInfo, tempFileName).GetAwaiter().GetResult(); File.Move(tempFileName, filename); }
public CallMethodResultInfo(MethodCallbackInfo callbackInfo, IStreamInfo streamInfo, List <HttpKeyAttribute> httpKeyAttributees, Type serviceType, MethodInfo method, object serviceInstance, FileActionResult fileActionResult, T context, object result) { CallbackInfo = callbackInfo; StreamInfo = streamInfo; HttpKeyAttributees = httpKeyAttributees; ServiceType = serviceType; Method = method; ServiceInstance = serviceInstance; FileActionResult = fileActionResult; Context = context; Result = result; }
private static async Task DownloadPlaylist(string folder, string id) { //Playlist playlist = await Client.Playlists.GetAsync(id); await foreach (Video video in Client.Playlists.GetVideosAsync(new PlaylistId(id))) { Console.WriteLine(video.Title); StreamManifest streamManifest = await Client.Videos.Streams.GetManifestAsync(video.Id); IStreamInfo streamInfo = streamManifest.GetAudioOnly().Where(stream => stream.Container == Container.Mp4).WithHighestBitrate(); await Client.Videos.Streams.DownloadAsync(streamInfo, Path.Combine(folder, SanitizeFilename(video.Title) + ".mp3")); } }
public static void UpdateUrl(this IStreamInfo streamInfo, string url) { Guard.NotNull(streamInfo, nameof(streamInfo)); if (string.IsNullOrEmpty(streamInfo.Url)) { return; } var field = streamInfo.GetType().GetField("<Url>k__BackingField", BindingFlags.Instance | BindingFlags.NonPublic); field.SetValue(streamInfo, url); }
public async Task SaveAudioToDiskAsync(string link, Playlist playList) { string source = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName, @"music\"); playList.PlaylistName += @"\"; //playlistname is the foldername YoutubeClient youtube = new YoutubeClient(); Video video = await youtube.Videos.GetAsync(link); string legalTitle = string.Join("", video.Title.Split(Path.GetInvalidFileNameChars())); // Removes all possible illegal filename characetrs from the title StreamManifest streamManifest = await youtube.Videos.Streams.GetManifestAsync(link); IStreamInfo streamInfo = streamManifest.GetAudioOnly().WithHighestBitrate(); if (streamInfo != null) { // Download the stream to file string fileName = $"{source + playList.PlaylistName + legalTitle}"; await youtube.Videos.Streams.DownloadAsync(streamInfo, fileName + ".mp4"); //downloaden van mp4 FFMpegConverter ffMpeg = new FFMpegConverter(); ffMpeg.ConvertMedia(fileName + ".mp4", fileName + ".mp3", "mp3"); //converteren van mp4 naar mp3 File.Delete(fileName + ".mp4"); Song newSong = new Song(fileName + ".mp3"); //aanmaken van songobject newSong.ArtistName = video.Author; //zetten van de filetags newSong.SongTitle = video.Title; newSong.AlbumTitle = null; newSong.AlbumTrack = 0; newSong.MaxAlbumTrack = 0; newSong.Year = 0; newSong.BPM = 0; /* downloaden van thumbnail*/ using (WebClient client = new WebClient()) { client.DownloadFile(video.Thumbnails.HighResUrl, fileName + ".jpg"); } newSong.setAlbumArt(fileName + ".jpg"); //zetten van albumart metadata File.Delete(fileName + ".jpg"); //deleten van thumbnail image file newSong.saveFileTag(); //opslaan van filetags playList.addSong(newSong); //toevoegen aan database DbManager db = new DbManager(); db.addSongToDatabase(newSong); } }
public async void DownloadVideo(string uri, string directory, string format) { if (format == "1") { var youtube = new YoutubeClient(); var vid = await youtube.Videos.GetAsync(uri); YourTube yourTube = new YourTube(); if (File.Exists(directory + "\\" + vid.Title + ".mp4")) { yourTube.YourHaveVideo(); } else { var streamManifest = await youtube.Videos.Streams.GetManifestAsync(vid.Id); var streamInfo = streamManifest.GetMuxed().WithHighestVideoQuality(); if (streamInfo != null) { await youtube.Videos.Streams.GetAsync(streamInfo); await youtube.Videos.Streams.DownloadAsync(streamInfo, vid.Title + ".mp4"); } string data = Directory.GetCurrentDirectory() + "\\"; File.Move(data + vid.Title + ".mp4", directory + "\\" + vid.Title + ".mp4"); int index = 1; progressBar1.Invoke((int)index); yourTube.DownloadEn(); } } else { var youtube = new YoutubeClient(); var vid = await youtube.Videos.GetAsync(uri); // Get stream manifest var streamManifest = await youtube.Videos.Streams.GetManifestAsync(uri); // Select streams (1080p60 / highest bitrate audio) var audioStreamInfo = streamManifest.GetAudioOnly().WithHighestBitrate(); var videoStreamInfo = streamManifest.GetVideoOnly().Where(s => s.Container == Container.Mp4).WithHighestVideoQuality(); var streamInfos = new IStreamInfo[] { audioStreamInfo, videoStreamInfo }; // Download and process them into one file string data = Directory.GetCurrentDirectory() + "\\"; await youtube.Videos.DownloadAsync(streamInfos, new ConversionRequestBuilder("a").Build()); } }
private async Task <IAttemptResult> DownloadVideoInternalAsync(IStreamInfo targetStream, Action <string> onMessage, IDownloadContext context, int maxParallelSegmentDLCount, string segmentDirectoryName, CancellationToken token) { try { await this._videoDownloadHelper.DownloadAsync(targetStream, onMessage, context, maxParallelSegmentDLCount, segmentDirectoryName, token); } catch (Exception e) { this._logger.Error($"動画のダウンロード中にエラーが発生しました。({this.context!.GetLogContent()})", e); onMessage("動画のダウンロードに失敗"); return(AttemptResult.Fail($"動画のダウンロード中にエラーが発生しました。(詳細: {e.Message})")); } return(AttemptResult.Succeeded()); }
/// <summary> /// Downloads separate audio and video streams, and multiplexes them together. /// </summary> /// <param name="video">The video to download.</param> /// <param name="audioStreamInfo">Audio stream information.</param> /// <param name="videoStreamInfo">Video stream information.</param> /// <param name="cancellationToken">Used to cancel asynchronous operations.</param> public static async Task DownloadMultipleStreamsAsync(IVideo video, IStreamInfo audioStreamInfo, IStreamInfo videoStreamInfo, CancellationToken cancellationToken) { var streamInfos = new IStreamInfo[] { audioStreamInfo, videoStreamInfo }; var conversionRequest = new ConversionRequestBuilder( $@"{App.VideoFolderPath}/{video.Id.Value}.{videoStreamInfo.Container.Name}") .SetFormat(videoStreamInfo.Container.Name) .SetPreset(ConversionPreset.Medium) .Build(); await Youtube.Client.Videos.DownloadAsync( streamInfos, conversionRequest, cancellationToken : cancellationToken); }
/// <summary> /// Gets the actual stream which is identified by the specified metadata. /// </summary> public Task <Stream> GetAsync(IStreamInfo streamInfo) { // YouTube streams are often rate-limited -- they return data at about the same rate // as the actual video is going. This helps them avoid unnecessary bandwidth by not loading // all data eagerly. On the other hand, we want to download the streams as fast as possible, // so we'll be splitting the stream into small segments and retrieving them separately, to // work around rate limiting. var segmentSize = streamInfo.IsRateLimited() ? 9_898_989 // this number was carefully devised through research : long.MaxValue; // don't use segmentation for non-rate-limited streams var stream = _httpClient.CreateSegmentedStream(streamInfo.Url, streamInfo.Size.TotalBytes, segmentSize); return(Task.FromResult <Stream>(stream)); }
public async Task <IActionResult> Download(string id) { var client = new YoutubeClient(); var converter = new YoutubeConverter(client); var streamManifest = await client.Videos.Streams.GetManifestAsync(id); var title = client.Videos.GetAsync(id).Result.Title; string path = $"{id}.mp3"; var streamInfo = streamManifest.GetAudioOnly().WithHighestBitrate(); var mediaStreamInfos = new IStreamInfo[] { streamInfo }; await converter.DownloadAndProcessMediaStreamsAsync(mediaStreamInfos, path, "mp3"); byte[] buff = System.IO.File.ReadAllBytes(path); System.IO.File.Delete(path); return(File(buff, "application/force-download", $"{title}.mp3")); }
/// <summary> /// Erzeugt eine neue Zugriffsinstanz. /// </summary> /// <param name="main">Die zugehörige Anwendung.</param> /// <param name="streamIndex">Teilaufzeichnung, die betrachtet werden soll.</param> /// <param name="timeshift">Gesetzt, wenn der Timeshift Modus aktiviert werden soll.</param> public VCRAdaptor(IViewerSite main, int streamIndex, bool timeshift) : base(main) { // Connect to alternate interfaces ChannelInfo = (IChannelInfo)main; StreamInfo = (IStreamInfo)main; // Remember m_Profile = RemoteInfo.VCRProfile; // Use default if (string.IsNullOrEmpty(m_Profile)) { m_Profile = "*"; } // Construct Url var uri = RemoteInfo.ServerUri; // Connect to stream Connect(StreamInfo.BroadcastIP, StreamInfo.BroadcastPort, uri.Host); // Find all current activities var activities = VCRNETRestProxy.GetActivitiesForProfile(EndPoint, Profile); if (activities.Count < 1) { StartLIVE(true); } else { // Find the activity var current = activities.FirstOrDefault(activity => activity.streamIndex == streamIndex); if (current == null) { StartWatch(null, true); } else if (timeshift && string.IsNullOrEmpty(StreamInfo.BroadcastIP) && (current.files.Length > 0)) { StartReplay(current.files[0], current.name, current, true); } else { StartWatch(string.Format("dvbnet:{0}", streamIndex), true); } } }
private string FormatText(IStreamInfo info) { if (info is MuxedStreamInfo muxed) { return(string.Format("V&A: {0} | {1} , Size: {2}", muxed.Container.Name, muxed.VideoResolution, muxed.Size)); } else if (info is VideoOnlyStreamInfo vo) { return(string.Format("V Only: {0} | {1} , Size: {2}", vo.Container.Name, vo.VideoResolution, vo.Size)); } else if (info is AudioOnlyStreamInfo ao) { return(string.Format("A Only: {0} | {1} , Size: {2}", ao.Container.Name, ao.Bitrate, ao.Size)); } return("Unknown Stream Info"); }
private static async Task HandleRequest(JukeboxConnection connection, JukeboxRequest request) { connection.CurrentRequest = request; IVoiceState voiceState = (IVoiceState)request.User; YoutubeClient youtube = new(); // Try to look up the video's manifest from YouTube StreamManifest streamManifest = await youtube.Videos.Streams.GetManifestAsync(request.VideoId); if (streamManifest != null) { // Get a reference to the audio-only stream from YouTube for the specified video IStreamInfo streamInfo = streamManifest.GetAudioOnly().WithHighestBitrate(); if (streamInfo != null) { // Ensure that the bot is connected to the requesting user's channel await EnsureConnectedToUsersChannel(connection, voiceState); // Create a new stream object to send audio to the Discord channel using AudioOutStream audioOutStream = connection.AudioClient.CreatePCMStream(AudioApplication.Music); // Start ffmpeg.exe and prepare to start capturing the output using Process ffmpeg = CreateFfmpeg(); Task ffmpegOutputTask = ffmpeg.StandardOutput.BaseStream.CopyToAsync(audioOutStream); // Transfer the audio data from YouTube to the ffmpeg input stream await youtube.Videos.Streams.CopyToAsync(streamInfo, ffmpeg.StandardInput.BaseStream); ffmpeg.StandardInput.BaseStream.Close(); // Wait until all output has been captured from ffmpeg and sent to Discord ffmpegOutputTask.Wait(); // By this point the song has finished playing await connection.AudioClient.SetSpeakingAsync(false); connection.LastActivity = DateTime.Now; connection.CurrentRequest = null; } } }
/// <summary> /// Erzeugte eine neue Zugriffsinstanz. /// </summary> /// <param name="profile">Zu verwendende DVB.NET Hardware Abstraktion.</param> /// <param name="main">Zugehörige Anwendung.</param> public DeviceAdpator(Profile profile, IViewerSite main) : base(main) { // Remember Profile = profile; // Attach to the device Device = HardwareManager.OpenHardware(Profile); // Create m_TTXConnector = new TTXStreamConsumer(this); // Load alternate interfaces GeneralInfo = (IGeneralInfo)main; ChannelInfo = (IChannelInfo)main; StreamInfo = (IStreamInfo)main; LocalInfo = (ILocalInfo)main; // Initialize core - DirectShow Graph feed directly from a Transport Stream SetAccessor(new AudioVideoAccessor()); }
public async Task <string> DownloadYouTubeVideo(string youTubeVideoId, string downloadDirectory = "Music/") { //Get the video Video videoData = await ytClient.Videos.GetAsync(youTubeVideoId); try { if (cancellationToken.IsCancellationRequested) { return(null); } //Get the audio stream info StreamManifest steamManifest = await ytClient.Videos.Streams.GetManifestAsync(youTubeVideoId); IStreamInfo audioSteam = steamManifest.GetAudioOnly().WithHighestBitrate(); string downloadLocation = $"{musicDirectory}{videoData.Title.RemoveIllegalChars()}.{audioSteam.Container.Name}"; Logger.Debug("Downloading YouTube video {@VideoTitle}({@VideoID}) to {@DownloadLocation}", videoData.Title, videoData.Id.Value, downloadLocation); await ytClient.Videos.Streams.DownloadAsync(audioSteam, downloadLocation, null, cancellationToken); return(!File.Exists(downloadLocation) ? null : downloadLocation); } catch (OperationCanceledException) { //User cancelled return(null); } catch (Exception ex) { Logger.Error("An error occured while download a YouTube video! {@Exception}", ex); return(null); } }
/// <summary> /// Erzeugt eine neue Zugriffsinstanz. /// </summary> /// <param name="main">Die zugehörige Anwendung.</param> /// <param name="streamIndex">Teilaufzeichnung, die betrachtet werden soll.</param> /// <param name="timeshift">Gesetzt, wenn der Timeshift Modus aktiviert werden soll.</param> public VCRAdaptor( IViewerSite main, int streamIndex, bool timeshift ) : base( main ) { // Connect to alternate interfaces ChannelInfo = (IChannelInfo) main; StreamInfo = (IStreamInfo) main; // Remember m_Profile = RemoteInfo.VCRProfile; // Use default if (string.IsNullOrEmpty( m_Profile )) m_Profile = "*"; // Construct Url var uri = RemoteInfo.ServerUri; // Connect to stream Connect( StreamInfo.BroadcastIP, StreamInfo.BroadcastPort, uri.Host ); // Find all current activities var activities = VCRNETRestProxy.GetActivitiesForProfile( EndPoint, Profile ); if (activities.Count < 1) StartLIVE( true ); else { // Find the activity var current = activities.FirstOrDefault( activity => activity.streamIndex == streamIndex ); if (current == null) StartWatch( null, true ); else if (timeshift && string.IsNullOrEmpty( StreamInfo.BroadcastIP ) && (current.files.Length > 0)) StartReplay( current.files[0], current.name, current, true ); else StartWatch( string.Format( "dvbnet:{0}", streamIndex ), true ); } }
private void Dispose(bool disposing) { if (this.disposed) return; if (disposing) { this.source = null; this.streamInfo = null; this.graph = null; this.videoRender = null; this.audioRender = null; this.videoGrabber = null; this.audioGrabber = null; if (this.sampleHandler != null) { this.sampleHandler.Dispose(); this.sampleHandler = null; } this.isConfigured = false; } this.disposed = true; }
/// <summary> /// Erzeugte eine neue Zugriffsinstanz. /// </summary> /// <param name="profile">Zu verwendende DVB.NET Hardware Abstraktion.</param> /// <param name="main">Zugehörige Anwendung.</param> public DeviceAdpator( Profile profile, IViewerSite main ) : base( main ) { // Remember Profile = profile; // Attach to the device Device = HardwareManager.OpenHardware( Profile ); // Create m_TTXConnector = new TTXStreamConsumer( this ); // Load alternate interfaces GeneralInfo = (IGeneralInfo) main; ChannelInfo = (IChannelInfo) main; StreamInfo = (IStreamInfo) main; LocalInfo = (ILocalInfo) main; // Initialize core - DirectShow Graph feed directly from a Transport Stream SetAccessor( new AudioVideoAccessor() ); }
/// <summary> /// Erzeugt eine neue Zugriffsinstanz. /// </summary> /// <param name="main">Die zugehörige Anwendung.</param> /// <param name="replayPath">Pfad zu einer VCR.NET Aufzeichnungsdatei.</param> public VCRAdaptor( IViewerSite main, string replayPath ) : base( main ) { // Connect to alternate interfaces ChannelInfo = (IChannelInfo) main; StreamInfo = (IStreamInfo) main; // Remember m_Profile = RemoteInfo.VCRProfile; // Use default if (string.IsNullOrEmpty( m_Profile )) m_Profile = "*"; // Construct Url Uri uri = RemoteInfo.ServerUri; // Connect to stream Connect( StreamInfo.BroadcastIP, StreamInfo.BroadcastPort, uri.Host ); // Check startup mode if (string.IsNullOrEmpty( replayPath )) { // Special if LIVE is active var current = VCRNETRestProxy.GetFirstActivityForProfile( EndPoint, Profile ); if (current != null) if (!current.IsActive) current = null; else if ("LIVE".Equals( current.name )) current = null; // Start correct access module if (current == null) StartLIVE( true ); else StartWatch( null, true ); } else { // Start remote file replay StartReplay( replayPath, null, null, true ); } }