Hello Friends,
www.ecubicle.net
Most of the time you are really in good mood to watch your faviourite videos on youtube but you face some kind of problem with the net connection. And then you think at that time if there is any utitlity by which I can keep my faviourite videos on my pc or laptop so next time my I don’t need to afraid with net connection and bandwidth.
So if you are asp.net programmer or even not then your wish can be full fill here I am with the example how to download a youtube video on system?
So first thing is thanks to
which provide a web service which return url of your video.For download you tube video on your system you have to do some simple steps
www.ecubicle.net which is “http://www.ecubicle.net/youtubedownloader.asmx you make reference in your project you can easily use it. See below fig for it.
“ As
1) Add the webservice given by
http://www.youtube.com/watch?v=6×1ddBJ3kiY )
2) Then just design your screen according to your requirement current I have taken three textbox one is for video URL like (
Which you want to download and second is the path on your hard disk where you want to store download file & third is filename by which name you want your file to store. And a button with name downloads.
3) The web service which we added in reference doesn’t return file it just return the original file path.
4) Now when you press download button just write following code:-
Protected Sub btnDownLoad_Click(ByVal sender As Object, ByVal e As EventArgs) Handles
btnDownLoad.Click
Try
If Me.txtPath.Text.Trim <> String.Empty AndAlso Me.txtUrl.Text.Trim <> String.Empty Then
Dim strDownLoadUrl As String
Dim mtube As New net.ecubicle.www.YouTubeDownloader ‘object of web services
strDownLoadUrl = mtube.GetDownloadURL(strUrl.OriginalString) ‘ returning as string
Dim downloadClient As New WebClient ‘create object of web client
downloadClient.DownloadFile(strDownLoadUrl,Me.txtPath.Text & “\” & Me.txtFileName.Text) ‘ download file
downloadClient.Dispose()
End If
Catch ex As Exception
Throw ex
End Try
End Sub
There is only one drawback in current code it hangs your screen till download.
No issue that one also either you can use ajax progress bar for it or thread code to make process in background.
So here is the solution with “Threading ” which will run in background.
Protected Sub btnDownLoad_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnDownLoad.Click
Try
If Me.txtPath.Text.Trim <> String.Empty AndAlso Me.txtUrl.Text.Trim <> String.Empty Then
Dim strUrl As New Uri(Me .txtUrl.Text.Trim)
strDownLoadUrl = mtube.GetDownloadURL(strUrl.OriginalString)
Dim mtube As New net.ecubicle.www.YouTubeDownloader
strStoragePath = Me.txtPath.Text & “\” & Me .txtFileName.Text mythread.Start()
Dim mythread As New Threading.Thread(AddressOf pvt_DownLoad) ‘calling thread
End If
Catch ex As Exception
Throw ex End Try End Sub
Private Sub pvt_DownLoad()
Try Dim downloadClient As New WebClient()
downloadClient.DownloadFile(strDownLoadUrl, strStoragePath)
downloadClient.Dispose()
Catch ex As Exception
Throw ex
End Try
End Sub
I think you got the idea how to work on it.
Enjoy downloading youtube videos.Enjoy weekend
God bless
Thanks
Rajat Jaiswal