Imports System.Net
Imports System.IO
Imports System.Diagnostics
Public Class Form1
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
SaveFileDialog1.FileName = vbNullString
SaveFileDialog1.ShowDialog()
If SaveFileDialog1.FileName <> vbNullString Then
My.Computer.Network.DownloadFile(lstv.SelectedItems(0).Tag, SaveFileDialog1.FileName, _
vbNullString, vbNullString, True, 5000, True)
End If
End Sub
Private Function ParseLike(ByVal url As String) As String
Dim i As Long
Dim ToRep As String
Dim tmp As String
Dim theC As String
For i = 1 To Len(url) - 1
tmp = Mid(url, i, 1)
If tmp = "%" Then
tmp = Mid(url, i + 1, 2)
tmp = "&H" + tmp
theC = Chr(Val(tmp))
ToRep = Mid(url, i, 3)
url = Replace(url, ToRep, theC)
End If
Next
ParseLike = url
End Function
Private Function GetValuse(ByVal thecode As String, ByVal begin As String, ByVal ending As String) As String
Dim st() As Integer
Dim en() As Integer
Dim Result() As String
Dim pos As Integer
Dim i As Integer
pos = InStr(thecode, begin)
While pos > 0
ReDim Preserve st(i)
pos += Len(begin)
st(i) = pos
i += 1
pos = InStr(pos, thecode, begin)
End While
ReDim en(i)
i = 0
pos = InStr(st(i), thecode, ending)
en(0) = pos
For i = 1 To UBound(st)
pos = InStr(st(i), thecode, ending)
en(i) = pos
Next
ReDim Result(i)
For i = 0 To UBound(st)
Result(i) = ParseLike(Mid(thecode, st(i), en(i) - st(i)))
Next
GetValuse = Result
End Function
Private Function GetBetween(ByVal sSea As String, ByVal Sstart As String, ByVal sStop As String, Optional ByVal lSea As Integer = 1)
Dim lTemp As Long
lSea = InStr(lSea, sSea, Sstart)
If lSea > 0 Then
lSea += Len(Sstart)
lTemp = InStr(lSea, sSea, sStop)
If lTemp > lSea Then
GetBetween = Trim(Mid(sSea, lSea, lTemp = lSea))
End If
End If
End Function
Private Function GetPage(ByVal PageUrl As String) As String
Dim s As String = ""
Try
Dim request As HttpWebRequest = WebRequest.Create(PageUrl)
Dim response As HttpWebResponse = request.GetResponse
Using reader As StreamReader = New StreamReader(response.GetResponseStream())
s = reader.ReadToEnd
End Using
Catch ex As Exception
Debug.WriteLine("Error : " + ex.Message)
End Try
Return s
End Function
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
lstv.Columns.Add("URL", CInt(lstv.Width / 3))
lstv.Columns.Add("Type", CInt(lstv.Width / 3))
lstv.Columns.Add("Quality", CInt(lstv.Width / 3))
lstv.View = View.Details
End Sub
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim objItem As ListViewItem
Dim theSection As String
Dim Url() As String
Dim Type() As String
Dim Qua() As String
Dim i As Integer
Dim page As String = GetPage(Textbox1.Text)
theSection = GetBetween(page, "yt.playerConfig = ", ");")
Url = GetValuse(theSection, "url=", "\")
Type = GetValuse(theSection, "type", "\")
Qua = GetValuse(theSection, "quality", "\")
For i = 0 To UBound(Url) - 1
objItem = lstv.Items.Add(Url(i))
objItem.SubItems.Add(Type(i))
objItem.SubItems.Add(Qua(i))
Next
End Sub
End Class
ช่วยแก้ให้หน่อยน่ะ ครับ
มันติดตรงนี้ ครับ
Code (VB.NET)
GetValuse = Result
และ
Code (VB.NET)
Url = GetValuse(theSection, "url=", "\")
Type = GetValuse(theSection, "type", "\")
Qua = GetValuse(theSection, "quality", "\")
ได้แระครับ list มาได้แต่โหลดไม่ได้ครับน่าจะติดที่ url
Code (VB.NET)
Imports System.Net
Imports System.IO
Imports System.Diagnostics
Public Class Form1
'http://www.youtube.com/watch?v=AcPxHFecum8
'http://www.youtube.com/watch?v=n3tdS0Xrl7U&list=RDn3tdS0Xrl7U
Private Function ParseLink(Optional ByVal url As String = "") As String
Dim i As Integer
For i = 1 To Len(url) - 1
If Mid(url, i, 1) = "%" Then
url = Replace(url, Mid(url, i, 3), Chr(Val("&H" + Mid(url, i + 1, 2))))
End If
Next
ParseLink = url
End Function
Private Function GetValuse(ByVal thecode As String, ByVal begin As String, ByVal ending As String) As String()
Dim st() As Integer
Dim en() As Integer
Dim Result() As String
Dim pos As Integer
Dim i As Integer
pos = InStr(thecode, begin)
While pos > 0
ReDim Preserve st(i)
pos += Len(begin)
st(i) = pos
i += 1
pos = InStr(pos, thecode, begin)
End While
ReDim en(i)
i = 0
pos = InStr(st(i), thecode, ending)
en(0) = pos
For i = 1 To UBound(st)
pos = InStr(st(i), thecode, ending)
en(i) = pos
Next
ReDim Result(i)
For i = 0 To UBound(st)
Result(i) = ParseLink(Mid(thecode, st(i), en(i) - st(i)))
Next
GetValuse = Result
End Function
Private Function GetBetween(ByVal sSea As String, ByVal Sstart As String, ByVal sStop As String) As String
Dim tmp As String = ""
Dim result As String = ""
If sSea.IndexOf(Sstart) > 0 Then
tmp = sSea.Substring(sSea.IndexOf(Sstart) + Sstart.Length)
result = tmp.Substring(1, tmp.IndexOf(sStop) + 1)
End If
GetBetween = result
End Function
Private Function GetPage(ByVal PageUrl As String) As String
Dim s As String = ""
Try
Dim request As HttpWebRequest = WebRequest.Create(PageUrl)
Dim response As HttpWebResponse = request.GetResponse
Using reader As StreamReader = New StreamReader(response.GetResponseStream())
s = reader.ReadToEnd
End Using
Catch ex As Exception
Debug.WriteLine("Error : " + ex.Message)
End Try
Return s
End Function
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
lstv.Columns.Add("URL", CInt(lstv.Width / 3))
lstv.Columns.Add("Type", CInt(lstv.Width / 3))
lstv.Columns.Add("Quality", CInt(lstv.Width / 3))
lstv.View = View.Details
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim objItem As ListViewItem
Dim theSection As String
Dim Url() As String
Dim Type() As String
Dim Qua() As String
Dim i As Integer
Dim page As String = GetPage(TextBox1.Text)
theSection = GetBetween(page, "ytplayer.config = ", ");</script>")
Url = GetValuse(theSection, "url=", "\")
Type = GetValuse(theSection, "type", "\")
Qua = GetValuse(theSection, "quality", "\")
On Error Resume Next
For i = 0 To UBound(Url) - 1
objItem = lstv.Items.Add(Url(i))
objItem.SubItems.Add(Type(i))
objItem.SubItems.Add(Qua(i))
Next
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
SaveFileDialog1.FileName = vbNullString
SaveFileDialog1.ShowDialog()
If SaveFileDialog1.FileName <> vbNullString Then
TextBox2.Text = lstv.SelectedItems(0).Text
My.Computer.Network.DownloadFile(lstv.SelectedItems(0).Tag, SaveFileDialog1.FileName, _
vbNullString, vbNullString, True, 5000, True)
End If
End Sub
End Class
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
SaveFileDialog1.FileName = vbNullString
SaveFileDialog1.ShowDialog()
If SaveFileDialog1.FileName <> vbNullString Then
TextBox2.Text = lstv.SelectedItems(0).Text
My.Computer.Network.DownloadFile(TextBox2.Text, SaveFileDialog1.FileName, _
vbNullString, vbNullString, True, 5000, True)
End If
End Sub