- [DEVEXPRESS] Chia sẻ code các tạo report in nhiều hóa đơn trên XtraReport C#
- [POWER AUTOMATE] Hướng dẫn gởi tin nhắn zalo từ file Excel - No code
- [C#] Chia sẻ code lock và unlock user trong domain Window
- [SOFTWARE] Giới thiệu bộ phần mềm tính Kết Cấu Thép HatteSale, Mộng Đơn, Dầm, Sàn, Móng Cọc, Vách, Xà Gồ, Tính Tải Trọng
- [DEVEXPRESS] Vẽ Biểu Đồ Stock Chứng Khoán - Công Cụ Thiết Yếu Cho Nhà Đầu Tư trên Winform
- [C#] Hướng dẫn bảo mật ứng dụng 2FA (Multi-factor Authentication) trên Winform
- [C#] Hướng dẫn convert HTML code sang PDF File trên NetCore 7 Winform
- [C#] Hướng dẫn viết ứng dụng chat với Gemini AI Google Winform
- Hướng dẫn khóa file bằng nhiều process id, không cho xóa tập tin
- Hướng dẫn cách tạo Product Id cho ứng dụng phần mềm XXXXX-XXXXX-XXXXX-XXXXX
- [SQLSERVER] Hướng dẫn tạo script sql từ ứng dụng Sqlserver management Studio
- [C#] Hướng dẫn sử dụng thư viện AutoITx lấy id và password Ultraviewer trên winform
- [VB.NET] Hướng dẫn lấy thông tin tài khoản đăng nhập windows và khởi động lại ứng dụng ở chế độ Administrator
- [C#] Sử dụng thư viện Polly gửi lại request api khi request bị lỗi hay rớt mạng
- [DEVEXPRESS] Chia sẻ source code tạo báo cáo report in tem nhãn label trên C# winform
- [DEVEXPRESS] Hướng dẫn vẽ biểu đồ Bar Chart trên Winform
- [C#] Tạo form đăng nhập và đăng ký với hiệu ứng Sliding Animation Effect
- [C#] Hướng dẫn tạo thanh toán đơn hàng qua mã vạch VietQR sử dụng API PayOS hoàn toàn miễn phí
- [C#] Hướng dẫn ghi log ra RichTextBox giống Console trên Winform sử dụng thư viện Serilog
- [C#] Hướng dẫn cách tạo mã QR Code trên file Excel
[C#] Hướng dẫn download video Youtube trong lap trinh csharp
Bài viết này, mình hướng dẫn các bạn cách download video Youtube về máy tính của mình sử dụng ngôn ngữ lập trình csharp.
Trong tutorial này, mình sử dụng thư viện Youtube Extractor để download video về.
Các bạn, có thể sử dụng công cụ quản lý thư viện Nuget để tải về. Nếu bạn nào còn chưa biết sử dụng Nuget có thể tìm hiểu qua những bài mình đã giới thiệu.
Ứng dụng download video bằng lập trình Csharp này, thư viện Youtube Extractor có hỗ trợ cho chúng ta chọn chất lượng video để tải về, các bạn có thể chọn chất lượng: 320, 480, hoặc 720HD.
Giao diện demo ứng dụng:
Trong bài viết này:
Mình sử dụng các component sau.
1. Textbox (txtLink)
2. Combobox (cobResolution)
3. Progressbar
4. Và nút button để download
Source code bằng C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using YoutubeExtractor;
namespace DownloadVideoYoutube
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
cobResolution.SelectedIndex = 0;
}
string link;
private void btnDownload_Click(object sender, EventArgs e)
{
progressBar1.Minimum = 0;
progressBar1.Maximum = 100;
IEnumerable videos = DownloadUrlResolver.GetDownloadUrls(txtLink.Text);
VideoInfo video = videos.First(p => p.VideoType == VideoType.Mp4 && p.Resolution == Convert.ToInt32(cobResolution.Text));
if (video.RequiresDecryption)
DownloadUrlResolver.DecryptDownloadUrl(video);
//Link video
link = Application.StartupPath + "" + video.Title + video.VideoExtension;
link = link.Replace("|", "_").Replace(" ", "_");
VideoDownloader downloader = new VideoDownloader(video, link);
downloader.DownloadProgressChanged += DownloadProgressChanged;
Thread thread = new Thread(() => { downloader.Execute(); }) { IsBackground = true };
thread.Start();
}
private void DownloadProgressChanged(object sender, ProgressEventArgs e)
{
Invoke(new MethodInvoker(delegate ()
{
progressBar1.Value = (int)e.ProgressPercentage;
lblPercent.Text = $"{string.Format("{0:0,##}", e.ProgressPercentage)}%";
progressBar1.Update();
if(e.ProgressPercentage == 100)
{
Process.Start(link);
}
}));
}
}
}
Video demo ứng dụng
CHÚC CÁC BẠN THÀNH CÔNG!