Spaces:
Paused
Paused
Create streams.js
Browse files123456789101112131415161718192021222324252627282930const express = require('express');const log = require('../helpers/logger');const { fetchStreamingLinks } = require('../tmdb');
const router = express.Router();
router.get('/streams/:type/:id', async (req, res) => { const { type, id } = req.params; // `type` can be "movie" or "tv" const region = req.query.region || 'US'; // Default to US region const tmdbApiKey = process.env.TMDB_API_KEY;
try { log.info(`Fetching streams for ${type} ID ${id}, region: ${region}`);
const streams = await fetchStreamingLinks(id, type, tmdbApiKey, region);
res.json({ streams: streams.map(provider => ({ title: provider.provider_name, url: provider.link, isFree: provider.is_free || false, })), }); } catch (error) { log.error(`Error fetching streams for ${type} ID ${id}: ${error.message}`); res.status(500).send('Error fetching streams.'); }});
module.exports = router;src/routes/streams.jsAdded+30