blob: 8177eee0a3fc50ddac828c87fd8796f1263acd28 (
plain) (
blame)
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
|
import { JSDOM } from "jsdom";
import { mapNodeList } from "./util";
function selectTrimTextContent(ele: Element, selector: string): string {
return ele.querySelector(selector)?.textContent?.replace(/\s+/g, "") || "";
}
function dataFromAThumbnail(thumb: Element) {
const time = selectTrimTextContent(thumb, ".datetime")
const name = selectTrimTextContent(thumb, ".name")
const images = mapNodeList(
thumb.querySelectorAll("img"),
(img) => img.src
)
.filter((src) => src.startsWith("https://yt3.ggpht.com"));
return {
time,
name,
images,
};
}
function parseScheduleHtml(html: string | Buffer) {
const { window } = new JSDOM(html);
const { document } = window;
const allThumbnail = document.querySelectorAll("a.thumbnail");
const data = mapNodeList(allThumbnail, dataFromAThumbnail);
console.log(data);
return "";
}
export default parseScheduleHtml;
|