mirror of
https://github.com/tapframe/NuvioStreaming.git
synced 2026-01-11 20:10:25 +00:00
| .. | ||
| netlify/functions | ||
| public | ||
| DEPLOYMENT.md | ||
| netlify.toml | ||
| package-lock.json | ||
| package.json | ||
| README.md | ||
| server.js | ||
| test.js | ||
| youtube-search.js | ||
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:
brew install yt-dlp
Linux:
pip install yt-dlp
Windows:
pip install yt-dlp
Installation
- Clone/Navigate to the server directory:
cd trailer-server
- Install dependencies:
npm install
- Start the server:
# 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
curl http://localhost:3001/health
GET /trailer
Get direct streaming URL for a YouTube trailer
Parameters:
youtube_url(required): YouTube URL of the trailertitle(optional): Movie/show titleyear(optional): Release year
Example:
curl "http://localhost:3001/trailer?youtube_url=https://www.youtube.com/watch?v=example&title=Avengers&year=2019"
Response:
{
"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:
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:
// 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<string | null> {
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
- Create
netlify/functions/trailer.js - Adapt the server code for serverless
- Deploy to Netlify
Vercel
- Create
api/trailer.js - Adapt for Vercel's serverless functions
- Deploy to Vercel
Railway/Render
- Push to GitHub
- Connect to Railway/Render
- Set environment variables
- Deploy
Troubleshooting
yt-dlp not found:
- Ensure yt-dlp is installed and in PATH
- Try:
which yt-dlpto 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