Files
ESH-Media/search-scripts/rutube.js
eshmeshek ecb5e7e49f init: media-center v2
Rewrite of ESH-Media v1 with separated main/renderer/shared architecture
(vite-plugin-electron, React 18, react-router-dom). Includes NeDB storage,
electron-store config, proxy manager with FoxyProxy/uBlock extensions,
custom server-checked updater, NSIS installer.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-11 23:49:43 +03:00

64 lines
1.8 KiB
JavaScript

/**
* Rutube.ru search script
*
* This script searches for videos on rutube.ru using their API
*
* @param {string} query - Search query from user
* @param {string} siteUrl - Base URL of the site
* @param {boolean} useProxy - Whether to use proxy for requests
* @param {object} axios - Axios instance for HTTP requests
* @param {object} cheerio - Cheerio instance for HTML parsing (not used)
* @param {object} proxyConfig - Proxy configuration {host, port}
* @returns {Promise<Array>} Array of search results [{name, url, image?, description?}]
*/
async function search(query, siteUrl, useProxy, axios, cheerio, proxyConfig) {
try {
const searchUrl = `${siteUrl}/api/search/video/`;
// Prepare request config
const config = {
params: {
query: query,
limit: 20
},
timeout: 15000,
headers: {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'
}
};
// Add proxy if needed (Rutube usually doesn't require proxy in Russia)
if (useProxy && proxyConfig) {
config.proxy = {
host: proxyConfig.host,
port: proxyConfig.port
};
}
// Make request
const response = await axios.get(searchUrl, config);
const data = response.data;
// Check if results exist
if (!data.results || !Array.isArray(data.results)) {
return [];
}
// Map results to our format
const results = data.results.map(item => {
return {
name: item.title || '',
url: item.video_url || (siteUrl + '/video/' + item.id),
image: item.thumbnail_url || undefined,
description: item.description || undefined
};
});
return results.filter(r => r.name && r.url);
} catch (error) {
console.error('Rutube search error:', error.message);
return [];
}
}