UNPKG

soop.js

Version:

대한민국의 인터넷 방송 플랫폼 SOOP(숲)의 비공식 API 라이브러리

60 lines (59 loc) 2.98 kB
"use strict"; 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.channel = void 0; const channel = (browser, bj) => __awaiter(void 0, void 0, void 0, function* () { const page = yield browser.newPage(); yield page.goto(`https://bj.afreecatv.com/${bj}`); const [streamerId, streamerName, streamerThumbnail, streamerFavorites, streamerSubscribe, streamerExplanation] = yield Promise.all([ getStreamerId(page), getTextContent(page, "#bs-navi > div > article.article_bj_box > section > div > div > h2"), getStreamerThumbnail(page), getTextContent(page, "#bs-contents > article.bs-contents-header.expansion > section.bs-infomation_wrap > div > div.items_wrap > div > button.favor > span"), getTextContent(page, "#bs-contents > article.bs-contents-header.expansion > section.bs-infomation_wrap > div > div.items_wrap > div > button.subscribe > span"), getTextContent(page, "#bs-contents > article.bs-contents-header.expansion > section.bs-infomation_wrap > div > div.title-wrap > div.explanation > p > span") ]); yield page.close(); return { streamerId, streamerName, streamerThumbnail, streamerFavorites, streamerSubscribe, streamerExplanation, }; }); exports.channel = channel; const getTextContent = (page, selector) => __awaiter(void 0, void 0, void 0, function* () { try { const element = yield page.$(selector); return element ? yield element.textContent() : null; } catch (_a) { return null; } }); const getStreamerId = (page) => __awaiter(void 0, void 0, void 0, function* () { const element = yield getTextContent(page, "#bs-navi > div > article.article_bj_box > section > div > div > span"); return element ? element.slice(1, -1) : null; }); const getStreamerThumbnail = (page) => __awaiter(void 0, void 0, void 0, function* () { try { const element = yield page.$("#bs-navi > div > article.article_bj_box > section > a > div > img"); if (!element) return null; const src = yield element.evaluate(node => node.getAttribute('src')); return src ? src.replace("//profile", "https://profile") : null; } catch (_b) { return null; } });