From 3ed08baa80b1d627d6f52336dc0fc37f774ef294 Mon Sep 17 00:00:00 2001 From: Korbs Date: Sat, 22 Jun 2024 16:51:15 -0400 Subject: [PATCH] Add support for Twtich --- src/pages/live.astro | 35 +++++++++ src/pages/search.astro | 175 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 210 insertions(+) create mode 100644 src/pages/live.astro create mode 100644 src/pages/search.astro diff --git a/src/pages/live.astro b/src/pages/live.astro new file mode 100644 index 0000000..76ecb9f --- /dev/null +++ b/src/pages/live.astro @@ -0,0 +1,35 @@ +--- +// Layout +import Base from "@layouts/Default.astro"; + +// Environment Variables +const DEFAULT_SAFETWITCH_BACKEND = import.meta.env.DEFAULT_SAFETWITCH_BACKEND + +// Components + +// Fetch +const Channel = Astro.url.href.split("live?=").pop(); +const video = await fetch('https://' + DEFAULT_SAFETWITCH_BACKEND + "/api/v1/videos/" + Channel).then((response) => response.json()); +const comments = await fetch('https://' + DEFAULT_SAFETWITCH_BACKEND + "/api/v1/comments/" + Channel).then((response) => response.json()); +--- + + + +
+ + +
+ + + + + + \ No newline at end of file diff --git a/src/pages/search.astro b/src/pages/search.astro new file mode 100644 index 0000000..ebd5653 --- /dev/null +++ b/src/pages/search.astro @@ -0,0 +1,175 @@ +--- +// Layout +import Base from '@layouts/Default.astro' + +// Components +import Video from '@components/common/VideoItem.astro' + +// Environment Variables +const DEFAULT_INVIDIOUS_INSTANCE = import.meta.env.DEFAULT_INVIDIOUS_INSTANCE +const DEFAULT_SAFETWITCH_BACKEND = import.meta.env.DEFAULT_SAFETWITCH_BACKEND + +// Fetch +const Query = Astro.url.href.split("search?q=").pop() +const InvidiousResponse = await fetch('https://' + DEFAULT_INVIDIOUS_INSTANCE + "/api/v1/search?q=" + Query) +.catch((error) => { + console.log(error) +}) + +const TwitchResponse = await fetch('https://' + DEFAULT_SAFETWITCH_BACKEND + "/api/search/?query=" + Query) +.catch((error) => { + console.log(error) +}) + +const InvidiousData = await InvidiousResponse.json() +const TwitchData = await TwitchResponse.json() +--- + + +
+

Search

+
+

Twitch Channels related to "{Query}"

+
+ {TwitchData.data.channels.map((channel) => + + +
+ +
+

{channel.username}

+

{channel.about}

+
+
+
+ )} +
+

Twitch Live streams with the tag "{Query}"

+
+ {TwitchData.data.relatedChannels.map((channel) => + + +
+ +
+

{channel.username}

+

{channel.about}

+
+
+
+ )} +
+

YouTube Videos

+
+ {InvidiousData.map((data) => +
+ + + + + + \ No newline at end of file