Spaces:
Paused
Paused
fix: TMDb 검색에 제목 변형 후보 추가
Browse files증상: 히든싱어8, 나는 SOLO ...(나솔사계) 등 시즌 숫자/괄호 줄임말이
원제목에 붙은 작품을 TMDb가 못 찾음. 변형 없이는 namu fallback인데
namu CDN이 차단되어 빈 박스로 노출됨.
조치: tmdbTitleCandidates() 추가.
- 원제목 그대로
- 끝 시즌 숫자 제거 ("히든싱어8" → "히든싱어")
- 시즌 표기 제거 ("...시즌2", "...S2")
- 괄호 줄임말 제거 ("...(나솔사계)" → "...")
- SOLO ↔ 솔로 한영 변환
fetchTmdbPoster가 후보 순차 시도, 첫 매치 사용. 영구 캐시는 원제목
기준이라 같은 title 다시 호출하면 이미 캐시된 결과 즉시 반환.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
server.js
CHANGED
|
@@ -1434,6 +1434,29 @@ function namuTitleCandidates(title) {
|
|
| 1434 |
return out.filter(t => t.length >= 2);
|
| 1435 |
}
|
| 1436 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1437 |
// TMDb (themoviedb.org) 포스터 검색 — namu 차단 우회용. TMDB_API_KEY 환경변수 필요.
|
| 1438 |
// image.tmdb.org는 hotlink 허용이라 클라이언트가 직접 src로 사용 가능.
|
| 1439 |
// /search/multi로 영화·TV 한 번에 검색, 첫 결과의 poster_path 사용.
|
|
@@ -1445,23 +1468,29 @@ async function fetchTmdbPoster(title) {
|
|
| 1445 |
const cacheFile = `tmdb_poster_${Buffer.from(title).toString('base64').slice(0, 80).replace(/[+/=]/g, '_')}.json`;
|
| 1446 |
const cached = readCachePermanent(cacheFile);
|
| 1447 |
if (cached) return cached.poster || null;
|
|
|
|
| 1448 |
try {
|
| 1449 |
-
const url = `https://api.themoviedb.org/3/search/multi?query=${encodeURIComponent(title)}&language=ko-KR&include_adult=false`;
|
| 1450 |
const headers = apiKey.startsWith('eyJ')
|
| 1451 |
? { 'Authorization': `Bearer ${apiKey}`, 'Accept': 'application/json' } // v4 Read Token (JWT)
|
| 1452 |
: null;
|
| 1453 |
-
|
| 1454 |
-
|
| 1455 |
-
|
| 1456 |
-
|
| 1457 |
-
|
| 1458 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1459 |
}
|
| 1460 |
-
|
| 1461 |
-
const hit = (data.results || []).find(r => r.poster_path && (r.media_type === 'tv' || r.media_type === 'movie'));
|
| 1462 |
-
const poster = hit?.poster_path ? `https://image.tmdb.org/t/p/w500${hit.poster_path}` : null;
|
| 1463 |
-
if (poster) console.log(`[tmdb] "${title}" → ${hit.media_type}/${hit.id} → ${poster.slice(0, 70)}`);
|
| 1464 |
-
else console.warn(`[tmdb] "${title}" no result`);
|
| 1465 |
writeCache(cacheFile, { poster, checked_at: new Date().toISOString() });
|
| 1466 |
return poster;
|
| 1467 |
} catch (e) {
|
|
|
|
| 1434 |
return out.filter(t => t.length >= 2);
|
| 1435 |
}
|
| 1436 |
|
| 1437 |
+
// TMDb 검색 후보 생성 — 원제목 + 일반적 변형.
|
| 1438 |
+
// 예: "히든싱어8" → ["히든싱어8","히든싱어"], "...(나솔사계)" → ["...(나솔사계)","..."]
|
| 1439 |
+
function tmdbTitleCandidates(title) {
|
| 1440 |
+
const base = String(title).trim();
|
| 1441 |
+
const out = [];
|
| 1442 |
+
const seen = new Set();
|
| 1443 |
+
const push = (t) => {
|
| 1444 |
+
t = String(t || '').trim();
|
| 1445 |
+
if (t && !seen.has(t)) { seen.add(t); out.push(t); }
|
| 1446 |
+
};
|
| 1447 |
+
push(base);
|
| 1448 |
+
// 끝에 시즌 숫자 제거: "히든싱어8" → "히든싱어"
|
| 1449 |
+
push(base.replace(/\s*\d+\s*$/, '').trim());
|
| 1450 |
+
// 끝에 시즌 표기 제거: "...시즌2" / "...S2"
|
| 1451 |
+
push(base.replace(/\s*(시즌\s*\d+|S\d+)\s*$/, '').trim());
|
| 1452 |
+
// 괄호 안 줄임말 제거: "나는 SOLO ...(나솔사계)" → "나는 SOLO ..."
|
| 1453 |
+
push(base.replace(/\s*\([^)]*\)\s*/g, ' ').trim());
|
| 1454 |
+
// SOLO ↔ 솔로 (한영 혼용)
|
| 1455 |
+
if (/SOLO/i.test(base)) push(base.replace(/SOLO/gi, '솔로'));
|
| 1456 |
+
if (/솔로/.test(base)) push(base.replace(/솔로/g, 'SOLO'));
|
| 1457 |
+
return out.filter(t => t.length >= 2);
|
| 1458 |
+
}
|
| 1459 |
+
|
| 1460 |
// TMDb (themoviedb.org) 포스터 검색 — namu 차단 우회용. TMDB_API_KEY 환경변수 필요.
|
| 1461 |
// image.tmdb.org는 hotlink 허용이라 클라이언트가 직접 src로 사용 가능.
|
| 1462 |
// /search/multi로 영화·TV 한 번에 검색, 첫 결과의 poster_path 사용.
|
|
|
|
| 1468 |
const cacheFile = `tmdb_poster_${Buffer.from(title).toString('base64').slice(0, 80).replace(/[+/=]/g, '_')}.json`;
|
| 1469 |
const cached = readCachePermanent(cacheFile);
|
| 1470 |
if (cached) return cached.poster || null;
|
| 1471 |
+
const candidates = tmdbTitleCandidates(title);
|
| 1472 |
try {
|
|
|
|
| 1473 |
const headers = apiKey.startsWith('eyJ')
|
| 1474 |
? { 'Authorization': `Bearer ${apiKey}`, 'Accept': 'application/json' } // v4 Read Token (JWT)
|
| 1475 |
: null;
|
| 1476 |
+
let poster = null;
|
| 1477 |
+
for (const cand of candidates) {
|
| 1478 |
+
const url = `https://api.themoviedb.org/3/search/multi?query=${encodeURIComponent(cand)}&language=ko-KR&include_adult=false`;
|
| 1479 |
+
const finalUrl = headers ? url : `${url}&api_key=${encodeURIComponent(apiKey)}`;
|
| 1480 |
+
const resp = await fetch(finalUrl, { headers: headers || {} });
|
| 1481 |
+
if (!resp.ok) {
|
| 1482 |
+
console.warn(`[tmdb] "${cand}" → HTTP ${resp.status}`);
|
| 1483 |
+
continue;
|
| 1484 |
+
}
|
| 1485 |
+
const data = await resp.json();
|
| 1486 |
+
const hit = (data.results || []).find(r => r.poster_path && (r.media_type === 'tv' || r.media_type === 'movie'));
|
| 1487 |
+
if (hit?.poster_path) {
|
| 1488 |
+
poster = `https://image.tmdb.org/t/p/w500${hit.poster_path}`;
|
| 1489 |
+
console.log(`[tmdb] "${title}" via "${cand}" → ${hit.media_type}/${hit.id} → ${poster.slice(0, 70)}`);
|
| 1490 |
+
break;
|
| 1491 |
+
}
|
| 1492 |
}
|
| 1493 |
+
if (!poster) console.warn(`[tmdb] "${title}" no result (tried ${candidates.length})`);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1494 |
writeCache(cacheFile, { poster, checked_at: new Date().toISOString() });
|
| 1495 |
return poster;
|
| 1496 |
} catch (e) {
|