Classic ASP Active Server Pages Examples, code, tutorials, scriptsUse ASP to dynamically parse a Youtube XML playlist to render to html.

SITE MENU

I used to wonder what the big deal was about XML. Then when I began to think about integrating Youtube playlists into my own site, I realized that one of the conveniences of XML is that it prepares the data to be remotely included without all the unneeded tables and images and text, etc.  I integrated code from other folks that puts the XML data into a recordset and pages it.  If you find this example to be useful or interesting, please rate or send me an email.

One possible advantage of displaying playlists on your own site is that you may be able to avoid exposing your visitors to content that would be inappropriate for family viewing, if that is important to you.

I recorded a webcast and wanted to display the banners of the webcast sponsors along with the playlist, which is another of the reasons I wanted to retrieve the playlist remotely:

The code is posted below the demo that follows. Here's the playlist XML we want to parse, format, and display: APHA World Show 2007 Videos. Here is how I did the final product: www.PaintHorseVideos.com
Rated:
by Aspin.com users
What do you think?


There are 38 videos in this playlist.




Author: ImproperUsername
Id: tp-JejDQ9wo
Title: APHA World 2007 13 & Under Western Pleasure Final
Length: 2845
Rating Avg: 3.88
Rating Count: 8
Description: APHA World 2007 13 and Under Western Pleasure Final painthorsevideos.com
View Count: 3004
Upload Time: 6/29/2007 7:39:24 PM
Comments: 5
Tags: APHA World 2007 Western Pleasure Paints
URL: http://www.youtube.com/watch?v=tp-JejDQ9wo
Thumbnail:
Embed ID: KD83gDBiCSEGUgL7qMU7cJ6bowzm1k1AF-xinpMQ7ng=



Author: ImproperUsername
Id: QIoyvUoH6qU
Title: APHA World 2007 14-18 Western Pleasure Final
Length: 2589
Rating Avg: 4.41
Rating Count: 22
Description: APHA World 2007 14-18 Western Pleasure Final painthorsevideos.com
View Count: 14487
Upload Time: 6/29/2007 7:53:42 PM
Comments: 12
Tags: APHA World 2007 Western Pleasure Paints
URL: http://www.youtube.com/watch?v=QIoyvUoH6qU
Thumbnail:
Embed ID: KD83gDBiCSEGUgL7qMU7cJDuwKaqOJFh6oOEW7kx6Ow=



Author: ImproperUsername
Id: cb7e_CsvdZQ
Title: APHA World 2007 19-44 SR Western Pleasure Final
Length: 2364
Rating Avg: 4.43
Rating Count: 7
Description: APHA World 2007 19-44 SR Western Pleasure Final PaintHorseVideos.com
View Count: 3564
Upload Time: 7/2/2007 8:57:45 AM
Comments: 2
Tags: APHA World 2007 Western Pleasure Paints
URL: http://www.youtube.com/watch?v=cb7e_CsvdZQ
Thumbnail:
Embed ID: KD83gDBiCSEGUgL7qMU7cErzNd4TjFPwLkw3aIAUC7Y=



Author: ImproperUsername
Id: 9pIE8IievOE
Title: APHA World 2007 Amateur Junior Hunter Under Saddle 19-44 1
Length: 1958
Rating Avg: 4.50
Rating Count: 6
Description: APHA World 2007 Amateur Junior Hunter Under Saddle 19-44 part 1 - paint horses - www.PaintHorseVideos.com
View Count: 793
Upload Time: 7/9/2007 3:03:54 PM
Comments: 2
Tags: APHA World 2007 Amateur Junior Hunter Under Saddle 19-44
URL: http://www.youtube.com/watch?v=9pIE8IievOE
Thumbnail:
Embed ID: KD83gDBiCSEGUgL7qMU7cPgtwBrU7VAQa1N3P-m5wdc=



Author: ImproperUsername
Id: PJEDcbmXsCI
Title: APHA World 2007 Amateur Junior Hunter Under Saddle 19-44 2
Length: 1962
Rating Avg: 5.00
Rating Count: 5
Description: APHA World 2007 Amateur Junior Hunter Under Saddle 19-44 part 2 - paint horses - www.PaintHorseVideos.com
View Count: 4925
Upload Time: 7/9/2007 3:28:34 PM
Comments: 3
Tags: APHA World 2007 Amateur Junior Hunter Under Saddle paint horses
URL: http://www.youtube.com/watch?v=PJEDcbmXsCI
Thumbnail:
Embed ID: KD83gDBiCSEGUgL7qMU7cD_jO-Uiw38darhi409Beg8=



Author: ImproperUsername
Id: SgRzggzKKhE
Title: APHA World 2007 Amateur Junior Western Pleasure 19-44 pt 1
Length: 1723
Rating Avg: 4.50
Rating Count: 2
Description: Amateur Junior Western Pleasure 19-44 part one. PaintHorseVideos.com
View Count: 320
Upload Time: 7/3/2007 3:52:43 PM
Comments: 2
Tags: APHA World 2007 Western Pleasure Paints
URL: http://www.youtube.com/watch?v=SgRzggzKKhE
Thumbnail:
Embed ID: KD83gDBiCSEGUgL7qMU7cGnT2J-sgJzapYEx_hTef-o=



Author: ImproperUsername
Id: fYvr8OTvzDE
Title: APHA World 2007 Amateur Junior Western Pleasure 19-44 pt 2
Length: 1724
Rating Avg: 4.86
Rating Count: 7
Description: APHA World 2007 Amateur Junior Western Pleasure 19-44 part 2. PaintHorseVideos.com
View Count: 701
Upload Time: 7/3/2007 4:15:07 PM
Comments: 0
Tags: APHA World 2007 Western Pleasure Paints
URL: http://www.youtube.com/watch?v=fYvr8OTvzDE
Thumbnail:
Embed ID: KD83gDBiCSEGUgL7qMU7cENfJeeecCRsjDIf9PgFiXA=



Author: ImproperUsername
Id: fYvr8OTvzDE
Title: APHA World 2007 Amateur Junior Western Pleasure 19-44 pt 2
Length: 1724
Rating Avg: 4.86
Rating Count: 7
Description: APHA World 2007 Amateur Junior Western Pleasure 19-44 part 2. PaintHorseVideos.com
View Count: 701
Upload Time: 7/3/2007 4:15:07 PM
Comments: 0
Tags: APHA World 2007 Western Pleasure Paints
URL: http://www.youtube.com/watch?v=fYvr8OTvzDE
Thumbnail:
Embed ID: KD83gDBiCSEGUgL7qMU7cENfJeeecCRsjDIf9PgFiXA=



Author: ImproperUsername
Id: 7_omZ65E2hs
Title: APHA World 2007 Bridleless Western Pleasure
Length: 1674
Rating Avg: 4.72
Rating Count: 29
Description: APHA World Show Western Pleasure Paint horses shown without bridles - www.PaintHorseVideos.com
View Count: 29152
Upload Time: 7/8/2007 4:48:21 AM
Comments: 28
Tags: APHA World 2007 Western Pleasure Paints bridleless
URL: http://www.youtube.com/watch?v=7_omZ65E2hs
Thumbnail:
Embed ID: KD83gDBiCSEGUgL7qMU7cKS7dwUj4I3At2_y9_50Lo8=



Author: ImproperUsername
Id: 1Qrq2re2iQs
Title: APHA World 2007 Freestyle Reining Part 1
Length: 2387
Rating Avg: 4.90
Rating Count: 10
Description: APHA World 2007 Freestyle Reining Part 1 - www.PaintHorseVideos.com
View Count: 7149
Upload Time: 7/8/2007 4:54:31 PM
Comments: 4
Tags: APHA World 2007 Freestyle Reining Paint Horses
URL: http://www.youtube.com/watch?v=1Qrq2re2iQs
Thumbnail:
Embed ID: KD83gDBiCSEGUgL7qMU7cG9FFjIaIc206XsBXilrxbU=



Author: ImproperUsername
Id: jv1gUlbGQmI
Title: APHA World 2007 Freestyle Reining Part 2
Length: 1304
Rating Avg: 3.83
Rating Count: 6
Description: APHA World 2007 Freestyle Reining Part 2 - www.PaintHorseVideos.com
View Count: 4740
Upload Time: 7/8/2007 4:37:33 PM
Comments: 0
Tags: APHA World 2007 Freestyle Reining Paint Horses
URL: http://www.youtube.com/watch?v=jv1gUlbGQmI
Thumbnail:
Embed ID: KD83gDBiCSEGUgL7qMU7cLhVfs4Dsa11Agt4XG000pg=



Author: ImproperUsername
Id: uZ6FDTcqlFY
Title: APHA World 2007 Freestyle Reining Part 3
Length: 2331
Rating Avg: 4.39
Rating Count: 23
Description: APHA World 2007 Freestyle Reining Part 3 and conclusion - www.PaintHorseVideos.com
View Count: 18699
Upload Time: 7/8/2007 4:55:49 PM
Comments: 4
Tags: APHA World 2007 Freestyle Reining Paint Horses
URL: http://www.youtube.com/watch?v=uZ6FDTcqlFY
Thumbnail:
Embed ID: KD83gDBiCSEGUgL7qMU7cN2fLP1yWU_J7cclC0s9oio=



Author: ImproperUsername
Id: Cj0snJiCdGo
Title: APHA World 2007 Green Working Hunter Pt 1
Length: 2910
Rating Avg: 4.80
Rating Count: 15
Description: APHA World 2007 Green Working Hunter Paint Horses part one www.PaintHorseVideos.com
View Count: 4451
Upload Time: 7/5/2007 1:56:25 AM
Comments: 6
Tags: APHA World show Paint horses Green Working Hunter
URL: http://www.youtube.com/watch?v=Cj0snJiCdGo
Thumbnail:
Embed ID: KD83gDBiCSEGUgL7qMU7cEuwp15_qCmPAGdAo_Xbx0A=



Author: ImproperUsername
Id: tfmeSoIyNks
Title: APHA World 2007 Green Working Hunter Pt 2
Length: 2918
Rating Avg: 4.67
Rating Count: 3
Description: APHA World 2007 Green Working Hunter Paint Horses part two. www.PaintHorseVideos.com
View Count: 278
Upload Time: 7/5/2007 3:00:13 AM
Comments: 1
Tags: APHA World 2007 Green Working Hunter Paint Horses
URL: http://www.youtube.com/watch?v=tfmeSoIyNks
Thumbnail:
Embed ID: KD83gDBiCSEGUgL7qMU7cJiob3jg35hzx1PRuQ0hgEA=
1 2 3 >

<%
'
parseplaylist.asp
'This sample code by Lil Peck, http://equineexpo.com/aspexamples . Thanks to all the other coders from whom I got code for this!
'Free to use and adapt as you like, but please rate or send me an email. LilPeck@gmail.com
Response.expires = 0
Response.expiresabsolute = Now() - 1
Response.addHeader "pragma", "no-cache"
Response.addHeader "cache-control", "private"
Response.CacheControl = "no-cache"


%>


<%
dim objHTTP
dim objXML
dim objXSL

' set-up XMLHTTP

set objHTTP = Server.CreateObject("Microsoft.XMLHTTP")

' get the requested XML data from the remote location
' change the URL as per your feed.
objHTTP.open "GET", "http://www.youtube.com/api2_rest?method=youtube.videos.list_by_playlist&dev_id=DEVELOPERIDGOESHERE&id=PLAYLISTIDGOESHERE", false
'Youtube also has an option that includes paging that I haven't tested, http://www.youtube.com/api2_rest?method=youtube.videos.list_by_playlist&dev_id=dev_id&id=id&page=page&per_page=per_page
objHTTP.send

' save the XML in objXML as XML
set objXML = objHTTP.responseXML

If objXML.parseError.errorCode <> 0 Then
response.write "Oops, I can't load the XML file, sorry."
End If

Set objLst = objXML.getElementsByTagName("video") 'HERE


noOfHeadlines = objLst.length
response.write "<center><b>There are " & noOfHeadlines & " videos in this playlist.</center></b>"


CONST adFldIsNullable = &H00000020
CONST adVarChar = 200
CONST adDate = 7
CONST adOpenDynamic = 2
CONST adUseClient = 3


if noOfHeadlines > 0 then
Set rs = CreateObject("ADODB.recordset")

'declare variables
Dim Currpage, pageLen, lastNumber, PageRem, PageTen
Dim connection, rs, sSQL, sConnString, next10, prev10, P
Dim RSPrevPage, RSNextPage, start
'Get the current page the user is on, if it's the first time they
'visit and the variable 'PageNo' is empty, then 'CurrPage' gets set to 1
'Else the current page variable 'CurrPage' is set to the page number requested
If IsEmpty(Request.Querystring("PageNo")) then
CurrPage = 1
Else
CurrPage = Cint(Request.Querystring("PageNo"))
End If

'the two functions below return the next 10 and prev 10 page number
Function getNext10(num)
pageLen = len(num)
If pageLen = 1 Then
next10 = 10
Else If pageLen>1 Then
pageRem = 10
pageTen = right(num, 1)
next10 = num + pageRem - pageTen
End If
End If
getNext10 = next10
End Function

Function getPrev10(num)
pageLen = len(num)
If pageLen = 1 then
prev10 = 1
Else If pageLen>1 then
lastNumber = right(num, 1)
prev10 = num - lastNumber - 10
End If
End If
If prev10 = 0 then
prev10 = 1
End If
getPrev10 = prev10
End Function


With rs
.CursorLocation = adUseClient
.CursorType = adOpenDynamic
'.Fields.Append "VIDEO", adVarChar, 255, adFldIsNullable
'.Fields.Append "ID", adDate, 32, adFldIsNullable


.Fields.Append"author",adVarChar,255,adFldIsNullable
.Fields.Append"id",adVarChar,255,adFldIsNullable
.Fields.Append"title",adVarChar,255,adFldIsNullable
.Fields.Append"length_seconds",adVarChar,255,adFldIsNullable
.Fields.Append"rating_avg",adVarChar,255,adFldIsNullable
.Fields.Append"rating_count",adVarChar,255,adFldIsNullable
.Fields.Append"description",adVarChar,255,adFldIsNullable
.Fields.Append"view_count",adVarChar,255,adFldIsNullable
.Fields.Append"upload_time",adVarChar,255,adFldIsNullable
.Fields.Append"comment_count",adVarChar,255,adFldIsNullable
.Fields.Append"tags",adVarChar,255,adFldIsNullable
.Fields.Append"url",adVarChar,255,adFldIsNullable
.Fields.Append"thumbnail_url",adVarChar,255,adFldIsNullable
.Fields.Append"embed_id",adVarChar,255,adFldIsNullable


.open


on error resume next
'Set objHdl = objLst.item

      '  For i = 0 To (noOfHeadlines) Not using this anymore
For i = 0 To (noOfHeadlines)-1 'Thank you George for providing this correction.


Set objHdl = objLst.item(i)

.AddNew

.Fields("author") = (objHdl.childNodes(0).text)
.Fields("id") = (objHdl.childNodes(1).text)
.Fields("title") = (objHdl.childNodes(2).text)
.Fields("length_seconds") = (objHdl.childNodes(3).text)
.Fields("rating_avg") = (objHdl.childNodes(4).text)
.Fields("rating_count") = (objHdl.childNodes(5).text)
.Fields("description") = (objHdl.childNodes(6).text)
.Fields("view_count") = (objHdl.childNodes(7).text)
.Fields("upload_time") = (objHdl.childNodes(8).text)
.Fields("comment_count") = (objHdl.childNodes(9).text)
.Fields("tags") = (objHdl.childNodes(10).text)
.Fields("url") = (objHdl.childNodes(11).text)
.Fields("thumbnail_url") = (objHdl.childNodes(12).text)
.Fields("embed_id") = (objHdl.childNodes(13).text)

.update


' list alphabetically

.Sort = "title ASC"
.MoveFirst

.sort
next


set folder = nothing
set fso = nothing
' pagesize is used to set the number of records that will be
' displayed on each page. For our purposes 10 records is what we want.
rs.PageSize = 15
%>
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Display Youtube Playlist XML with ASP</title>
</head>

<body>
<p align="center">Here's the playlist XML we want to parse, format, and display:
<a target="_blank" href="http://www.youtube.com/api2_rest?method=youtube.videos.list_by_playlist&dev_id=zpsaJ4q4Yo0&id=F48E2331F43A70C3">
APHA World Show 2007 Videos</a>.</p>
<div align="center">
<table border="0" width="600">
<tr>

<%
'get the next 10 and prev 10 page number
next10 = getNext10(CurrPage)
prev10 = getPrev10(CurrPage)

'If there are no records
If rs.EOF Then
Response.write "No records to display"

Else
'this moves the record pointer to the first record of the current page
rs.AbsolutePage = CurrPage


'the below loop will loop until all the records of the current page have been
'displayed or it has reached the end of the rs
Do Until rs.AbsolutePage <> CurrPage OR rs.Eof


x=x +1

'function unUDate(intTimeStamp) to convert Unix timestamp to regular date
mydate = DateAdd("s", rs("upload_time"), "01/01/1970 00:00:00")
'End Function


response.write "<tr><td><BR>"
if NOT rs("id") = "" then 'I put this in because of mistake somewhere that made a blank row

Response.Write "<br>"& "<BR>" &_
("Author: ")& rs("author") & "<BR>" &_
("Id: ") & rs("id") & "<BR>" &_
"Title: " & rs("title") & "<BR>" &_
"Length: " & rs("length_seconds") & "<BR>" &_
"Rating Avg: " & rs("rating_avg") & "<BR>" &_
"Rating Count: " & rs("rating_count")& "<BR>" &_
"Description: " & rs("description") & "<BR>" &_
"View Count: " & rs("view_count") & "<BR>" &_
"Upload Time: " & mydate & "<BR>" &_
"Comments: " & rs("comment_count") & "<BR>" &_
"Tags: " & rs("tags") & "<BR>" &_
"URL: " & "<a target=_blank href=" & rs("url") & ">" & rs("url") & "</a><BR>" &_
"Thumbnail: " & "<img src=" & rs("thumbnail_url") & "><BR>" &_
"Embed ID: " & rs("embed_id")

response.write "<hr>"
end if

response.write "</td><td>"
if x = 5 then ' this is if you want multiple columns
response.write "</tr><tr>"
x = 0
end if

rs.MoveNext

Loop

end if
%>
</tr>
</table>
</div>
<div align="center" style="font-size: 12pt; font-weight: bold">
<%
'the next 2 lines setup the page number for the "previous" and "next" links
RSPrevPage = CurrPage -1
RSNextPage = CurrPage + 1

'find out the number of pages returned in the rs
'if the Next10 page number is greater than the rs page count
'then set Next10 to the rs pagecount
If Next10 > rs.PageCount Then
Next10 = rs.PageCount
End If

'the variable start determines where to start the page number navigation
' i.e. 1, 10, 20, 30 and so on.
If prev10 = 1 AND next10 - 1 < 10 Then
start = 1
Else
start = Next10 - 10
If right(start, 1) > 0 Then
start = replace(start, right(start, 1), "0")
start = start + 10
End If
End If

'This checks to make sure that there is more than one page of results
If rs.PageCount > 1 Then
'Work out whether to show the Previous 10 '<<'
If currpage > 1 Then
response.write("<a href=""list.asp?PageNo=" & Prev10 & """><<</a> ")
End If
'Work out whether to show the Previous link '<'
If NOT RSPrevPage = 0 then
response.write("<a href=""list.asp?PageNo=" & RSPrevPage & """><</a> ")
End If

'Loop through the page number navigation using P as our loopcounter variable
For P = start to Next10

If NOT P = CurrPage then
response.write("<a href=""list.asp?PageNo=" & P & """>" & P & "</a> ")
Else
'Don't hyperlink the current page number
response.write(" <b>" & P & " </b>")
End If
Next
'this does the same as the "previous" link, but for the "next" link
If NOT RSNextPage > rs.PageCount Then
response.write("<a href=""list.asp?PageNo=" & RSNextPage & """>></a> ")
End If

'Work out whether to show the Next 10 '>>'
If NOT Next10 = rs.PageCount Then
response.write(" <a href=""list.asp?PageNo=" & Next10 & """>>></a>")
End If
End If

' Close the rs and connection object
rs.Close
Set rs =Nothing
end with
end if
%>
</div>
</body>

</html>

 

ASP Examples Menu of Active Server Pages scripts code Classic ASP

Classic ASP Active Server Pages Examples, code, tutorials, scriptsASP Examples Menu (below*)



Active Server Pages | ASP | Scripts | Tutorials | Code | Web Programming | Examples
Active Server Pages ASP code examples, tutorials, and snippets for use in Programming interactive websites.

NOTE: Recently changed hosting and url so some demos aren't working now because I haven't updated pathing; if you find omissions or errors let me know.
 

*

Multiple records per row with paging

Display multiple records per row

Get ID of newly inserted record, Classic ASP, Access Database

Javascript timer with ASP to keep track of time expired until login expires / timeout session is up

Multiple Javascript event functions triggered from single form onsubmit

Get Querystring key names along with querystring variables

ASP Youtube Downloader  Version FOUR
All ASP code. Allows user client side downloads of Youtube videos. You have the option to allow files to be saved directly to your site also.

ASP/PHP video downloader (Works better than ASP for large files)

Use ASP to dynamically parse a Youtube XML playlist to render to html.

Zip up an archive file of your site for backup if you need to restore website with ASP and free Zip Component.

Zip all files in a folder into an archive or backup file dynamically by specific file extension.

Sanitize or clean price cost field for database insertion or display.

Javascript image dimensions and image file size preview.

Put recordset into array, assign keys to the records then use record associated with specific array key as a variable elsewhere.

Access Database Interface Generator Wizard to read your table and field names and to create a table display.

Combining dropdown selection box menu with dynamic ASP database page.

How to redirect user to original page they tried to view before logging, after they are logged in.

Previous/Current/Next Records, or Buddy Ring Script

Custom ASP 404 page not found error script sends visitors to virtual folders

ASP Example: Combine ASP with Javascript for popup windows
dynamically sized to image dimensions.

ASP Example: How to use ASPJPEG to create thumbnails
Click for free Highly recommended thumbnailer for which you don't need Server access

ASPjpeg: How to re-scale aspect ratio of thumbnails by height instead of width.

ASP Example: What if your host has an older version of ASPJPEG that doesn't support gifs?

Using inline frames as "dynamic includes" (offline for updating)

Select Count Distinct Records for Access Database

Upload Image to folder and insert filename into database

Get date in such a way that it can be made part of a file name

Isolate a file name away from its path or extension or strip a path from a file name or strip characters from database field

User-customized on-the-fly stylesheet css files

Enhanced Page Hits Counter (also counts downloads and menu link hits)

Loop through array and compare to string with select case

Aphabetical Paging for your ASP scripts

Web Wiz Guide's Site Searcher Script modified as a file content indexer

Let Users Select How Many Records to View

Access Database for your PayPal IPN scripts

Miscellaneous collected code

You don't have to be a genius, just persistent, to write original Active Server Pages scripts

Software Recommendation: bare_bones_no_bells_and_whistles_asp_code_generator_database_interface_maker

--Lil at gmail.com