From 7a306e433e343818e259eaf757e5c63af3d1c93b Mon Sep 17 00:00:00 2001 From: Fuwn Date: Sat, 17 Feb 2024 16:32:59 -0800 Subject: refactor(hololive): move lives to component --- src/lib/Hololive/Lives.svelte | 167 ++++++++++++++++++++++++++++++++++++++++++ src/lib/Hololive/hololive.ts | 12 +++ 2 files changed, 179 insertions(+) create mode 100644 src/lib/Hololive/Lives.svelte create mode 100644 src/lib/Hololive/hololive.ts (limited to 'src/lib/Hololive') diff --git a/src/lib/Hololive/Lives.svelte b/src/lib/Hololive/Lives.svelte new file mode 100644 index 00000000..9c5b6b04 --- /dev/null +++ b/src/lib/Hololive/Lives.svelte @@ -0,0 +1,167 @@ + + +{#if schedule.lives.length === 0} + +{/if} + +
+ {#each schedule.lives + .filter((live) => { + try { + $locale().hololive.dateFormatter(new Date(live.time)); + + return true; + } catch { + return false; + } + }) + .sort((a, b) => { + const now = Date.now(); + const aTime = new Date(a.time).getTime(); + const bTime = new Date(b.time).getTime(); + const aIsLive = a.streaming; + const bIsLive = b.streaming; + const aIsClosestPinned = closestUpcomingPinnedStreams.get(a.streamer) === a; + const bIsClosestPinned = closestUpcomingPinnedStreams.get(b.streamer) === b; + + if (aIsLive && pinnedStreams.includes(a.streamer)) return -1; + if (bIsLive && pinnedStreams.includes(b.streamer)) return 1; + + if (aIsLive && !bIsLive) return -1; + if (bIsLive && !aIsLive) return 1; + + if (aIsClosestPinned && !bIsClosestPinned) return -1; + if (bIsClosestPinned && !aIsClosestPinned) return 1; + + if (aTime > now && !(aTime < now && !aIsLive)) return -1; + if (bTime > now && !(bTime < now && !bIsLive)) return 1; + + return bTime - aTime; + }) as live} +
+ {#if $identity.id !== -2} + + {/if} + +

+ [{#if live.streaming} + {$locale().hololive.live}{:else if new Date(live.time).getTime() < Date.now()} + {$locale().hololive.ended}{:else} + {$locale().hololive.upcoming}{/if}] + {live.streamer} | + {$locale().hololive.dateFormatter(new Date(live.time))} + {#if live.guests.length > 0} +
+ + {$locale().hololive.with}{live.guests + .join($locale().hololive.comma) + .replace( + new RegExp( + `${$locale().hololive.comma}([^${$locale().hololive.commaNoSpace}]+)$`, + 'g' + ), + `${$locale().hololive.comma}${$locale().hololive.ampersand}$1` + )} + + {/if} +

+ + + Stream Thumbnail + +
+ {/each} +
+ + diff --git a/src/lib/Hololive/hololive.ts b/src/lib/Hololive/hololive.ts new file mode 100644 index 00000000..4ba7e46e --- /dev/null +++ b/src/lib/Hololive/hololive.ts @@ -0,0 +1,12 @@ +export interface ParseResult { + lives: { + time: Date; + link: string; + videoId: string; + streamer: string; + livePreviewImage: string; + guests: string[]; + streaming: boolean; + }[]; + dict: Record; +} -- cgit v1.2.3