-
Notifications
You must be signed in to change notification settings - Fork 0
/
video.ts
75 lines (68 loc) · 1.73 KB
/
video.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { ImageResponse } from "@vercel/og";
import { promises as fs } from "fs";
import { TwitterOpenApi } from "twitter-openapi-typescript";
import { RenderOceanBlueColor } from "../src/render/color/color";
import { getFont } from "./utils";
const tweetIdList = [
"1722118869178081318",
"1770496837046415364",
"1684781634049163264",
"1700878617528713271",
];
const res = tweetIdList.map(async (tweetId) => {
const { segoeui400i, segoeui400, segoeui700i, segoeui700 } = await getFont();
const client = await new TwitterOpenApi().getGuestClient();
const api = client.getDefaultApi();
const tweet = await api.getTweetResultByRestId({
tweetId: tweetId,
});
const render = new RenderOceanBlueColor({
width: 600,
video: true,
});
const element = render.imageRender({
data: tweet.data!,
});
const img = new ImageResponse(element, {
width: 600,
height: undefined,
fonts: [
{
data: segoeui400i,
name: "segoeui",
weight: 500,
style: "italic",
},
{
data: segoeui400,
name: "segoeui",
weight: 500,
style: "normal",
},
{
data: segoeui700i,
name: "segoeui",
weight: 700,
style: "italic",
},
{
data: segoeui700,
name: "segoeui",
weight: 700,
style: "normal",
},
],
});
const png = Buffer.from(await img.arrayBuffer());
await fs.writeFile(`temp/${tweetId}.png`, png);
const res = await render.videoRender!({
data: tweet.data!,
image: `temp/${tweetId}.png`,
output: `temp/${tweetId}.mp4`,
});
const removed = res.temp.map((e) => fs.unlink(e));
await Promise.all(removed);
});
(async () => {
await Promise.all(res);
})();