Sixem

.NET Youtube Fetch MP3 - YoutubeInMP3 API

Jul 30th, 2013
508
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 2.01 KB | None | 0 0
  1. Private Sub Youtube_DL_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Youtube_DL_Button.Click
  2.         Dim ID As String = Nothing
  3.         Try
  4.         'Split Youtube URL By ID
  5.             ID = Regex.Split(Youtube_URL.Text, "v=").GetValue(1)
  6.         Catch ex As Exception
  7.         End Try
  8.         'If ID Is Valid
  9.         'Initiate Download & Add Handle
  10.         If ID.Length > 4 = True Then
  11.             ID = "http://www.youtube.com/watch?v=" & ID
  12.             Dim Download_Handle As New Net.WebClient
  13.             If Youtube_SaveAs.Text.Length > 0 Then
  14.                 AddHandler Download_Handle.DownloadProgressChanged, AddressOf DownloadProgressCallback
  15.                 Download_Handle.DownloadFileAsync(New Uri("http://youtubeinmp3.com/fetch/?video=" & ID), Youtube_SaveLocation.Text & "\" & Youtube_SaveAs.Text & ".mp3")
  16.             Else
  17.                 AddHandler Download_Handle.DownloadProgressChanged, AddressOf DownloadProgressCallback
  18.                 Download_Handle.DownloadFileAsync(New Uri("http://youtubeinmp3.com/fetch/?video=" & ID), Youtube_SaveLocation.Text & "\" & Regex.Split(ID, "v=").GetValue(1) & ".mp3")
  19.             End If
  20.         Else
  21.         'If Invalid URL
  22.             MessageBox.Show("Invalid URL!", Me.Text)
  23.         End If
  24.     End Sub
  25.         'Download Progress Handle
  26.     Public Sub DownloadProgressCallback(ByVal sender As Object, ByVal e As DownloadProgressChangedEventArgs)
  27.         Youtube_Progressbar.Value = e.ProgressPercentage
  28.         Dim File_Size As Long = e.TotalBytesToReceive
  29.         Dim File_Received As Long = e.BytesReceived
  30.         Youtube_Progressbar.Value = e.ProgressPercentage
  31.         'Calculates Kilobytes Left
  32.         Youtube_Status.Text = String.Format("{0} kB / {1} kB", Math.Round((File_Received / 1024)), Math.Round((File_Size / 1024)))
  33.         'If Download Is Finished
  34.         If e.ProgressPercentage = 100 Then
  35.             Youtube_Progressbar.Value = 100
  36.             Youtube_Status.Text = "Download complete!"
  37.         End If
  38.     End Sub
Advertisement
Add Comment
Please, Sign In to add comment