Wednesday, January 24, 2007

GetVideoURL and GetVideoName from Youtube

Update: 1/15/2009 YouTube made breaking changes to their site, the code below no longer works.

The function GetVideoURL returns the direct URL to the movie file in a Youtube page by passing the page's HTML source.

Private Function GetVideoURL(ByVal htmlSource As String) As String
'Youtube's url to retrieve the video
Dim targetUrl As String = ""
'locate the src url passed to the flash player
Dim regexpFindID = New Regex("/player2.swf?((.\n)*?)"",", RegexOptions.IgnoreCase)
Dim matchID As Match
matchID = regexpFindID.Match(htmlSource)
If matchID.Success Then
'extract the videoID query string
Dim vidID As String
vidID = matchID.Value.Substring(13, matchID.Value.Length - 15)
Return targetUrl + vidID
Return Nothing
End If
End Function

Private Function GetVideoName(ByVal htmlSource As String) As String
'locate the title based on the div tag
Dim regexpFindName = New Regex("video_title"">((.\n)*?)", RegexOptions.IgnoreCase)
Dim matchName As Match
matchName = regexpFindName.Match(htmlSource)
If matchName.Success Then
'extract the title
Dim vidName As String
vidName = matchName.Value.Substring(13, matchName.Value.Length - 18)
'remove common invalid file system chars & html syntax
Dim arrInvalids As String() = {"\", "/", ":", "?", "<", ">", "", " ", "<", ">", "&", """}
Dim invalid As String
For Each invalid In arrInvalids
If vidName.Contains(invalid) Then
vidName = vidName.Replace(invalid, "")
End If
Return vidName
Return Nothing
End If
End Function

Xido is just an IE control using these functions along with threaded asynchronous calls using the Net.WebClient object to download the files (the download limit is by design to prevent abuse).
Many people are now focusing on these kinds of applications, both running as clients or web applications and are including video transcoding as well as other features.

By contrast Xido is only a small application built out of boredom using these old functions which I had once written out of my frustration while using Sites like KeepVid forced me to copy/paste URLs and manually rename every single file. Xido was only meant to alleviate this problem and should be considered defunct until an interesting challenge comes up using embedded Flash video.

Go build your own rip site like :

Someone even built a webservice that does this same thing (I still don't know why).

Monday, January 15, 2007

Download from Youtube

Xido 1.0
Youtube ripper application

With this application you can download videos from Youtube as you browse the actual Youtube website. It will download videos directly to a folder with the same title as in the website.
  1. Download (link below)
  2. Unzip the file
  3. Run xido.exe
  4. Browse to a video on the website
  5. Click on the television button to download the video
The videos are in flash video format (.flv) , you might need to download VLC to play them.
You must have the .net framework 2.0 installed in your system for Xido to run. The application notifies the user of a completed download by yelling "toasty!" (like in Mortal Kombat 2) you can disable or change this by deleting or replacing the toasty.wav file.

This originated from an unfinished post regarding embedded flash video. This is a quick and dirty personal app.

Download Here