Last active
August 29, 2015 14:27
-
-
Save xWHoZx/639aebd7f3a0a5f4c9bd to your computer and use it in GitHub Desktop.
[C#] Download YouTube MP3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Net; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace YourApplication | |
{ | |
public class YouTubeMp3 | |
{ | |
private WebClient downloadMp3 = new WebClient(); | |
public long bytesDownloaded = 0; | |
public long totalBytes = 0; | |
public YouTubeMp3(string youtubeUrl, string directory) | |
{ | |
downloadMp3.DownloadProgressChanged += downloadMp3_DownloadProgressChanged; | |
downloadMp3.DownloadFileCompleted += downloadMp3_DownloadFileCompleted; | |
downloadMp3.DownloadFileAsync(new Uri(string.Format("http://youtubeinmp3.com/fetch/?video={0}", youtubeUrl)), directory); | |
} | |
private void downloadMp3_DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e) | |
{ | |
downloadMp3.Dispose(); | |
} | |
private void downloadMp3_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) | |
{ | |
bytesDownloaded = e.BytesReceived; | |
totalBytes = e.TotalBytesToReceive; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment