decord/source/modules/spotify/SpotifyUtils.tsx

254 lines
8.6 KiB
TypeScript
Raw Normal View History

2026-08-24 06:08:38 +00:00
// Module ID: 10953
// Function ID: 10954
2026-07-29 08:29:29 +00:00
// Name: asString
2026-08-24 06:08:38 +00:00
// Dependencies: [5, 4508, 7282, 7279, 7280, 676, 687, 5102, 7281, 10954, 2]
2026-07-20 16:05:17 +00:00
// Exports: ensureSpotifyPlayable, ensureSpotifyPremium, getSpotifyMetadataFromActivity, isSpotifyPlayable, isSpotifyPremium
2026-08-24 06:08:38 +00:00
// Module 10953 (asString)
import setDefault from "set" /* 687 */;
import closure_3 from "asyncGeneratorStep" /* 5 */;
import closure_4 from "initialize" /* 4508 */;
import closure_5 from "isProtocolRegistered" /* 7282 */;
import closure_6 from "upsertAccount" /* 7279 */;
import SPOTIFY_APP_PROTOCOL from "SPOTIFY_APP_PROTOCOL" /* 7280 */;
import { PlatformTypes } from "ME" /* 676 */;
2026-07-23 10:11:24 +00:00
const require = arg1;
2026-08-04 21:03:28 +00:00
function asString(str) {
if (typeof str === "string") {
return str;
2026-07-20 16:05:17 +00:00
} else {
2026-07-29 08:29:29 +00:00
const _Error = Error;
2026-08-24 06:08:38 +00:00
error = new Error("value is not a string");
2026-07-29 08:29:29 +00:00
throw error;
}
}
function _getSpotifyMetadataFromActivity() {
const self = this;
const tmp = callback((arg0, arg1) => {
2026-08-24 06:08:38 +00:00
closure_0 = arg0;
closure_1 = arg1;
c5 = 0;
c6 = 0;
2026-07-29 08:29:29 +00:00
return (function*(arg0, arg1) {
if (c6 === 2) {
c6 = 3;
HermesBuiltin.throwTypeError();
} else if (tmp4 === 3) {
if (arg0 === 1) {
throw arg1;
} else if (arg0 === 2) {
let obj = { value: null, done: true };
obj[0] = arg1;
return obj;
2026-07-20 16:05:17 +00:00
} else {
2026-08-24 06:08:38 +00:00
return { value: "HermesInternal", done: null };
2026-07-29 08:29:29 +00:00
}
} else {
try {
c6 = 2;
if (0 === c5) {
if (arg0 === 1) {
c6 = 3;
throw arg1;
} else if (arg0 === 2) {
c6 = 3;
obj = { value: null, done: true };
obj[0] = arg1;
return obj;
} else {
2026-08-24 06:08:38 +00:00
closure_4 = tmp5;
closure_3 = tmp2;
2026-07-29 08:29:29 +00:00
let lib;
2026-08-24 06:08:38 +00:00
closure_1 = undefined;
let obj2 = lib(closure_1_2[9]);
2026-07-29 08:29:29 +00:00
c5 = 1;
c6 = 1;
2026-08-24 06:08:38 +00:00
obj1 = { value: null, done: false };
2026-07-29 08:29:29 +00:00
obj1[0] = obj2.getMetadata(lib, closure_1);
return obj1;
}
} else if (arg0 === 1) {
c6 = 3;
throw arg1;
} else if (arg0 === 2) {
c6 = 3;
obj2 = { value: null, done: true };
obj2[0] = arg1;
return obj2;
} else {
lib = arg1;
const type = lib.type;
let TRACK = type;
if (type == null) {
TRACK = constants.TRACK;
}
callback(TRACK);
closure_1 = closure_9(TRACK);
if (null === closure_1) {
const _Error = Error;
const _HermesInternal = HermesInternal;
2026-08-24 06:08:38 +00:00
error = new Error("invalid type " + lib.type);
2026-07-29 08:29:29 +00:00
throw error;
} else {
let context_uri;
2026-08-04 21:03:28 +00:00
if (typeof lib.context_uri === "string") {
2026-07-29 08:29:29 +00:00
context_uri = lib.context_uri;
}
obj = { context_uri: null, album_id: null, artist_ids: null, type: null, button_urls: null };
obj[0] = context_uri;
const album_id = lib.album_id;
callback(album_id);
obj[1] = album_id;
const _Array = Array;
if (Array.isArray(lib.artist_ids)) {
const artist_ids = lib.artist_ids;
let mapped = artist_ids.map(callback);
} else {
mapped = [];
}
obj[2] = mapped;
obj[3] = closure_1;
const _Array2 = Array;
if (Array.isArray(lib.button_urls)) {
const button_urls = lib.button_urls;
let mapped1 = button_urls.map(callback);
2026-07-20 16:05:17 +00:00
} else {
2026-07-29 08:29:29 +00:00
mapped1 = [];
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
obj[4] = mapped1;
c6 = 3;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
const tmp49 = closure_9;
const tmp50 = callback;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
} catch (tmp41) {
c6 = tmp;
throw tmp41;
2026-07-20 16:05:17 +00:00
}
}
2026-07-29 08:29:29 +00:00
})();
});
2026-08-24 06:08:38 +00:00
closure_13 = tmp;
2026-07-29 08:29:29 +00:00
const apply = tmp.apply;
if (typeof apply === "unknown") {
let applyArgumentsResult = HermesBuiltin.applyArguments(self);
2026-07-20 16:05:17 +00:00
} else {
2026-07-29 08:29:29 +00:00
applyArgumentsResult = apply(self, arguments);
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
return applyArgumentsResult;
2026-07-20 16:05:17 +00:00
}
2026-08-24 06:08:38 +00:00
({ SPOTIFY_APP_PROTOCOL: error, SpotifyResourceTypes: closure_8, getSpotifyResourceType: c9 } = SPOTIFY_APP_PROTOCOL);
let closure_11 = 30 * setDefault.Millis.SECOND;
const result = require("set").fileFinishedImporting("modules/spotify/SpotifyUtils.tsx");
2026-07-20 16:05:17 +00:00
export const isSpotifyPlayable = function isSpotifyPlayable(getActiveSocketAndDevice) {
let isProtocolRegisteredResult = null != getActiveSocketAndDevice.getActiveSocketAndDevice();
if (!isProtocolRegisteredResult) {
2026-08-24 06:08:38 +00:00
isProtocolRegisteredResult = closure_5.isProtocolRegistered();
2026-07-20 16:05:17 +00:00
}
return isProtocolRegisteredResult;
};
export const ensureSpotifyPlayable = function ensureSpotifyPlayable() {
2026-07-29 08:29:29 +00:00
let obj = store;
2026-07-20 16:05:17 +00:00
const activeSocketAndDevice = store.getActiveSocketAndDevice();
if (null != activeSocketAndDevice) {
return Promise.resolve(activeSocketAndDevice);
2026-08-24 06:08:38 +00:00
} else if (closure_5.isProtocolRegistered()) {
2026-07-29 08:29:29 +00:00
let playableComputerDevices = obj.getPlayableComputerDevices();
if (observedAppRunning.isObservedAppRunning(obj2.get(PlatformTypes.SPOTIFY).name)) {
2026-07-20 16:05:17 +00:00
if (playableComputerDevices.length > 0) {
({ socket, device } = playableComputerDevices[0]);
2026-08-24 06:08:38 +00:00
playableComputerDevices(7281).setActiveDevice(socket.accountId, device.id);
2026-07-29 08:29:29 +00:00
obj = { socket: null, device: null };
obj[0] = socket;
obj[1] = device;
2026-07-20 16:05:17 +00:00
return Promise.resolve(obj);
}
}
const promise = new Promise((arg0, arg1) => {
2026-08-24 06:08:38 +00:00
closure_0 = arg0;
closure_1 = arg1;
2026-07-20 16:05:17 +00:00
function onSpotifyStoreChange() {
2026-08-24 06:08:38 +00:00
playableComputerDevices = closure_2_6.getPlayableComputerDevices();
2026-07-20 16:05:17 +00:00
function _loop(socket, device) {
2026-08-24 06:08:38 +00:00
closure_0 = socket;
closure_1 = device;
if (null == closure_1_0.find((device) => device.device.id === device.id)) {
2026-07-20 16:05:17 +00:00
const _clearTimeout = clearTimeout;
2026-07-29 08:29:29 +00:00
clearTimeout(closure_2);
2026-08-24 06:08:38 +00:00
closure_2_6.removeChangeListener(closure_3);
2026-07-20 16:05:17 +00:00
const _setImmediate = setImmediate;
setImmediate(() => {
2026-07-29 08:29:29 +00:00
let obj = socket(table[8]);
2026-07-23 10:11:24 +00:00
obj.setActiveDevice(socket.accountId, device.id);
obj = { socket, device };
2026-07-29 08:29:29 +00:00
socket(obj);
2026-07-20 16:05:17 +00:00
});
}
}
2026-07-29 08:29:29 +00:00
const iter = playableComputerDevices[Symbol.iterator]();
const nextResult = iter.next();
while (iter !== undefined) {
let _loopResult = _loop(nextResult.socket, nextResult.device);
continue;
2026-07-20 16:05:17 +00:00
}
}
const timeout = setTimeout(() => {
2026-08-24 06:08:38 +00:00
closure_2_6.removeChangeListener(onSpotifyStoreChange);
error = new Error("timeout launching spotify");
2026-07-23 10:11:24 +00:00
callback(error);
2026-08-24 06:08:38 +00:00
}, closure_1_11);
closure_1_6.addChangeListener(onSpotifyStoreChange);
window.open("" + closure_1_7 + ":");
2026-07-20 16:05:17 +00:00
});
return promise;
} else {
const _Error = Error;
2026-08-24 06:08:38 +00:00
error = new Error("protocol is not registered");
2026-07-20 16:05:17 +00:00
return Promise.reject(error);
}
};
export const isSpotifyPremium = function isSpotifyPremium() {
const activeSocketAndDevice = store.getActiveSocketAndDevice();
let isPremium = null;
if (null != activeSocketAndDevice) {
isPremium = activeSocketAndDevice.socket.isPremium;
}
return isPremium;
};
export const ensureSpotifyPremium = function ensureSpotifyPremium() {
const activeSocketAndDevice = store.getActiveSocketAndDevice();
if (null == activeSocketAndDevice) {
2026-07-23 10:11:24 +00:00
let _Error = Error;
2026-08-24 06:08:38 +00:00
error = new Error("no active profile");
2026-07-20 16:05:17 +00:00
return Promise.reject(error);
} else {
const socket = activeSocketAndDevice.socket;
if (socket.isPremium) {
let resolved = Promise.resolve();
} else {
2026-08-24 06:08:38 +00:00
const profile = socket(7281).getProfile(socket.accountId, socket.accessToken);
2026-07-20 16:05:17 +00:00
resolved = profile.then(() => {
if (!socket.isPremium) {
const _Error = Error;
2026-08-24 06:08:38 +00:00
error = new Error("spotify account is not premium");
2026-07-20 16:05:17 +00:00
return Promise.reject(error);
}
});
2026-08-24 06:08:38 +00:00
const obj = socket(7281);
2026-07-20 16:05:17 +00:00
}
return resolved;
}
};
2026-07-23 10:11:24 +00:00
export const getSpotifyMetadataFromActivity = function getSpotifyMetadataFromActivity(closure_0, closure_1) {
2026-07-29 08:29:29 +00:00
const self = this;
const apply = _getSpotifyMetadataFromActivity.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
};