mikmc commited on
Commit
085d0e8
·
verified ·
1 Parent(s): bf3e624

Create streams.js

Browse files
Files changed (1) hide show
  1. src/routes/streams.js +30 -0
src/routes/streams.js ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const express = require('express');
2
+ const log = require('../helpers/logger');
3
+ const { fetchStreamingLinks } = require('../tmdb');
4
+
5
+ const router = express.Router();
6
+
7
+ router.get('/streams/:type/:id', async (req, res) => {
8
+ const { type, id } = req.params; // `type` can be "movie" or "tv"
9
+ const region = req.query.region || 'US'; // Default to US region
10
+ const tmdbApiKey = process.env.TMDB_API_KEY;
11
+
12
+ try {
13
+ log.info(`Fetching streams for ${type} ID ${id}, region: ${region}`);
14
+
15
+ const streams = await fetchStreamingLinks(id, type, tmdbApiKey, region);
16
+
17
+ res.json({
18
+ streams: streams.map(provider => ({
19
+ title: provider.provider_name,
20
+ url: provider.link,
21
+ isFree: provider.is_free || false,
22
+ })),
23
+ });
24
+ } catch (error) {
25
+ log.error(`Error fetching streams for ${type} ID ${id}: ${error.message}`);
26
+ res.status(500).send('Error fetching streams.');
27
+ }
28
+ });
29
+
30
+ module.exports = router;