Podcast: search for new shows and add them
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
675df5710b
commit
66a376d22c
3 files changed
+30
-7
No files matched your search
+10
@@ -17,6 +17,16 @@ const enabled = () => !!BASE;
|
||||
async function handle(req, res) {
|
||||
if (!BASE) return json(res, 503, { error: 'Podcasts are not set up on this server' });
|
||||
const u = new URL(req.url, 'http://x'), p = u.pathname.slice('/api/podcast'.length) || '/';
|
||||
if (p === '/discover') { // find new shows in Apple's free podcast directory (the search words go to Apple; nothing else does)
|
||||
const q = (u.searchParams.get('q') || '').trim().slice(0, 100);
|
||||
if (q.length < 2) return json(res, 200, []);
|
||||
try {
|
||||
const r = await fetch('https://itunes.apple.com/search?' + new URLSearchParams({ media: 'podcast', limit: '15', term: q }), { signal: AbortSignal.timeout(10000) });
|
||||
if (!r.ok) throw new Error('status ' + r.status);
|
||||
const out = ((await r.json()).results || []).filter(x => /^https?:\/\//i.test(x.feedUrl || '')).map(x => ({ title: x.collectionName, author: x.artistName, feedUrl: x.feedUrl, image: x.artworkUrl100 }));
|
||||
return json(res, 200, out);
|
||||
} catch { return json(res, 502, { error: 'The podcast directory did not answer' }); }
|
||||
}
|
||||
if (p === '/status') return json(res, 200, { ok: true, host: new URL(BASE).host });
|
||||
if (!ALLOWED.some(([m, re]) => m === req.method && re.test(p))) return json(res, 404, { error: 'Not found' });
|
||||
const hasBody = req.method === 'POST' || req.method === 'PATCH';
|
||||
|
||||
Reference in new issue
Block a user