-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathyoutube.ts
43 lines (33 loc) · 940 Bytes
/
youtube.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// === START === Making Youtube.js work
import "event-target-polyfill";
import "web-streams-polyfill";
import "text-encoding-polyfill";
import "react-native-url-polyfill/auto";
import { decode, encode } from "base-64";
import { MMKV } from "react-native-mmkv";
import Innertube, { UniversalCache } from "youtubei.js";
if (!global.btoa) {
global.btoa = encode;
}
if (!global.atob) {
global.atob = decode;
}
// @ts-expect-error
global.mmkvStorage = MMKV as any;
class CustomEvent extends Event {
#detail;
constructor(type: string, options?: CustomEventInit<any[]>) {
super(type, options);
this.#detail = options?.detail ?? null;
}
get detail() {
return this.#detail;
}
}
global.CustomEvent = CustomEvent as any;
// === END === Making Youtube.js work
let innertube: Promise<Innertube> = Innertube.create({
cache: new UniversalCache(false),
generate_session_locally: true,
});
export default innertube;