TubeGripClient – Play Any Movie on YouTube in AS3 with your own player!

Hi Everyone,

as some of you might have noticed, KeepVid went downhill. I don’t know exactly when, however I found an alternative: http://www.tubegrip.com. It works pretty well…

Here is a sample use of this library:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
public function startTest():void
{
	_client = TubeGripClient.getInstance();
 
	// this takes a url from YouTube they call Watch Urls.. basically, the url you get when you try
	// to share a video with a friend...
	_client.getFLVUrl("http://www.youtube.com/watch?v=WPzgGs_cHWo");
	_client.addEventListener(TubeGripEvent.URL_READY, doUrlReady);
	_client.addEventListener(TubeGripEvent.REQUEST_FAILED, doRequestFailed);
}
 
protected function doUrlReady(evt:TubeGripEvent):void
{
	trace("urls are:");
	trace("[flv] " + evt.flvUrl);
	trace("[hd] " + evt.hdUrl);
	trace("[hq] " + evt.hqUrl);
}
 
protected function doRequestFailed(evt:TubeGripEvent):void
{
	trace("request failed.. for whatever reason");
}

This library uses the RESTProxy. The tricky part was, as always, extracting the useful information from the HTML returned by TubeGrip.

So I used the following Regular Expressions to do that:

1
2
3
var flvFilter:RegExp = /href="(http:\/\/v[^"]+)" target="_blank"><b>Download Video<\/b>/g;
var hqFilter:RegExp = /href="(http:\/\/v[^"]+)" target="_blank"><b>Download High Quality Video<\/b>/g;
var hdFilter:RegExp = /href="(http:\/\/v[^"]+)" target="_blank"><b>Download HD Video<\/b>/g;

I used this really cool REGex Tester for tuning the regular expressions…

It was much easier to handle on TubeGrip than KeepVid; mind you.

Full source code.

Cheers,

Martin

3 comments on “TubeGripClient – Play Any Movie on YouTube in AS3 with your own player!

  1. Thanks martin, i just discovered your blog.. I credited you on my blog for the use of the date util class in AS3 , sorry for the mistake !
    I’m currently working on a stream video player for my company,and they host videos on you tube , so i think your code will be of some great help !! Thanks !

  2. soliton on said:

    Hi Martin
    Great Help indeed!
    a bit embarrassing, i couldn’t get it to work though :(
    i tried a few links from youtube
    checked them manually on tubegrip
    no success still
    are there any other requirements besides connecting the Main class as the Document Class to a new FLA?
    cheers
    s
    :)

  3. Stephen Koch on said:

    Is this a work in progress or functioning?

Leave a Reply

Your email address will not be published. Required fields are marked *

*

36,110 Spam Comments Blocked so far by Spam Free Wordpress

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">