1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
Namespace YouTubeVB
Public Class Video
Private VideoYouTubeVideoID As String = Nothing
Property YouTubeVideoID() As String
Get
Return VideoYouTubeVideoID
End Get
Set(ByVal value As String)
VideoYouTubeVideoID = value
End Set
End Property
Public Function GetDownloadLink() As String
If Not VideoYouTubeVideoID = Nothing Then
Try
GetDownloadLink = "http://youtube.com/get_video?video_id=" & VideoYouTubeVideoID & "&t=" & GetTrackingID(YouTubeVideoID)
Catch ex As Exception
MsgBox("Error: " & ex.Message, MsgBoxStyle.Critical, "YouTubeVB GetDownloadLink")
GetDownloadLink = Nothing
End Try
Else
GetDownloadLink = Nothing
End If
End Function
Public Function GetTrackingID() As String
If Not VideoYouTubeVideoID = Nothing Then
Try
Dim HttpWebRequest As Net.HttpWebRequest
Dim HttpWebReponse As Net.HttpWebResponse
HttpWebRequest = Net.WebRequest.Create("http://www.youtube.com/v/" & YouTubeVideoID)
HttpWebReponse = HttpWebRequest.GetResponse()
GetTrackingID = HttpWebReponse.ResponseUri.ToString.Substring(HttpWebReponse.ResponseUri.ToString.LastIndexOf("&t=") + 3)
Catch ex As Exception
MsgBox("Error: " & ex.Message, MsgBoxStyle.Critical, "YouTubeVB GetTrackingID")
GetTrackingID = Nothing
End Try
Else
Return Nothing
End If
End Function
End Class
Public Class Search
Private STitle As New List(Of String)
Private SUrl As New List(Of String)
Private SPlayer As New List(Of String)
Private SImagelist As New List(Of List(Of Image))
ReadOnly Property Title(ByVal index As Integer) As String
Get
Return STitle(index)
End Get
End Property
ReadOnly Property Url(ByVal index As Integer) As String
Get
Return SUrl(index)
End Get
End Property
ReadOnly Property Player(ByVal index As Integer) As String
Get
Return SPlayer(index)
End Get
End Property
ReadOnly Property Imagelist(ByVal index As Integer) As List(Of Image)
Get
Return SImagelist(index)
End Get
End Property
Public Sub Search(ByVal SearchTerm As String, _
Optional ByVal StartIndex As Integer = 0, _
Optional ByVal NumberToRetrieve As Integer = 5)
Try
Dim GoogleQuery As New Google.GData.Client.FeedQuery()
Dim GoogleService As New Google.GData.Client.Service("youtube")
GoogleQuery.Uri = New Uri("http://gdata.youtube.com/feeds/videos?q=" + System.Web.HttpUtility.UrlEncode(SearchTerm))
GoogleQuery.StartIndex = StartIndex
GoogleQuery.NumberToRetrieve = NumberToRetrieve
Dim Atom As Google.GData.Client.AtomFeed
Atom = GoogleService.Query(GoogleQuery)
Dim AtomEntries As Google.GData.Client.AtomEntry
For Each AtomEntries In Atom.Entries
Dim Element As System.Xml.XmlElement
For Each Element In AtomEntries.ExtensionElements
If Element.Name = "media:group" Then
Dim XmlThumbs As System.Xml.XmlNodeList = Element.GetElementsByTagName("media:thumbnail")
Dim XmlURL As System.Xml.XmlNodeList = Element.GetElementsByTagName("media:content")
STitle.Add(AtomEntries.Title.Text)
Dim UrlStrings As New List(Of String)
For Each XmlUrlValue As Xml.XmlElement In XmlURL
UrlStrings.Add(XmlUrlValue.GetAttribute("url"))
Next
SPlayer.Add(UrlStrings(0))
SUrl.Add(AtomEntries.AlternateUri.ToString)
SImagelist.Add(GetImageFromURL(XmlThumbs))
End If
Next
Next
Catch ex As Exception
MsgBox("Error: " & ex.Message, MsgBoxStyle.Critical, "YouTubeVB Search")
End Try
End Sub
Public Function Count() As Integer
Try
Count = STitle.Count
Catch ex As Exception
MsgBox("Error: " & ex.Message, MsgBoxStyle.Critical, "YouTubeVB Count")
Count = Nothing
End Try
End Function
Private Function GetImageFromURL(ByVal NodeList As System.Xml.XmlNodeList) As List(Of Image)
Try
GetImageFromURL = Nothing
Dim Imagelist As New List(Of Image)
Dim HttpWebRequest As Net.HttpWebRequest
Dim HttpWebReponse As Net.HttpWebResponse
Dim ImageStream As System.IO.Stream
Dim SImage As Image
For Each _xmltemp As System.Xml.XmlElement In NodeList
HttpWebRequest = Net.WebRequest.Create(_xmltemp.GetAttribute("url"))
HttpWebReponse = HttpWebRequest.GetResponse
ImageStream = HttpWebReponse.GetResponseStream
SImage = Drawing.Image.FromStream(ImageStream)
Imagelist.Add(SImage)
Next
GetImageFromURL = Imagelist
Catch ex As Exception
MsgBox("Error: " & ex.Message, MsgBoxStyle.Critical, "YouTubeVB GetImageFromURL")
GetImageFromURL = Nothing
End Try
End Function
End Class
End Namespace
|