Take0n
Member
- Joined
- Apr 19, 2007
- Messages
- 7
- Programming Experience
- 1-3
Hello
I am making a program that downloads videos from youtube but the problem I have is a problem I had before and will sure have in the future!
Well when connecting to a website (in this case youtube: http://www.youtube.com/watch?v=mHwV2JuwZls), I read the data and display it in a textbox BUT if the link doesn't exists I don't get any errors or something! If I i.e. use a link that doesn't exist in youtube: http://www.youtube.com/watch?v=mHwV2JuwZlx then I don't get any errors or data and that is because youtube redirects the error page to another link in this case http://www.youtube.com/browse?&sess...ELq0NGfPsfW6qmGT7SUissDt_xWE-8gTZtxjN2SMw9GvK
The code I use is:
I want to know if its possible to get the redirected link or what to do to know if the video link exists or not! The "else" doesn't even occur and I can't understand why I end up with a blank textbox and no msgbox!
Sorry for my bad English but I hope you can understand what I want to do and what my problem is!
I am making a program that downloads videos from youtube but the problem I have is a problem I had before and will sure have in the future!
Well when connecting to a website (in this case youtube: http://www.youtube.com/watch?v=mHwV2JuwZls), I read the data and display it in a textbox BUT if the link doesn't exists I don't get any errors or something! If I i.e. use a link that doesn't exist in youtube: http://www.youtube.com/watch?v=mHwV2JuwZlx then I don't get any errors or data and that is because youtube redirects the error page to another link in this case http://www.youtube.com/browse?&sess...ELq0NGfPsfW6qmGT7SUissDt_xWE-8gTZtxjN2SMw9GvK
The code I use is:
VB.NET:
Private Function GetLink(ByVal URL As String) As String
On Error GoTo Err
Dim WReq As System.Net.WebRequest = System.Net.WebRequest.Create(URL)
Dim WRes As System.Net.WebResponse = WReq.GetResponse()
Dim strRes As String
Dim Enc As System.Text.Encoding
Dim SR As System.IO.StreamReader = New System.IO.StreamReader(WRes.GetResponseStream(), Enc.Default)
strRes = SR.ReadToEnd
WRes.Close()
If (strRes <> "") Then
TextBox1.Text = strRes
Else
MsgBox("The given link is not working" & vbCrLf & "Wrong link?", MsgBoxStyle.Critical, "Error")
End If
Err:
Return ""
MsgBox("There was an error connecting to the website", MsgBoxStyle.Critical, "Error")
Exit Function
End Function
Sorry for my bad English but I hope you can understand what I want to do and what my problem is!
Last edited: