GeorgioWan / video-parser

How to solve cross domain issue by using jsonp and its proxy page. We use youtube video information page as implement example.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Youtube Video Parser implemented by YUI jsonp.

This is utility to get youtube stream url by using pure javascript ( but with javascript cross domain restriction, we use jsonp to solve .)

#How to use.

##Include script.

 <script type="text/javascript" src="http://yui.yahooapis.com/3.6.0/build/yui/yui-min.js"></script>

<script type="text/javascript" src="video-parser.js"></script>

##YUI.use() to use this utility.

YUI().use('video-parser','console', function (Y) {
         var url, callback;
             url = "http://www.youtube.com/watch?v=GokKUqLcvD8"; //youtube video url

             callback = function (o){ //this callback function will bring  stream urls 
                 Y.log(o.streamUrl);
             };
            (new Y.Console({height:"600px"})).render(".log");
        Y.VideoParser.parse(url, callback);
     });

#Some knowhow

Cross domain restriction

We use YUI jsonp to handle cross domain restriction. In proxy.php, we you can send parameter id, url into this page. It will echo Youtube Video infomation. We add a jsonp handle in line 16. Therefore it can be use by YUI jsonp function. Proxy.php is not designed only for youtube but any website which can acquire data.

Video Information

We handle youtube video information with YUI QueryString. It helps us to parse video information.

jsonp

http://en.wikipedia.org/wiki/JSONP

About

How to solve cross domain issue by using jsonp and its proxy page. We use youtube video information page as implement example.