Ich habs nie ausgetestet aber von der theorie her müssts klappen ausser ich hab nen dummen fehler gemacht
habs gemacht weil mir langweilig war
Download von youtube video im 3gp format
Das mpeg4 format hätte etwas mehr arbeit gekostet (Den Mobile safari simulieren)
Hier der code
Have Fun
Code
Public Class YoutubeDownload
Private Function Decode(ByVal WebStream As IO.Stream) As String
Dim reader As New IO.StreamReader(WebStream)
Dim Link As String = ""
Do Until reader.EndOfStream
Dim Line As String = reader.ReadLine.TrimEnd.TrimStart
If Line.StartsWith("<a href=" + Chr(34) + "rtsp://") Then
For i As Integer = 10 To Line.Count
If Mid(Line, i, 1) = Chr(34) Then
Exit For
Else
Link += Mid(Line, i, 1)
End If
Next
Exit Do
End If
Loop
Return Link
End Function
Private Function GetMobileLink(ByVal YoutubeLink As String) As String
Dim MobileLink As String = ""
Dim VideoID As String = ""
Dim a As Boolean = False
For i As Integer = 1 To YoutubeLink.Count
If a = False Then
If Mid(YoutubeLink, i, 2) = "?v=" Or Mid(YoutubeLink, i, 2) = "&v=" Then
a = True
End If
Else
Try
If Mid(YoutubeLink, i, 1) = "&" Then
a = False
Exit For
Else
VideoID += Mid(YoutubeLink, i, 1)
End If
Catch ex As Exception
End Try
End If
Next
MobileLink = "http://m.youtube.com/watch?v=" & VideoID
Return MobileLink
End Function
Private Function DownloadVideo(ByVal Url As String) As Byte()
Return New Net.WebClient().DownloadData(Url)
End Function
Public Sub DownloadYoutubeVideo(ByVal Url As String)
Dim MobileLink As String = GetMobileLink(Url)
Dim WebC As New Net.WebClient
Dim IE As New Windows.Forms.WebBrowser
IE.Navigate(New Uri(MobileLink))
Dim HtmlStream As IO.MemoryStream = IE.DocumentStream
IE.Dispose()
Dim VideoUrl As String = Decode(HtmlStream)
Dim buffer As Byte() = DownloadVideo(VideoUrl)
Dim sfd As New Windows.Forms.SaveFileDialog
sfd.Filter = "3GP Video File(*.3gp)|*.3gp"
If sfd.ShowDialog = Windows.Forms.DialogResult.OK Then
IO.File.WriteAllBytes(sfd.FileName, buffer)
End If
End Sub
Public Sub DownloadYoutubeVideo(ByVal Url As String, ByVal Save As String)
Dim MobileLink As String = GetMobileLink(Url)
Dim WebC As New Net.WebClient
Dim IE As New Windows.Forms.WebBrowser
IE.Navigate(New Uri(MobileLink))
Dim HtmlStream As IO.MemoryStream = IE.DocumentStream
IE.Dispose()
Dim VideoUrl As String = Decode(HtmlStream)
Dim buffer As Byte() = DownloadVideo(VideoUrl)
If Not Save.EndsWith(".3gp") Then
Save += ".3gp"
End If
IO.File.WriteAllBytes(Save, buffer)
End Sub
End Class
Alles anzeigen
Ps wer meint einfach copy u Paste machen zu können wird Fehler bekommen
Ich hab schon 2 Fehler gefunden