videos v0.19

Version: 0.19


Project Info

videos.bentasker.co.uk is used to embed platform agnostic videos into various sites, including www.bentasker.co.uk and https://snippets.bentasker.co.uk.

It provides the means to organise videos as well as to trivially reference them from other locations.


Release Notes

Version 0.19 was made to support delivering www.bentasker.co.uk via eepsite

  • Implement ability to embed videos without document.write()
  • Allow delivery of video via I2P eepsite

However, unless the user has an outproxy configured, there are supporting changes required on the embedding website (because the user won't be able to fetch https://videos.bentasker.co.uk/resources/embed/embed.min.js). Assuming the site is dual-homed, it obviously isn't an option to just embed the I2P name.

The following javascript, when called, will iterate over any <script> tags and rewrite their source. And additional video tag is inserted at the event to act as a ready-ness switch for calling the embed function.

function Clearnet2I2P(){
    if (window.location.hostname.split(".").pop().toLowerCase() != "i2p"){
        /* Nothing to do */
        return;
    }

    var video_found = false;

    mappings = {
        "pfanalytics.bentasker.co.uk" : "5es4aj6pfdxoz6oz6vbcczix25dlfelrdav6a6hw7tuudb7kxwba.b32.i2p",
        "videos.bentasker.co.uk" : "bapmqkdc7xotvlym3bj75gdb4tlgg2poezkmz36w64qum4racpyq.b32.i2p"
    }

    var i, src, dom, newurl, newele;
    var buf = [];
    var eles = document.getElementsByTagName('script');

    for (i=0; i<eles.length; i++){
        src = eles[i].getAttribute("src");
        if (!src || src[0] == "/" || src[0] == "."){
            // Relative or empty link, skip
            continue;
        }

        dom = src.split("/")[2].toLowerCase();

        if (!video_found && dom.includes("videos.bentasker.co.uk")){
            video_found = true;
        }

        // Do we have a mapping for that domain?
        if (mappings[dom]){
            newurl = src.replace("://"+dom, "://" + mappings[dom]).replace("https://","http://");

            newele = document.createElement('script');
            newele.setAttribute("src", newurl);

            // Push to a buffer - the DOM will be updated later
            //
            // This helps avert an infinite loop
            buf.push([newele, eles[i]]);
        }
    }

    // Process anything we've found
    for (i=0; i<buf.length; i++){
        buf[i][1].parentNode.insertBefore(buf[i][0], buf[i][1]);
    }

    if (video_found){
        // We want to re-detect videos once we know the script has loaded
        s = document.createElement('script');
        s.setAttribute('src', 'http://bapmqkdc7xotvlym3bj75gdb4tlgg2poezkmz36w64qum4racpyq.b32.i2p/resources/embed/embed.min.js');
        s.addEventListener('load',function(){embedBensPlayerDivs()});
        document.body.appendChild(s);
    }

}

Clearnet2I2P();

As of the release of v0.19, embeds should refer only to the minified embed script and should embed using the div method:

<div style="width: 60%">
    <script type="text/javascript" 
            src="https://videos.bentasker.co.uk/resources/embed/embed.min.js"></script>
    <div class="embedBensPlayer" data-src='2017/201705_Lua_split_string/lua_string_split.mp4_master.m3u8'></div>
    </script>
</div>

Player example

The following player uses release 0.19