Back to Home

Flash to Html5 or Swiffy sneaky api

Hello. I think it’s no secret to anyone that on September 1 (that is · tomorrow) · Google stops playing peripheral flash content in chrome. In other words · flash banners stop running ...

Flash to Html5 or Swiffy sneaky api

    Hello. I think it’s no secret to anyone that on September 1 (that is, tomorrow), Google stops playing peripheral flash content in chrome. In other words, flash-banners cease to run without a direct indication of the user (which is unlikely to follow). Therefore, it makes sense to start switching to the so-called html5 banners. And to soften the transition, you need to convert flash to html5.

    Many people know that Google has a service for such a conversion - Swiffy . However, it exists either as a web application or as an extension to Flash Professional. There is no public api (and especially its documentation). However, it is not.

    If you look closely at the swiffy extension for flash, you will notice that it works with the google web service. And once it works, then we will try. It is enough to send a post request to a specific url with a json object:

    {
     apiVersion : "v1",
     method : "swiffy.convertToHtml",
     params : {
       client = "Swiffy Flash Extension",
       input = "base64Data"
     }
    }
    

    where in the input field we write base64 encoded flash content. And we must not forget in base64 encoding replace '+' with '-' and '/' with '_' for url safe format.

    If all is well, then in return we get the following object:

    {
     result : {
       response : {
         version : "api version",
         status: "SUCESS",
         output: "base64response"
       } 
     }
    }
    

    If an error occurs, the answer will be:

    {
     error : {
       message: "Сообщение об ошибке" 
     }
    }
    

    where version is the version number of the api swiffy, and output is the encoded base64 response. Let us dwell on it.
    First, for decoding, one must not forget to reverse the replacement of '-' with '+' and '_' with '/'. Next, if necessary (so that the size is a multiple of 4) add 1 or 2 characters '=' (as an indication of an extra zero byte). Now you can decode. However, that is not all. Having decoded, we will not receive the html code, but we will get the gzip archive with the html code. After unpacking, we will finally have html - the equivalent (I would like to think so) of the loaded flash drive.

    There is an implementation for all this in the npm package: swiffy-convert from Rafael Belvederese.

    For .net, I wrote a small library: jdart.swiffy ,
    Using it is very simple:

    var swf = File.ReadAllBytes("sample.swf");
    var swiffyClient = new SwiffyClient();
    string html5page = await swiffyClient.ConvertToHtml5Async(swf);
    File.WriteAllBytes("sample.html", Encoding.UTF8.GetBytes(html5page));
    


    Using this approach, you can quickly convert a large number of flash drives, or leave flash support in the interface of your product, where conversion will be performed behind the scenes. Do not forget that not all flash drives can be converted and this is an objective risk.

    Thanks for attention.

    Read Next