How to recreate the preview from Instagram#39;s media_preview raw data?(如何从 Instagram 的 media_preview 原始数据重新创建预览?)
问题描述
如果您从 Instagram 的 API 获取 JSON 数据,您会发现一个 media_preview
键,其值是一些 Base64 编码的数据.它真的看起来像一些非常小的预览二进制数据.可能被压缩了.
If you get JSON data from Instagram's API you will find a media_preview
key, the value of which is some Base64-encoded data. It really looks like some very small preview binary data. Maybe compressed.
以这篇文章为例.它只是一个黑色方块,它的预览非常小.查看 它的 JSON:data['graphql']['media_preview'] = "ACoq5miiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKAP/Z"
Take this post for example. It's just a black square and its preview is very small. Look at its JSON:
data['graphql']['media_preview'] = "ACoq5miiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKAP/Z"
我无法反转代码并找出 Instagram 是如何使用这些数据的.我应该怎么做才能从这些数据中创建预览?
I could not reverse the code and find out how Instagram uses this data. What should I do to create a preview from this data?
我不擅长理解缩小的 js,但我认为它会在动态创建的画布上为敏感内容"绘制模糊预览.
I am not good at understanding minified js, but I think it draws blurred preview for "sensitive content" on a dynamically created canvas.
这是一个帖子,以一些敏感内容(医疗)为例
Here is a post with some sensitive content (medical) as an example
更新:我注意到 b64decoded 数据总是以 00 2A 2A
开头并以 FF D9
结尾.
Update: I've noticed that b64decoded data always starts with 00 2A 2A
and ends with FF D9
.
推荐答案
我已经调试了几行代码,为你编译了这个函数.media_preview
部分数据非常小,因为在我的示例中,完整的 jpeg 标头已经在代码中可用,例如 jpegtpl
:
I've debugged a few lines of code and compiled this function for you. media_preview
part of data is so small because full jpeg header already available in code as jpegtpl
in my example:
function ig_media_preview(base64data) {
var jpegtpl = "/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEABsaGikdKUEmJkFCLy8vQkc/Pj4/R0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0cBHSkpNCY0PygoP0c/NT9HR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR//AABEIABQAKgMBIgACEQEDEQH/xAGiAAABBQEBAQEBAQAAAAAAAAAAAQIDBAUGBwgJCgsQAAIBAwMCBAMFBQQEAAABfQECAwAEEQUSITFBBhNRYQcicRQygZGhCCNCscEVUtHwJDNicoIJChYXGBkaJSYnKCkqNDU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6g4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2drh4uPk5ebn6Onq8fLz9PX29/j5+gEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoLEQACAQIEBAMEBwUEBAABAncAAQIDEQQFITEGEkFRB2FxEyIygQgUQpGhscEJIzNS8BVictEKFiQ04SXxFxgZGiYnKCkqNTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqCg4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2dri4+Tl5ufo6ery8/T19vf4+fr/2gAMAwEAAhEDEQA/AA==",
t = atob(base64data),
p = t.slice(3).split(""),
o = t.substring(0, 3).split("").map(function(e) {
return e.charCodeAt(0)
}),
c = atob(jpegtpl).split("");
c[162] = String.fromCharCode(o[1]);
c[160] = String.fromCharCode(o[2]);
return base64data ? "data:image/jpeg;base64," + btoa(c.concat(p).join("")) : null
};
var data = "ACoq5miiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKAP/Z";
var uri = ig_media_preview(data);
document.body.insertAdjacentHTML('beforeend', '<img src="' + uri + '">');
这篇关于如何从 Instagram 的 media_preview 原始数据重新创建预览?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何从 Instagram 的 media_preview 原始数据重新创建预览?
基础教程推荐
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- 直接将值设置为滑块 2022-01-01
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01
- Chart.js 在线性图表上拖动点 2022-01-01
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01