Error: " & Err.Description & "
") End If objXml.Open "GET", feed, False objXml.Send() ' Check response status If objXml.Status <> 200 Then GetXML = "Could not retrieve XML from source! Status HTTP1.1/" & objXml.Status Else ' Get response GetXML = objXml.responseText End If Set objXml = Nothing End Function ' Parse XML feed and return YouTubeVideo objects ' ' @param Dictionary dict Dictionary object ' @param string xml XML results Private Sub ParseResults(dict, xml) ' Create objects Set objXml = Server.CreateObject("MSXML2.DOMDocument.3.0") objXml.async = False ' Load string objXml.loadXML xml Set xmlNode = objXml.documentElement ' Set object attributes yt_updated = xmlNode.childNodes(1).Text yt_totalResults = xmlNode.childNodes(11).Text yt_startIndex = xmlNode.childNodes(12).Text If xmlNode.childNodes.length > 13 Then yt_itemsPerPage = xmlNode.childNodes(13).Text For Each oNode In xmlNode.childNodes If oNode.nodeName = "entry" Then ' Create YouTubeVideo object Set objVideo = New YouTubeVideo ' Set object attributes tmpId = GetNamedItem(oNode, "id") objVideo.ID = Mid(tmpId, InStrRev(tmpId, "/")+1, Len(tmpId)) objVideo.Published = GetNamedItem(oNode, "published") objVideo.Updated = GetNamedItem(oNode, "updated") objVideo.Title = GetNamedItem(oNode, "title") objVideo.Statistics = GetNamedItemAttr(oNode, "yt:statistics", "viewCount") objVideo.Rating = GetNamedItemAttr(oNode, "gd:rating", "average") For Each oChildNode in oNode.childNodes If oChildNode.nodeName = "media:group" Then objVideo.ShortDescription = GetNamedItem(oChildNode, "media:description") objVideo.Duration = GetNamedItemAttr(oChildNode, "yt:duration", "seconds") 'objVideo.MediaURL = GetNamedItemAttr(oChildNode, "media:content", "url") 'objVideo.MediaType = GetNamedItemAttr(oChildNode, "media:content", "type") objVideo.ThumbnailURL = GetNamedItemAttr(oChildNode, "media:thumbnail", "url") objVideo.ThumbnailWidth = GetNamedItemAttr(oChildNode, "media:thumbnail", "width") objVideo.ThumbnailHeight = GetNamedItemAttr(oChildNode, "media:thumbnail", "height") GetMediaContent oChildNode, objVideo End If If oChildNode.nodeName = "media:group" Then objVideo.CommentsLink = GetNamedItemAttr(oChildNode, "gd:feedLink", "href") End If Next ' Add object to results 'yt_results.Add objVideo.ID, objVideo dict.Add objVideo.ID, objVideo ' Destroy object Set objVideo = Nothing End If Next End Sub ' Get media content ' ' @param XMLNode oNode XML Node ' @param YouTubeVideo oVideo Video object Private Sub GetMediaContent(oNode, oVideo) For Each oChildNode in oNode.childNodes If oChildNode.nodeName = "media:content" Then If oChildNode.getAttribute("isDefault") = "true" Then oVideo.MediaURL = oChildNode.getAttribute("url") oVideo.MediaType = oChildNode.getAttribute("type") End If End If Next End Sub ' Get named node ' ' @param XMLNode oNode XML Node ' @param string name Node name ' @return XMLNode Private Function GetNamedItem(oNode, name) For Each oChildNode in oNode.childNodes If oChildNode.nodeName = name Then GetNamedItem = oChildNode.Text End If Next End Function ' Get named node attribute ' ' @param XMLNode oNode XML Node ' @param string name Node name ' @param string attribute Attribute name ' @return XMLNode Private Function GetNamedItemAttr(oNode, name, attr) For Each oChildNode in oNode.childNodes If oChildNode.nodeName = name Then GetNamedItemAttr = oChildNode.getAttribute(attr) End If Next End Function ' Search for videos ' ' @param Dictionary dict Dictionary object to hold results ' @param string query The query ' @param string author User name ' @param int startIndex Start index (1-based) ' @param int maxResults Number of results to return ' @param string feed Name of feed to search ' @param bool restricted Include restricted (adult) content ' @param int format Only include specific video format in results (allowed values: 0, 1, 5) ' @param string order Sort results (allowed values: updated, viewCount, rating, relevance) Public Sub Search(dict, query, author, startIndex, maxResults, feed, restricted, format, order) ' Convert bool to string If restricted Then restricted = "include" Else restricted = "exclude" End If ' Construct query url = yt_feeds.Item(feed) If query <> "" Then url = url & "?vq=" & Trim(query) If author <> "" Then url = url & "?author=" & author url = url & "&start-index=" & CInt(startIndex) _ & "&max-results=" & CInt(maxResults) _ & "&racy=" & restricted _ & "&orderby=" & order If format <> "0" Then url = url & "&format=" & CInt(format) ' Get XML results strXml = GetXML(url) ' Parse results and load into yt_results variable ParseResults dict, strXml End Sub End Class ' Class representing a YouTube video ' ' The YouTubeVideo class is a object representation of a YouTube video item. The ' class is used by the YouYube class witch allows you to search for and display ' YouTube videos on your own web pages. ' ' @author Peter Törnstrand