soop.js
Version:
대한민국의 인터넷 방송 플랫폼 SOOP(숲)의 비공식 API 라이브러리
45 lines (44 loc) • 2.05 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.info = void 0;
const search_1 = require("../api/search");
const info = (browser, bj) => __awaiter(void 0, void 0, void 0, function* () {
const page = yield browser.newPage();
try {
const url = `https://play.sooplive.co.kr/${bj}`;
yield page.goto(url, { waitUntil: 'networkidle' });
const currentUrl = page.url();
const pathSuffix = currentUrl.replace(url, "");
if (currentUrl.includes("not_found") || pathSuffix.includes("null")) {
return null;
}
const directory = pathSuffix.replace("/", "");
const [streamerInfo, streamTitle] = yield Promise.all([
(0, search_1.channel)(browser, bj),
page.$("#infoTitle").then(el => { var _a; return (_a = el === null || el === void 0 ? void 0 : el.textContent()) !== null && _a !== void 0 ? _a : null; })
]);
return {
streamerInfo,
streamUrl: `https://ch.sooplive.co.kr/${bj}`,
streamTitle,
thumbnailUrl: `https://liveimg.afreecatv.com/h/${directory}.webp`,
};
}
catch (error) {
console.error(`[soop.js] Error fetching live info for ${bj}:`, error);
return null;
}
finally {
yield page.close();
}
});
exports.info = info;