Spaces:
Paused
Paused
Upload 5 files
Browse files- cache/catalog_cache.json +0 -0
- cache/meta_cache.json +0 -0
- index.js +44 -53
- package-lock.json +0 -17
- package.json +3 -4
cache/catalog_cache.json
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
cache/meta_cache.json
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
require('dotenv').config();
|
| 2 |
const { addonBuilder, serveHTTP } = require('stremio-addon-sdk');
|
| 3 |
const axios = require('axios');
|
| 4 |
const fs = require('fs').promises;
|
|
@@ -6,11 +5,14 @@ const path = require('path');
|
|
| 6 |
const winston = require('winston');
|
| 7 |
const schedule = require('node-schedule');
|
| 8 |
|
|
|
|
| 9 |
const logger = winston.createLogger({
|
| 10 |
level: 'debug',
|
| 11 |
format: winston.format.combine(
|
| 12 |
winston.format.timestamp(),
|
| 13 |
-
winston.format.printf(({ level, message, timestamp }) =>
|
|
|
|
|
|
|
| 14 |
),
|
| 15 |
transports: [
|
| 16 |
new winston.transports.Console(),
|
|
@@ -18,37 +20,27 @@ const logger = winston.createLogger({
|
|
| 18 |
]
|
| 19 |
});
|
| 20 |
|
| 21 |
-
const TMDB_API_KEY =
|
| 22 |
const TMDB_BASE_URL = 'https://api.themoviedb.org/3';
|
| 23 |
const CACHE_DIR = path.join(__dirname, 'cache');
|
| 24 |
const CATALOG_CACHE_FILE = path.join(CACHE_DIR, 'catalog_cache.json');
|
| 25 |
const META_CACHE_FILE = path.join(CACHE_DIR, 'meta_cache.json');
|
| 26 |
|
| 27 |
-
const YEAR_START = process.env.YEAR_START || 2000;
|
| 28 |
-
const YEAR_END = process.env.YEAR_END || new Date().getFullYear();
|
| 29 |
-
const MIN_SCORE = parseFloat(process.env.MIN_SCORE) || 4;
|
| 30 |
-
const MAX_PAGES = parseInt(process.env.MAX_PAGES, 10) || 10;
|
| 31 |
-
const PAGE_SIZE = parseInt(process.env.PAGE_SIZE, 10) || 25;
|
| 32 |
-
|
| 33 |
-
const GENRES = process.env.GENRES.split(',').map(Number);
|
| 34 |
-
const GENRES_OR = process.env.GENRES_OR ? process.env.GENRES_OR.split('|').map(Number) : [];
|
| 35 |
-
const EXCLUDE_GENRES = process.env.EXCLUDE_GENRES.split(',').map(Number);
|
| 36 |
-
const EXCLUDE_GENRES_OR = process.env.EXCLUDE_GENRES_OR ? process.env.EXCLUDE_GENRES_OR.split('|').map(Number) : [];
|
| 37 |
-
|
| 38 |
let catalogCache = {};
|
| 39 |
let metaCache = {};
|
| 40 |
|
|
|
|
| 41 |
const manifest = {
|
| 42 |
-
id: 'org.stremio.
|
| 43 |
version: '1.0.0',
|
| 44 |
-
name: '
|
| 45 |
-
description: 'Stremio Add-on to showcase movies
|
| 46 |
catalogs: [
|
| 47 |
{
|
| 48 |
-
id: '
|
| 49 |
-
name: '
|
| 50 |
type: 'Easynews',
|
| 51 |
-
pageSize:
|
| 52 |
extra: [{ name: 'search', isRequired: false }]
|
| 53 |
}
|
| 54 |
],
|
|
@@ -96,53 +88,49 @@ async function saveCache() {
|
|
| 96 |
}
|
| 97 |
}
|
| 98 |
|
| 99 |
-
async function
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
let page = 1;
|
| 101 |
-
let totalPages = 1;
|
| 102 |
const allResults = [];
|
| 103 |
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
const excludeGenreOrQuery = EXCLUDE_GENRES_OR.length ? `without_genres=${EXCLUDE_GENRES_OR.join('|')}` : '';
|
| 108 |
-
|
| 109 |
-
const combinedFilters = [genreQuery, genreOrQuery, excludeGenreQuery, excludeGenreOrQuery]
|
| 110 |
-
.filter(Boolean)
|
| 111 |
-
.join('&');
|
| 112 |
-
|
| 113 |
-
try {
|
| 114 |
-
do {
|
| 115 |
-
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}`;
|
| 116 |
-
logger.debug(`Requesting TMDB: ${url}`);
|
| 117 |
|
|
|
|
| 118 |
const response = await axios.get(url);
|
| 119 |
const { results, total_pages } = response.data;
|
| 120 |
-
totalPages = total_pages;
|
| 121 |
|
| 122 |
-
|
| 123 |
|
| 124 |
-
|
| 125 |
-
allResults.push(...
|
| 126 |
|
| 127 |
-
page
|
| 128 |
-
} while (page <= totalPages && page <= MAX_PAGES);
|
| 129 |
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
return [];
|
| 136 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 137 |
}
|
| 138 |
|
| 139 |
async function fetchMovieMetadata(movieId) {
|
| 140 |
try {
|
| 141 |
const url = `${TMDB_BASE_URL}/movie/${movieId}?api_key=${TMDB_API_KEY}`;
|
| 142 |
const response = await axios.get(url);
|
|
|
|
| 143 |
return response.data;
|
| 144 |
} catch (error) {
|
| 145 |
-
logger.error(`Error fetching metadata for movie ID ${movieId}:
|
| 146 |
return { error: 'Failed to fetch movie data' };
|
| 147 |
}
|
| 148 |
}
|
|
@@ -150,12 +138,13 @@ async function fetchMovieMetadata(movieId) {
|
|
| 150 |
async function updateCatalogAndMetaCache() {
|
| 151 |
logger.info('Updating catalog and meta cache...');
|
| 152 |
try {
|
| 153 |
-
const results = await
|
| 154 |
catalogCache = {
|
| 155 |
timestamp: Date.now(),
|
| 156 |
data: results
|
| 157 |
};
|
| 158 |
|
|
|
|
| 159 |
for (const movie of results) {
|
| 160 |
const movieId = movie.id;
|
| 161 |
logger.debug(`Fetching meta for movie ID: ${movieId}`);
|
|
@@ -181,7 +170,7 @@ builder.defineCatalogHandler(async (args) => {
|
|
| 181 |
logger.debug(`Catalog cache has ${results.length} items`);
|
| 182 |
|
| 183 |
if (searchQuery) {
|
| 184 |
-
results = results.filter(movie =>
|
| 185 |
movie.title.toLowerCase().includes(searchQuery.toLowerCase())
|
| 186 |
);
|
| 187 |
logger.debug(`Filtered results for "${searchQuery}": ${results.length}`);
|
|
@@ -190,7 +179,7 @@ builder.defineCatalogHandler(async (args) => {
|
|
| 190 |
const metas = results.map(item => ({
|
| 191 |
id: `tmdb-${item.id}`,
|
| 192 |
type: 'movie',
|
| 193 |
-
name: item.title,
|
| 194 |
poster: item.poster_path ? `https://image.tmdb.org/t/p/w500${item.poster_path}` : null,
|
| 195 |
description: item.overview || 'No description available',
|
| 196 |
releaseInfo: item.release_date ? item.release_date.split('-')[0] : 'Unknown'
|
|
@@ -227,7 +216,7 @@ builder.defineMetaHandler(async (args) => {
|
|
| 227 |
backdrop_path
|
| 228 |
} = movieData;
|
| 229 |
|
| 230 |
-
logger.
|
| 231 |
return {
|
| 232 |
meta: {
|
| 233 |
id: args.id,
|
|
@@ -253,8 +242,10 @@ async function startServer() {
|
|
| 253 |
await updateCatalogAndMetaCache();
|
| 254 |
}
|
| 255 |
|
|
|
|
| 256 |
schedule.scheduleJob('0 0 * * *', refreshCache);
|
| 257 |
|
|
|
|
| 258 |
if (!catalogCache.timestamp || Date.now() - catalogCache.timestamp > 24 * 60 * 60 * 1000) {
|
| 259 |
logger.info('Initial cache refresh needed');
|
| 260 |
await refreshCache();
|
|
@@ -263,7 +254,7 @@ async function startServer() {
|
|
| 263 |
}
|
| 264 |
|
| 265 |
const interface = builder.getInterface();
|
| 266 |
-
const port = process.env.PORT ||
|
| 267 |
|
| 268 |
logger.info(`Starting Stremio Add-on server on port ${port}`);
|
| 269 |
serveHTTP(interface, { port });
|
|
|
|
|
|
|
| 1 |
const { addonBuilder, serveHTTP } = require('stremio-addon-sdk');
|
| 2 |
const axios = require('axios');
|
| 3 |
const fs = require('fs').promises;
|
|
|
|
| 5 |
const winston = require('winston');
|
| 6 |
const schedule = require('node-schedule');
|
| 7 |
|
| 8 |
+
// Winston logger configuration
|
| 9 |
const logger = winston.createLogger({
|
| 10 |
level: 'debug',
|
| 11 |
format: winston.format.combine(
|
| 12 |
winston.format.timestamp(),
|
| 13 |
+
winston.format.printf(({ level, message, timestamp }) => {
|
| 14 |
+
return `${timestamp} ${level}: ${message}`;
|
| 15 |
+
})
|
| 16 |
),
|
| 17 |
transports: [
|
| 18 |
new winston.transports.Console(),
|
|
|
|
| 20 |
]
|
| 21 |
});
|
| 22 |
|
| 23 |
+
const TMDB_API_KEY = 'f051e7366c6105ad4f9aafe4733d9dae';
|
| 24 |
const TMDB_BASE_URL = 'https://api.themoviedb.org/3';
|
| 25 |
const CACHE_DIR = path.join(__dirname, 'cache');
|
| 26 |
const CATALOG_CACHE_FILE = path.join(CACHE_DIR, 'catalog_cache.json');
|
| 27 |
const META_CACHE_FILE = path.join(CACHE_DIR, 'meta_cache.json');
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
let catalogCache = {};
|
| 30 |
let metaCache = {};
|
| 31 |
|
| 32 |
+
// Manifest
|
| 33 |
const manifest = {
|
| 34 |
+
id: 'org.stremio.horror-movies',
|
| 35 |
version: '1.0.0',
|
| 36 |
+
name: 'Horror Movies Since 2015',
|
| 37 |
+
description: 'Stremio Add-on to showcase Horror movies from the year 2015 onward',
|
| 38 |
catalogs: [
|
| 39 |
{
|
| 40 |
+
id: 'horror-movie-catalog',
|
| 41 |
+
name: 'Horror Movies',
|
| 42 |
type: 'Easynews',
|
| 43 |
+
pageSize: 25,
|
| 44 |
extra: [{ name: 'search', isRequired: false }]
|
| 45 |
}
|
| 46 |
],
|
|
|
|
| 88 |
}
|
| 89 |
}
|
| 90 |
|
| 91 |
+
async function fetchHorrorMovies() {
|
| 92 |
+
const pageSize = 20; // Number of results per page
|
| 93 |
+
const maxPages = 40; // Limit to prevent too many requests
|
| 94 |
+
const startYear = 2021;
|
| 95 |
+
|
| 96 |
let page = 1;
|
|
|
|
| 97 |
const allResults = [];
|
| 98 |
|
| 99 |
+
while (page <= maxPages) {
|
| 100 |
+
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`;
|
| 101 |
+
logger.debug(`Requesting TMDB: ${url}`);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
|
| 103 |
+
try {
|
| 104 |
const response = await axios.get(url);
|
| 105 |
const { results, total_pages } = response.data;
|
|
|
|
| 106 |
|
| 107 |
+
if (results.length === 0) break; // Exit if no more results
|
| 108 |
|
| 109 |
+
logger.debug(`Page ${page} fetched. Results: ${results.length}`);
|
| 110 |
+
allResults.push(...results);
|
| 111 |
|
| 112 |
+
if (page >= total_pages) break; // Exit if we've reached the last page
|
|
|
|
| 113 |
|
| 114 |
+
page++;
|
| 115 |
+
} catch (error) {
|
| 116 |
+
logger.error(`Error fetching page ${page}: ${error.message}`);
|
| 117 |
+
break; // Stop fetching if an error occurs
|
| 118 |
+
}
|
|
|
|
| 119 |
}
|
| 120 |
+
|
| 121 |
+
allResults.sort((a, b) => new Date(b.release_date) - new Date(a.release_date));
|
| 122 |
+
logger.info(`Total Horror movies fetched since ${startYear}: ${allResults.length}`);
|
| 123 |
+
return allResults;
|
| 124 |
}
|
| 125 |
|
| 126 |
async function fetchMovieMetadata(movieId) {
|
| 127 |
try {
|
| 128 |
const url = `${TMDB_BASE_URL}/movie/${movieId}?api_key=${TMDB_API_KEY}`;
|
| 129 |
const response = await axios.get(url);
|
| 130 |
+
logger.debug(`Metadata fetched for movie ID ${movieId}: ${JSON.stringify(response.data)}`);
|
| 131 |
return response.data;
|
| 132 |
} catch (error) {
|
| 133 |
+
logger.error(`Error fetching metadata for movie ID ${movieId}: ${error.message}`);
|
| 134 |
return { error: 'Failed to fetch movie data' };
|
| 135 |
}
|
| 136 |
}
|
|
|
|
| 138 |
async function updateCatalogAndMetaCache() {
|
| 139 |
logger.info('Updating catalog and meta cache...');
|
| 140 |
try {
|
| 141 |
+
const results = await fetchHorrorMovies();
|
| 142 |
catalogCache = {
|
| 143 |
timestamp: Date.now(),
|
| 144 |
data: results
|
| 145 |
};
|
| 146 |
|
| 147 |
+
// Fetch meta information for all movies
|
| 148 |
for (const movie of results) {
|
| 149 |
const movieId = movie.id;
|
| 150 |
logger.debug(`Fetching meta for movie ID: ${movieId}`);
|
|
|
|
| 170 |
logger.debug(`Catalog cache has ${results.length} items`);
|
| 171 |
|
| 172 |
if (searchQuery) {
|
| 173 |
+
results = results.filter(movie =>
|
| 174 |
movie.title.toLowerCase().includes(searchQuery.toLowerCase())
|
| 175 |
);
|
| 176 |
logger.debug(`Filtered results for "${searchQuery}": ${results.length}`);
|
|
|
|
| 179 |
const metas = results.map(item => ({
|
| 180 |
id: `tmdb-${item.id}`,
|
| 181 |
type: 'movie',
|
| 182 |
+
name: item.title || 'Unknown Title',
|
| 183 |
poster: item.poster_path ? `https://image.tmdb.org/t/p/w500${item.poster_path}` : null,
|
| 184 |
description: item.overview || 'No description available',
|
| 185 |
releaseInfo: item.release_date ? item.release_date.split('-')[0] : 'Unknown'
|
|
|
|
| 216 |
backdrop_path
|
| 217 |
} = movieData;
|
| 218 |
|
| 219 |
+
logger.debug(`Metadata for movie ID ${id}: ${JSON.stringify(movieData)}`);
|
| 220 |
return {
|
| 221 |
meta: {
|
| 222 |
id: args.id,
|
|
|
|
| 242 |
await updateCatalogAndMetaCache();
|
| 243 |
}
|
| 244 |
|
| 245 |
+
// Schedule cache refresh every day at midnight
|
| 246 |
schedule.scheduleJob('0 0 * * *', refreshCache);
|
| 247 |
|
| 248 |
+
// Initial cache refresh if needed
|
| 249 |
if (!catalogCache.timestamp || Date.now() - catalogCache.timestamp > 24 * 60 * 60 * 1000) {
|
| 250 |
logger.info('Initial cache refresh needed');
|
| 251 |
await refreshCache();
|
|
|
|
| 254 |
}
|
| 255 |
|
| 256 |
const interface = builder.getInterface();
|
| 257 |
+
const port = process.env.PORT || 5056;
|
| 258 |
|
| 259 |
logger.info(`Starting Stremio Add-on server on port ${port}`);
|
| 260 |
serveHTTP(interface, { port });
|
package-lock.json
CHANGED
|
@@ -10,7 +10,6 @@
|
|
| 10 |
"license": "MIT",
|
| 11 |
"dependencies": {
|
| 12 |
"axios": "^0.27.2",
|
| 13 |
-
"dotenv": "^16.4.5",
|
| 14 |
"node-schedule": "^2.1.0",
|
| 15 |
"stremio-addon-sdk": "^1.6.10",
|
| 16 |
"winston": "^3.8.2"
|
|
@@ -343,17 +342,6 @@
|
|
| 343 |
"npm": "1.2.8000 || >= 1.4.16"
|
| 344 |
}
|
| 345 |
},
|
| 346 |
-
"node_modules/dotenv": {
|
| 347 |
-
"version": "16.4.5",
|
| 348 |
-
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.5.tgz",
|
| 349 |
-
"integrity": "sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==",
|
| 350 |
-
"engines": {
|
| 351 |
-
"node": ">=12"
|
| 352 |
-
},
|
| 353 |
-
"funding": {
|
| 354 |
-
"url": "https://dotenvx.com"
|
| 355 |
-
}
|
| 356 |
-
},
|
| 357 |
"node_modules/ee-first": {
|
| 358 |
"version": "1.1.1",
|
| 359 |
"resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",
|
|
@@ -1738,11 +1726,6 @@
|
|
| 1738 |
"resolved": "https://registry.npmjs.org/destroy/-/destroy-1.2.0.tgz",
|
| 1739 |
"integrity": "sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg=="
|
| 1740 |
},
|
| 1741 |
-
"dotenv": {
|
| 1742 |
-
"version": "16.4.5",
|
| 1743 |
-
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.5.tgz",
|
| 1744 |
-
"integrity": "sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg=="
|
| 1745 |
-
},
|
| 1746 |
"ee-first": {
|
| 1747 |
"version": "1.1.1",
|
| 1748 |
"resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",
|
|
|
|
| 10 |
"license": "MIT",
|
| 11 |
"dependencies": {
|
| 12 |
"axios": "^0.27.2",
|
|
|
|
| 13 |
"node-schedule": "^2.1.0",
|
| 14 |
"stremio-addon-sdk": "^1.6.10",
|
| 15 |
"winston": "^3.8.2"
|
|
|
|
| 342 |
"npm": "1.2.8000 || >= 1.4.16"
|
| 343 |
}
|
| 344 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 345 |
"node_modules/ee-first": {
|
| 346 |
"version": "1.1.1",
|
| 347 |
"resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",
|
|
|
|
| 1726 |
"resolved": "https://registry.npmjs.org/destroy/-/destroy-1.2.0.tgz",
|
| 1727 |
"integrity": "sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg=="
|
| 1728 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1729 |
"ee-first": {
|
| 1730 |
"version": "1.1.1",
|
| 1731 |
"resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",
|
package.json
CHANGED
|
@@ -15,11 +15,10 @@
|
|
| 15 |
"author": "Your Name",
|
| 16 |
"license": "MIT",
|
| 17 |
"dependencies": {
|
| 18 |
-
"axios": "^0.27.2",
|
| 19 |
-
"dotenv": "^16.4.5",
|
| 20 |
-
"node-schedule": "^2.1.0",
|
| 21 |
"stremio-addon-sdk": "^1.6.10",
|
| 22 |
-
"
|
|
|
|
|
|
|
| 23 |
},
|
| 24 |
"engines": {
|
| 25 |
"node": ">=14.0.0"
|
|
|
|
| 15 |
"author": "Your Name",
|
| 16 |
"license": "MIT",
|
| 17 |
"dependencies": {
|
|
|
|
|
|
|
|
|
|
| 18 |
"stremio-addon-sdk": "^1.6.10",
|
| 19 |
+
"axios": "^0.27.2",
|
| 20 |
+
"winston": "^3.8.2",
|
| 21 |
+
"node-schedule": "^2.1.0"
|
| 22 |
},
|
| 23 |
"engines": {
|
| 24 |
"node": ">=14.0.0"
|