debug: TV xREL debug endpoint

This commit is contained in:
2026-06-18 12:10:33 +02:00
parent 5f6319c310
commit 7bfd9d003e

View File

@@ -621,4 +621,58 @@ router.get('/debug-xrel3', authenticate, async (req, res) => {
res.json(log);
});
// Debug xREL für TV
router.get('/debug-xrel-tv', authenticate, async (req, res) => {
const { title='', orig='', imdb_id='', year='0', id='0' } = req.query;
try {
const clean = s => (s||'').toLowerCase().trim();
const allQueries = [orig, title].filter(Boolean).filter((v,i,a)=>a.indexOf(v)===i);
// 1. Suche
const searchResults = await Promise.all(allQueries.map(async q => {
try {
const data = await xrelFetch('/search/ext_info.json', { q: q.replace(/[*#!?:]/g,''), type:'tv', limit:10 });
return { q, results: data?.results||[], total: data?.total||0 };
} catch(e) { return { q, error: e.message }; }
}));
// 2. IMDb-Match
let extInfoId = null;
if (imdb_id) {
for (const r of searchResults) {
const hit = (r.results||[]).find(h => (h.uris||[]).includes(`imdb:${imdb_id}`));
if (hit) { extInfoId = hit.id; break; }
}
}
// 3. Titel-Match
if (!extInfoId) {
for (const r of searchResults) {
for (const h of r.results||[]) {
if (clean(h.title)===clean(orig)||clean(h.title)===clean(title)||
clean(h.alt_title)===clean(orig)||clean(h.alt_title)===clean(title)) {
extInfoId = h.id; break;
}
}
if (extInfoId) break;
}
}
// 4. Releases wenn gefunden
let releases = [];
if (extInfoId) {
const [scene, p2p] = await Promise.all([
xrelFetch('/release/ext_info.json', { id: extInfoId, per_page: 25 }).catch(()=>({})),
xrelFetch('/p2p/releases.json', { ext_info_id: extInfoId, per_page: 25 }).catch(()=>({})),
]);
releases = [
...(scene.list||[]).map(r=>({ src:'scene', dirname:r.dirname, german:/german|deutsch/i.test(r.dirname||'') })),
...(p2p.list||[]).map(r=>({ src:'p2p', dirname:r.dirname, german: r.main_lang==='german' })),
];
}
res.json({ searchResults, extInfoId, releases: releases.slice(0,20) });
} catch(e) { res.status(500).json({ error: e.message }); }
});
module.exports = router;