Play Google Drive Video in JW Player And Get Direct Link For Google Drive Video

I want to PLay google drive videos in JW player in my website .I know it is possible because a lot of websites doing this e.g fmovies

Is there any API or piece of code through which i can achieve this URL for google drive video https://redirector.googlevideo.com/videoplayback?id=4d0be5bc491e2dd7&itag=18&source=webdrive&requiressl=yes&ttl=transient&pl=21&mime=video/mp4&ipbits=0&sparams=api,expire,id,ip,ipbits,itag,mime,mm,mn,ms,mv,pl,requiressl,source,ttl&api=FsxSHTiLgbCln6EzpdilVgW6JQxNqam8I5YPHEFLs3E=&cms_redirect=yes&expire=1499015322&ip=37.187.148.42&mm=30&mn=sn-25ge7ney&ms=nxu&mt=1499000741&mv=m&signature=658276E5F00AAFD155876EC75453507DE10DDEDB.7FAD65986F21E14B5FAFB6E145252310F86A10B6&key=cms1&app=storage

I already tried juicy API but its not working for me

Upvotes: 3

Views: 22294

Answers (5)

I was trying to do this, I'm able to get the URL, but then there's the problem of streaming it from the server back to the client, basically use puppeteer to go to the URL, click the play button, wait for the video eleemnt to appear, get the "src" attribute, then (somehow over XMLHttpRequest) stream it back to the server, then have the server (nodeJS) stream it back to the client, then use that URL to embed the video (not complete yet see my [very humble] question on it for more):

var puppeteer = require("puppeteer-core");
var http=require("https");
var fs=require("fs");
var fetch=require("fetch-node");
(async() => {
    var browser = await puppeteer.launch({
        executablePath:"./cobchrome/chrome.exe"
    });
    console.log("Got browser", browser);
    var page = await browser.newPage();

    console.log(page,"got page");

    await page.goto("https://docs.google.com/file/d/0B9aMNh1shw_4VUVVWkF0TjRHWTA/preview?enablejsapi=1&playerapiid=player4");
    console.log("went to page..");


    var newClickID = ".ndfHFb-c4YZDc";
    var clicker = await page.waitForSelector(newClickID);

    await page.click(newClickID);

    var frame = await page.waitForSelector("iframe[id=drive-viewer-video-player-object-0]");




    var cf = await frame.contentFrame();

    await cf.waitFor(() => !!document.querySelector("video"))

    var video = await cf.$("video");

    var videoEl = await cf.evaluate(
        v =>{
            var result = {};
            for(var k in v) {
                result[k] = v[k];
            }
            return result;
        },
        video
    );
    var src = videoEl.src;


    await page.goto(src);
    console.log("went to video page ", src);
    var file = fs.createWriteStream("output/therebbe.mp4");
        var count = 0;

    page.on("console", c => {
        var txt = (c.text()),
            buff = Buffer.from(txt,"base64");
     //   var pic = fs.createWriteStream("output/frame"+count+".png");
       // pic.write(buff);
      //  pic.end();
        console.log("Consoling ",count++, buff);
    //    file.write(buff);
    });

    await page.evaluate(() => {
        function _arrayBufferToBase64( buffer ) {
            var binary = '';
            var bytes = new Uint8Array( buffer );
            var len = bytes.byteLength;
            for (var i = 0; i < len; i++) {
                binary += String.fromCharCode( bytes[ i ] );
            }
            return window.btoa( binary );
        }
        function str2ab(str) {
            var buf = new ArrayBuffer(str.length*2); // 2 bytes for each char
            var bufView = new Uint16Array(buf);
            for (var i=0, strLen=str.length; i < strLen; i++) {
                bufView[i] = str.charCodeAt(i);
            }
            return buf;
        }

        var x = new XMLHttpRequest();
        var url = location.href;
        x.onreadystatechange = function(){
            if(x.readyState == 200) {
                console.log("done");
            } else {
                console.log(
                    _arrayBufferToBase64(
                        str2ab(x.response)
                    )
                );
            }
        }
      //  x.responseType="arraybuffer";
        x.open("GET",url,true);
        x.send("");
    });








 // await browser.close();
})();

Upvotes: 0

user9859477
user9859477

Reputation:

if you have WordPress Webiste you can use GD Player WordPress Plugin works with Google Drive Mp4 etc.. it can also set subtitles in videos. I use it, and it for me works very well. I hope this helps.

Upvotes: 0

Ronnie Smith
Ronnie Smith

Reputation: 18585

Just an idea: You don't need JW player or PHP, I's all baked into browsers (HTML5) these days. Here's an example of how to do it (with Google's Material Design UI). Just plain old HTML/CSS/JS.

https://github.com/rhroyston/mdl-audio

Upvotes: -1

Chloe
Chloe

Reputation: 26294

You can try this Perl script to get the direct download link. If you want to play it in JWPlayer, you'll have to run the script from the server to get the link, then insert that link into the HTML.

https://circulosmeos.wordpress.com/2014/04/12/google-drive-direct-download-of-big-files/

Files hosted at Google Drive service can be shared publicly. Nevertheless, if they’re too big, Google pages advice that “Google Drive can’t scan this file for viruses” and ask the user for confirmation in order to proceed with the download.

If for any reason you’re trying to do an unattended download of the file or downloading it on a resource-limited environment, this will prevent direct use of the link.

Here is the script

https://github.com/circulosmeos/gdown.pl

However, the script downloads the file to the filesystem, so you'll have to modify it so on the last URL re-direct, you save the final URL instead of downloading it.

Upvotes: 0

Mick
Mick

Reputation: 25491

If you just want to stream a video from Google drive then this can be done - you can see a working example here:

You can see exactly how it is coded by right clicking and inspecting in your browser

<video controls="controls" style="margin-bottom:20px;width:590px">    
         <source src="https://drive.google.com/uc?export=download&amp;id=0B0JMGMGgxp9WMEdWb1hyQUhlOWs" type="video/mp4"> 
</video>

To create a signed URL for Google cloud storage programatically you need to follow their instructions at the link below - I have not copied or summarised them here as, if the similar AWS mechanism is anything to go by, the approach can change often and it is best to always check the latest official documentation:

Upvotes: 3

Related Questions