diff --git a/local-scrapers-repo b/local-scrapers-repo index 37b9ae4..e6c0e8c 160000 --- a/local-scrapers-repo +++ b/local-scrapers-repo @@ -1 +1 @@ -Subproject commit 37b9ae4298bd38b8119d45e8670f40bec2780a8b +Subproject commit e6c0e8c0d75a8595031fe450e29db0c40969b5b8 diff --git a/src/screens/PluginsScreen.tsx b/src/screens/PluginsScreen.tsx index fc0e0d8..fa814fb 100644 --- a/src/screens/PluginsScreen.tsx +++ b/src/screens/PluginsScreen.tsx @@ -11,12 +11,12 @@ import { RefreshControl, StatusBar, Platform, - Image, ActivityIndicator, Modal, Dimensions, Animated, } from 'react-native'; +import { Image } from 'expo-image'; import { SafeAreaView } from 'react-native-safe-area-context'; import { Ionicons } from '@expo/vector-icons'; import { useNavigation } from '@react-navigation/native'; @@ -1475,8 +1475,8 @@ const PluginsScreen: React.FC = () => { {scraper.logo ? ( ) : ( diff --git a/src/services/trailerService.ts b/src/services/trailerService.ts index d4dd007..44626fe 100644 --- a/src/services/trailerService.ts +++ b/src/services/trailerService.ts @@ -7,8 +7,11 @@ export interface TrailerData { } export class TrailerService { - private static readonly BASE_URL = 'https://db.xprime.tv/trailers'; + private static readonly XPRIME_URL = 'https://db.xprime.tv/trailers'; + private static readonly LOCAL_SERVER_URL = 'http://192.168.1.11:3001/trailer'; + private static readonly AUTO_SEARCH_URL = 'http://192.168.1.11:3001/search-trailer'; private static readonly TIMEOUT = 10000; // 10 seconds + private static readonly USE_LOCAL_SERVER = true; // Toggle between local and XPrime /** * Fetches trailer URL for a given title and year @@ -17,13 +20,84 @@ export class TrailerService { * @returns Promise - The trailer URL or null if not found */ static async getTrailerUrl(title: string, year: number): Promise { + if (this.USE_LOCAL_SERVER) { + // Try local server first, fallback to XPrime if it fails + const localResult = await this.getTrailerFromLocalServer(title, year); + if (localResult) { + return localResult; + } + + logger.info('TrailerService', `Local server failed, falling back to XPrime for: ${title} (${year})`); + return this.getTrailerFromXPrime(title, year); + } else { + return this.getTrailerFromXPrime(title, year); + } + } + + /** + * Fetches trailer from local server using auto-search (no YouTube URL needed) + * @param title - The movie/series title + * @param year - The release year + * @returns Promise - The trailer URL or null if not found + */ + private static async getTrailerFromLocalServer(title: string, year: number): Promise { try { const controller = new AbortController(); const timeoutId = setTimeout(() => controller.abort(), this.TIMEOUT); - const url = `${this.BASE_URL}?title=${encodeURIComponent(title)}&year=${year}`; + const url = `${this.AUTO_SEARCH_URL}?title=${encodeURIComponent(title)}&year=${year}`; - logger.info('TrailerService', `Fetching trailer for: ${title} (${year})`); + logger.info('TrailerService', `Auto-searching trailer for: ${title} (${year})`); + + const response = await fetch(url, { + method: 'GET', + headers: { + 'Accept': 'application/json', + 'User-Agent': 'Nuvio/1.0', + }, + signal: controller.signal, + }); + + clearTimeout(timeoutId); + + if (!response.ok) { + logger.warn('TrailerService', `Auto-search failed: ${response.status} ${response.statusText}`); + return null; + } + + const data = await response.json(); + + if (!data.url || !this.isValidTrailerUrl(data.url)) { + logger.warn('TrailerService', `Invalid trailer URL from auto-search: ${data.url}`); + return null; + } + + logger.info('TrailerService', `Successfully found trailer: ${data.url.substring(0, 50)}...`); + return data.url; + } catch (error) { + if (error instanceof Error && error.name === 'AbortError') { + logger.warn('TrailerService', 'Auto-search request timed out'); + } else { + logger.error('TrailerService', 'Error in auto-search:', error); + } + return null; // Return null to trigger XPrime fallback + } + } + + /** + * Fetches trailer from XPrime API (original method) + * @param title - The movie/series title + * @param year - The release year + * @returns Promise - The trailer URL or null if not found + */ + private static async getTrailerFromXPrime(title: string, year: number): Promise { + try { + const controller = new AbortController(); + const timeoutId = setTimeout(() => controller.abort(), this.TIMEOUT); + + const url = `${this.XPRIME_URL}?title=${encodeURIComponent(title)}&year=${year}`; + + logger.info('TrailerService', `Fetching trailer from XPrime for: ${title} (${year})`); const response = await fetch(url, { method: 'GET', @@ -37,32 +111,32 @@ export class TrailerService { clearTimeout(timeoutId); if (!response.ok) { - logger.warn('TrailerService', `Failed to fetch trailer: ${response.status} ${response.statusText}`); + logger.warn('TrailerService', `XPrime failed: ${response.status} ${response.statusText}`); return null; } const trailerUrl = await response.text(); - // Validate the response is a valid URL if (!trailerUrl || !this.isValidTrailerUrl(trailerUrl.trim())) { - logger.warn('TrailerService', `Invalid trailer URL received: ${trailerUrl}`); + logger.warn('TrailerService', `Invalid trailer URL from XPrime: ${trailerUrl}`); return null; } const cleanUrl = trailerUrl.trim(); - logger.info('TrailerService', `Successfully fetched trailer URL: ${cleanUrl}`); + logger.info('TrailerService', `Successfully fetched trailer from XPrime: ${cleanUrl}`); return cleanUrl; } catch (error) { if (error instanceof Error && error.name === 'AbortError') { - logger.warn('TrailerService', 'Trailer fetch request timed out'); + logger.warn('TrailerService', 'XPrime request timed out'); } else { - logger.error('TrailerService', 'Error fetching trailer:', error); + logger.error('TrailerService', 'Error fetching from XPrime:', error); } return null; } } + /** * Validates if the provided string is a valid trailer URL * @param url - The URL to validate @@ -86,7 +160,12 @@ export class TrailerService { 'dailymotion.com', 'twitch.tv', 'amazonaws.com', - 'cloudfront.net' + 'cloudfront.net', + 'googlevideo.com', // Google's CDN for YouTube videos + 'sn-aigl6nzr.googlevideo.com', // Specific Google CDN servers + 'sn-aigl6nze.googlevideo.com', + 'sn-aigl6nsk.googlevideo.com', + 'sn-aigl6ns6.googlevideo.com' ]; const hostname = urlObj.hostname.toLowerCase(); @@ -94,13 +173,17 @@ export class TrailerService { hostname.includes(domain) || hostname.endsWith(domain) ); + // Special check for Google Video CDN (YouTube direct streaming URLs) + const isGoogleVideoCDN = hostname.includes('googlevideo.com') || + hostname.includes('sn-') && hostname.includes('.googlevideo.com'); + // Check for video file extensions or streaming formats const hasVideoFormat = /\.(mp4|m3u8|mpd|webm|mov|avi|mkv)$/i.test(urlObj.pathname) || url.includes('formats=') || url.includes('manifest') || url.includes('playlist'); - return isValidDomain || hasVideoFormat; + return isValidDomain || hasVideoFormat || isGoogleVideoCDN; } catch { return false; } @@ -161,6 +244,78 @@ export class TrailerService { year }; } + + /** + * Switch between local server and XPrime API + * @param useLocal - true for local server, false for XPrime + */ + static setUseLocalServer(useLocal: boolean): void { + (this as any).USE_LOCAL_SERVER = useLocal; + logger.info('TrailerService', `Switched to ${useLocal ? 'local server' : 'XPrime API'}`); + } + + /** + * Get current server status + * @returns object with server information + */ + static getServerStatus(): { usingLocal: boolean; localUrl: string; xprimeUrl: string; fallbackEnabled: boolean } { + return { + usingLocal: this.USE_LOCAL_SERVER, + localUrl: this.LOCAL_SERVER_URL, + xprimeUrl: this.XPRIME_URL, + fallbackEnabled: true // Always enabled now + }; + } + + /** + * Test both servers and return their status + * @returns Promise with server status information + */ + static async testServers(): Promise<{ + localServer: { status: 'online' | 'offline'; responseTime?: number }; + xprimeServer: { status: 'online' | 'offline'; responseTime?: number }; + }> { + const results = { + localServer: { status: 'offline' as const }, + xprimeServer: { status: 'offline' as const } + }; + + // Test local server + try { + const startTime = Date.now(); + const response = await fetch(`${this.AUTO_SEARCH_URL}?title=test&year=2023`, { + method: 'GET', + signal: AbortSignal.timeout(5000) // 5 second timeout + }); + if (response.ok || response.status === 404) { // 404 is ok, means server is running + results.localServer = { + status: 'online', + responseTime: Date.now() - startTime + }; + } + } catch (error) { + logger.warn('TrailerService', 'Local server test failed:', error); + } + + // Test XPrime server + try { + const startTime = Date.now(); + const response = await fetch(`${this.XPRIME_URL}?title=test&year=2023`, { + method: 'GET', + signal: AbortSignal.timeout(5000) // 5 second timeout + }); + if (response.ok || response.status === 404) { // 404 is ok, means server is running + results.xprimeServer = { + status: 'online', + responseTime: Date.now() - startTime + }; + } + } catch (error) { + logger.warn('TrailerService', 'XPrime server test failed:', error); + } + + return results; + } } export default TrailerService; \ No newline at end of file diff --git a/test-trailer-integration.js b/test-trailer-integration.js new file mode 100644 index 0000000..2433781 --- /dev/null +++ b/test-trailer-integration.js @@ -0,0 +1,54 @@ +// Quick test to verify TrailerService integration +// Run this from the main Nuvio directory + +const TrailerService = require('./src/services/trailerService.ts'); + +async function testTrailerIntegration() { + console.log('๐Ÿงช Testing TrailerService Integration...\n'); + + // Test 1: Check server status + console.log('1๏ธโƒฃ Server Status:'); + const status = TrailerService.getServerStatus(); + console.log('โœ… Using Local Server:', status.usingLocal); + console.log('๐Ÿ”— Local URL:', status.localUrl); + console.log('๐Ÿ”— XPrime URL:', status.xprimeUrl); + + console.log('\n'); + + // Test 2: Try to fetch a trailer + console.log('2๏ธโƒฃ Testing trailer fetch...'); + try { + const trailerUrl = await TrailerService.getTrailerUrl('Test Movie', 2023); + if (trailerUrl) { + console.log('โœ… Trailer URL fetched successfully!'); + console.log('๐Ÿ”— URL:', trailerUrl.substring(0, 80) + '...'); + } else { + console.log('โŒ No trailer URL returned'); + } + } catch (error) { + console.log('โŒ Error fetching trailer:', error.message); + } + + console.log('\n'); + + // Test 3: Test trailer data + console.log('3๏ธโƒฃ Testing trailer data...'); + try { + const trailerData = await TrailerService.getTrailerData('Test Movie', 2023); + if (trailerData) { + console.log('โœ… Trailer data fetched successfully!'); + console.log('๐Ÿ“น Title:', trailerData.title); + console.log('๐Ÿ“… Year:', trailerData.year); + console.log('๐Ÿ”— URL:', trailerData.url.substring(0, 80) + '...'); + } else { + console.log('โŒ No trailer data returned'); + } + } catch (error) { + console.log('โŒ Error fetching trailer data:', error.message); + } + + console.log('\n๐Ÿ Integration test complete!'); +} + +// Run the test +testTrailerIntegration().catch(console.error); diff --git a/trailer-server/DEPLOYMENT.md b/trailer-server/DEPLOYMENT.md new file mode 100644 index 0000000..d38068c --- /dev/null +++ b/trailer-server/DEPLOYMENT.md @@ -0,0 +1,137 @@ +# ๐Ÿš€ Deployment Guide + +## Netlify Deployment + +### Option 1: Deploy via Netlify CLI + +1. **Install Netlify CLI:** +```bash +npm install -g netlify-cli +``` + +2. **Login to Netlify:** +```bash +netlify login +``` + +3. **Deploy:** +```bash +netlify deploy --prod --dir=. +``` + +### Option 2: Deploy via GitHub + +1. **Push to GitHub:** +```bash +git init +git add . +git commit -m "Initial trailer server" +git remote add origin https://github.com/yourusername/nuvio-trailer-server.git +git push -u origin main +``` + +2. **Connect to Netlify:** + - Go to [netlify.com](https://netlify.com) + - Click "New site from Git" + - Connect your GitHub repository + - Build settings will be auto-detected from `netlify.toml` + +### Option 3: Manual Deploy + +1. **Build the functions:** +```bash +npm run build +``` + +2. **Upload to Netlify:** + - Zip the entire folder + - Upload via Netlify dashboard + +## Important Notes + +### โš ๏ธ yt-dlp Limitation +**Netlify Functions don't support yt-dlp by default.** You have a few options: + +1. **Use Railway/Render instead** (recommended) +2. **Use a different approach** (see alternatives below) +3. **Custom Netlify build** (complex) + +### Alternative Platforms + +#### Railway (Recommended) +```bash +# Install Railway CLI +npm install -g @railway/cli + +# Login and deploy +railway login +railway init +railway up +``` + +#### Render +1. Connect GitHub repository +2. Set build command: `npm install` +3. Set start command: `npm start` +4. Deploy + +#### Vercel +```bash +# Install Vercel CLI +npm install -g vercel + +# Deploy +vercel --prod +``` + +## Update Your App + +After deployment, update your TrailerService: + +```typescript +// In src/services/trailerService.ts +private static readonly LOCAL_SERVER_URL = 'https://your-deployed-url.netlify.app/trailer'; +``` + +## Testing Deployment + +```bash +# Test health endpoint +curl https://your-deployed-url.netlify.app/health + +# Test trailer endpoint +curl "https://your-deployed-url.netlify.app/trailer?youtube_url=https://www.youtube.com/watch?v=dQw4w9WgXcQ&title=Test&year=2023" +``` + +## Environment Variables + +Set these in your deployment platform: + +- `NODE_ENV`: `production` +- `PORT`: `3001` (if needed) + +## Monitoring + +- Check Netlify Functions dashboard for logs +- Monitor function execution time +- Watch for rate limiting issues + +## Troubleshooting + +### Common Issues: + +1. **yt-dlp not found**: Use Railway/Render instead of Netlify +2. **Function timeout**: Increase timeout in platform settings +3. **Rate limiting**: Implement better caching +4. **CORS issues**: Check headers in functions + +### Debug Commands: + +```bash +# Test locally +npm test + +# Check function logs +netlify functions:list +netlify functions:invoke trailer +``` diff --git a/trailer-server/README.md b/trailer-server/README.md new file mode 100644 index 0000000..11459b3 --- /dev/null +++ b/trailer-server/README.md @@ -0,0 +1,182 @@ +# Nuvio Trailer Server + +A Node.js server that converts YouTube trailer URLs to direct streaming links using yt-dlp. + +## Features + +- ๐ŸŽฌ Convert YouTube URLs to direct streaming links +- ๐Ÿ’พ Intelligent caching (24-hour TTL) +- ๐Ÿšฆ Rate limiting (10 requests/minute per IP) +- ๐Ÿ”’ Security headers with Helmet +- ๐Ÿ“Š Health monitoring endpoint +- ๐Ÿงช Built-in testing suite + +## Prerequisites + +- Node.js 16+ +- yt-dlp installed on your system + +### Install yt-dlp + +**macOS:** +```bash +brew install yt-dlp +``` + +**Linux:** +```bash +pip install yt-dlp +``` + +**Windows:** +```bash +pip install yt-dlp +``` + +## Installation + +1. **Clone/Navigate to the server directory:** +```bash +cd trailer-server +``` + +2. **Install dependencies:** +```bash +npm install +``` + +3. **Start the server:** +```bash +# Development mode (with auto-restart) +npm run dev + +# Production mode +npm start +``` + +The server will start on `http://localhost:3001` + +## API Endpoints + +### GET /health +Health check endpoint +```bash +curl http://localhost:3001/health +``` + +### GET /trailer +Get direct streaming URL for a YouTube trailer + +**Parameters:** +- `youtube_url` (required): YouTube URL of the trailer +- `title` (optional): Movie/show title +- `year` (optional): Release year + +**Example:** +```bash +curl "http://localhost:3001/trailer?youtube_url=https://www.youtube.com/watch?v=example&title=Avengers&year=2019" +``` + +**Response:** +```json +{ + "url": "https://direct-streaming-url.com/video.mp4", + "title": "Avengers", + "year": "2019", + "source": "youtube", + "cached": false, + "timestamp": "2023-12-01T10:00:00.000Z" +} +``` + +### GET /cache +View cached trailers (for debugging) + +### DELETE /cache +Clear all cached trailers + +## Testing + +Run the test suite: +```bash +npm test +``` + +This will test: +- Health endpoint +- Trailer fetching +- Cache functionality +- Rate limiting + +## Integration with Nuvio App + +Update your `TrailerService.ts` to use the local server: + +```typescript +// In src/services/trailerService.ts +export class TrailerService { + private static readonly BASE_URL = 'http://localhost:3001/trailer'; + + static async getTrailerUrl(title: string, year: number): Promise { + try { + // You'll need to find the YouTube URL first + const youtubeUrl = await this.findYouTubeTrailer(title, year); + if (!youtubeUrl) return null; + + const response = await fetch( + `${this.BASE_URL}?youtube_url=${encodeURIComponent(youtubeUrl)}&title=${encodeURIComponent(title)}&year=${year}` + ); + + if (!response.ok) return null; + + const data = await response.json(); + return data.url; + } catch (error) { + logger.error('TrailerService', 'Error fetching trailer:', error); + return null; + } + } +} +``` + +## Environment Variables + +- `PORT`: Server port (default: 3001) +- `NODE_ENV`: Environment (development/production) + +## Deployment + +### Netlify Functions +1. Create `netlify/functions/trailer.js` +2. Adapt the server code for serverless +3. Deploy to Netlify + +### Vercel +1. Create `api/trailer.js` +2. Adapt for Vercel's serverless functions +3. Deploy to Vercel + +### Railway/Render +1. Push to GitHub +2. Connect to Railway/Render +3. Set environment variables +4. Deploy + +## Troubleshooting + +**yt-dlp not found:** +- Ensure yt-dlp is installed and in PATH +- Try: `which yt-dlp` to verify installation + +**Rate limited:** +- Wait 1 minute or clear cache +- Check rate limiting settings + +**Trailer not found:** +- Verify YouTube URL is valid +- Check if video is available in your region +- Try different quality settings + +## License + +MIT diff --git a/trailer-server/netlify.toml b/trailer-server/netlify.toml new file mode 100644 index 0000000..2dfbb18 --- /dev/null +++ b/trailer-server/netlify.toml @@ -0,0 +1,27 @@ +[build] + command = "npm install" + functions = "netlify/functions" + publish = "public" + +[functions] + node_bundler = "esbuild" + +[[redirects]] + from = "/trailer" + to = "/.netlify/functions/trailer" + status = 200 + +[[redirects]] + from = "/health" + to = "/.netlify/functions/health" + status = 200 + +[[redirects]] + from = "/cache" + to = "/.netlify/functions/cache" + status = 200 + +[dev] + command = "npm run dev" + port = 3001 + publish = "public" diff --git a/trailer-server/netlify/functions/cache.js b/trailer-server/netlify/functions/cache.js new file mode 100644 index 0000000..a1486d6 --- /dev/null +++ b/trailer-server/netlify/functions/cache.js @@ -0,0 +1,44 @@ +exports.handler = async (event, context) => { + const headers = { + 'Access-Control-Allow-Origin': '*', + 'Access-Control-Allow-Headers': 'Content-Type', + 'Access-Control-Allow-Methods': 'GET, DELETE, OPTIONS', + }; + + if (event.httpMethod === 'OPTIONS') { + return { + statusCode: 200, + headers, + body: '', + }; + } + + if (event.httpMethod === 'GET') { + return { + statusCode: 200, + headers, + body: JSON.stringify({ + message: 'Cache endpoint available', + timestamp: new Date().toISOString(), + note: 'Cache is managed per function instance in Netlify' + }), + }; + } + + if (event.httpMethod === 'DELETE') { + return { + statusCode: 200, + headers, + body: JSON.stringify({ + message: 'Cache cleared (per function instance)', + timestamp: new Date().toISOString() + }), + }; + } + + return { + statusCode: 405, + headers, + body: JSON.stringify({ error: 'Method not allowed' }), + }; +}; diff --git a/trailer-server/netlify/functions/health.js b/trailer-server/netlify/functions/health.js new file mode 100644 index 0000000..424cc98 --- /dev/null +++ b/trailer-server/netlify/functions/health.js @@ -0,0 +1,26 @@ +exports.handler = async (event, context) => { + const headers = { + 'Access-Control-Allow-Origin': '*', + 'Access-Control-Allow-Headers': 'Content-Type', + 'Access-Control-Allow-Methods': 'GET, OPTIONS', + }; + + if (event.httpMethod === 'OPTIONS') { + return { + statusCode: 200, + headers, + body: '', + }; + } + + return { + statusCode: 200, + headers, + body: JSON.stringify({ + status: 'healthy', + timestamp: new Date().toISOString(), + environment: 'netlify', + function: 'health' + }), + }; +}; diff --git a/trailer-server/netlify/functions/trailer.js b/trailer-server/netlify/functions/trailer.js new file mode 100644 index 0000000..2310a93 --- /dev/null +++ b/trailer-server/netlify/functions/trailer.js @@ -0,0 +1,148 @@ +const { exec } = require('child_process'); +const { promisify } = require('util'); + +const execAsync = promisify(exec); + +// Simple in-memory cache for Netlify functions +const cache = new Map(); +const CACHE_TTL = 24 * 60 * 60 * 1000; // 24 hours + +exports.handler = async (event, context) => { + // Enable CORS + const headers = { + 'Access-Control-Allow-Origin': '*', + 'Access-Control-Allow-Headers': 'Content-Type', + 'Access-Control-Allow-Methods': 'GET, POST, OPTIONS', + }; + + // Handle preflight requests + if (event.httpMethod === 'OPTIONS') { + return { + statusCode: 200, + headers, + body: '', + }; + } + + try { + const { youtube_url, title, year } = event.queryStringParameters || {}; + + // Validate required parameters + if (!youtube_url) { + return { + statusCode: 400, + headers, + body: JSON.stringify({ + error: 'youtube_url parameter is required' + }), + }; + } + + // Create cache key + const cacheKey = `trailer_${title}_${year}_${youtube_url}`; + + // Check cache first + const cachedResult = cache.get(cacheKey); + if (cachedResult && (Date.now() - cachedResult.timestamp) < CACHE_TTL) { + console.log(`๐ŸŽฏ Cache hit for: ${title} (${year})`); + return { + statusCode: 200, + headers, + body: JSON.stringify(cachedResult.data), + }; + } + + console.log(`๐Ÿ” Fetching trailer for: ${title} (${year})`); + + // Use yt-dlp to get direct streaming URL + // Note: yt-dlp needs to be available in the Netlify environment + const command = `yt-dlp -f "best[height<=720][ext=mp4]/best[height<=720]/best" -g --no-playlist "${youtube_url}"`; + + const { stdout, stderr } = await execAsync(command, { + timeout: 30000, // 30 second timeout + maxBuffer: 1024 * 1024 // 1MB buffer + }); + + if (stderr && !stderr.includes('WARNING')) { + console.error('yt-dlp stderr:', stderr); + } + + const directUrl = stdout.trim(); + + if (!directUrl || !isValidUrl(directUrl)) { + console.log(`โŒ No valid URL found for: ${title} (${year})`); + return { + statusCode: 404, + headers, + body: JSON.stringify({ + error: 'Trailer not found or invalid URL' + }), + }; + } + + const result = { + url: directUrl, + title: title || 'Unknown', + year: year || 'Unknown', + source: 'youtube', + cached: false, + timestamp: new Date().toISOString() + }; + + // Cache the result + cache.set(cacheKey, { + data: result, + timestamp: Date.now() + }); + + console.log(`โœ… Successfully fetched trailer for: ${title} (${year})`); + + return { + statusCode: 200, + headers, + body: JSON.stringify(result), + }; + + } catch (error) { + console.error('Error fetching trailer:', error); + + if (error.code === 'TIMEOUT') { + return { + statusCode: 408, + headers, + body: JSON.stringify({ + error: 'Request timeout - video processing took too long' + }), + }; + } + + if (error.message.includes('not found') || error.message.includes('unavailable')) { + return { + statusCode: 404, + headers, + body: JSON.stringify({ + error: 'Trailer not found' + }), + }; + } + + return { + statusCode: 500, + headers, + body: JSON.stringify({ + error: 'Internal server error', + message: process.env.NODE_ENV === 'development' ? error.message : 'Something went wrong' + }), + }; + } +}; + +// Helper function to validate URLs +function isValidUrl(string) { + try { + new URL(string); + return true; + } catch (_) { + return false; + } +} diff --git a/trailer-server/package-lock.json b/trailer-server/package-lock.json new file mode 100644 index 0000000..5d52bbc --- /dev/null +++ b/trailer-server/package-lock.json @@ -0,0 +1,1317 @@ +{ + "name": "nuvio-trailer-server", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "nuvio-trailer-server", + "version": "1.0.0", + "license": "MIT", + "dependencies": { + "cors": "^2.8.5", + "express": "^4.18.2", + "helmet": "^7.1.0", + "node-cache": "^5.1.2", + "node-fetch": "^2.7.0", + "rate-limiter-flexible": "^2.4.1" + }, + "devDependencies": { + "nodemon": "^3.0.2" + }, + "engines": { + "node": ">=16.0.0" + } + }, + "node_modules/accepts": { + "version": "1.3.8", + "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz", + "integrity": "sha512-PYAthTa2m2VKxuvSD3DPC/Gy+U+sOA1LAuT8mkmRuvw+NACSaeXEQ+NHcVF7rONl6qcaxV3Uuemwawk+7+SJLw==", + "license": "MIT", + "dependencies": { + "mime-types": "~2.1.34", + "negotiator": "0.6.3" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/anymatch": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.3.tgz", + "integrity": "sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw==", + "dev": true, + "license": "ISC", + "dependencies": { + "normalize-path": "^3.0.0", + "picomatch": "^2.0.4" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/array-flatten": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", + "integrity": "sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg==", + "license": "MIT" + }, + "node_modules/balanced-match": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", + "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", + "dev": true, + "license": "MIT" + }, + "node_modules/binary-extensions": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.3.0.tgz", + "integrity": "sha512-Ceh+7ox5qe7LJuLHoY0feh3pHuUDHAcRUeyL2VYghZwfpkNIy/+8Ocg0a3UuSoYzavmylwuLWQOf3hl0jjMMIw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/body-parser": { + "version": "1.20.3", + "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.3.tgz", + "integrity": "sha512-7rAxByjUMqQ3/bHJy7D6OGXvx/MMc4IqBn/X0fcM1QUcAItpZrBEYhWGem+tzXH90c+G01ypMcYJBO9Y30203g==", + "license": "MIT", + "dependencies": { + "bytes": "3.1.2", + "content-type": "~1.0.5", + "debug": "2.6.9", + "depd": "2.0.0", + "destroy": "1.2.0", + "http-errors": "2.0.0", + "iconv-lite": "0.4.24", + "on-finished": "2.4.1", + "qs": "6.13.0", + "raw-body": "2.5.2", + "type-is": "~1.6.18", + "unpipe": "1.0.0" + }, + "engines": { + "node": ">= 0.8", + "npm": "1.2.8000 || >= 1.4.16" + } + }, + "node_modules/brace-expansion": { + "version": "1.1.12", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.12.tgz", + "integrity": "sha512-9T9UjW3r0UW5c1Q7GTwllptXwhvYmEzFhzMfZ9H7FQWt+uZePjZPjBP/W1ZEyZ1twGWom5/56TF4lPcqjnDHcg==", + "dev": true, + "license": "MIT", + "dependencies": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "node_modules/braces": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz", + "integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==", + "dev": true, + "license": "MIT", + "dependencies": { + "fill-range": "^7.1.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/bytes": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", + "integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/call-bind-apply-helpers": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz", + "integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/call-bound": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/call-bound/-/call-bound-1.0.4.tgz", + "integrity": "sha512-+ys997U96po4Kx/ABpBCqhA9EuxJaQWDQg7295H4hBphv3IZg0boBKuwYpt4YXp6MZ5AmZQnU/tyMTlRpaSejg==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.2", + "get-intrinsic": "^1.3.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/chokidar": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.6.0.tgz", + "integrity": "sha512-7VT13fmjotKpGipCW9JEQAusEPE+Ei8nl6/g4FBAmIm0GOOLMua9NDDo/DWp0ZAxCr3cPq5ZpBqmPAQgDda2Pw==", + "dev": true, + "license": "MIT", + "dependencies": { + "anymatch": "~3.1.2", + "braces": "~3.0.2", + "glob-parent": "~5.1.2", + "is-binary-path": "~2.1.0", + "is-glob": "~4.0.1", + "normalize-path": "~3.0.0", + "readdirp": "~3.6.0" + }, + "engines": { + "node": ">= 8.10.0" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + }, + "optionalDependencies": { + "fsevents": "~2.3.2" + } + }, + "node_modules/clone": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/clone/-/clone-2.1.2.tgz", + "integrity": "sha512-3Pe/CF1Nn94hyhIYpjtiLhdCoEoz0DqQ+988E9gmeEdQZlojxnOb74wctFyuwWQHzqyf9X7C7MG8juUpqBJT8w==", + "license": "MIT", + "engines": { + "node": ">=0.8" + } + }, + "node_modules/concat-map": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", + "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==", + "dev": true, + "license": "MIT" + }, + "node_modules/content-disposition": { + "version": "0.5.4", + "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.4.tgz", + "integrity": "sha512-FveZTNuGw04cxlAiWbzi6zTAL/lhehaWbTtgluJh4/E95DqMwTmha3KZN1aAWA8cFIhHzMZUvLevkw5Rqk+tSQ==", + "license": "MIT", + "dependencies": { + "safe-buffer": "5.2.1" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/content-type": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.5.tgz", + "integrity": "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/cookie": { + "version": "0.7.1", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.1.tgz", + "integrity": "sha512-6DnInpx7SJ2AK3+CTUE/ZM0vWTUboZCegxhC2xiIydHR9jNuTAASBrfEpHhiGOZw/nX51bHt6YQl8jsGo4y/0w==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/cookie-signature": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz", + "integrity": "sha512-QADzlaHc8icV8I7vbaJXJwod9HWYp8uCqf1xa4OfNu1T7JVxQIrUgOWtHdNDtPiywmFbiS12VjotIXLrKM3orQ==", + "license": "MIT" + }, + "node_modules/cors": { + "version": "2.8.5", + "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz", + "integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==", + "license": "MIT", + "dependencies": { + "object-assign": "^4", + "vary": "^1" + }, + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "license": "MIT", + "dependencies": { + "ms": "2.0.0" + } + }, + "node_modules/depd": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", + "integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/destroy": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.2.0.tgz", + "integrity": "sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg==", + "license": "MIT", + "engines": { + "node": ">= 0.8", + "npm": "1.2.8000 || >= 1.4.16" + } + }, + "node_modules/dunder-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", + "integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.1", + "es-errors": "^1.3.0", + "gopd": "^1.2.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/ee-first": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", + "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==", + "license": "MIT" + }, + "node_modules/encodeurl": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-2.0.0.tgz", + "integrity": "sha512-Q0n9HRi4m6JuGIV1eFlmvJB7ZEVxu93IrMyiMsGC0lrMJMWzRgx6WGquyfQgZVb31vhGgXnfmPNNXmxnOkRBrg==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/es-define-property": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz", + "integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-errors": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", + "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-object-atoms": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.1.tgz", + "integrity": "sha512-FGgH2h8zKNim9ljj7dankFPcICIK9Cp5bm+c2gQSYePhpaG5+esrLODihIorn+Pe6FGJzWhXQotPv73jTaldXA==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/escape-html": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", + "integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==", + "license": "MIT" + }, + "node_modules/etag": { + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", + "integrity": "sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/express": { + "version": "4.21.2", + "resolved": "https://registry.npmjs.org/express/-/express-4.21.2.tgz", + "integrity": "sha512-28HqgMZAmih1Czt9ny7qr6ek2qddF4FclbMzwhCREB6OFfH+rXAnuNCwo1/wFvrtbgsQDb4kSbX9de9lFbrXnA==", + "license": "MIT", + "dependencies": { + "accepts": "~1.3.8", + "array-flatten": "1.1.1", + "body-parser": "1.20.3", + "content-disposition": "0.5.4", + "content-type": "~1.0.4", + "cookie": "0.7.1", + "cookie-signature": "1.0.6", + "debug": "2.6.9", + "depd": "2.0.0", + "encodeurl": "~2.0.0", + "escape-html": "~1.0.3", + "etag": "~1.8.1", + "finalhandler": "1.3.1", + "fresh": "0.5.2", + "http-errors": "2.0.0", + "merge-descriptors": "1.0.3", + "methods": "~1.1.2", + "on-finished": "2.4.1", + "parseurl": "~1.3.3", + "path-to-regexp": "0.1.12", + "proxy-addr": "~2.0.7", + "qs": "6.13.0", + "range-parser": "~1.2.1", + "safe-buffer": "5.2.1", + "send": "0.19.0", + "serve-static": "1.16.2", + "setprototypeof": "1.2.0", + "statuses": "2.0.1", + "type-is": "~1.6.18", + "utils-merge": "1.0.1", + "vary": "~1.1.2" + }, + "engines": { + "node": ">= 0.10.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/fill-range": { + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz", + "integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==", + "dev": true, + "license": "MIT", + "dependencies": { + "to-regex-range": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/finalhandler": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.3.1.tgz", + "integrity": "sha512-6BN9trH7bp3qvnrRyzsBz+g3lZxTNZTbVO2EV1CS0WIcDbawYVdYvGflME/9QP0h0pYlCDBCTjYa9nZzMDpyxQ==", + "license": "MIT", + "dependencies": { + "debug": "2.6.9", + "encodeurl": "~2.0.0", + "escape-html": "~1.0.3", + "on-finished": "2.4.1", + "parseurl": "~1.3.3", + "statuses": "2.0.1", + "unpipe": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/forwarded": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz", + "integrity": "sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/fresh": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", + "integrity": "sha512-zJ2mQYM18rEFOudeV4GShTGIQ7RbzA7ozbU9I/XBpm7kqgMywgmylMwXHxZJmkVoYkna9d2pVXVXPdYTP9ej8Q==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/fsevents": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", + "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, + "node_modules/function-bind": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", + "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/get-intrinsic": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz", + "integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.2", + "es-define-property": "^1.0.1", + "es-errors": "^1.3.0", + "es-object-atoms": "^1.1.1", + "function-bind": "^1.1.2", + "get-proto": "^1.0.1", + "gopd": "^1.2.0", + "has-symbols": "^1.1.0", + "hasown": "^2.0.2", + "math-intrinsics": "^1.1.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/get-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz", + "integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==", + "license": "MIT", + "dependencies": { + "dunder-proto": "^1.0.1", + "es-object-atoms": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/glob-parent": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", + "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", + "dev": true, + "license": "ISC", + "dependencies": { + "is-glob": "^4.0.1" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/gopd": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz", + "integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has-flag": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", + "integrity": "sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=4" + } + }, + "node_modules/has-symbols": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz", + "integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/hasown": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz", + "integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==", + "license": "MIT", + "dependencies": { + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/helmet": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/helmet/-/helmet-7.2.0.tgz", + "integrity": "sha512-ZRiwvN089JfMXokizgqEPXsl2Guk094yExfoDXR0cBYWxtBbaSww/w+vT4WEJsBW2iTUi1GgZ6swmoug3Oy4Xw==", + "license": "MIT", + "engines": { + "node": ">=16.0.0" + } + }, + "node_modules/http-errors": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.0.tgz", + "integrity": "sha512-FtwrG/euBzaEjYeRqOgly7G0qviiXoJWnvEH2Z1plBdXgbyjv34pHTSb9zoeHMyDy33+DWy5Wt9Wo+TURtOYSQ==", + "license": "MIT", + "dependencies": { + "depd": "2.0.0", + "inherits": "2.0.4", + "setprototypeof": "1.2.0", + "statuses": "2.0.1", + "toidentifier": "1.0.1" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/iconv-lite": { + "version": "0.4.24", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", + "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==", + "license": "MIT", + "dependencies": { + "safer-buffer": ">= 2.1.2 < 3" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/ignore-by-default": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/ignore-by-default/-/ignore-by-default-1.0.1.tgz", + "integrity": "sha512-Ius2VYcGNk7T90CppJqcIkS5ooHUZyIQK+ClZfMfMNFEF9VSE73Fq+906u/CWu92x4gzZMWOwfFYckPObzdEbA==", + "dev": true, + "license": "ISC" + }, + "node_modules/inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", + "license": "ISC" + }, + "node_modules/ipaddr.js": { + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz", + "integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==", + "license": "MIT", + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/is-binary-path": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz", + "integrity": "sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==", + "dev": true, + "license": "MIT", + "dependencies": { + "binary-extensions": "^2.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/is-extglob": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", + "integrity": "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/is-glob": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz", + "integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==", + "dev": true, + "license": "MIT", + "dependencies": { + "is-extglob": "^2.1.1" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/is-number": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", + "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.12.0" + } + }, + "node_modules/math-intrinsics": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz", + "integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/media-typer": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", + "integrity": "sha512-dq+qelQ9akHpcOl/gUVRTxVIOkAJ1wR3QAvb4RsVjS8oVoFjDGTc679wJYmUmknUF5HwMLOgb5O+a3KxfWapPQ==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/merge-descriptors": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.3.tgz", + "integrity": "sha512-gaNvAS7TZ897/rVaZ0nMtAyxNyi/pdbjbAwUpFQpN70GqnVfOiXpeUUMKRBmzXaSQ8DdTX4/0ms62r2K+hE6mQ==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/methods": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz", + "integrity": "sha512-iclAHeNqNm68zFtnZ0e+1L2yUIdvzNoauKU4WBA3VvH/vPFieF7qfRlwUZU+DA9P9bPXIS90ulxoUoCH23sV2w==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz", + "integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==", + "license": "MIT", + "bin": { + "mime": "cli.js" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "license": "MIT", + "dependencies": { + "mime-db": "1.52.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/minimatch": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "dev": true, + "license": "ISC", + "dependencies": { + "brace-expansion": "^1.1.7" + }, + "engines": { + "node": "*" + } + }, + "node_modules/ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", + "license": "MIT" + }, + "node_modules/negotiator": { + "version": "0.6.3", + "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz", + "integrity": "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/node-cache": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/node-cache/-/node-cache-5.1.2.tgz", + "integrity": "sha512-t1QzWwnk4sjLWaQAS8CHgOJ+RAfmHpxFWmc36IWTiWHQfs0w5JDMBS1b1ZxQteo0vVVuWJvIUKHDkkeK7vIGCg==", + "license": "MIT", + "dependencies": { + "clone": "2.x" + }, + "engines": { + "node": ">= 8.0.0" + } + }, + "node_modules/node-fetch": { + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz", + "integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==", + "license": "MIT", + "dependencies": { + "whatwg-url": "^5.0.0" + }, + "engines": { + "node": "4.x || >=6.0.0" + }, + "peerDependencies": { + "encoding": "^0.1.0" + }, + "peerDependenciesMeta": { + "encoding": { + "optional": true + } + } + }, + "node_modules/nodemon": { + "version": "3.1.10", + "resolved": "https://registry.npmjs.org/nodemon/-/nodemon-3.1.10.tgz", + "integrity": "sha512-WDjw3pJ0/0jMFmyNDp3gvY2YizjLmmOUQo6DEBY+JgdvW/yQ9mEeSw6H5ythl5Ny2ytb7f9C2nIbjSxMNzbJXw==", + "dev": true, + "license": "MIT", + "dependencies": { + "chokidar": "^3.5.2", + "debug": "^4", + "ignore-by-default": "^1.0.1", + "minimatch": "^3.1.2", + "pstree.remy": "^1.1.8", + "semver": "^7.5.3", + "simple-update-notifier": "^2.0.0", + "supports-color": "^5.5.0", + "touch": "^3.1.0", + "undefsafe": "^2.0.5" + }, + "bin": { + "nodemon": "bin/nodemon.js" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/nodemon" + } + }, + "node_modules/nodemon/node_modules/debug": { + "version": "4.4.1", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.1.tgz", + "integrity": "sha512-KcKCqiftBJcZr++7ykoDIEwSa3XWowTfNPo92BYxjXiyYEVrUQh2aLyhxBCwww+heortUFxEJYcRzosstTEBYQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "ms": "^2.1.3" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/nodemon/node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "dev": true, + "license": "MIT" + }, + "node_modules/normalize-path": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", + "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==", + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/object-inspect": { + "version": "1.13.4", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.4.tgz", + "integrity": "sha512-W67iLl4J2EXEGTbfeHCffrjDfitvLANg0UlX3wFUUSTx92KXRFegMHUVgSqE+wvhAbi4WqjGg9czysTV2Epbew==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/on-finished": { + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz", + "integrity": "sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==", + "license": "MIT", + "dependencies": { + "ee-first": "1.1.1" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/parseurl": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", + "integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/path-to-regexp": { + "version": "0.1.12", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.12.tgz", + "integrity": "sha512-RA1GjUVMnvYFxuqovrEqZoxxW5NUZqbwKtYz/Tt7nXerk0LbLblQmrsgdeOxV5SFHf0UDggjS/bSeOZwt1pmEQ==", + "license": "MIT" + }, + "node_modules/picomatch": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", + "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8.6" + }, + "funding": { + "url": "https://github.com/sponsors/jonschlinkert" + } + }, + "node_modules/proxy-addr": { + "version": "2.0.7", + "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz", + "integrity": "sha512-llQsMLSUDUPT44jdrU/O37qlnifitDP+ZwrmmZcoSKyLKvtZxpyV0n2/bD/N4tBAAZ/gJEdZU7KMraoK1+XYAg==", + "license": "MIT", + "dependencies": { + "forwarded": "0.2.0", + "ipaddr.js": "1.9.1" + }, + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/pstree.remy": { + "version": "1.1.8", + "resolved": "https://registry.npmjs.org/pstree.remy/-/pstree.remy-1.1.8.tgz", + "integrity": "sha512-77DZwxQmxKnu3aR542U+X8FypNzbfJ+C5XQDk3uWjWxn6151aIMGthWYRXTqT1E5oJvg+ljaa2OJi+VfvCOQ8w==", + "dev": true, + "license": "MIT" + }, + "node_modules/qs": { + "version": "6.13.0", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.13.0.tgz", + "integrity": "sha512-+38qI9SOr8tfZ4QmJNplMUxqjbe7LKvvZgWdExBOmd+egZTtjLB67Gu0HRX3u/XOq7UU2Nx6nsjvS16Z9uwfpg==", + "license": "BSD-3-Clause", + "dependencies": { + "side-channel": "^1.0.6" + }, + "engines": { + "node": ">=0.6" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/range-parser": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz", + "integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/rate-limiter-flexible": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/rate-limiter-flexible/-/rate-limiter-flexible-2.4.2.tgz", + "integrity": "sha512-rMATGGOdO1suFyf/mI5LYhts71g1sbdhmd6YvdiXO2gJnd42Tt6QS4JUKJKSWVVkMtBacm6l40FR7Trjo6Iruw==", + "license": "ISC" + }, + "node_modules/raw-body": { + "version": "2.5.2", + "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.2.tgz", + "integrity": "sha512-8zGqypfENjCIqGhgXToC8aB2r7YrBX+AQAfIPs/Mlk+BtPTztOvTS01NRW/3Eh60J+a48lt8qsCzirQ6loCVfA==", + "license": "MIT", + "dependencies": { + "bytes": "3.1.2", + "http-errors": "2.0.0", + "iconv-lite": "0.4.24", + "unpipe": "1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/readdirp": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz", + "integrity": "sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==", + "dev": true, + "license": "MIT", + "dependencies": { + "picomatch": "^2.2.1" + }, + "engines": { + "node": ">=8.10.0" + } + }, + "node_modules/safe-buffer": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "MIT" + }, + "node_modules/safer-buffer": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", + "license": "MIT" + }, + "node_modules/semver": { + "version": "7.7.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.2.tgz", + "integrity": "sha512-RF0Fw+rO5AMf9MAyaRXI4AV0Ulj5lMHqVxxdSgiVbixSCXoEmmX/jk0CuJw4+3SqroYO9VoUh+HcuJivvtJemA==", + "dev": true, + "license": "ISC", + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/send": { + "version": "0.19.0", + "resolved": "https://registry.npmjs.org/send/-/send-0.19.0.tgz", + "integrity": "sha512-dW41u5VfLXu8SJh5bwRmyYUbAoSB3c9uQh6L8h/KtsFREPWpbX1lrljJo186Jc4nmci/sGUZ9a0a0J2zgfq2hw==", + "license": "MIT", + "dependencies": { + "debug": "2.6.9", + "depd": "2.0.0", + "destroy": "1.2.0", + "encodeurl": "~1.0.2", + "escape-html": "~1.0.3", + "etag": "~1.8.1", + "fresh": "0.5.2", + "http-errors": "2.0.0", + "mime": "1.6.0", + "ms": "2.1.3", + "on-finished": "2.4.1", + "range-parser": "~1.2.1", + "statuses": "2.0.1" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/send/node_modules/encodeurl": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz", + "integrity": "sha512-TPJXq8JqFaVYm2CWmPvnP2Iyo4ZSM7/QKcSmuMLDObfpH5fi7RUGmd/rTDf+rut/saiDiQEeVTNgAmJEdAOx0w==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/send/node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "license": "MIT" + }, + "node_modules/serve-static": { + "version": "1.16.2", + "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.16.2.tgz", + "integrity": "sha512-VqpjJZKadQB/PEbEwvFdO43Ax5dFBZ2UECszz8bQ7pi7wt//PWe1P6MN7eCnjsatYtBT6EuiClbjSWP2WrIoTw==", + "license": "MIT", + "dependencies": { + "encodeurl": "~2.0.0", + "escape-html": "~1.0.3", + "parseurl": "~1.3.3", + "send": "0.19.0" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/setprototypeof": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz", + "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==", + "license": "ISC" + }, + "node_modules/side-channel": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.1.0.tgz", + "integrity": "sha512-ZX99e6tRweoUXqR+VBrslhda51Nh5MTQwou5tnUDgbtyM0dBgmhEDtWGP/xbKn6hqfPRHujUNwz5fy/wbbhnpw==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "object-inspect": "^1.13.3", + "side-channel-list": "^1.0.0", + "side-channel-map": "^1.0.1", + "side-channel-weakmap": "^1.0.2" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-list": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/side-channel-list/-/side-channel-list-1.0.0.tgz", + "integrity": "sha512-FCLHtRD/gnpCiCHEiJLOwdmFP+wzCmDEkc9y7NsYxeF4u7Btsn1ZuwgwJGxImImHicJArLP4R0yX4c2KCrMrTA==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "object-inspect": "^1.13.3" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-map": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/side-channel-map/-/side-channel-map-1.0.1.tgz", + "integrity": "sha512-VCjCNfgMsby3tTdo02nbjtM/ewra6jPHmpThenkTYh8pG9ucZ/1P8So4u4FGBek/BjpOVsDCMoLA/iuBKIFXRA==", + "license": "MIT", + "dependencies": { + "call-bound": "^1.0.2", + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.5", + "object-inspect": "^1.13.3" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-weakmap": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/side-channel-weakmap/-/side-channel-weakmap-1.0.2.tgz", + "integrity": "sha512-WPS/HvHQTYnHisLo9McqBHOJk2FkHO/tlpvldyrnem4aeQp4hai3gythswg6p01oSoTl58rcpiFAjF2br2Ak2A==", + "license": "MIT", + "dependencies": { + "call-bound": "^1.0.2", + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.5", + "object-inspect": "^1.13.3", + "side-channel-map": "^1.0.1" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/simple-update-notifier": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/simple-update-notifier/-/simple-update-notifier-2.0.0.tgz", + "integrity": "sha512-a2B9Y0KlNXl9u/vsW6sTIu9vGEpfKu2wRV6l1H3XEas/0gUIzGzBoP/IouTcUQbm9JWZLH3COxyn03TYlFax6w==", + "dev": true, + "license": "MIT", + "dependencies": { + "semver": "^7.5.3" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/statuses": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz", + "integrity": "sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/supports-color": { + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", + "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", + "dev": true, + "license": "MIT", + "dependencies": { + "has-flag": "^3.0.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/to-regex-range": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", + "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "is-number": "^7.0.0" + }, + "engines": { + "node": ">=8.0" + } + }, + "node_modules/toidentifier": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz", + "integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==", + "license": "MIT", + "engines": { + "node": ">=0.6" + } + }, + "node_modules/touch": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/touch/-/touch-3.1.1.tgz", + "integrity": "sha512-r0eojU4bI8MnHr8c5bNo7lJDdI2qXlWWJk6a9EAFG7vbhTjElYhBVS3/miuE0uOuoLdb8Mc/rVfsmm6eo5o9GA==", + "dev": true, + "license": "ISC", + "bin": { + "nodetouch": "bin/nodetouch.js" + } + }, + "node_modules/tr46": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", + "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==", + "license": "MIT" + }, + "node_modules/type-is": { + "version": "1.6.18", + "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz", + "integrity": "sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==", + "license": "MIT", + "dependencies": { + "media-typer": "0.3.0", + "mime-types": "~2.1.24" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/undefsafe": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/undefsafe/-/undefsafe-2.0.5.tgz", + "integrity": "sha512-WxONCrssBM8TSPRqN5EmsjVrsv4A8X12J4ArBiiayv3DyyG3ZlIg6yysuuSYdZsVz3TKcTg2fd//Ujd4CHV1iA==", + "dev": true, + "license": "MIT" + }, + "node_modules/unpipe": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", + "integrity": "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/utils-merge": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz", + "integrity": "sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==", + "license": "MIT", + "engines": { + "node": ">= 0.4.0" + } + }, + "node_modules/vary": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", + "integrity": "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/webidl-conversions": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", + "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==", + "license": "BSD-2-Clause" + }, + "node_modules/whatwg-url": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", + "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", + "license": "MIT", + "dependencies": { + "tr46": "~0.0.3", + "webidl-conversions": "^3.0.0" + } + } + } +} diff --git a/trailer-server/package.json b/trailer-server/package.json new file mode 100644 index 0000000..bc2370b --- /dev/null +++ b/trailer-server/package.json @@ -0,0 +1,28 @@ +{ + "name": "nuvio-trailer-server", + "version": "1.0.0", + "description": "Trailer server for Nuvio app using yt-dlp", + "main": "server.js", + "scripts": { + "start": "node server.js", + "dev": "nodemon server.js", + "test": "node test.js" + }, + "dependencies": { + "express": "^4.18.2", + "cors": "^2.8.5", + "helmet": "^7.1.0", + "rate-limiter-flexible": "^2.4.1", + "node-cache": "^5.1.2", + "node-fetch": "^2.7.0" + }, + "devDependencies": { + "nodemon": "^3.0.2" + }, + "engines": { + "node": ">=16.0.0" + }, + "keywords": ["trailer", "yt-dlp", "streaming", "nuvio"], + "author": "Nuvio Team", + "license": "MIT" +} diff --git a/trailer-server/public/index.html b/trailer-server/public/index.html new file mode 100644 index 0000000..d68d268 --- /dev/null +++ b/trailer-server/public/index.html @@ -0,0 +1,105 @@ + + + + + + Nuvio Trailer Server + + + +
+

๐ŸŽฌ Nuvio Trailer Server

+ +
+ โœ… Server is running and ready! +
+ +
+
GET
+
/health
+
Health check endpoint to verify server status
+
+ +
+
GET
+
/trailer?youtube_url=YOUTUBE_URL&title=TITLE&year=YEAR
+
Convert YouTube trailer URL to direct streaming link using yt-dlp
+
+ +
+
GET
+
/cache
+
View cached trailers (for debugging)
+
+ +
+
DELETE
+
/cache
+
Clear all cached trailers
+
+ + +
+ + diff --git a/trailer-server/server.js b/trailer-server/server.js new file mode 100644 index 0000000..06fbc47 --- /dev/null +++ b/trailer-server/server.js @@ -0,0 +1,288 @@ +const express = require('express'); +const cors = require('cors'); +const helmet = require('helmet'); +const { RateLimiterMemory } = require('rate-limiter-flexible'); +const NodeCache = require('node-cache'); +const { exec } = require('child_process'); +const { promisify } = require('util'); +const { searchYouTubeTrailer } = require('./youtube-search'); + +const execAsync = promisify(exec); + +const app = express(); +const PORT = process.env.PORT || 3001; + +// Cache configuration - cache trailer URLs for 24 hours +const trailerCache = new NodeCache({ + stdTTL: 24 * 60 * 60, // 24 hours + checkperiod: 60 * 60 // Check for expired keys every hour +}); + +// Rate limiting - 10 requests per minute per IP +const rateLimiter = new RateLimiterMemory({ + keyPrefix: 'trailer_api', + points: 10, // Number of requests + duration: 60, // Per 60 seconds +}); + +// Middleware +app.use(helmet()); +app.use(cors()); +app.use(express.json()); + +// Rate limiting middleware +const rateLimiterMiddleware = async (req, res, next) => { + try { + await rateLimiter.consume(req.ip); + next(); + } catch (rejRes) { + res.status(429).json({ + error: 'Too many requests', + retryAfter: Math.round(rejRes.msBeforeNext / 1000) || 1 + }); + } +}; + +// Health check endpoint +app.get('/health', (req, res) => { + res.json({ + status: 'healthy', + timestamp: new Date().toISOString(), + cache: { + keys: trailerCache.keys().length, + stats: trailerCache.getStats() + } + }); +}); + +// Auto-search trailer endpoint (no YouTube URL needed) +app.get('/search-trailer', rateLimiterMiddleware, async (req, res) => { + try { + const { title, year } = req.query; + + // Validate required parameters + if (!title) { + return res.status(400).json({ + error: 'title parameter is required' + }); + } + + // Create cache key + const cacheKey = `search_${title}_${year}`; + + // Check cache first + const cachedResult = trailerCache.get(cacheKey); + if (cachedResult) { + console.log(`๐ŸŽฏ Cache hit for search: ${title} (${year})`); + return res.json(cachedResult); + } + + console.log(`๐Ÿ” Auto-searching trailer for: ${title} (${year})`); + + // Search for YouTube trailer + const searchQuery = `${title} ${year || ''} official trailer`.trim(); + const youtubeUrl = await searchYouTubeTrailer(searchQuery); + + if (!youtubeUrl) { + console.log(`โŒ No trailer found for: ${title} (${year})`); + return res.status(404).json({ + error: 'Trailer not found' + }); + } + + // Now get the direct streaming URL + const command = `yt-dlp -f "best[height<=720][ext=mp4]/best[height<=720]/best" -g --no-playlist "${youtubeUrl}"`; + + const { stdout, stderr } = await execAsync(command, { + timeout: 30000, + maxBuffer: 1024 * 1024 + }); + + if (stderr && !stderr.includes('WARNING')) { + console.error('yt-dlp stderr:', stderr); + } + + const directUrl = stdout.trim(); + + if (!directUrl || !isValidUrl(directUrl)) { + console.log(`โŒ No valid streaming URL found for: ${title} (${year})`); + return res.status(404).json({ + error: 'Trailer not found or invalid URL' + }); + } + + const result = { + url: directUrl, + title: title || 'Unknown', + year: year || 'Unknown', + source: 'youtube', + youtubeUrl: youtubeUrl, + cached: false, + timestamp: new Date().toISOString() + }; + + // Cache the result + trailerCache.set(cacheKey, result); + console.log(`โœ… Successfully found and processed trailer for: ${title} (${year})`); + + res.json(result); + + } catch (error) { + console.error('Error in auto-search:', error); + + if (error.code === 'TIMEOUT') { + return res.status(408).json({ + error: 'Request timeout - video processing took too long' + }); + } + + res.status(500).json({ + error: 'Internal server error', + message: process.env.NODE_ENV === 'development' ? error.message : 'Something went wrong' + }); + } +}); + +// Main trailer endpoint +app.get('/trailer', rateLimiterMiddleware, async (req, res) => { + try { + const { youtube_url, title, year } = req.query; + + // Validate required parameters + if (!youtube_url) { + return res.status(400).json({ + error: 'youtube_url parameter is required' + }); + } + + // Create cache key + const cacheKey = `trailer_${title}_${year}_${youtube_url}`; + + // Check cache first + const cachedResult = trailerCache.get(cacheKey); + if (cachedResult) { + console.log(`๐ŸŽฏ Cache hit for: ${title} (${year})`); + return res.json(cachedResult); + } + + console.log(`๐Ÿ” Fetching trailer for: ${title} (${year})`); + + // Use yt-dlp to get direct streaming URL + // Prefer MP4 format, max 720p for better compatibility + const command = `yt-dlp -f "best[height<=720][ext=mp4]/best[height<=720]/best" -g --no-playlist "${youtube_url}"`; + + const { stdout, stderr } = await execAsync(command, { + timeout: 30000, // 30 second timeout + maxBuffer: 1024 * 1024 // 1MB buffer + }); + + if (stderr && !stderr.includes('WARNING')) { + console.error('yt-dlp stderr:', stderr); + } + + const directUrl = stdout.trim(); + + if (!directUrl || !isValidUrl(directUrl)) { + console.log(`โŒ No valid URL found for: ${title} (${year})`); + return res.status(404).json({ + error: 'Trailer not found or invalid URL' + }); + } + + const result = { + url: directUrl, + title: title || 'Unknown', + year: year || 'Unknown', + source: 'youtube', + cached: false, + timestamp: new Date().toISOString() + }; + + // Cache the result + trailerCache.set(cacheKey, result); + console.log(`โœ… Successfully fetched trailer for: ${title} (${year})`); + + res.json(result); + + } catch (error) { + console.error('Error fetching trailer:', error); + + if (error.code === 'TIMEOUT') { + return res.status(408).json({ + error: 'Request timeout - video processing took too long' + }); + } + + if (error.message.includes('not found') || error.message.includes('unavailable')) { + return res.status(404).json({ + error: 'Trailer not found' + }); + } + + res.status(500).json({ + error: 'Internal server error', + message: process.env.NODE_ENV === 'development' ? error.message : 'Something went wrong' + }); + } +}); + +// Get cached trailers (for debugging) +app.get('/cache', (req, res) => { + const keys = trailerCache.keys(); + const cacheData = {}; + + keys.forEach(key => { + cacheData[key] = trailerCache.get(key); + }); + + res.json({ + count: keys.length, + keys: keys, + data: cacheData + }); +}); + +// Clear cache endpoint (for maintenance) +app.delete('/cache', (req, res) => { + trailerCache.flushAll(); + res.json({ + message: 'Cache cleared successfully', + timestamp: new Date().toISOString() + }); +}); + +// Helper function to validate URLs +function isValidUrl(string) { + try { + new URL(string); + return true; + } catch (_) { + return false; + } +} + +// Error handling middleware +app.use((error, req, res, next) => { + console.error('Unhandled error:', error); + res.status(500).json({ + error: 'Internal server error' + }); +}); + +// 404 handler +app.use('*', (req, res) => { + res.status(404).json({ + error: 'Endpoint not found', + availableEndpoints: ['/health', '/trailer', '/cache'] + }); +}); + +// Start server +app.listen(PORT, () => { + console.log(`๐Ÿš€ Trailer server running on port ${PORT}`); + console.log(`๐Ÿ“Š Health check: http://localhost:${PORT}/health`); + console.log(`๐ŸŽฌ Trailer endpoint: http://localhost:${PORT}/trailer`); + console.log(`๐Ÿ’พ Cache endpoint: http://localhost:${PORT}/cache`); +}); + +module.exports = app; diff --git a/trailer-server/test.js b/trailer-server/test.js new file mode 100644 index 0000000..b68fce4 --- /dev/null +++ b/trailer-server/test.js @@ -0,0 +1,87 @@ +const fetch = require('node-fetch'); + +const SERVER_URL = 'http://localhost:3001'; + +async function testServer() { + console.log('๐Ÿงช Testing Trailer Server...\n'); + + // Test 1: Health check + console.log('1๏ธโƒฃ Testing health endpoint...'); + try { + const healthResponse = await fetch(`${SERVER_URL}/health`); + const healthData = await healthResponse.json(); + console.log('โœ… Health check passed:', healthData.status); + console.log('๐Ÿ“Š Cache stats:', healthData.cache); + } catch (error) { + console.log('โŒ Health check failed:', error.message); + } + + console.log('\n'); + + // Test 2: Trailer endpoint with sample YouTube URL + console.log('2๏ธโƒฃ Testing trailer endpoint...'); + const testTrailer = { + youtube_url: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ', // Rick Roll for testing + title: 'Test Movie', + year: '2023' + }; + + try { + const trailerResponse = await fetch( + `${SERVER_URL}/trailer?${new URLSearchParams(testTrailer)}` + ); + + if (trailerResponse.ok) { + const trailerData = await trailerResponse.json(); + console.log('โœ… Trailer fetch successful!'); + console.log('๐Ÿ“น Title:', trailerData.title); + console.log('๐Ÿ“… Year:', trailerData.year); + console.log('๐Ÿ”— URL:', trailerData.url.substring(0, 50) + '...'); + console.log('โฐ Timestamp:', trailerData.timestamp); + } else { + const errorData = await trailerResponse.json(); + console.log('โŒ Trailer fetch failed:', errorData.error); + } + } catch (error) { + console.log('โŒ Trailer test failed:', error.message); + } + + console.log('\n'); + + // Test 3: Cache endpoint + console.log('3๏ธโƒฃ Testing cache endpoint...'); + try { + const cacheResponse = await fetch(`${SERVER_URL}/cache`); + const cacheData = await cacheResponse.json(); + console.log('โœ… Cache endpoint working'); + console.log('๐Ÿ“ฆ Cached items:', cacheData.count); + } catch (error) { + console.log('โŒ Cache test failed:', error.message); + } + + console.log('\n'); + + // Test 4: Rate limiting + console.log('4๏ธโƒฃ Testing rate limiting...'); + try { + const promises = Array(12).fill().map(() => + fetch(`${SERVER_URL}/trailer?youtube_url=https://www.youtube.com/watch?v=dQw4w9WgXcQ&title=Test&year=2023`) + ); + + const responses = await Promise.all(promises); + const rateLimited = responses.some(r => r.status === 429); + + if (rateLimited) { + console.log('โœ… Rate limiting working correctly'); + } else { + console.log('โš ๏ธ Rate limiting may not be working'); + } + } catch (error) { + console.log('โŒ Rate limiting test failed:', error.message); + } + + console.log('\n๐Ÿ Testing complete!'); +} + +// Run tests +testServer().catch(console.error); diff --git a/trailer-server/youtube-search.js b/trailer-server/youtube-search.js new file mode 100644 index 0000000..de80eb3 --- /dev/null +++ b/trailer-server/youtube-search.js @@ -0,0 +1,58 @@ +const { exec } = require('child_process'); +const { promisify } = require('util'); + +const execAsync = promisify(exec); + +/** + * Search YouTube for trailers using yt-dlp search functionality + * @param {string} query - Search query (e.g., "Avengers Endgame 2019 official trailer") + * @returns {Promise} - YouTube URL or null if not found + */ +async function searchYouTubeTrailer(query) { + try { + console.log(`๐Ÿ” Searching YouTube for: ${query}`); + + // Use yt-dlp to search YouTube and get the YouTube URL (not direct streaming URL) + // --get-url returns direct streaming URLs, we need --get-id to get YouTube video ID + const command = `yt-dlp --get-id --no-playlist "ytsearch1:${query}"`; + + const { stdout, stderr } = await execAsync(command, { + timeout: 15000, // 15 second timeout + maxBuffer: 1024 * 1024 // 1MB buffer + }); + + if (stderr && !stderr.includes('WARNING')) { + console.error('yt-dlp search stderr:', stderr); + } + + const videoId = stdout.trim(); + + if (!videoId || videoId.length !== 11) { + console.log(`โŒ No valid YouTube video ID found for: ${query}`); + return null; + } + + const youtubeUrl = `https://www.youtube.com/watch?v=${videoId}`; + console.log(`โœ… Found YouTube URL: ${youtubeUrl}`); + return youtubeUrl; + } catch (error) { + console.error('Error searching YouTube:', error); + return null; + } +} + +/** + * Validate if the URL is a valid YouTube URL + * @param {string} url - URL to validate + * @returns {boolean} - True if valid YouTube URL + */ +function isValidYouTubeUrl(url) { + try { + const urlObj = new URL(url); + return urlObj.hostname.includes('youtube.com') || urlObj.hostname.includes('youtu.be'); + } catch { + return false; + } +} + +module.exports = { searchYouTubeTrailer };