Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Private Sub Youtube_DL_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Youtube_DL_Button.Click
- Dim ID As String = Nothing
- Try
- 'Split Youtube URL By ID
- ID = Regex.Split(Youtube_URL.Text, "v=").GetValue(1)
- Catch ex As Exception
- End Try
- 'If ID Is Valid
- 'Initiate Download & Add Handle
- If ID.Length > 4 = True Then
- ID = "http://www.youtube.com/watch?v=" & ID
- Dim Download_Handle As New Net.WebClient
- If Youtube_SaveAs.Text.Length > 0 Then
- AddHandler Download_Handle.DownloadProgressChanged, AddressOf DownloadProgressCallback
- Download_Handle.DownloadFileAsync(New Uri("http://youtubeinmp3.com/fetch/?video=" & ID), Youtube_SaveLocation.Text & "\" & Youtube_SaveAs.Text & ".mp3")
- Else
- AddHandler Download_Handle.DownloadProgressChanged, AddressOf DownloadProgressCallback
- Download_Handle.DownloadFileAsync(New Uri("http://youtubeinmp3.com/fetch/?video=" & ID), Youtube_SaveLocation.Text & "\" & Regex.Split(ID, "v=").GetValue(1) & ".mp3")
- End If
- Else
- 'If Invalid URL
- MessageBox.Show("Invalid URL!", Me.Text)
- End If
- End Sub
- 'Download Progress Handle
- Public Sub DownloadProgressCallback(ByVal sender As Object, ByVal e As DownloadProgressChangedEventArgs)
- Youtube_Progressbar.Value = e.ProgressPercentage
- Dim File_Size As Long = e.TotalBytesToReceive
- Dim File_Received As Long = e.BytesReceived
- Youtube_Progressbar.Value = e.ProgressPercentage
- 'Calculates Kilobytes Left
- Youtube_Status.Text = String.Format("{0} kB / {1} kB", Math.Round((File_Received / 1024)), Math.Round((File_Size / 1024)))
- 'If Download Is Finished
- If e.ProgressPercentage = 100 Then
- Youtube_Progressbar.Value = 100
- Youtube_Status.Text = "Download complete!"
- End If
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment