decord/source/stores/ExternalStreamingStore.tsx

566 lines
18 KiB
TypeScript
Raw Normal View History

2026-08-25 06:04:03 +00:00
// Module ID: 10508
// Function ID: 10509
2026-07-29 08:29:29 +00:00
// Name: makeTwitchRequest
2026-08-25 06:04:03 +00:00
// Dependencies: [5, 5106, 4225, 676, 687, 530, 5231, 709, 8396, 5108, 659, 589, 2]
2026-07-20 16:05:17 +00:00
2026-08-25 06:04:03 +00:00
// Module 10508 (makeTwitchRequest)
2026-08-24 06:08:38 +00:00
import sendRequest from "sendRequest" /* 530 */;
import initializeDefault from "initialize" /* 589 */;
import isUndefinedOrNullDefault from "isUndefinedOrNull" /* 659 */;
import setDefault from "set" /* 687 */;
import dispatcherDefault from "dispatcher" /* 709 */;
2026-08-25 06:04:03 +00:00
import callbackDefault from "callback" /* 5231 */;
2026-08-24 06:08:38 +00:00
import closure_3 from "asyncGeneratorStep" /* 5 */;
2026-08-25 06:04:03 +00:00
import closure_4 from "set" /* 5106 */;
import closure_5 from "initialize" /* 4225 */;
2026-08-24 06:08:38 +00:00
import { PlatformTypes } from "ME" /* 676 */;
import set from "set" /* 2 */;
2026-07-23 10:11:24 +00:00
2026-08-24 06:08:38 +00:00
require = arg1;
2026-07-20 16:05:17 +00:00
function makeTwitchRequest(arg0, query) {
2026-08-24 06:08:38 +00:00
const HTTP = sendRequest.HTTP;
obj = { url: "https://api.twitch.tv/helix" + arg0, query, headers: null, rejectWithError: false };
2026-07-23 10:11:24 +00:00
obj = { "Client-ID": "33kozedd0zs6fbauka98psnc7zwom2s", Authorization: "Bearer " + arg2 };
2026-07-29 08:29:29 +00:00
obj[2] = obj;
2026-07-20 16:05:17 +00:00
return HTTP.get(obj);
}
function _getTwitchGame() {
2026-07-29 08:29:29 +00:00
const self = this;
const tmp = callback((arg0, arg1) => {
2026-08-24 06:08:38 +00:00
closure_0 = arg0;
closure_1 = arg1;
c4 = 0;
c5 = 0;
2026-07-29 08:29:29 +00:00
return (function*(arg0, body) {
2026-08-24 06:08:38 +00:00
closure_3 = tmp2;
2026-08-04 21:03:28 +00:00
let name = tmp3;
2026-08-24 06:08:38 +00:00
if (null != closure_1_14[closure_0]) {
2026-08-04 21:03:28 +00:00
return tmp27;
2026-07-29 08:29:29 +00:00
}
2026-08-04 21:03:28 +00:00
const obj2 = { id: null };
obj2[0] = tmp24;
2026-08-24 06:08:38 +00:00
yield closure_1_15("/games", obj2, tmp25);
2026-08-04 21:03:28 +00:00
const data = body.body.data;
const first = data[0];
if (first != null) {
name = first.name;
}
closure_14[closure_0] = name;
return name;
2026-07-29 08:29:29 +00:00
})();
});
2026-08-24 06:08:38 +00:00
closure_16 = tmp;
2026-07-29 08:29:29 +00:00
const apply = tmp.apply;
if (typeof apply === "unknown") {
let applyArgumentsResult = HermesBuiltin.applyArguments(self);
} else {
applyArgumentsResult = apply(self, arguments);
}
return applyArgumentsResult;
2026-07-20 16:05:17 +00:00
}
function streamerModeUpdate() {
2026-08-24 06:08:38 +00:00
if (closure_5.enabled) {
2026-07-20 16:05:17 +00:00
obj.start();
} else {
obj.stop();
}
}
2026-08-24 06:08:38 +00:00
const MINUTE = setDefault.Millis.MINUTE;
let closure_8 = 5 * setDefault.Millis.MINUTE;
2026-07-29 08:29:29 +00:00
const re9 = /live_user_(.*)-\{width\}/;
let c10 = null;
let c11 = 0;
let c12 = null;
2026-07-23 10:11:24 +00:00
let set = new Set();
2026-07-29 08:29:29 +00:00
let closure_14 = {};
class StreamingPoller {
constructor() {
obj = Object.create(new.target.prototype);
obj._started = false;
return obj;
}
}
const prototype = StreamingPoller.prototype;
prototype["start"] = function start() {
const self = this;
if (!this._started) {
self._started = true;
if (closure_4.isFetching()) {
2026-08-24 06:08:38 +00:00
const response = callbackDefault.fetch();
obj = callbackDefault;
2026-07-29 08:29:29 +00:00
} else {
self._check();
2026-07-20 16:05:17 +00:00
}
}
2026-07-29 08:29:29 +00:00
};
prototype["stop"] = function stop() {
this._started = false;
2026-08-24 06:08:38 +00:00
c12 = null;
c11 = 0;
2026-07-29 08:29:29 +00:00
if (null != this._nextCheck) {
const _clearTimeout = clearTimeout;
clearTimeout(tmp._nextCheck);
}
2026-08-24 06:08:38 +00:00
dispatcherDefault.dispatch({ type: "STREAMING_UPDATE", stream: null });
2026-07-29 08:29:29 +00:00
};
prototype["_checkTwitch"] = function _checkTwitch(accessToken, arg1) {
2026-08-24 06:08:38 +00:00
closure_0 = accessToken;
2026-07-29 08:29:29 +00:00
let tmp = arg1;
if (arg1 === undefined) {
tmp = null;
}
2026-08-24 06:08:38 +00:00
let thumbnail_url = tmp;
let game_id = this;
return title(function*() {
2026-07-29 08:29:29 +00:00
if (c8 === 2) {
c8 = 3;
HermesBuiltin.throwTypeError();
} else if (tmp6 === 3) {
if (arg0 === 1) {
throw arg1;
} else if (arg0 === 2) {
2026-08-24 06:08:38 +00:00
obj = { value: null, done: true };
2026-07-29 08:29:29 +00:00
obj[0] = arg1;
return obj;
} else {
2026-08-25 06:04:03 +00:00
return { value: "HermesInternal", done: "HermesInternal" };
2026-07-29 08:29:29 +00:00
}
} else {
try {
c8 = 2;
if (0 === c7) {
if (arg0 === 1) {
c8 = 3;
throw arg1;
} else if (arg0 === 2) {
c8 = 3;
obj = { value: null, done: true };
obj[0] = arg1;
return obj;
} else {
2026-08-24 06:08:38 +00:00
c4 = tmp3;
c3 = tmp7;
2026-07-29 08:29:29 +00:00
let accessToken;
2026-08-24 06:08:38 +00:00
c1 = undefined;
2026-07-29 08:29:29 +00:00
let name;
c3 = undefined;
c4 = undefined;
let status;
let constants;
c7 = undefined;
c8 = undefined;
2026-08-24 06:08:38 +00:00
c9 = undefined;
if (closure_1_0.revoked) {
2026-07-29 08:29:29 +00:00
c8 = 3;
return { value: null, done: true };
} else {
2026-08-24 06:08:38 +00:00
accessToken = callback;
if (callback == null) {
accessToken = closure_1_0.accessToken;
2026-07-29 08:29:29 +00:00
}
2026-08-24 06:08:38 +00:00
callback = accessToken;
2026-07-29 08:29:29 +00:00
if (null == accessToken) {
c8 = 3;
return { value: null, done: true };
} else {
constants = 1;
2026-08-24 06:08:38 +00:00
obj1 = { user_id: null, first: 1 };
obj1[0] = closure_1_0.id;
2026-07-29 08:29:29 +00:00
c7 = 2;
c8 = 1;
const obj2 = { value: null, done: false };
2026-08-24 06:08:38 +00:00
obj2[0] = closure_1_15("/streams", obj1, callback);
2026-07-29 08:29:29 +00:00
return obj2;
}
}
}
} else if (1 === tmp7) {
constants = 0;
let catchPromise = null;
if (401 === status.status) {
catchPromise = null;
if (null == thumbnail_url) {
2026-08-24 06:08:38 +00:00
let obj8 = callback(closure_1_2[6]);
2026-07-29 08:29:29 +00:00
const refreshAccessTokenResult = obj8.refreshAccessToken(accessToken.type, accessToken.id);
catchPromise = obj8.refreshAccessToken(accessToken.type, accessToken.id).then((arg0) => name._checkTwitch(accessToken, arg0)).catch(() => null);
const nextPromise = obj8.refreshAccessToken(accessToken.type, accessToken.id).then((arg0) => name._checkTwitch(accessToken, arg0));
}
}
c8 = 3;
const obj3 = { value: null, done: true };
obj3[0] = catchPromise;
return obj3;
} else if (2 === tmp7) {
if (arg0 === 1) {
c8 = 3;
throw arg1;
} else if (arg0 === 2) {
constants = 0;
c8 = 3;
let obj4 = { value: null, done: true };
obj4[0] = arg1;
return obj4;
} else {
2026-08-24 06:08:38 +00:00
closure_0 = arg1.body.data[0];
2026-07-29 08:29:29 +00:00
if (null != closure_0) {
if ("live" === closure_0.type) {
thumbnail_url = closure_0.thumbnail_url;
2026-08-24 06:08:38 +00:00
game_id = closure_0.game_id;
title = closure_0.title;
2026-07-29 08:29:29 +00:00
let tmp42;
if (null != thumbnail_url) {
2026-08-24 06:08:38 +00:00
obj4 = closure_1_0(closure_1_2[8]);
2026-07-29 08:29:29 +00:00
const assetFromImageURL = obj4.getAssetFromImageURL(constants.TWITCH, thumbnail_url);
c1 = assetFromImageURL;
if (assetFromImageURL == null) {
c1 = undefined;
}
tmp42 = c1;
}
2026-08-24 06:08:38 +00:00
obj5 = { large_image: null };
2026-07-29 08:29:29 +00:00
obj5[0] = tmp42;
c7 = 3;
c8 = 1;
const obj6 = { value: null, done: false };
2026-08-24 06:08:38 +00:00
obj6[0] = (function getTwitchGame(game_id, closure_1) {
const self = this;
2026-07-29 08:29:29 +00:00
const apply = closure_16.apply;
if (typeof apply === "unknown") {
let applyArgumentsResult = HermesBuiltin.applyArguments(self);
} else {
applyArgumentsResult = apply(self, arguments);
}
return applyArgumentsResult;
2026-08-24 06:08:38 +00:00
})(game_id, callback);
2026-07-29 08:29:29 +00:00
return obj6;
}
}
const _Error = Error;
2026-08-24 06:08:38 +00:00
error = new Error("no stream");
2026-07-29 08:29:29 +00:00
throw error;
}
} else if (arg0 === 1) {
c8 = 3;
throw arg1;
} else if (arg0 === 2) {
constants = 0;
c8 = 3;
const obj7 = { value: null, done: true };
obj7[0] = arg1;
return obj7;
} else {
status = arg1;
2026-08-24 06:08:38 +00:00
constants = callback(closure_1_2[9]).get(constants.TWITCH);
2026-07-29 08:29:29 +00:00
const tmp84 = (function parseUsernameFromThumbnail(c1) {
const match = _undefined.exec(c1);
let tmp2;
if (match != null) {
tmp2 = match[1];
}
return tmp2;
})(c1);
name = tmp84;
if (tmp84 == null) {
name = closure_0.name;
}
2026-08-24 06:08:38 +00:00
closure_7 = name;
substr = undefined;
if (null != title) {
if ("" !== title) {
substr = title.slice(0, 128);
2026-07-29 08:29:29 +00:00
}
}
2026-08-24 06:08:38 +00:00
substr1 = undefined;
if (null != closure_2_5) {
if ("" !== closure_2_5) {
substr1 = closure_2_5.slice(0, 128);
2026-07-29 08:29:29 +00:00
}
}
2026-08-24 06:08:38 +00:00
const getPlatformUserUrl = closure_2_6.getPlatformUserUrl;
2026-07-29 08:29:29 +00:00
let platformUserUrl;
if (getPlatformUserUrl != null) {
obj = { id: null, name: null };
obj[0] = accessToken.id;
obj[1] = c7;
platformUserUrl = getPlatformUserUrl(obj);
}
obj8 = { url: null, name: null, assets: null, details: null, state: null };
obj8[0] = platformUserUrl;
2026-08-24 06:08:38 +00:00
obj8[1] = closure_2_6.name;
obj8[2] = obj5;
obj8[3] = substr;
obj8[4] = substr1;
2026-07-29 08:29:29 +00:00
constants = 0;
c8 = 3;
const obj9 = { value: null, done: true };
obj9[0] = obj8;
return obj9;
}
} catch (tmp68) {
status = tmp68;
if (tmp4 === constants) {
c8 = tmp2;
throw tmp68;
2026-07-20 16:05:17 +00:00
} else {
2026-07-29 08:29:29 +00:00
c7 = tmp;
2026-07-20 16:05:17 +00:00
}
}
}
2026-07-29 08:29:29 +00:00
})();
};
prototype["_checkYouTube"] = function _checkYouTube(c0, arg1) {
2026-08-24 06:08:38 +00:00
closure_0 = c0;
2026-07-29 08:29:29 +00:00
let tmp = arg1;
if (arg1 === undefined) {
tmp = null;
}
2026-08-24 06:08:38 +00:00
c1 = tmp;
2026-07-29 08:29:29 +00:00
const self = this;
return callback(function*() {
if (constants === 2) {
constants = 3;
HermesBuiltin.throwTypeError();
} else if (tmp6 === 3) {
if (arg0 === 1) {
throw arg1;
} else if (arg0 === 2) {
2026-08-24 06:08:38 +00:00
obj = { value: null, done: true };
2026-07-29 08:29:29 +00:00
obj[0] = arg1;
return obj;
} else {
2026-08-25 06:04:03 +00:00
return { value: "HermesInternal", done: "HermesInternal" };
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
} else {
try {
constants = 2;
if (0 === thumbnails) {
if (arg0 === 1) {
constants = 3;
throw arg1;
} else if (arg0 === 2) {
constants = 3;
obj = { value: null, done: true };
obj[0] = arg1;
return obj;
} else {
let id = tmp3;
2026-08-24 06:08:38 +00:00
closure_1 = tmp7;
2026-07-29 08:29:29 +00:00
let length;
closure_1 = undefined;
id = undefined;
let snippet;
let arr;
thumbnails = undefined;
constants = undefined;
let substr;
2026-08-24 06:08:38 +00:00
closure_8 = undefined;
let obj4 = null;
if (!closure_1_0.revoked) {
if (!closure_1_13.has(closure_1_0.id)) {
2026-07-29 08:29:29 +00:00
arr = 1;
2026-08-24 06:08:38 +00:00
const HTTP = closure_1_0(closure_1_2[5]).HTTP;
2026-07-29 08:29:29 +00:00
let get = HTTP.get;
2026-08-24 06:08:38 +00:00
obj1 = { url: "https://www.googleapis.com/youtube/v3/liveBroadcasts", query: null, headers: null, oldFormErrors: true, rejectWithError: false };
2026-07-29 08:29:29 +00:00
obj1[1] = { part: "id,snippet", broadcastStatus: "active", broadcastType: "all" };
2026-08-24 06:08:38 +00:00
if (null != closure_1_1) {
let accessToken = closure_1_1;
2026-07-29 08:29:29 +00:00
} else {
2026-08-24 06:08:38 +00:00
accessToken = closure_1_0.accessToken;
2026-07-29 08:29:29 +00:00
}
let obj2 = { Authorization: null };
const _HermesInternal2 = HermesInternal;
obj2[0] = "Bearer " + accessToken;
obj1[2] = obj2;
get = get(obj1);
thumbnails = 2;
constants = 1;
}
}
constants = 3;
return { value: null, done: true };
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
} else if (1 === tmp7) {
arr = 0;
2026-08-24 06:08:38 +00:00
closure_9 = snippet;
if (401 !== closure_9.status) {
if (403 === closure_9.status) {
closure_1_13.add(closure_1_0.id);
2026-07-29 08:29:29 +00:00
}
constants = 3;
2026-07-20 16:05:17 +00:00
}
2026-08-24 06:08:38 +00:00
let obj5 = closure_1_1(closure_1_2[6]);
const refreshAccessTokenResult = obj5.refreshAccessToken(closure_1_0.type, closure_1_0.id);
obj5.refreshAccessToken(closure_1_0.type, closure_1_0.id).then((arg0) => id._checkYouTube(c0, arg0)).catch(() => null);
const nextPromise = obj5.refreshAccessToken(closure_1_0.type, closure_1_0.id).then((arg0) => id._checkYouTube(c0, arg0));
2026-07-29 08:29:29 +00:00
} else if (arg0 === 1) {
constants = 3;
throw arg1;
} else if (arg0 === 2) {
arr = 0;
constants = 3;
const obj3 = { value: null, done: true };
obj3[0] = arg1;
return obj3;
} else {
length = arg1.body.items;
if (length.length < 1) {
const _Error = Error;
2026-08-24 06:08:38 +00:00
error = new Error("no stream");
2026-07-29 08:29:29 +00:00
throw error;
} else {
closure_1 = length[0];
id = closure_1.id;
snippet = closure_1.snippet;
arr = snippet.title;
thumbnails = snippet.thumbnails;
2026-08-24 06:08:38 +00:00
const assetFromImageURL = closure_1_0(closure_1_2[8]).getAssetFromImageURL(constants.YOUTUBE, thumbnails.high.url);
2026-07-29 08:29:29 +00:00
length = assetFromImageURL;
if (assetFromImageURL == null) {
length = undefined;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
obj = { large_image: null };
obj[0] = length;
constants = obj;
substr = undefined;
if (null != arr) {
if ("" !== arr) {
substr = arr.slice(0, 128);
2026-07-20 16:05:17 +00:00
}
}
2026-08-24 06:08:38 +00:00
obj4 = { url: null, name: null, details: null, assets: null };
2026-07-29 08:29:29 +00:00
closure_8 = id;
const _HermesInternal = HermesInternal;
obj4[0] = "https://youtube.com/watch?v=" + closure_8;
2026-08-24 06:08:38 +00:00
obj2 = closure_1_1(closure_1_2[9]);
2026-07-29 08:29:29 +00:00
obj4[1] = obj2.get(constants.YOUTUBE).name;
obj4[2] = substr;
obj4[3] = constants;
arr = 0;
constants = 3;
obj5 = { value: null, done: true };
obj5[0] = obj4;
return obj5;
}
}
} catch (tmp50) {
snippet = tmp50;
if (tmp4 === arr) {
constants = tmp2;
throw tmp50;
} else {
thumbnails = tmp;
2026-07-20 16:05:17 +00:00
}
}
}
2026-07-29 08:29:29 +00:00
})();
};
prototype["_check"] = function _check() {
let self = this;
self = this;
if (this._started) {
const accounts = closure_4.getAccounts();
if (null != accounts) {
if (null != self._nextCheck) {
const _clearTimeout = clearTimeout;
clearTimeout(self._nextCheck);
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
const items = [PlatformTypes.TWITCH];
const _Date = Date;
const timestamp = Date.now();
if (closure_11 <= timestamp) {
items.push(tmp5.YOUTUBE);
closure_11 = timestamp + closure_8;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
const found = accounts.filter((type) => items.includes(type.type));
Promise.allSettled(found.map((type) => {
2026-08-24 06:08:38 +00:00
if (type.type === closure_1_6.TWITCH) {
2026-07-29 08:29:29 +00:00
let _checkTwitchResult = self._checkTwitch(type);
} else {
_checkTwitchResult = self._checkYouTube(type);
}
return _checkTwitchResult;
})).then((arr) => {
2026-08-24 06:08:38 +00:00
obj = self;
2026-07-29 08:29:29 +00:00
if (self._started) {
const iter = arr.find((status) => {
let tmp = "fulfilled" === status.status;
if (tmp) {
tmp = null != status.value;
}
return tmp;
});
let value;
if (iter != null) {
value = iter.value;
}
let tmp4 = null == value;
if (tmp4) {
2026-08-24 06:08:38 +00:00
tmp4 = null != closure_1_12;
2026-07-29 08:29:29 +00:00
}
if (tmp4) {
2026-08-24 06:08:38 +00:00
value = closure_1_12;
2026-07-29 08:29:29 +00:00
}
obj = { type: "STREAMING_UPDATE", stream: null };
obj[1] = value;
2026-08-24 06:08:38 +00:00
self(closure_1_2[7]).dispatch(obj);
const obj2 = self(closure_1_2[7]);
2026-07-29 08:29:29 +00:00
}
obj._scheduleCheck();
});
const allSettledResult = Promise.allSettled(found.map((type) => {
2026-08-24 06:08:38 +00:00
if (type.type === closure_1_6.TWITCH) {
2026-07-29 08:29:29 +00:00
let _checkTwitchResult = self._checkTwitch(type);
} else {
_checkTwitchResult = self._checkYouTube(type);
}
return _checkTwitchResult;
}));
tmp5 = PlatformTypes;
2026-07-20 16:05:17 +00:00
}
}
2026-07-29 08:29:29 +00:00
};
prototype["_scheduleCheck"] = function _scheduleCheck() {
const self = this;
if (this._started) {
const _setTimeout = setTimeout;
tmp._nextCheck = setTimeout(() => self._check(), MINUTE);
}
};
let obj = Object.create(StreamingPoller.prototype);
obj._started = false;
2026-08-24 06:08:38 +00:00
const Store = initializeDefault.Store;
2026-07-29 08:29:29 +00:00
class ExternalStreamingStore extends Store {
}
const prototype2 = ExternalStreamingStore.prototype;
prototype2["initialize"] = function initialize() {
2026-08-24 06:08:38 +00:00
if (closure_5.enabled) {
2026-07-29 08:29:29 +00:00
obj.start();
}
2026-08-24 06:08:38 +00:00
this.waitFor(closure_4, closure_5);
const items = [closure_5];
2026-07-29 08:29:29 +00:00
this.syncWith(items, streamerModeUpdate);
};
prototype2["getStream"] = function getStream() {
return c10;
};
ExternalStreamingStore.displayName = "ExternalStreamingStore";
obj = {
2026-07-20 16:05:17 +00:00
STREAMING_UPDATE: function streamUpdate(stream) {
2026-08-24 06:08:38 +00:00
if (isUndefinedOrNullDefault(stream.stream, stream)) {
2026-07-20 16:05:17 +00:00
return false;
} else {
stream = stream.stream;
2026-07-29 08:29:29 +00:00
if (stream == null) {
stream = null;
2026-07-20 16:05:17 +00:00
}
}
},
USER_CONNECTIONS_UPDATE() {
2026-07-29 08:29:29 +00:00
return obj._check();
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
};
2026-08-24 06:08:38 +00:00
const externalStreamingStore = new ExternalStreamingStore(dispatcherDefault, obj);
2026-07-29 08:29:29 +00:00
const result = set.fileFinishedImporting("stores/ExternalStreamingStore.tsx");
2026-07-20 16:05:17 +00:00
2026-07-29 08:29:29 +00:00
export default externalStreamingStore;