开发者

Classic ASP (VBScript) Display only first image (YouTube image)

This is my first time posting here - it's a great resource, I keep seeming to find solutions on here. I'm writing code to display an image gallery of YouTube videos on a website. I'm using Classic ASP to parse the RSS feed, and so far I've successfully got the thumbnail of the YouTube video. Now I'm trying to display only one of the 4 Jpegs - the URL of the YouTube RSS for thumbnails seems to be in the following format:

  1. http://i.ytimg.com/vi/oh_OMkstzMQ/0.jpg
  2. http://i.ytimg.com/vi/oh_OMkstzMQ/1.jpg
  3. http://i.ytimg.com/vi/oh_OMkstzMQ/2.jpg
  4. http://i.ytimg.com/vi/oh_OMkstzMQ/3.jpg

So, I was wondering if someone could suggest a way to only get 0.jpg from the feed? I'll post my code below:

<%
Dim xml, xhr, ns,开发者_JAVA技巧 YouTubeID, TrimmedID, GetJpeg, GetJpeg2, GetJpeg3, thumbnailUrl, xmlList, nodeList, TrimmedThumbnailUrl
Set xml = Server.CreateObject("MSXML2.FreeThreadedDOMDocument")
xml.async = False
xml.setProperty "ServerHTTPRequest", True
xml.Load("http://gdata.youtube.com/feeds/api/users/Shuggy23/favorites?orderby=updated")
If xml.parseError.errorCode <> 0 Then
    Response.Write xml.parseError.reason
End If
Set xmlList = xml.getElementsByTagName("entry")
Set nodeList = xml.SelectNodes("//media:thumbnail")
For Each xmlItem In xmlList
    YouTubeID = xmlItem.getElementsByTagName("id")(0).Text
    TrimmedID = Replace(YouTubeID, "http://gdata.youtube.com/feeds/api/videos/", "")
    For Each xmlItem2 In nodeList
        thumbnailUrl = xmlItem2.getAttribute("url")

        Response.Write thumbnailUrl & "<br />"
    Next    
Next    
%>

Hope someone can help. Thanks very much.

Douglas


If you just want to get 0.jpg from the thumbnail URL, try:

Right(thumbnailUrl, Len(thumbnailUrl) - InStrRev(thumbnailUrl, "/"))

If you want to just get the first thumbnail, you could use Exit For to bail out of the loop.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜