Spaces:
Paused
Paused
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 lines4567891011121314151617181 unmodified line20212223242526272829303132333435363738394041424344454641 unmodified lines8889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251 unmodified line1271281291301311321331341351361 unmodified line13813914014114214314414514614714814915028 unmodified lines17918018118218318418530 unmodified lines21621721821922022122231 unmodified lines2542552562572582592603 unmodified linesconst path = require('path');const winston = require('winston');const schedule = require('node-schedule');// Winston logger configurationconst logger = winston.createLogger({level: 'debug',format: winston.format.combine(winston.format.timestamp(),winston.format.printf(({ level, message, timestamp }) => {return `${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 CATALOG_CACHE_FILE = path.join(CACHE_DIR, 'catalog_cache.json');const META_CACHE_FILE = path.join(CACHE_DIR, 'meta_cache.json');let catalogCache = {};let metaCache = {};// Manifestconst manifest = {id: 'org.stremio.horror-movies',version: '1.0.0',name: 'Horror Movies Since 2015',description: 'Stremio Add-on to showcase Horror movies from the year 2015 onward',catalogs: [{id: 'horror-movie-catalog',name: 'Horror Movies',type: 'Easynews',pageSize: 25,extra: [{ name: 'search', isRequired: false }]}],41 unmodified lines}}async function fetchHorrorMovies() {const pageSize = 20; // Number of results per pageconst maxPages = 40; // Limit to prevent too many requestsconst startYear = 2021;let page = 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 {const response = await axios.get(url);const { results, total_pages } = response.data;if (results.length === 0) break; // Exit if no more resultslogger.debug(`Page ${page} fetched. Results: ${results.length}`);allResults.push(...results);if (page >= total_pages) break; // Exit if we've reached the last pagepage++;} catch (error) {logger.error(`Error fetching page ${page}: ${error.message}`);break; // Stop fetching if an error occurs}}allResults.sort((a, b) => new Date(b.release_date) - new Date(a.release_date));logger.info(`Total Horror movies fetched since ${startYear}: ${allResults.length}`);return allResults;}1 unmodified linetry {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}`);return { error: 'Failed to fetch movie data' };}}1 unmodified lineasync function updateCatalogAndMetaCache() {logger.info('Updating catalog and meta cache...');try {const results = await fetchHorrorMovies();catalogCache = {timestamp: Date.now(),data: results};// Fetch meta information for all moviesfor (const movie of results) {const movieId = movie.id;logger.debug(`Fetching meta for movie ID: ${movieId}`);28 unmodified linesconst metas = results.map(item => ({id: `tmdb-${item.id}`,type: 'movie',name: item.title || 'Unknown 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 linesbackdrop_path} = movieData;logger.debug(`Metadata for movie ID ${id}: ${JSON.stringify(movieData)}`);return {meta: {id: args.id,31 unmodified lines}const interface = builder.getInterface();const port = process.env.PORT || 3000;logger.info(`Starting Stremio Add-on server on port ${port}`);serveHTTP(interface, { port });3 unmodified lines45678910111213141516171 unmodified line1920212223242526272829303132333435363738394041424344454647484950515253545556575859606141 unmodified lines1031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471 unmodified line1491501511521531541551561571 unmodified line15916016116216316416516616716816917028 unmodified lines19920020120220320420530 unmodified lines23623723823924024124231 unmodified lines2742752762772782792803 unmodified linesconst path = require('path');const winston = require('winston');const schedule = require('node-schedule');require('dotenv').config(); // Load environment variables// Logger configurationconst logger = winston.createLogger({level: 'debug',format: winston.format.combine(winston.format.timestamp(),winston.format.printf(({ level, message, timestamp }) => `${timestamp} ${level}: ${message}`)),transports: [new winston.transports.Console(),1 unmodified line]});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 = {};const manifest = {id: 'org.stremio.action-addon',version: '1.0.0',name: 'Action Varied',description: 'Stremio Add-on to showcase movies with configurable filters',catalogs: [{type: 'Easynews',id: 'action-movies-catalog',name: 'Action Varied',extra: [{ name: 'search', isRequired: false }]}],41 unmodified lines}}async function fetchMoviesForCombination(genreCombination) {let page = 1;let totalPages = 1;const allResults = [];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}`);const response = await axios.get(url);const { results, total_pages } = response.data;totalPages = total_pages;logger.debug(`Page ${page}/${totalPages} fetched for genre combination ${genreCombination}. Results: ${results.length}`);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 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 movies fetched: ${allResults.length}`);return allResults;}1 unmodified linetry {const url = `${TMDB_BASE_URL}/movie/${movieId}?api_key=${TMDB_API_KEY}`;const response = await axios.get(url);return response.data;} catch (error) {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 fetchMovies();catalogCache = {timestamp: Date.now(),data: results};for (const movie of results) {const movieId = movie.id;logger.debug(`Fetching meta for movie ID: ${movieId}`);28 unmodified linesconst metas = results.map(item => ({id: `tmdb-${item.id}`,type: 'movie',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 linesbackdrop_path} = 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 || 8082;logger.info(`Starting Stremio Add-on server on port ${port}`);serveHTTP(interface, { port });
123456789101112131415326 unmodified lines3423433443453463471378 unmodified lines172617271728172917301731{"name": "stremio-ufc-addon","version": "1.2.0","lockfileVersion": 2,"requires": true,"packages": {"": {"name": "stremio-ufc-addon","version": "1.2.0","license": "MIT","dependencies": {"axios": "^0.27.2","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/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=="},"ee-first": {"version": "1.1.1","resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",12345678910111213141516326 unmodified lines3433443453463473483493503513523533543553563573583591378 unmodified lines17381739174017411742174317441745174617471748{"name": "stremio-custom-addon","version": "1.2.0","lockfileVersion": 2,"requires": true,"packages": {"": {"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",
123456789101112131415161 unmodified line18192021222324{"name": "stremio-ufc-addon","version": "1.2.0","description": "Stremio Add-on to showcase UFC movies from TMDB with daily updates","main": "addon.js","scripts": {"start": "node index.js"},"keywords": ["stremio","addon","ufc","movies"],"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"},"engines": {"node": ">=14.0.0"12345678910111213141516171 unmodified line1920212223242526{"name": "stremio-custom-addon","version": "1.2.0","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","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","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