또수정
This commit is contained in:
@@ -345,6 +345,24 @@ const server = http.createServer((req, res) => {
|
||||
}
|
||||
|
||||
// 아바타 이미지 src 추출
|
||||
let handleText = null;
|
||||
// 채널 핸들(@...) 추출: 헤더 텍스트 → canonical 폴백
|
||||
try {
|
||||
const handleNode = header.locator('.yt-core-attributed-string:has-text("@")').first();
|
||||
await handleNode.waitFor({ state: 'visible', timeout: 4000 });
|
||||
const txt = (await handleNode.innerText())?.trim();
|
||||
const m = txt?.match(/@[^\s•|]+/);
|
||||
if (m && m[0]) handleText = m[0];
|
||||
} catch {}
|
||||
if (!handleText) {
|
||||
try {
|
||||
const href = await page.locator('link[rel="canonical"]').getAttribute('href');
|
||||
if (href) {
|
||||
const mm = href.match(/https?:\/\/www\.youtube\.com\/(%2F)?(@[^/?#]+)/);
|
||||
if (mm && mm[2]) handleText = decodeURIComponent(mm[2]);
|
||||
}
|
||||
} catch {}
|
||||
}
|
||||
let avatar = null;
|
||||
try {
|
||||
const img = header.locator('img[src^="https://yt3.googleusercontent.com/"]').first();
|
||||
@@ -354,7 +372,7 @@ const server = http.createServer((req, res) => {
|
||||
|
||||
await context.close();
|
||||
await browser.close();
|
||||
sendJson(res, 200, { success: true, foundtext, avatar });
|
||||
sendJson(res, 200, { success: true, foundtext, avatar, handle: handleText });
|
||||
} catch (e) {
|
||||
try { await browser?.close(); } catch {}
|
||||
console.error('[isCodeMatch] playwright error:', e);
|
||||
@@ -447,6 +465,30 @@ const server = http.createServer((req, res) => {
|
||||
if (t && t.startsWith('@')) handleText = t;
|
||||
if (handleText) console.log(`[gethandle] (${id}) channel page handle found:`, handleText);
|
||||
} catch {}
|
||||
// 대체1: 채널 헤더 내 텍스트 기반(@...) 추출
|
||||
if (!handleText) {
|
||||
try {
|
||||
console.log(`[gethandle] (${id}) try channel header text selector: #page-header .yt-core-attributed-string:has-text("@")`);
|
||||
const textNode = page.locator('#page-header .yt-core-attributed-string:has-text("@")').first();
|
||||
await textNode.waitFor({ state: 'visible', timeout: 4000 });
|
||||
const txt = (await textNode.innerText())?.trim();
|
||||
const m = txt?.match(/@[^\s•|]+/);
|
||||
if (m && m[0]) handleText = m[0];
|
||||
if (handleText) console.log(`[gethandle] (${id}) channel header text handle found:`, handleText);
|
||||
} catch {}
|
||||
}
|
||||
// 대체2: canonical 링크에서 @handle 파싱
|
||||
if (!handleText) {
|
||||
try {
|
||||
console.log(`[gethandle] (${id}) try canonical link for handle`);
|
||||
const href = await page.locator('link[rel="canonical"]').getAttribute('href');
|
||||
if (href) {
|
||||
const m = href.match(/https?:\/\/www\.youtube\.com\/(%2F)?(@[^/?#]+)/);
|
||||
if (m && m[2]) handleText = decodeURIComponent(m[2]);
|
||||
}
|
||||
if (handleText) console.log(`[gethandle] (${id}) canonical handle found:`, handleText);
|
||||
} catch {}
|
||||
}
|
||||
// 채널 아바타
|
||||
try {
|
||||
console.log(`[gethandle] (${id}) try channel page avatar selector: img[src*="yt3"]`);
|
||||
|
||||
Reference in New Issue
Block a user