Upload 5 files
Browse filesFiles changed (5)
12341 unmodified line6789101112131415161 unmodified line1819202122232425262728293031323334353637383940414243444546474849505152535441 unmodified lines969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481 unmodified line15015115215315415515615715815916016119 unmodified lines1811821831841851861872 unmodified lines19019119219319419519630 unmodified lines22722822923023123223319 unmodified lines2532542552562572582592602 unmodified lines263264265266267268269require('dotenv').config();const { addonBuilder, serveHTTP } = require('stremio-addon-sdk');const axios = require('axios');const fs = require('fs').promises;1 unmodified lineconst winston = require('winston');const schedule = require('node-schedule');const 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 = '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');const YEAR_START = process.env.YEAR_START || 2000;const YEAR_END = process.env.YEAR_END || new Date().getFullYear();const MIN_SCORE = parseFloat(process.env.MIN_SCORE) || 4;const MAX_PAGES = parseInt(process.env.MAX_PAGES, 10) || 10;const PAGE_SIZE = parseInt(process.env.PAGE_SIZE, 10) || 25;const GENRES = process.env.GENRES.split(',').map(Number);const GENRES_OR = process.env.GENRES_OR ? process.env.GENRES_OR.split('|').map(Number) : [];const EXCLUDE_GENRES = process.env.EXCLUDE_GENRES.split(',').map(Number);const EXCLUDE_GENRES_OR = process.env.EXCLUDE_GENRES_OR ? process.env.EXCLUDE_GENRES_OR.split('|').map(Number) : [];let catalogCache = {};let metaCache = {};const manifest = {id: 'org.stremio.custom-movies',version: '1.0.0',name: 'Action Fantasy',description: 'Stremio Add-on to showcase movies based on custom search terms',catalogs: [{id: 'custom-movies-catalog',name: 'Action Fantasy',type: 'Easynews',pageSize: PAGE_SIZE,extra: [{ name: 'search', isRequired: false }]}],41 unmodified lines}}async function fetchMovies() {let page = 1;let totalPages = 1;const allResults = [];const genreQuery = GENRES.length ? `with_genres=${GENRES.join(',')}` : '';const genreOrQuery = GENRES_OR.length ? `with_genres=${GENRES_OR.join('|')}` : '';const excludeGenreQuery = EXCLUDE_GENRES.length ? `without_genres=${EXCLUDE_GENRES.join(',')}` : '';const excludeGenreOrQuery = EXCLUDE_GENRES_OR.length ? `without_genres=${EXCLUDE_GENRES_OR.join('|')}` : '';const combinedFilters = [genreQuery, genreOrQuery, excludeGenreQuery, excludeGenreOrQuery].filter(Boolean).join('&');try {do {const url = `${TMDB_BASE_URL}/discover/movie?api_key=${TMDB_API_KEY}&include_adult=false&include_video=false&language=en&page=${page}&sort_by=primary_release_date.desc&primary_release_date.gte=${YEAR_START}-01-01&primary_release_date.lte=${YEAR_END}-12-31&vote_average.gte=${MIN_SCORE}&${combinedFilters}`;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. Results: ${results.length}`);const validResults = results.filter(movie => movie.release_date && !isNaN(new Date(movie.release_date)));allResults.push(...validResults);page++;} while (page <= totalPages && page <= MAX_PAGES);allResults.sort((a, b) => new Date(b.release_date) - new Date(a.release_date));logger.info(`Total movies fetched: ${allResults.length}`);return allResults;} catch (error) {logger.error('Error fetching movies:', error);return [];}}async function fetchMovieMetadata(movieId) {try {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}`);19 unmodified lineslogger.debug(`Catalog cache has ${results.length} items`);if (searchQuery) {results = results.filter(movie =>movie.title.toLowerCase().includes(searchQuery.toLowerCase()));logger.debug(`Filtered results for "${searchQuery}": ${results.length}`);2 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,19 unmodified linesawait updateCatalogAndMetaCache();}schedule.scheduleJob('0 0 * * *', refreshCache);if (!catalogCache.timestamp || Date.now() - catalogCache.timestamp > 24 * 60 * 60 * 1000) {logger.info('Initial cache refresh needed');await refreshCache();2 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 });1231 unmodified line567891011121314151617181 unmodified line20212223242526272829303132333435363738394041424344454641 unmodified lines8889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361 unmodified line13813914014114214314414514614714814915019 unmodified lines1701711721731741751762 unmodified lines17918018118218318418530 unmodified lines21621721821922022122219 unmodified lines2422432442452462472482492502512 unmodified lines254255256257258259260const { addonBuilder, serveHTTP } = require('stremio-addon-sdk');const axios = require('axios');const fs = require('fs').promises;1 unmodified lineconst 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;}async function fetchMovieMetadata(movieId) {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}`);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}`);19 unmodified lineslogger.debug(`Catalog cache has ${results.length} items`);if (searchQuery) {results = results.filter(movie =>movie.title.toLowerCase().includes(searchQuery.toLowerCase()));logger.debug(`Filtered results for "${searchQuery}": ${results.length}`);2 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,19 unmodified linesawait updateCatalogAndMetaCache();}// Schedule cache refresh every day at midnightschedule.scheduleJob('0 0 * * *', refreshCache);// Initial cache refresh if neededif (!catalogCache.timestamp || Date.now() - catalogCache.timestamp > 24 * 60 * 60 * 1000) {logger.info('Initial cache refresh needed');await refreshCache();2 unmodified lines}const interface = builder.getInterface();const port = process.env.PORT || 5056;logger.info(`Starting Stremio Add-on server on port ${port}`);serveHTTP(interface, { port });
9 unmodified lines10111213141516326 unmodified lines3433443453463473483493503513523533543553563573583591378 unmodified lines173817391740174117421743174417451746174717489 unmodified lines"license": "MIT","dependencies": {"axios": "^0.27.2","dotenv": "^16.4.5","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",9 unmodified lines101112131415326 unmodified lines3423433443453463471378 unmodified lines1726172717281729173017319 unmodified lines"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",
14 unmodified lines151617181920212223242514 unmodified lines"author": "Your Name","license": "MIT","dependencies": {"axios": "^0.27.2","dotenv": "^16.4.5","node-schedule": "^2.1.0","stremio-addon-sdk": "^1.6.10","winston": "^3.8.2"},"engines": {"node": ">=14.0.0"14 unmodified lines1516171819202122232414 unmodified lines"author": "Your Name","license": "MIT","dependencies": {"stremio-addon-sdk": "^1.6.10","axios": "^0.27.2","winston": "^3.8.2","node-schedule": "^2.1.0"},"engines": {"node": ">=14.0.0"
cache/catalog_cache.json
cache/meta_cache.json
index.js+44-53
package-lock.json-17
package.json+3-4