Downloader

  • VB.NET

Es gibt 11 Antworten in diesem Thema. Der letzte Beitrag () ist von toto.

    Hallo an alle die sich beteiligt haben
    und an alle die die Interesse haben
    und an die die Probleme mit dem PB haben.
    bei mir funzt endlich, hier mein Code:

    VB.NET-Quellcode

    1. [spoiler]
    2. Private Sub btnAddDown_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddDown.Click
    3. Dim Link As String
    4. Link = txtURL.Text
    5. Get_Video_Info(Link)
    6. End Sub
    7. Public Sub Get_Video_Info(ByVal Link As String)
    8. Dim Request As HttpWebRequest = HttpWebRequest.Create(Link)
    9. Dim Response As HttpWebResponse = Request.GetResponse()
    10. Dim reader As StreamReader = New StreamReader(Response.GetResponseStream)
    11. Dim httpContent As String
    12. httpContent = reader.ReadToEnd
    13. Dim TitleRegEx As New Regex("title=""(?<Title>(.*))"" />")
    14. Dim title As String
    15. title = TitleRegEx.Match(httpContent).Groups("Title").ToString
    16. Dim LängeVideo As New Regex("<span class=""video-time""><span>(.*?)<\/span>")
    17. Dim Länge As String
    18. Länge = LängeVideo.Match(httpContent).Groups(1).Value()
    19. Dim tRegEx As New Regex("""t"": ""(?<t>(.*)) """)
    20. Dim t As String
    21. t = (Mid$(tRegEx.Match(httpContent).Groups("t").ToString, 1, 46))
    22. Dim i As ListViewItem
    23. i = LwDown.Items.Add(Link)
    24. With i
    25. .SubItems.Add(title)
    26. .Tag = t
    27. End With
    28. End Sub
    29. Private Sub btnDownload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDownload.Click
    30. If LwDown.SelectedItems.Count <> 1 Then
    31. MsgBox("Bitte ein Video auswählen!")
    32. Else
    33. Try
    34. Dim httpURL As New System.Uri(txtURL.Text)
    35. Dim request As HttpWebRequest = HttpWebRequest.Create(httpURL)
    36. request.Method = WebRequestMethods.Http.Get
    37. Dim response As HttpWebResponse = request.GetResponse()
    38. Dim reader As New StreamReader(response.GetResponseStream())
    39. Dim start_DL_url As String = reader.ReadToEnd()
    40. response.Close()
    41. ' Download Link
    42. Dim anfang_stelle_des_video_downloads_1 As Integer = InStr(start_DL_url, "<!-- end contenttop section -->") + 30
    43. Dim anfang_stelle_des_video_downloads_2 As Integer = InStr(anfang_stelle_des_video_downloads_1, start_DL_url, "url_map") + 13
    44. Dim ende_stelle_des_video_downloads_1 As Integer = InStr(anfang_stelle_des_video_downloads_2 + 5, start_DL_url, "%2C")
    45. Dim Laenge_des_downloads_1 As Integer = ende_stelle_des_video_downloads_1 - anfang_stelle_des_video_downloads_2
    46. Dim Name_des_downloads_1 As String
    47. Name_des_downloads_1 = Mid(start_DL_url, anfang_stelle_des_video_downloads_2, Laenge_des_downloads_1)
    48. Dim end_DL_url As String = Name_des_downloads_1.Replace("%3F", "?").Replace("%3D", "=").Replace("%26", "&").Replace("%25", "%").Replace("%2C", ",").Replace("%25", "%").Replace("%3A", ":").Replace("%2F", "/")
    49. 'Ordner & Download
    50. Dim sfd As New SaveFileDialog
    51. sfd.Filter = "Video|.flv"
    52. If sfd.ShowDialog = Windows.Forms.DialogResult.OK Then
    53. downloader.DownloadFileAsync(New Uri(end_DL_url), sfd.FileName)
    54. txtDown.Text = sfd.FileName
    55. End If
    56. Catch ex As Exception
    57. MsgBox("Kein gültiges Video gefunden! Bitte verwenden Sie nur YouTube Videos!")
    58. End Try
    59. End If
    60. End Sub
    61. ' Fortschrittsanzeige
    62. Private Sub downloader_DownloadProgressChanged(ByVal sender As Object, ByVal e As System.Net.DownloadProgressChangedEventArgs) Handles downloader.DownloadProgressChanged
    63. 'ProgressBar1.Maximum = 100
    64. ProgressBar1.Value = e.ProgressPercentage
    65. Dim Totalbytes As Long = e.TotalBytesToReceive / 1024
    66. Dim bytes As Long = e.BytesReceived / 1024
    67. Dim p As Integer = CInt((bytes / Totalbytes) * 100)
    68. Me.lblProgress.Text = e.BytesReceived & " KB von"
    69. Me.lblTotal.Text = e.TotalBytesToReceive & "KB"
    70. Me.lblProzent.Text = p.ToString() & "%"
    71. End Sub
    72. ' Download beendet
    73. Private Sub downloader_DownloadFileCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs) Handles downloader.DownloadFileCompleted
    74. MsgBox("Download war erfolgreich!", MsgBoxStyle.Information, "Fertig!")
    75. LwDown.SelectedItems.Clear()
    76. End Sub[/spoiler]



    Wichtig ist:
    Imports System.Net
    Friend WithEvents downloader As New System.Net.WebClient ' WebClient für Datei-Download

    Dazu sage ich noch dazu das mit der Länge anzeigen noch nicht klappt sonst funzt alles.

    Zu mei Code hätte ich eine Frage und zwar wird mir alles in KB angezeigt, ich möchte aber das es in MB angezeigt wird, jemand ein Tipp?
    viel Spass

    lg

    toto
    lg toto
    Bitte ersetzen oder ergänzen:

    Me.lblProgress.Text = e.BytesReceived & " KB von"
    Me.lblTotal.Text = e.TotalBytesToReceive & "KB"

    durch:

    Me.Label5.Text = Format(e.BytesReceived / 1024 ^ 2, "###0.00") & " MB von"
    Me.Label4.Text = Format(e.TotalBytesToReceive / 1024 ^ 2, "###0.00") & " MB"


    oder beide einsetzen.
    lg
    toto
    lg toto
    Sorry Samus Aran,

    ich habe in meinem Projekt einige Passagen wo

    "Option Strict On" lässt keine impliziten Konvertierungen von Object in String zu
    "Option Strict On" lässt keine impliziten Konvertierungen von Object in Integer zu.
    "Option Strict On" lässt keine impliziten Konvertierungen von System.Net.WebRequest in System.Net.HttpWebRequest zu.

    usw. ich kann diese Fehlermeldungen allein nicht beheben,
    ohen "Option Strict On" läuft mein Projekt einwandfrei.

    lg
    toto
    lg toto