-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
68 lines (56 loc) · 1.31 KB
/
main.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
import { parse } from "jsr:@std/csv";
const decoder = new TextDecoder("utf-8");
const a = await Deno.readFile("data/2024.csv").then((data) =>
decoder.decode(data)
);
const data = parse(a, { skipFirstRow: true, strip: true });
const w2024 = data.map((a) => {
return ({
title: a["動画タイトル"],
url: a["動画URL"],
count: parseInt(a["票数"].slice(0, -1), 10),
type: estimateType(a["動画URL"]),
});
});
await Deno.writeFile(
"pages/data.json",
new TextEncoder().encode(JSON.stringify({
2024: w2024,
})),
);
function estimateType(
vurl: string,
):
| "nicovideo"
| "nicovideo-live"
| "youtube"
| "twitter"
| "bilibili"
| "soundcloud"
| "linevoom"
| "unknown" {
if (vurl === null) return "unknown";
switch (new URL(vurl).host) {
case "www.nicovideo.jp":
return "nicovideo";
case "live.nicovideo.jp":
return "nicovideo-live";
case "www.youtube.com":
case "m.youtube.com":
case "youtu.be":
return "youtube";
case "twitter.com":
case "www.twitter.com":
case "x.com":
return "twitter";
case "bilibili.com":
case "www.bilibili.com":
return "bilibili";
case "soundcloud.com":
return "soundcloud";
case "linevoom.line.me":
return "linevoom";
default:
return "unknown";
}
}