📜 ⬆️ ⬇️

Flash to Html5 or secret api Swiffy

Hello. I think it is no secret to anyone that on September 1 (that is, tomorrow), Google stops in peripheral flash content playback in chrome. In other words, flash-banners stop running without direct instructions from the user (which one 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. No public api (and especially its documentation) seems to be absent. However, it is not.

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

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

where in the input field we write base64-encoded flash-content. And you should not forget in base64-encoding to replace '+' with '-' and '/' with '_' for url safe format.
')
If everything is good, then in response we will receive 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 base64 encoded response. On it we will stop.
First, for decoding, you need to remember to make a reverse replacement of '-' with '+' and '_' with '/'. Further, it is necessary, if necessary (for the size to be a multiple of 4), add 1 or 2 '=' characters (as an indication of an extra zero byte). Now you can decode. However, this is not all. Having decoded, we will not receive the html-code, but we will receive a gzip-archive with html-code. After unpacking, we will finally have html - the equivalent (I would like to think so) of a 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 , which is available through the nuget package .
It is very easy to use:

 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 the flash support in the interface of your product, where converting will be done behind the scenes. Do not forget that not all flash drives can convert and this is an objective risk.

Thanks for attention.

Source: https://habr.com/ru/post/265739/


All Articles