Upload 6 files
Browse filesFiles changed (6)
- .envAdded+33
- cache/catalog_cache.json
- cache/meta_cache.json
- index.js+60-40
- package-lock.json+19-2
- package.json+8-6
123456789101112131415161718192021222324252627282930313233# TMDB API Key
TMDB_API_KEY=f051e7366c6105ad4f9aafe4733d9dae
# TMDB Base URL
TMDB_BASE_URL=https://api.themoviedb.org/3
# Cache Directory
CACHE_DIR=cache
# Cache Files
CATALOG_CACHE_FILE=cache/catalog_cache.json
META_CACHE_FILE=cache/meta_cache.json
# Filtering Configuration
START_YEAR=2015
END_YEAR=2024
MIN_SCORE=5
NUM_PAGES=25
# Genres to exclude (comma-separated)
EXCLUDED_GENRES=16,10402
# Genres to include (comma-separated)
INCLUDED_GENRES=28,12,35,14
# Genres to include with OR combinations (pipe-separated)
INCLUDED_GENRES_OR=28|12|35|14
# Language
LANGUAGE=en
# Genre Combinations (pipe-separated)
GENRE_COMBINATIONS=28,12|28,35|28,14|14,12|14,353 unmodified lines456788910111213131415141516171 unmodified line192021232425222324252627282930313233343536373839404142434445464748324934505136375253545540415643575859606141 unmodified lines1031041059192939495106107108109110991001011111121131141151031161171181191071201211091101111121221231241251261271281151161171181291301311321331341351361371381391401411421431221441451461471 unmodified line1491501511301521531331541551561571 unmodified line15916016114116216316416516616714716816917028 unmodified lines19920020118220220320420530 unmodified lines23623723821923924024124231 unmodified lines2742752762572772782792803 unmodified linesconst path = require('path');const winston = require('winston');const schedule = require('node-schedule');require('dotenv').config(); // Load environment variables
// Winston logger configuration// Logger configurationconst logger = winston.createLogger({ level: 'debug', format: winston.format.combine( winston.format.timestamp(), winston.format.printf(({ level, message, timestamp }) => { return `${timestamp} ${level}: ${message}`; }) winston.format.printf(({ level, message, timestamp }) => `${timestamp} ${level}: ${message}`) ), transports: [ new winston.transports.Console(),1 unmodified line ]});
const TMDB_API_KEY = 'f051e7366c6105ad4f9aafe4733d9dae';const TMDB_BASE_URL = 'https://api.themoviedb.org/3';const CACHE_DIR = path.join(__dirname, 'cache');const TMDB_API_KEY = process.env.TMDB_API_KEY;const TMDB_BASE_URL = process.env.TMDB_BASE_URL;const CACHE_DIR = path.join(__dirname, process.env.CACHE_DIR);const CATALOG_CACHE_FILE = path.join(CACHE_DIR, 'catalog_cache.json');const META_CACHE_FILE = path.join(CACHE_DIR, 'meta_cache.json');
const START_YEAR = process.env.START_YEAR || 2015;const END_YEAR = process.env.END_YEAR || 2024;const MIN_SCORE = process.env.MIN_SCORE || 4;const NUM_PAGES = process.env.NUM_PAGES || 5;const EXCLUDED_GENRES = process.env.EXCLUDED_GENRES || '16,10402';const INCLUDED_GENRES = process.env.INCLUDED_GENRES || '28,12,35,14'; // Single genresconst INCLUDED_GENRES_OR = process.env.INCLUDED_GENRES_OR || '28|12|35|14'; // OR combinationsconst LANGUAGE = process.env.LANGUAGE || 'en';
// Genre Combinations for queryingconst GENRE_COMBINATIONS = [ '28,12', // Action, Adventure '28,35', // Action, Comedy '28,14', // Action, Fantasy '14,12', // Fantasy, Adventure '14,35' // Fantasy, Comedy];
let catalogCache = {};let metaCache = {};
// Manifestconst manifest = { id: 'org.stremio.horror-movies', id: 'org.stremio.action-addon', version: '1.0.0', name: 'Horror Movies Since 2015', description: 'Stremio Add-on to showcase Horror movies from the year 2015 onward', name: 'Action Varied', description: 'Stremio Add-on to showcase movies with configurable filters', catalogs: [ { id: 'horror-movie-catalog', name: 'Horror Movies', type: 'Easynews', pageSize: 25, id: 'action-movies-catalog', name: 'Action Varied', extra: [{ name: 'search', isRequired: false }] } ],41 unmodified lines }}
async function fetchHorrorMovies() { const pageSize = 20; // Number of results per page const maxPages = 40; // Limit to prevent too many requests const startYear = 2021;
async function fetchMoviesForCombination(genreCombination) { let page = 1; let totalPages = 1; const allResults = [];
while (page <= maxPages) { const url = `${TMDB_BASE_URL}/discover/movie?api_key=${TMDB_API_KEY}&with_genres=27&sort_by=primary_release_date.desc&page=${page}&include_adult=false&include_video=false&primary_release_date.gte=${startYear}-01-01`; logger.debug(`Requesting TMDB: ${url}`); try { do { const url = `${TMDB_BASE_URL}/discover/movie?api_key=${TMDB_API_KEY}&include_adult=false&include_video=false&language=${LANGUAGE}&page=${page}&sort_by=primary_release_date.desc&primary_release_date.gte=${START_YEAR}-01-01&primary_release_date.lte=${END_YEAR}-12-31&vote_average.gte=${MIN_SCORE}&with_genres=${genreCombination}&with_original_language=${LANGUAGE}&without_genres=${EXCLUDED_GENRES}`; logger.debug(`Requesting TMDB: ${url}`);
try { const response = await axios.get(url); const { results, total_pages } = response.data; totalPages = total_pages;
if (results.length === 0) break; // Exit if no more results logger.debug(`Page ${page}/${totalPages} fetched for genre combination ${genreCombination}. Results: ${results.length}`);
logger.debug(`Page ${page} fetched. Results: ${results.length}`); allResults.push(...results);
if (page >= total_pages) break; // Exit if we've reached the last page const validResults = results.filter(movie => movie.release_date && !isNaN(new Date(movie.release_date))); allResults.push(...validResults);
page++; } while (page <= NUM_PAGES && page <= totalPages);
return allResults; } catch (error) { logger.error(`Error fetching page ${page}: ${error.message}`); break; // Stop fetching if an error occurs } } catch (error) { logger.error(`Error fetching movies for genre combination ${genreCombination}:`, error); return []; }}
async function fetchMovies() { const allResults = [];
for (const combination of GENRE_COMBINATIONS) { const results = await fetchMoviesForCombination(combination); allResults.push(...results); }
allResults.sort((a, b) => new Date(b.release_date) - new Date(a.release_date)); logger.info(`Total Horror movies fetched since ${startYear}: ${allResults.length}`); logger.info(`Total movies fetched: ${allResults.length}`); return allResults;}
1 unmodified line try { const url = `${TMDB_BASE_URL}/movie/${movieId}?api_key=${TMDB_API_KEY}`; const response = await axios.get(url); logger.debug(`Metadata fetched for movie ID ${movieId}: ${JSON.stringify(response.data)}`); return response.data; } catch (error) { logger.error(`Error fetching metadata for movie ID ${movieId}: ${error.message}`); logger.error(`Error fetching metadata for movie ID ${movieId}:`, error.message); return { error: 'Failed to fetch movie data' }; }}1 unmodified lineasync function updateCatalogAndMetaCache() { logger.info('Updating catalog and meta cache...'); try { const results = await fetchHorrorMovies(); const results = await fetchMovies(); catalogCache = { timestamp: Date.now(), data: results };
// Fetch meta information for all movies for (const movie of results) { const movieId = movie.id; logger.debug(`Fetching meta for movie ID: ${movieId}`);28 unmodified lines const metas = results.map(item => ({ id: `tmdb-${item.id}`, type: 'movie', name: item.title || 'Unknown Title', name: item.title, poster: item.poster_path ? `https://image.tmdb.org/t/p/w500${item.poster_path}` : null, description: item.overview || 'No description available', releaseInfo: item.release_date ? item.release_date.split('-')[0] : 'Unknown'30 unmodified lines backdrop_path } = movieData;
logger.debug(`Metadata for movie ID ${id}: ${JSON.stringify(movieData)}`); logger.info(`Meta request processed for movie ID: ${id}`); return { meta: { id: args.id,31 unmodified lines }
const interface = builder.getInterface(); const port = process.env.PORT || 3000; const port = process.env.PORT || 8082;
logger.info(`Starting Stremio Add-on server on port ${port}`); serveHTTP(interface, { port });1223456788910111213141516326 unmodified lines3433443453463473483493503513523533543553563573583591378 unmodified lines17381739174017411742174317441745174617471748{ "name": "stremio-ufc-addon", "name": "stremio-custom-addon", "version": "1.2.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "stremio-ufc-addon", "name": "stremio-custom-addon", "version": "1.2.0", "license": "MIT", "dependencies": { "axios": "^0.27.2", "dotenv": "^16.0.3", "node-schedule": "^2.1.0", "stremio-addon-sdk": "^1.6.10", "winston": "^3.8.2"326 unmodified lines "npm": "1.2.8000 || >= 1.4.16" } }, "node_modules/dotenv": { "version": "16.4.5", "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.5.tgz", "integrity": "sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==", "engines": { "node": ">=12" }, "funding": { "url": "https://dotenvx.com" } }, "node_modules/ee-first": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",1378 unmodified lines "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.2.0.tgz", "integrity": "sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg==" }, "dotenv": { "version": "16.4.5", "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.5.tgz", "integrity": "sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==" }, "ee-first": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",122345456789101112131213141516171 unmodified line192021212223242526{ "name": "stremio-ufc-addon", "name": "stremio-custom-addon", "version": "1.2.0", "description": "Stremio Add-on to showcase UFC movies from TMDB with daily updates", "main": "addon.js", "description": "Stremio Add-on to showcase custom movies based on TMDB with configurable filters", "main": "index.js", "scripts": { "start": "node index.js" }, "keywords": [ "stremio", "addon", "ufc", "movies" "movies", "tmdb", "custom" ], "author": "Your Name", "license": "MIT",1 unmodified line "stremio-addon-sdk": "^1.6.10", "axios": "^0.27.2", "winston": "^3.8.2", "node-schedule": "^2.1.0" "node-schedule": "^2.1.0", "dotenv": "^16.0.3" }, "engines": { "node": ">=14.0.0".envAdded+33
cache/catalog_cache.json
cache/meta_cache.json
index.js+60-40
package-lock.json+19-2
package.json+8-6