VB script for YouTube Feeds

Visual Basic (VB) is Microsoft programing language. Very useful. Especially for mundane routines; in this case, the creation of YouTube Feeds.

“Start-index” is a API parameter for displaying a feed, at a specific location within that feed. YouTube allows a maximum of 50 videos to be display in a single API request. In order to display 349 videos in a single complete feed, the start-index must increment 50 videos at for each API request, with the exception of the first request; because, there is no start-index=0. Start-index=1 begins the first API request with max-results=49. There must be seven separate requests to complete a single 349 video feed… (1 x 49) + (6 x 50).

Two separate template files are integrated together using VB to create a single HTML code. First file is the Java template for the Feed2JS request. Feed2JS is a server script converting the RSS feed format to HTML. The java script within the HTML code makes the request for Feed2JS to display the feed. So, the java script template is inserted into the HTML template file, and by using VB replacement command to insert the API parameters in the java template.

Java file template:
<br><script language="JavaScript" src="http://www.rapunzelsdelight.com/feed2js/feed2js.php?src=http%3A%2F%2Fgdata.youtube.com%2Ffeeds%2Fbase%2Fvideos%3Fq%3D*QUERY*%26orderby%3D*ORDERBY*%26start-index%3D*STARTINDEX*%26max-results%3D*MAXRESULTS*%26safeSearch%3Dmoderate%26v%3D2&chan=y&date=y&targ=y&utf=y&pc=y&html=a"  charset="UTF-8" type="text/javascript"></br></script><noscript><a href="http://www.rapunzelsdelight.com/feed2js/feed2js.php?src=http%3A%2F%2Fgdata.youtube.com%2Ffeeds%2Fbase%2Fvideos%3Fq%3D*QUERY*%26orderby%3D*ORDERBY*%26start-index%3D*STARTINDEX*%26max-results%3D*MAXRESULTS*%26safeSearch%3Dmoderate%26v%3D2&chan=y&date=y&targ=y&utf=y&pc=y&html=y">View RSS feed</a></noscript>
HTML file template:
<a name="Bookmark 1"></a>
<h5 style="text-align: center;">Select start index... <a style="text-decoration: none; line-height: 30px;" title="Start Index 1" href="#Bookmark 1">[1]</a> <a style="text-decoration: none;" title="Start Index 50" href="#Bookmark 2">[50]</a> <a style="text-decoration: none;" title="Start Index 100" href="#Bookmark 3">[100]</a> <a style="text-decoration: none;" title="Start Index 150" href="#Bookmark 4">[150]</a> <a style="text-decoration: none;" title="Start Index 200" href="#Bookmark 5">[200]</a> <a style="text-decoration: none;" title="Start Index 250" href="#Bookmark 6">[250]</a> <a style="text-decoration: none;" title="Start Index 300" href="#Bookmark 7">[300]</a></h5>
<h5 style="text-align: center;">Now at start index 1</h5>

INSERT JAVA HERE START INDEX 001

<a name="Bookmark 2"></a>
<h5 style="text-align: center;">Select start index... <a style="text-decoration: none; line-height: 30px;" title="Start Index 1" href="#Bookmark 1">[1]</a> <a style="text-decoration: none;" title="Start Index 50" href="#Bookmark 2">[50]</a> <a style="text-decoration: none;" title="Start Index 100" href="#Bookmark 3">[100]</a> <a style="text-decoration: none;" title="Start Index 150" href="#Bookmark 4">[150]</a> <a style="text-decoration: none;" title="Start Index 200" href="#Bookmark 5">[200]</a> <a style="text-decoration: none;" title="Start Index 250" href="#Bookmark 6">[250]</a> <a style="text-decoration: none;" title="Start Index 300" href="#Bookmark 7">[300]</a></h5>
<h5 style="text-align: center;">Now at start index 50</h5>

INSERT JAVA HERE START INDEX 050

<a name="Bookmark 3"></a>
<h5 style="text-align: center;">Select start index... <a style="text-decoration: none; line-height: 30px;" title="Start Index 1" href="#Bookmark 1">[1]</a> <a style="text-decoration: none;" title="Start Index 50" href="#Bookmark 2">[50]</a> <a style="text-decoration: none;" title="Start Index 100" href="#Bookmark 3">[100]</a> <a style="text-decoration: none;" title="Start Index 150" href="#Bookmark 4">[150]</a> <a style="text-decoration: none;" title="Start Index 200" href="#Bookmark 5">[200]</a> <a style="text-decoration: none;" title="Start Index 250" href="#Bookmark 6">[250]</a> <a style="text-decoration: none;" title="Start Index 300" href="#Bookmark 7">[300]</a></h5>
<h5 style="text-align: center;">Now at start index 100</h5>

INSERT JAVA HERE START INDEX 100

<a name="Bookmark 4"></a>
<h5 style="text-align: center;">Select start index... <a style="text-decoration: none; line-height: 30px;" title="Start Index 1" href="#Bookmark 1">[1]</a> <a style="text-decoration: none;" title="Start Index 50" href="#Bookmark 2">[50]</a> <a style="text-decoration: none;" title="Start Index 100" href="#Bookmark 3">[100]</a> <a style="text-decoration: none;" title="Start Index 150" href="#Bookmark 4">[150]</a> <a style="text-decoration: none;" title="Start Index 200" href="#Bookmark 5">[200]</a> <a style="text-decoration: none;" title="Start Index 250" href="#Bookmark 6">[250]</a> <a style="text-decoration: none;" title="Start Index 300" href="#Bookmark 7">[300]</a></h5>
<h5 style="text-align: center;">Now at start index 150</h5>

INSERT JAVA HERE START INDEX 150

<a name="Bookmark 5"></a>
<h5 style="text-align: center;">Select start index... <a style="text-decoration: none; line-height: 30px;" title="Start Index 1" href="#Bookmark 1">[1]</a> <a style="text-decoration: none;" title="Start Index 50" href="#Bookmark 2">[50]</a> <a style="text-decoration: none;" title="Start Index 100" href="#Bookmark 3">[100]</a> <a style="text-decoration: none;" title="Start Index 150" href="#Bookmark 4">[150]</a> <a style="text-decoration: none;" title="Start Index 200" href="#Bookmark 5">[200]</a> <a style="text-decoration: none;" title="Start Index 250" href="#Bookmark 6">[250]</a> <a style="text-decoration: none;" title="Start Index 300" href="#Bookmark 7">[300]</a></h5>
<h5 style="text-align: center;">Now at start index 200</h5>

INSERT JAVA HERE START INDEX 200

<a name="Bookmark 6"></a>
<h5 style="text-align: center;">Select start index... <a style="text-decoration: none; line-height: 30px;" title="Start Index 1" href="#Bookmark 1">[1]</a> <a style="text-decoration: none;" title="Start Index 50" href="#Bookmark 2">[50]</a> <a style="text-decoration: none;" title="Start Index 100" href="#Bookmark 3">[100]</a> <a style="text-decoration: none;" title="Start Index 150" href="#Bookmark 4">[150]</a> <a style="text-decoration: none;" title="Start Index 200" href="#Bookmark 5">[200]</a> <a style="text-decoration: none;" title="Start Index 250" href="#Bookmark 6">[250]</a> <a style="text-decoration: none;" title="Start Index 300" href="#Bookmark 7">[300]</a></h5>
<h5 style="text-align: center;">Now at start index 250</h5>

INSERT JAVA HERE START INDEX 250

<a name="Bookmark 7"></a>
<h5 style="text-align: center;">Select start index... <a style="text-decoration: none; line-height: 30px;" title="Start Index 1" href="#Bookmark 1">[1]</a> <a style="text-decoration: none;" title="Start Index 50" href="#Bookmark 2">[50]</a> <a style="text-decoration: none;" title="Start Index 100" href="#Bookmark 3">[100]</a> <a style="text-decoration: none;" title="Start Index 150" href="#Bookmark 4">[150]</a> <a style="text-decoration: none;" title="Start Index 200" href="#Bookmark 5">[200]</a> <a style="text-decoration: none;" title="Start Index 250" href="#Bookmark 6">[250]</a> <a style="text-decoration: none;" title="Start Index 300" href="#Bookmark 7">[300]</a></h5>
<h5 style="text-align: center;">Now at start index 300</h5>

INSERT JAVA HERE START INDEX 300
VB code:
Imports System.IO
Module Module1
Dim java As String
Dim html As String

Dim QueryString As String

Dim StartIndex As Integer

'Dim java As String
'Dim html As String

Dim javaInsert As String
Dim htmlInsert As String

Dim margin As String

Sub Main()

'Start building HTML text files +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Console.Write("Use quotes. Space plus -cut, will remove cut in results" + vbNewLine)
Console.Write("Enter query string:  ")
QueryString = Console.ReadLine()
QueryString = QueryString.Replace(Chr(34), "%2522")
QueryString = QueryString.Replace("+", "%2B")
QueryString = QueryString.Replace(" ", "%2B")

'Console.Write(QueryString)
'Console.Read()

Dim published As New StreamWriter("C:\Users\Alan\Desktop\YouTube RSS Feed Template\Finished orderby published.txt")
Dim rating As New StreamWriter("C:\Users\Alan\Desktop\YouTube RSS Feed Template\Finished orderby rating.txt")
Dim relevance As New StreamWriter("C:\Users\Alan\Desktop\YouTube RSS Feed Template\Finished orderby relevance.txt")
Dim viewCount As New StreamWriter("C:\Users\Alan\Desktop\YouTube RSS Feed Template\Finished orderby viewCount.txt")

Dim JavaTemplate As New StreamReader("C:\Users\Alan\Desktop\YouTube RSS Feed Template\java template.txt")
java = JavaTemplate.ReadLine
JavaTemplate.Close()


Dim HTMLTemplate As New StreamReader("C:\Users\Alan\Desktop\YouTube RSS Feed Template\html template.txt")
Do While HTMLTemplate.Peek() >= 0
html = html + HTMLTemplate.ReadLine
Loop
HTMLTemplate.Close()

margin = "style=" + Chr(34) + "margin=0;" + Chr(34)

'--------------------------------------------------------------------------------
'Published

javaInsert = java
htmlInsert = html

javaInsert = javaInsert.Replace("*QUERY*", QueryString)
javaInsert = javaInsert.Replace("*ORDERBY*", "published")
javaInsert = javaInsert.Replace("*STARTINDEX*", "1")
javaInsert = javaInsert.Replace("*MAXRESULTS*", "49")
htmlInsert = htmlInsert.Replace("INSERT JAVA HERE START INDEX 001", javaInsert)

javaInsert = java

javaInsert = javaInsert.Replace("*QUERY*", QueryString)
javaInsert = javaInsert.Replace("*ORDERBY*", "published")
javaInsert = javaInsert.Replace("*STARTINDEX*", "50")
javaInsert = javaInsert.Replace("*MAXRESULTS*", "50")
htmlInsert = htmlInsert.Replace("INSERT JAVA HERE START INDEX 050", javaInsert)

javaInsert = java

javaInsert = javaInsert.Replace("*QUERY*", QueryString)
javaInsert = javaInsert.Replace("*ORDERBY*", "published")
javaInsert = javaInsert.Replace("*STARTINDEX*", "100")
javaInsert = javaInsert.Replace("*MAXRESULTS*", "50")
htmlInsert = htmlInsert.Replace("INSERT JAVA HERE START INDEX 100", javaInsert)

javaInsert = java

javaInsert = javaInsert.Replace("*QUERY*", QueryString)
javaInsert = javaInsert.Replace("*ORDERBY*", "published")
javaInsert = javaInsert.Replace("*STARTINDEX*", "150")
javaInsert = javaInsert.Replace("*MAXRESULTS*", "50")
htmlInsert = htmlInsert.Replace("INSERT JAVA HERE START INDEX 150", javaInsert)

javaInsert = java

javaInsert = javaInsert.Replace("*QUERY*", QueryString)
javaInsert = javaInsert.Replace("*ORDERBY*", "published")
javaInsert = javaInsert.Replace("*STARTINDEX*", "200")
javaInsert = javaInsert.Replace("*MAXRESULTS*", "50")
htmlInsert = htmlInsert.Replace("INSERT JAVA HERE START INDEX 200", javaInsert)

javaInsert = java

javaInsert = javaInsert.Replace("*QUERY*", QueryString)
javaInsert = javaInsert.Replace("*ORDERBY*", "published")
javaInsert = javaInsert.Replace("*STARTINDEX*", "250")
javaInsert = javaInsert.Replace("*MAXRESULTS*", "50")
htmlInsert = htmlInsert.Replace("INSERT JAVA HERE START INDEX 250", javaInsert)

javaInsert = java

javaInsert = javaInsert.Replace("*QUERY*", QueryString)
javaInsert = javaInsert.Replace("*ORDERBY*", "published")
javaInsert = javaInsert.Replace("*STARTINDEX*", "300")
javaInsert = javaInsert.Replace("*MAXRESULTS*", "50")
htmlInsert = htmlInsert.Replace("INSERT JAVA HERE START INDEX 300", javaInsert)

published.WriteLine("<h4 style=" + Chr(34) + "margin: 0;" + Chr(34) + ">Feed order by published</h4>" + htmlInsert)
published.Close()

'--------------------------------------------------------------------------------
'Rating

javaInsert = java
htmlInsert = html

javaInsert = javaInsert.Replace("*QUERY*", QueryString)
javaInsert = javaInsert.Replace("*ORDERBY*", "rating")
javaInsert = javaInsert.Replace("*STARTINDEX*", "1")
javaInsert = javaInsert.Replace("*MAXRESULTS*", "49")
htmlInsert = htmlInsert.Replace("INSERT JAVA HERE START INDEX 001", javaInsert)

javaInsert = java

javaInsert = javaInsert.Replace("*QUERY*", QueryString)
javaInsert = javaInsert.Replace("*ORDERBY*", "rating")
javaInsert = javaInsert.Replace("*STARTINDEX*", "50")
javaInsert = javaInsert.Replace("*MAXRESULTS*", "50")
htmlInsert = htmlInsert.Replace("INSERT JAVA HERE START INDEX 050", javaInsert)

javaInsert = java

javaInsert = javaInsert.Replace("*QUERY*", QueryString)
javaInsert = javaInsert.Replace("*ORDERBY*", "rating")
javaInsert = javaInsert.Replace("*STARTINDEX*", "100")
javaInsert = javaInsert.Replace("*MAXRESULTS*", "50")
htmlInsert = htmlInsert.Replace("INSERT JAVA HERE START INDEX 100", javaInsert)

javaInsert = java

javaInsert = javaInsert.Replace("*QUERY*", QueryString)
javaInsert = javaInsert.Replace("*ORDERBY*", "rating")
javaInsert = javaInsert.Replace("*STARTINDEX*", "150")
javaInsert = javaInsert.Replace("*MAXRESULTS*", "50")
htmlInsert = htmlInsert.Replace("INSERT JAVA HERE START INDEX 150", javaInsert)

javaInsert = java

javaInsert = javaInsert.Replace("*QUERY*", QueryString)
javaInsert = javaInsert.Replace("*ORDERBY*", "rating")
javaInsert = javaInsert.Replace("*STARTINDEX*", "200")
javaInsert = javaInsert.Replace("*MAXRESULTS*", "50")
htmlInsert = htmlInsert.Replace("INSERT JAVA HERE START INDEX 200", javaInsert)

javaInsert = java

javaInsert = javaInsert.Replace("*QUERY*", QueryString)
javaInsert = javaInsert.Replace("*ORDERBY*", "rating")
javaInsert = javaInsert.Replace("*STARTINDEX*", "250")
javaInsert = javaInsert.Replace("*MAXRESULTS*", "50")
htmlInsert = htmlInsert.Replace("INSERT JAVA HERE START INDEX 250", javaInsert)

javaInsert = java

javaInsert = javaInsert.Replace("*QUERY*", QueryString)
javaInsert = javaInsert.Replace("*ORDERBY*", "rating")
javaInsert = javaInsert.Replace("*STARTINDEX*", "300")
javaInsert = javaInsert.Replace("*MAXRESULTS*", "50")
htmlInsert = htmlInsert.Replace("INSERT JAVA HERE START INDEX 300", javaInsert)

rating.WriteLine("<h4 style=" + Chr(34) + "margin: 0;" + Chr(34) + ">Feed order by rating</h4>" + htmlInsert)
rating.Close()

'--------------------------------------------------------------------------------
'relevance

javaInsert = java
htmlInsert = html

javaInsert = javaInsert.Replace("*QUERY*", QueryString)
javaInsert = javaInsert.Replace("*ORDERBY*", "relevance")
javaInsert = javaInsert.Replace("*STARTINDEX*", "1")
javaInsert = javaInsert.Replace("*MAXRESULTS*", "49")
htmlInsert = htmlInsert.Replace("INSERT JAVA HERE START INDEX 001", javaInsert)

javaInsert = java

javaInsert = javaInsert.Replace("*QUERY*", QueryString)
javaInsert = javaInsert.Replace("*ORDERBY*", "relevance")
javaInsert = javaInsert.Replace("*STARTINDEX*", "50")
javaInsert = javaInsert.Replace("*MAXRESULTS*", "50")
htmlInsert = htmlInsert.Replace("INSERT JAVA HERE START INDEX 050", javaInsert)

javaInsert = java

javaInsert = javaInsert.Replace("*QUERY*", QueryString)
javaInsert = javaInsert.Replace("*ORDERBY*", "relevance")
javaInsert = javaInsert.Replace("*STARTINDEX*", "100")
javaInsert = javaInsert.Replace("*MAXRESULTS*", "50")
htmlInsert = htmlInsert.Replace("INSERT JAVA HERE START INDEX 100", javaInsert)

javaInsert = java

javaInsert = javaInsert.Replace("*QUERY*", QueryString)
javaInsert = javaInsert.Replace("*ORDERBY*", "relevance")
javaInsert = javaInsert.Replace("*STARTINDEX*", "150")
javaInsert = javaInsert.Replace("*MAXRESULTS*", "50")
htmlInsert = htmlInsert.Replace("INSERT JAVA HERE START INDEX 150", javaInsert)

javaInsert = java

javaInsert = javaInsert.Replace("*QUERY*", QueryString)
javaInsert = javaInsert.Replace("*ORDERBY*", "relevance")
javaInsert = javaInsert.Replace("*STARTINDEX*", "200")
javaInsert = javaInsert.Replace("*MAXRESULTS*", "50")
htmlInsert = htmlInsert.Replace("INSERT JAVA HERE START INDEX 200", javaInsert)

javaInsert = java

javaInsert = javaInsert.Replace("*QUERY*", QueryString)
javaInsert = javaInsert.Replace("*ORDERBY*", "relevance")
javaInsert = javaInsert.Replace("*STARTINDEX*", "250")
javaInsert = javaInsert.Replace("*MAXRESULTS*", "50")
htmlInsert = htmlInsert.Replace("INSERT JAVA HERE START INDEX 250", javaInsert)

javaInsert = java

javaInsert = javaInsert.Replace("*QUERY*", QueryString)
javaInsert = javaInsert.Replace("*ORDERBY*", "relevance")
javaInsert = javaInsert.Replace("*STARTINDEX*", "300")
javaInsert = javaInsert.Replace("*MAXRESULTS*", "50")
htmlInsert = htmlInsert.Replace("INSERT JAVA HERE START INDEX 300", javaInsert)

relevance.WriteLine("<h4 style=" + Chr(34) + "margin: 0;" + Chr(34) + ">Feed order by relevance</h4>" + htmlInsert)
relevance.Close()

'--------------------------------------------------------------------------------
'viewCount

javaInsert = java
htmlInsert = html

javaInsert = javaInsert.Replace("*QUERY*", QueryString)
javaInsert = javaInsert.Replace("*ORDERBY*", "viewCount")
javaInsert = javaInsert.Replace("*STARTINDEX*", "1")
javaInsert = javaInsert.Replace("*MAXRESULTS*", "49")
htmlInsert = htmlInsert.Replace("INSERT JAVA HERE START INDEX 001", javaInsert)

javaInsert = java

javaInsert = javaInsert.Replace("*QUERY*", QueryString)
javaInsert = javaInsert.Replace("*ORDERBY*", "viewCount")
javaInsert = javaInsert.Replace("*STARTINDEX*", "50")
javaInsert = javaInsert.Replace("*MAXRESULTS*", "50")
htmlInsert = htmlInsert.Replace("INSERT JAVA HERE START INDEX 050", javaInsert)

javaInsert = java

javaInsert = javaInsert.Replace("*QUERY*", QueryString)
javaInsert = javaInsert.Replace("*ORDERBY*", "viewCount")
javaInsert = javaInsert.Replace("*STARTINDEX*", "100")
javaInsert = javaInsert.Replace("*MAXRESULTS*", "50")
htmlInsert = htmlInsert.Replace("INSERT JAVA HERE START INDEX 100", javaInsert)

javaInsert = java

javaInsert = javaInsert.Replace("*QUERY*", QueryString)
javaInsert = javaInsert.Replace("*ORDERBY*", "viewCount")
javaInsert = javaInsert.Replace("*STARTINDEX*", "150")
javaInsert = javaInsert.Replace("*MAXRESULTS*", "50")
htmlInsert = htmlInsert.Replace("INSERT JAVA HERE START INDEX 150", javaInsert)

javaInsert = java

javaInsert = javaInsert.Replace("*QUERY*", QueryString)
javaInsert = javaInsert.Replace("*ORDERBY*", "viewCount")
javaInsert = javaInsert.Replace("*STARTINDEX*", "200")
javaInsert = javaInsert.Replace("*MAXRESULTS*", "50")
htmlInsert = htmlInsert.Replace("INSERT JAVA HERE START INDEX 200", javaInsert)

javaInsert = java

javaInsert = javaInsert.Replace("*QUERY*", QueryString)
javaInsert = javaInsert.Replace("*ORDERBY*", "viewCount")
javaInsert = javaInsert.Replace("*STARTINDEX*", "250")
javaInsert = javaInsert.Replace("*MAXRESULTS*", "50")
htmlInsert = htmlInsert.Replace("INSERT JAVA HERE START INDEX 250", javaInsert)

javaInsert = java

javaInsert = javaInsert.Replace("*QUERY*", QueryString)
javaInsert = javaInsert.Replace("*ORDERBY*", "viewCount")
javaInsert = javaInsert.Replace("*STARTINDEX*", "300")
javaInsert = javaInsert.Replace("*MAXRESULTS*", "50")
htmlInsert = htmlInsert.Replace("INSERT JAVA HERE START INDEX 300", javaInsert)

viewCount.WriteLine("<h4 style=" + Chr(34) + "margin: 0;" + Chr(34) + ">Feed order by viewCount</h4>" + htmlInsert)
viewCount.Close()

'Console.Write(javaInsert)
'Console.Read()
End Sub

End Module

The post VB script for YouTube Feeds appeared first on Rapunzel's Delight.


Notice: Undefined property: WPOMatic::$admin in /var/www/vhosts/j-ext.net/wp371/wp-content/plugins/wp-o-matic/wpomatic.php on line 319

Notice: Undefined property: WPOMatic::$admin in /var/www/vhosts/j-ext.net/wp371/wp-content/plugins/wp-o-matic/wpomatic.php on line 319