04-06-2010, 03:43 AM
YouTube video Downloader - Fixed
Hello everyone. This is just simple example of YouTube Downloader, coded in Visual Basic .NET aka. Visual Basic 2008. Enjoy
What we need:
RichTextBox1 - Name: rtb
RichTextBox2 - Name: txturl
WebBrowser1
Proggressbar1
TextBox1
Button1 (Text: Validate)
Button2 (Text: Download)
Button3 (Text: Cancel)
Screnshot:
Source Codes:
Code:
'Coded by Soul Collector + Resource :)
Imports System.Net
Public Class frmMain
Private WithEvents download As WebClient
Private Sub TheLink()
Dim i As Integer
Dim l As Integer
Dim string1 As String
i = rtb.Find("watch_fullscreen")
l = rtb.Find("&title")
rtb.Select(i, rtb.Text.Length)
txturl.Text = rtb.SelectedText.ToString
rtb.Select(l, rtb.Text.Length)
string1 = rtb.SelectedText.ToString
txturl.Text = txturl.Text.Replace(string1, "&")
txturl.Text = txturl.Text.Insert(0, "http://www.youtube.com/get_video?")
End Sub
Private Sub done()
lblDld.Text = "Downloaded: 0 Bytes"
lblTitle.Text = "Video Title: "
lblProgress.Text = "0%"
ProgressBar1.Value = 0
End Sub
Private Sub download_DownloadProgressChanged(ByVal sender As Object, ByVal e As System.Net.DownloadProgressChangedEventArgs) Handles download.DownloadProgressChanged
ProgressBar1.Value = e.ProgressPercentage
lblProgress.Text = e.ProgressPercentage & " %"
lblDld.Text = e.BytesReceived & "Downloaded: " & e.TotalBytesToReceive & " Bytes"
done()
MsgBox("The video is downloaded.", MsgBoxStyle.Information, "")
End Sub
Private Sub WebBrowser1_Navigated(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserNavigatedEventArgs) Handles WebBrowser1.Navigated
If WebBrowser1.Url.ToString.Contains("http://www.youtube.com/") Then
lblTitle.Text = "Video Title: " & WebBrowser1.DocumentTitle
lblTitle.Text = lblTitle.Text.Replace("YouTube - ", "")
rtb.Text = WebBrowser1.DocumentText
WebBrowser1.Navigate("about:blank")
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If MessageBox.Show("Do you really want to quit progress?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
End
Else
Exit Sub
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
If Not txturl.Text = "" Then
If txturl.Text.Contains("http://www.youtube.com/watch?v") Then
WebBrowser1.Navigate(TextBox1.Text)
Else
MsgBox("Please type in valid YouTube URL.", MsgBoxStyle.Exclamation, "")
Exit Sub
End If
Else
MsgBox("Please type in valid YouTube URL.", MsgBoxStyle.Exclamation, "")
Exit Sub
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If txturl.Text.Contains("youtube.com") = False Then
MsgBox("Please type in valid YouTube URL.", MsgBoxStyle.Exclamation, "")
Exit Sub
End If
TheLink()
Dim sdlg As New SaveFileDialog
sdlg.Filter = "Flv Files |*.flv"
sdlg.FileName = lblTitle.Text & ".flv"
sdlg.ShowDialog()
download = New WebClient
Dim link = txturl.Text
Dim SavePath = sdlg.FileName
ProgressBar1.Value = 0
ProgressBar1.Maximum = 100
Try
download.DownloadFileAsync(New Uri(link), (SavePath))
Catch ex As Exception
MsgBox("Cannot download the video, please check your URL.", MsgBoxStyle.Exclamation, "")
Exit Sub
End Try
End Sub
End Class
Download Source:
http://www.multiupload.com/S4S3V9W7CK