I've finally used ASP.NET 2.0 on my web site. Today I uploaded an ASPX page that generates a tag cloud based on all the tags from a YouTube user's videos. I got this idea from Tweet Clouds, a web site that generates tag clouds based on Twitter posts. I searched the Internet and did not find any similar service for YouTube videos.
There were several challenges in this project. The first problem is that Google gData will only return 25 results at a time. Therefore I had to make an initial request just to determine how many videos I need to get. Then I had to remove nodes from that XML response and make several more requests to add 25 XML nodes at a time until I had a complete XML document. Below is the code snippet I used for that particular difficulty.
1: Dim objXmlNode As XmlNode
2: For Each objXmlNode In objEntryNodeList
3: objXmlDocument.DocumentElement.AppendChild(objXmlDocument.ImportNode(objXmlNode, True))
Technically I did not need that XML document since I'm only interested in the media keywords but I was able to save the XML as a file for debugging purposes.
After that there was the programming challenge of getting a count of each unique word. Fortunately life is an open book test. I did some research on the Internet and found that using a hash table would be the best way to handle this problem. I didn't find exactly the code I needed but I managed to figure out how to use a hash table. Below is a code snippet:
1: ' use a hashtable to get unique word counts
2: Dim strWord As String
3: For Each strWord In objKeywords
4: If objHashTable.Contains(strWord) Then
5: ' word already in hash table, increase its count
6: Dim intCount As Integer = objHashTable(strWord)
7: intCount = intCount + 1
8: objHashTable(strWord) = intCount
10: ' word not in hash table yet so add it
11: objHashTable.Add(strWord, 1)
12: End If
As for the actual tag cloud, I used a control that was published on http://www.codeproject.com/KB/aspnet/cloud.aspx. I did have to make a slight adjustment to its code to get a space in the generated HTML code. I could not get the tag cloud to word wrap without that space.
Another thing I learned on this project was how to add meta tags to a content page which uses a master page. According to many Search Engine Optimization experts, meta tags are not very important anymore but I at least wanted a description tag. The following code accomplishes that:
1: Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
2: ' create meta tags
3: Dim metaTagDesc As New HtmlMeta
4: metaTagDesc.Name = "description"
5: metaTagDesc.Content = "A web application that generates a tag cloud based on all the tags used in a YouTube user's videos."
7: Dim metaTagKeywords As New HtmlMeta
8: metaTagKeywords.Name = "keywords"
9: metaTagKeywords.Content = "YouCloud,YouTube Tag Cloud,Video Tag Cloud,YouTube Tags,YouTube Cloud,YouTube Video Cloud"
12: If Page.IsPostBack = False Then
13: btnSubmit.Attributes.Add("onclick", "loading();")
14: End If
15: End Sub
After completing this project I thought about how to make it all worth my while. The Tweet Clouds site has a Pay Pal donation button but that uses a form which did not work within my ASP.NET master page form. Pay Pal donation buttons have a bad reputation among YouTube vloggers because some users make e-begging videos asking for donations. That has created a lot of drama.
I thought it would be better to use Google AdSense. I checked my Google AdSense total earnings for all time and found I've made $6.37 in three years! Oh my, I better not spend all that in one place. Still it is better than the 89 cents in dividends I make from my two shares of Microsoft stock. Besides the text ads there was also the option of using a "video unit" which was more appropriate because it uses YouTube Partner videos. I created a video player featuring the videos of NutCheese, a vlogger who runs a Stickam webchat room that I spend 5 hours a night in. If she makes a fortune from my video unit then I'll hear about it.
You can generate a tag cloud for any YouTube user at: http://www.williamsportwebdeveloper.com/YouCloud.aspx
I've thought about changing this into a web service that returns the HTML for the tag cloud but I don't see how that would benefit me.