-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
1,606 additions
and
983 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { Credentials, buildAuthHeaders } from "./auth"; | ||
import { DEFAULT_HEADERS, DEFAULT_ORIGIN } from "./constants"; | ||
import fetch from "cross-fetch"; | ||
import { LiveChatContext, Metadata } from "./services/context/exports"; | ||
import { ReloadContinuationItems } from "./services/chat/exports"; | ||
import { debugLog } from "./util"; | ||
|
||
export class Base { | ||
public videoId!: string; | ||
protected apiKey!: string; | ||
protected credentials?: Credentials; | ||
|
||
public metadata!: Metadata; | ||
public continuation!: ReloadContinuationItems; | ||
protected isReplay!: boolean; | ||
protected liveChatContext?: LiveChatContext; | ||
|
||
protected get(input: string, init?: RequestInit) { | ||
if (!input.startsWith("http")) { | ||
input = DEFAULT_ORIGIN + input; | ||
} | ||
const parsedUrl = new URL(input); | ||
|
||
if (!parsedUrl.searchParams.has("key")) { | ||
parsedUrl.searchParams.append("key", this.apiKey); | ||
} | ||
|
||
const authHeaders = buildAuthHeaders(this.credentials); | ||
const headers = { | ||
...DEFAULT_HEADERS, | ||
...authHeaders, | ||
...init?.headers, | ||
}; | ||
|
||
debugLog("GET", parsedUrl.toString()); | ||
|
||
return fetch(parsedUrl.toString(), { | ||
...init, | ||
headers, | ||
}); | ||
} | ||
|
||
protected post(input: string, init?: RequestInit) { | ||
if (!input.startsWith("http")) { | ||
input = DEFAULT_ORIGIN + input; | ||
} | ||
const parsedUrl = new URL(input); | ||
|
||
if (!parsedUrl.searchParams.has("key")) { | ||
parsedUrl.searchParams.append("key", this.apiKey); | ||
} | ||
|
||
const authHeaders = buildAuthHeaders(this.credentials); | ||
const headers = { | ||
...DEFAULT_HEADERS, | ||
...authHeaders, | ||
...init?.headers, | ||
"Content-Type": "application/json", | ||
}; | ||
|
||
debugLog("POST", parsedUrl.toString(), init?.body); | ||
|
||
return fetch(parsedUrl.toString(), { | ||
...init, | ||
method: "POST", | ||
headers, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export const DEFAULT_ORIGIN = "https://www.youtube.com"; | ||
|
||
export const DEFAULT_HEADERS = { | ||
"Accept-Language": "en", | ||
"User-Agent": | ||
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36", | ||
}; | ||
|
||
export const DEFAULT_CLIENT = { | ||
clientName: "WEB", | ||
// clientVersion: "2.20210618.05.00-canary_control", | ||
clientVersion: "2.20210813.00.00", | ||
}; | ||
|
||
export const DEFAULT_API_KEY = "AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8"; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.