-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
136 lines (110 loc) · 2.62 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import { DOMParser } from "jsr:@b-fuze/deno-dom";
const years = [
2008,
2009,
2010,
2011,
2012,
2013,
2014,
2015,
2016,
2017,
2018,
2019,
2020,
2021,
2022,
2023,
2024,
];
const dat: Record<
number,
{
count: number;
url: string | null;
title: string;
type: ReturnType<typeof estimateType>;
}[]
> = {};
for (const year of years) {
const url = `http://oto10.s602.xrea.com/10sen/${year}-r.html`;
const t = await fetch(url).then((b) => b.text());
const a = new DOMParser().parseFromString(t, "text/html")!;
const dds = a.querySelectorAll("tr");
const recs: (typeof dat)[number] = [];
for (const dd of dds) {
const tds = dd.querySelectorAll("td");
const z0 = tds[0].textContent.trim();
if (!/^\d+$/.test(z0)) continue;
const href =
(tds[1].querySelector("a")?.attributes.getNamedItem("href")?.value
.trim()) ||
null;
const vurl = normalizeVUrl(href);
recs.push({
count: parseInt(z0, 10),
url: vurl,
title: tds[2].textContent.trim(),
type: estimateType(vurl),
});
}
dat[year] = recs;
}
function normalizeVUrl(vurl: string | null): string | null {
if (vurl === null) return null;
// 2011年『膳(Big_blue) 』
if (vurl === "http://www.nicovideo.jp/tag/Big_blue") {
return "https://www.nicovideo.jp/watch/sm13274282";
}
// 2010年『ヤマザキ春のTimepiece pan まIIり』
if (vurl === "http://www.nicovideo.jp/watch/1270563585") {
return "https://www.nicovideo.jp/watch/sm27116924";
}
// 2010年『アレミミズ』(詳細不明)
if (vurl === "http://www.nicovideo.jp/watch/1286180411") return null;
if (/^sm\d+$/.test(vurl)) {
return `https://www.nicovideo.jp/watch/${vurl}`;
}
return vurl;
}
function estimateType(
vurl: string | null,
):
| "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";
}
}
await Deno.writeFile(
"pages/data.json",
new TextEncoder().encode(JSON.stringify(dat)),
);