aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwabilin <[email protected]>2020-09-05 14:22:39 +0900
committerwabilin <[email protected]>2020-09-05 14:22:39 +0900
commitbad0eabe7d0d26002c76d31e537d5f234a8176fa (patch)
treea7edca387b793b1b073446db73460ab67fa3b989
parentv0.2.6 (diff)
downloadholo-schedule-bad0eabe7d0d26002c76d31e537d5f234a8176fa.tar.xz
holo-schedule-bad0eabe7d0d26002c76d31e537d5f234a8176fa.zip
add streaming and videoId
-rw-r--r--src/parseScheduleHtml.ts14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/parseScheduleHtml.ts b/src/parseScheduleHtml.ts
index 27f1347..728991b 100644
--- a/src/parseScheduleHtml.ts
+++ b/src/parseScheduleHtml.ts
@@ -31,6 +31,7 @@ interface LiveBlock {
avatarImages: string[]
livePreviewImage: string
link: string
+ streaming: boolean
}
function parseToLiveBlocks(html: string | Buffer): LiveBlock[] {
@@ -54,6 +55,7 @@ function parseToLiveBlocks(html: string | Buffer): LiveBlock[] {
const allThumbnail: NodeListOf<HTMLAnchorElement> = row.querySelectorAll('a.thumbnail')
allThumbnail.forEach(thumbnail => {
const link = thumbnail.href
+ const streaming = thumbnail.style.borderColor === 'red'
const { time, name, avatarImages, livePreviewImage } = dataFromAThumbnail(thumbnail)
lives.push({
@@ -62,6 +64,7 @@ function parseToLiveBlocks(html: string | Buffer): LiveBlock[] {
livePreviewImage,
time: new Date(`${year}-${date}T${time}:00+09:00`),
streamer: name,
+ streaming,
})
})
})
@@ -93,9 +96,11 @@ function reverseDict(dict: StreamerImageDict): ImageStreamerDict {
export interface LiveInfo {
time: Date
link: string
+ videoId: string
streamer: string
livePreviewImage: string
guests: string[]
+ streaming: boolean
}
interface ParseResult {
@@ -103,6 +108,10 @@ interface ParseResult {
dict: StreamerImageDict
}
+function getVideoId(link: string): string {
+ return link.replace('https://www.youtube.com/watch?v=', '')
+}
+
/**
* @param html - Html of https://schedule.hololive.tv. Get with Japan timezone (GTM+9)
* @param storedDict - An object stored { vtuberName: iconImageSrc }
@@ -118,16 +127,19 @@ function parseScheduleHtml(
const dict = reverseDict(streamerImageDict)
const lives = liveBlocks.map(liveBlocks => {
- const { streamer, avatarImages, time, link, livePreviewImage } = liveBlocks
+ const { streamer, avatarImages, time, link, livePreviewImage, streaming } = liveBlocks
const guests = avatarImages.splice(1).map(x => dict[x]).filter(Boolean)
+ const videoId = getVideoId(link)
return {
time,
streamer,
guests,
link,
+ videoId,
livePreviewImage,
+ streaming,
}
})