Youtube Video Player

// ytv by Ziah Zhangsun
// based on the youtubeplayer by Nebadon Izume
// with some few lines of code from DanFernandez Project innerTube

string yt_url = "http://www.youtube.com/watch?v="; // base url of yt vid
string vid_id = "";                                // video_id of yt video
string vid_base = "http://www.youtube.com/get_video?fmt=18&video_id=";
string vid_url = "";
key    reqid;

string StringBetween(integer pos, string source, string start, string end)
{
    if (pos > 0)
        source = llGetSubString(source, pos, -1);
    integer sindex = llSubStringIndex(source, start);
    integer eindex = llSubStringIndex(source, end);
    if (sindex == -1 || eindex == -1)
        return "";
    else return llGetSubString(source, sindex + llStringLength(start), eindex -1);
}

default {
   
    state_entry() {
        llListen(7,"",NULL_KEY,"");     
        llOwnerSay("Ready...");         
    }

    listen( integer channel, string name, key id, string message )
    {
        if(channel == 7) {
            vid_id = message;
            reqid = llHTTPRequest( yt_url + vid_id, [], "" );
        }
    }   
   
    http_response(key id, integer status, list meta, string body) {
        if ( id != reqid )
            return;

        //llOwnerSay(body);

        integer swfArgIdx = llSubStringIndex(body, "swfArgs");
        string stringArgs = StringBetween(swfArgIdx,body,"{","}");

       
        list allArgs = llParseString2List(stringArgs,[",","\""," "],[]);

        //find argName "t" and return value ( this is the token that has to bee added to the url to access the
        //video.mp4 directy.


        integer len = llGetListLength(allArgs);
        integer i;
        string pattern = "";
        string token = "";
        for (i = 0; i < len; ++i) {

            pattern = llList2String(allArgs,i);
            if(pattern == "t") {
                token = llList2String(allArgs,i+2);
                llOwnerSay("Found Token : " + token);
                i = len; //break from loop
            }
               
        }   

        //finally, if everything goes smooth, set the generated URL to the parcell media
       
        vid_url = vid_base + vid_id + "&t=" + token;
        //llOwnerSay(vid_url);
        llParcelMediaCommandList([PARCEL_MEDIA_COMMAND_URL,vid_url]);
    }
}
Navigation

Alternative Startseite
Helpdesk
Links
Maps
Radio
Suchmaschine


Drucken/exportieren