private static async Task MainAsync() { // Client var client = new YoutubeClient(); // Get the video ID Console.Write("Enter YouTube video ID or URL: "); var videoId = Console.ReadLine(); videoId = NormalizeVideoId(videoId); // Get media stream info set var streamInfoSet = await client.GetVideoMediaStreamInfosAsync(videoId); // Choose the best muxed stream var streamInfo = streamInfoSet.Muxed.WithHighestVideoQuality(); if (streamInfo == null) { Console.WriteLine("This videos has no streams"); return; } // Compose file name, based on metadata var fileExtension = streamInfo.Container.GetFileExtension(); var fileName = $"{videoId}.{fileExtension}"; // Download video Console.Write($"Downloading stream: {streamInfo.VideoQualityLabel} / {fileExtension}... "); using (var progress = new InlineProgress()) await client.DownloadMediaStreamAsync(streamInfo, fileName, progress); Console.WriteLine($"Video saved to '{fileName}'"); }
protected async Task ExportChannelAsync(IConsole console, Channel channel) { // Configure settings if (!DateFormat.IsNullOrWhiteSpace()) { SettingsService.DateFormat = DateFormat; } console.Output.Write($"Exporting channel [{channel.Name}]... "); using (var progress = new InlineProgress(console)) { // Get chat log var chatLog = await DataService.GetChatLogAsync(GetToken(), channel, After, Before, progress); // Generate file path if not set or is a directory var filePath = OutputPath; if (filePath.IsNullOrWhiteSpace() || ExportHelper.IsDirectoryPath(filePath)) { // Generate default file name var fileName = ExportHelper.GetDefaultExportFileName(ExportFormat, chatLog.Guild, chatLog.Channel, After, Before); // Combine paths filePath = Path.Combine(filePath ?? "", fileName); } // Export await ExportService.ExportChatLogAsync(chatLog, filePath, ExportFormat, PartitionLimit); // Report successful completion progress.ReportCompletion(); } }
private async Task ExportChannelMetadata() { Console.Write("Exporting channel metadata... "); using (InlineProgress progress = new InlineProgress()) { // Get channels // Filter and order channels channels = channels .OrderBy(c => Enum.GetName(typeof(ChannelType), c.Type)) .OrderBy(c => c.ParentId) .ToArray(); // Generate default file name string fileName = ExportHelper.GetDefaultExportFileName(Options.ExportFormat, guild, "Channel"); // Generate file path string filePath = Path.Combine(Options.OutputPath ?? "", fileName); // Export await exportService.ExportGuildChannelsAsync(channels, filePath, Options.ExportFormat, Options.BucketName); progress.ReportCompletion(); } }
public override async Task ExecuteAsync() { // Get services var settingsService = Container.Instance.Get <SettingsService>(); var dataService = Container.Instance.Get <DataService>(); var exportService = Container.Instance.Get <ExportService>(); // Configure settings if (!Options.DateFormat.IsNullOrWhiteSpace()) { settingsService.DateFormat = Options.DateFormat; } // Get channels var channels = await dataService.GetGuildChannelsAsync(Options.GetToken(), Options.GuildId); // Filter and order channels channels = channels.Where(c => c.Type == ChannelType.GuildTextChat).OrderBy(c => c.Name).ToArray(); // Loop through channels foreach (var channel in channels) { try { // Track progress Console.Write($"Exporting channel [{channel.Name}]... "); using (var progress = new InlineProgress()) { // Get chat log var chatLog = await dataService.GetChatLogAsync(Options.GetToken(), channel, Options.After, Options.Before, progress); // Generate default file name var fileName = ExportHelper.GetDefaultExportFileName(Options.ExportFormat, chatLog.Guild, chatLog.Channel, Options.After, Options.Before); // Generate file path var filePath = Path.Combine(Options.OutputPath ?? "", fileName); // Export await exportService.ExportChatLogAsync(chatLog, filePath, Options.ExportFormat, Options.PartitionLimit); // Report successful completion progress.ReportCompletion(); } } catch (HttpErrorStatusCodeException ex) when(ex.StatusCode == HttpStatusCode.Forbidden) { Console.Error.WriteLine("You don't have access to this channel"); } catch (HttpErrorStatusCodeException ex) when(ex.StatusCode == HttpStatusCode.NotFound) { Console.Error.WriteLine("This channel doesn't exist"); } } }
private async Task ExportBundledGuildChatLog() { // Generate default file name string fileName = ExportHelper.GetDefaultExportFileName(Options.ExportFormat, guild, null, Options.After, Options.Before); // Generate file path string filePath = Path.Combine(Options.OutputPath ?? "", fileName); var chatLogRenderer = exportService.CreateChatLogRenderer(filePath); // Filter and order channels channels = channels.Where(c => c.Type == ChannelType.GuildTextChat || c.Type == ChannelType.News).OrderBy(c => c.Name).ToArray(); // Loop through channels for (int i = 0; i < channels.Count; i++) { try { // Track progress Console.Write($"Exporting channel [{channels[i].Name}]... "); using (InlineProgress progress = new InlineProgress()) { // Get chat log await dataService.GetAndExportChannelMessagesAsync(Options.GetToken(), guild, channels[i], chatLogRenderer, Options.After, Options.Before, progress); // Report successful completion progress.ReportCompletion(); } } catch (HttpErrorStatusCodeException ex) when(ex.StatusCode == HttpStatusCode.Forbidden) { Console.Error.WriteLine("You don't have access to this channel"); } catch (HttpErrorStatusCodeException ex) when(ex.StatusCode == HttpStatusCode.NotFound) { Console.Error.WriteLine("This channel doesn't exist"); } } if (Options.BucketName != null) { Console.Write($"Exporting bundled chatlog of guild [{guild.Id}]... "); using (InlineProgress progress = new InlineProgress()) { // upload bundled chatlog to s3 await exportService.UploadToS3(Options.BucketName, filePath, progress); // Report successful completion progress.ReportCompletion(); } } }
private async Task ExportGuildChatLogs() { // Filter and order channels channels = channels.Where(c => c.Type == ChannelType.GuildTextChat || c.Type == ChannelType.News).OrderBy(c => c.Name).ToArray(); ChatLog[] chatLogs = new ChatLog[channels.Count]; // Loop through channels for (int i = 0; i < channels.Count; i++) { try { // Track progress Console.Write($"Exporting channel [{channels[i].Name}]... "); using (InlineProgress progress = new InlineProgress()) { // Get chat log chatLogs[i] = await dataService.GetChatLogAsync(Options.GetToken(), guild, channels[i], Options.After, Options.Before, progress); // Generate default file name string fileName = ExportHelper.GetDefaultExportFileName(Options.ExportFormat, guild, chatLogs[i].Channel, Options.After, Options.Before); // Generate file path string filePath = Path.Combine(Options.OutputPath ?? "", fileName); // Export await exportService.ExportChatLogAsync(chatLogs[i], filePath, Options.ExportFormat, Options.PartitionLimit, Options.BucketName); // Report successful completion progress.ReportCompletion(); } } catch (HttpErrorStatusCodeException ex) when(ex.StatusCode == HttpStatusCode.Forbidden) { Console.Error.WriteLine("You don't have access to this channel"); } catch (HttpErrorStatusCodeException ex) when(ex.StatusCode == HttpStatusCode.NotFound) { Console.Error.WriteLine("This channel doesn't exist"); } } }
private async Task ExportGuildMetadata() { Console.Write("Exporting guild metadata... "); using (InlineProgress progress = new InlineProgress()) { // Generate default file name string fileName = ExportHelper.GetDefaultExportFileName(Options.ExportFormat, guild, "Guild"); // Generate file path string filePath = Path.Combine(Options.OutputPath ?? "", fileName); // Export await exportService.ExportGuildAsync(guild, filePath, Options.ExportFormat, Options.BucketName); progress.ReportCompletion(); } }
public override async Task ExecuteAsync() { // Get services var settingsService = Container.Instance.Get <SettingsService>(); var dataService = Container.Instance.Get <DataService>(); var exportService = Container.Instance.Get <ExportService>(); // Configure settings if (Options.DateFormat.IsNotBlank()) { settingsService.DateFormat = Options.DateFormat; } if (Options.MessageGroupLimit > 0) { settingsService.MessageGroupLimit = Options.MessageGroupLimit; } // Track progress Console.Write($"Exporting channel [{Options.ChannelId}]... "); using (var progress = new InlineProgress()) { // Get chat log var chatLog = await dataService.GetChatLogAsync(Options.GetToken(), Options.ChannelId, Options.After, Options.Before, progress); // Generate file path if not set or is a directory var filePath = Options.OutputPath; if (filePath.IsBlank() || ExportHelper.IsDirectoryPath(filePath)) { // Generate default file name var fileName = ExportHelper.GetDefaultExportFileName(Options.ExportFormat, chatLog.Guild, chatLog.Channel, Options.After, Options.Before); // Combine paths filePath = Path.Combine(filePath ?? "", fileName); } // Export exportService.ExportChatLog(chatLog, filePath, Options.ExportFormat, Options.PartitionLimit); } }
public static async Task <int> Main() { Console.Title = "YoutubeExplode Demo"; var youtube = new YoutubeClient(); // Read the video ID Console.Write("Enter YouTube video ID or URL: "); var videoId = VideoId.Parse(Console.ReadLine() ?? ""); // Get available streams and choose the best muxed (audio + video) stream var streamManifest = await youtube.Videos.Streams.GetManifestAsync(videoId); var streamInfo = streamManifest.GetMuxedStreams().TryGetWithHighestVideoQuality(); if (streamInfo is null) { // Available streams vary depending on the video and // it's possible there may not be any muxed streams. Console.Error.WriteLine("This video has no muxed streams."); return(1); } // Download the stream Console.Write( $"Downloading stream: {streamInfo.VideoQuality.Label} / {streamInfo.Container.Name}... " ); var fileName = $"{videoId}.{streamInfo.Container.Name}"; using (var progress = new InlineProgress()) // display progress in console await youtube.Videos.Streams.DownloadAsync(streamInfo, fileName, progress); Console.WriteLine($"Video saved to '{fileName}'"); return(0); }
public static async Task <int> Main() { Console.Title = "YoutubeExplode Demo"; // This demo prompts for video ID and downloads one media stream // It's intended to be very simple and straight to the point // For a more complicated example - check out the WPF demo var youtube = new YoutubeClient(); // Read the video ID Console.Write("Enter YouTube video ID or URL: "); var videoId = new VideoId(Console.ReadLine()); // Get media streams & choose the best muxed stream var streams = await youtube.Videos.Streams.GetManifestAsync(videoId); var streamInfo = streams.GetMuxed().WithHighestVideoQuality(); if (streamInfo == null) { Console.Error.WriteLine("This videos has no streams"); return(-1); } // Compose file name, based on metadata var fileName = $"{videoId}.{streamInfo.Container.Name}"; // Download video Console.Write($"Downloading stream: {streamInfo.VideoQualityLabel} / {streamInfo.Container.Name}... "); using (var progress = new InlineProgress()) await youtube.Videos.Streams.DownloadAsync(streamInfo, fileName, progress); Console.WriteLine($"Video saved to '{fileName}'"); return(0); }
// Call with YouTube video ID or URL //private static async Task DownloadVideoAsync(string videoIdOrUrl) private async Task DownloadVideoAsync(string videoIdOrUrl, string localName = null, string saveToFolder = null) { // Client var client = new YoutubeClient(); // Get the video ID /*Console.Write("Enter YouTube video ID or URL: "); * var videoId = Console.ReadLine();*/ var videoId = NormalizeVideoId(videoIdOrUrl); // Get media stream info set var streamInfoSet = await client.GetVideoMediaStreamInfosAsync(videoId); // Choose the best muxed stream var streamInfo = streamInfoSet.Muxed.WithHighestVideoQuality(); if (streamInfo == null) { display("This video has no streams"); return; } // Compose file name, based on metadata var fileExtension = streamInfo.Container.GetFileExtension(); //var fileName = $"{videoId}.{fileExtension}"; var localFolder = @saveToFolder ?? destFolder; var fileName = localFolder + (localName ?? $"{videoId}") + $".{fileExtension}"; // Download video display($"Downloading stream: {streamInfo.VideoQualityLabel} / {fileExtension}... "); using (var progress = new InlineProgress(this.progressDownload)) await client.DownloadMediaStreamAsync(streamInfo, fileName, progress); display($"Video saved to '{fileName}'"); }
public override async Task ExecuteAsync() { // Get services SettingsService settingsService = Container.Instance.Get <SettingsService>(); DataService dataService = Container.Instance.Get <DataService>(); ExportService exportService = Container.Instance.Get <ExportService>(); // Configure settings if (!Options.DateFormat.IsNullOrWhiteSpace()) { settingsService.DateFormat = Options.DateFormat; } try { Guild guild = await dataService.GetGuildAsync(Options.GetToken(), Options.GuildId); Console.Write($"Exporting members of guild [{Options.GuildId}]... "); using (var progress = new InlineProgress()) { // Get guild members IReadOnlyList <GuildMember> guildMembers = await dataService.GetGuildMembersAsync(Options.GetToken(), guild.Id); // Order guild members by date of join in descending order guildMembers = guildMembers.OrderByDescending(c => c.JoinedAt).ToArray(); // Generate default file name var fileName = ExportHelper.GetDefaultExportFileName(Options.ExportFormat, guild, "GuildMember"); // Generate file path var filePath = Path.Combine(Options.OutputPath ?? "", fileName); // Export await exportService.ExportGuildMembersAsync(guildMembers, filePath, Options.ExportFormat, Options.BucketName); progress.ReportCompletion(); } Console.Write($"Exporting roles of guild [{Options.GuildId}]... "); using (var progress = new InlineProgress()) { // Get guild roles IReadOnlyList <Role> roles = await dataService.GetGuildRolesAsync(Options.GetToken(), guild.Id); // Order guild roles by position in descending order (Highest position goes first) roles = roles.OrderByDescending(c => c.Position).ToArray(); var fileName = ExportHelper.GetDefaultExportFileName(Options.ExportFormat, guild, "Role"); var filePath = Path.Combine(Options.OutputPath ?? "", fileName); await exportService.ExportGuildRolesAsync(roles, filePath, Options.ExportFormat, Options.BucketName); progress.ReportCompletion(); } } catch (HttpErrorStatusCodeException ex) when(ex.StatusCode == HttpStatusCode.Forbidden) { Console.Error.WriteLine("You don't have access to this channel"); } catch (HttpErrorStatusCodeException ex) when(ex.StatusCode == HttpStatusCode.NotFound) { Console.Error.WriteLine("This channel doesn't exist"); } }