Skip to content

Commit 3836aca

Browse files
committed
feat(bot): optional proxy for innertube
1 parent d9b1ead commit 3836aca

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ DISCORD_DEV_TOKEN='YOUR_DISCORD_DEV_TOKEN'
88

99
# YouTube API Key
1010
YOUTUBE_API_KEY='YOUR_YOUTUBE_API_KEY'
11+
YOUTUBE_INNERTUBE_PROXY_URL='YOUR_OPTIONAL_YOUTUBE_INNERTUBE_PROXY_URL'
1112

1213
# Twitch
1314
TWITCH_CLIENT_ID='YOUR_TWITCH_CLIENT_ID'

src/config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// FILL IN THIS INFORMATION IN .ENV
22
export const runningInDevMode: boolean = process.argv.includes("--dev");
33
export interface Config {
4+
youtubeInnertubeProxyUrl: string | null;
45
updateIntervalYouTube: number;
56
updateIntervalTwitch: number;
67
databaseUrl: string | undefined;
@@ -10,6 +11,7 @@ export interface Config {
1011
}
1112

1213
export const config: Config = {
14+
youtubeInnertubeProxyUrl: process.env?.YOUTUBE_INNERTUBE_PROXY_URL ?? null,
1315
updateIntervalYouTube: process.env?.CONFIG_UPDATE_INTERVAL_YOUTUBE
1416
? parseInt(process.env?.CONFIG_UPDATE_INTERVAL_YOUTUBE) * 1000
1517
: 60_000,

src/utils/youtube/search.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1+
import { config } from "../../config";
12
import type { InnertubeSearchRequest } from "../../types/youtube";
23

34
import formatLargeNumber from "../formatLargeNumber";
45

56
export default async function (query: string) {
67
try {
8+
// This will NOT work without Bun due to proxy not being in NodeJS
9+
// Unfortunately theres no type for this that will make Typescript happy so this is a TODO: thing
710
const response = await fetch(
811
"https://www.youtube.com/youtubei/v1/search?prettyPrint=false",
912
{
13+
proxy: config.youtubeInnertubeProxyUrl,
1014
headers: {
1115
"X-Goog-Fieldmask":
1216
"contents.twoColumnSearchResultsRenderer.primaryContents.sectionListRenderer.contents.itemSectionRenderer.contents",
@@ -22,7 +26,7 @@ export default async function (query: string) {
2226
query: query,
2327
}),
2428
method: "POST",
25-
},
29+
} as any,
2630
);
2731

2832
const data = (

0 commit comments

Comments
 (0)