NewTube/server/providers/rumble.mjs

44 lines
1005 B
JavaScript

/**
* Minimal Rumble provider handler
*/
const handler = {
id: 'ru',
label: 'Rumble',
/**
* @param {string} q
* @param {{ limit: number, page?: number }} opts
* @returns {Promise<Array<any>>}
*/
async search(q, opts) {
const { limit = 10 } = opts;
try {
const response = await fetch(
`https://rumble.com/api/search/videos?` +
new URLSearchParams({
q: q,
size: Math.min(limit, 50).toString()
})
);
if (!response.ok) {
throw new Error(`Rumble API error: ${response.status}`);
}
const data = await response.json();
return (data.videos || []).map(item => ({
title: item.title,
id: item.id,
url: `https://rumble.com${item.url}`,
thumbnail: item.thumbnail,
uploaderName: item.author.name,
type: 'video'
}));
} catch (error) {
console.error('Rumble search error:', error);
return [];
}
}
};
export default handler;