1 2 3 4 5 6 7 8 9 10 11 12 | Imports System.Net Imports System.IO Dim lstLink As New ListBox Dim intlstIndex As Integer = 0 Dim wc As WebClient Dim folderPath As String = "C:\twTELEVISION\" Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load BackgroundWorker1.RunWorkerAsync() End Sub |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | Private Function getHTML(ByVal Address As String) As String Dim rt As String = "" Dim wRequest As WebRequest Dim wResponse As WebResponse Dim SR As StreamReader wRequest = WebRequest.Create(Address) wResponse = wRequest.GetResponse SR = New StreamReader(wResponse.GetResponseStream) 'SR = New StreamReader(wResponse.GetResponseStream, System.Text.Encoding.GetEncoding(950)) '繁中 rt = SR.ReadToEnd SR.Close() Return rt End Function |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | Private Sub tsDownload(strLink As String) Dim rtbTemp As New RichTextBox rtbTemp.Text = getHTML(strLink) intlstIndex = 0 lstLink.Items.Clear() For i As Integer = 0 To rtbTemp.Lines.Count Try If rtbTemp.Lines(i).Substring(0, 1) <> "#" Then lstLink.Items.Add(rtbTemp.Lines(i)) End If Catch ex As Exception End Try Next BackgroundWorker2.RunWorkerAsync() End Sub |
1 2 3 4 5 6 7 | Private Sub DownloadProcess() wc = New WebClient() AddHandler wc.DownloadFileCompleted, AddressOf wc_DownloadFileCompleted Dim strText As String = lstLink.Items(intlstIndex) wc.DownloadFileAsync(New Uri(strText), folderPath & strText.Substring(strText.LastIndexOf("/") + 1)) intlstIndex += 1 End Sub |
1 2 3 4 5 6 7 | Private Sub wc_DownloadFileCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs) If intlstIndex <= lstLink.Items.Count Then DownloadProcess() Else MsgBox("下載完成", 64, "完成") End If End Sub |
1 2 3 | Private Sub BackgroundWorker1_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork tsDownload("http://ktv051.cdnak.ds.kylintv.net/nlds/kylin/formosatv/as/live/formosatv_4.m3u8") End Sub |
1 2 3 | Private Sub BackgroundWorker2_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker2.DoWork DownloadProcess() End Sub |
沒有留言:
張貼留言