mirror of
https://github.com/knightcrawler-stremio/knightcrawler.git
synced 2024-12-20 03:29:51 +00:00
migrate catalogs addon to esm structure
This commit is contained in:
@@ -1,11 +1,11 @@
|
|||||||
const Bottleneck = require('bottleneck');
|
import Bottleneck from 'bottleneck';
|
||||||
const moment = require('moment')
|
import moment from 'moment';
|
||||||
const { addonBuilder } = require('stremio-addon-sdk');
|
import { addonBuilder } from 'stremio-addon-sdk';
|
||||||
const { Providers } = require('../addon/lib/filter')
|
import { Providers } from '../addon/lib/filter.js';
|
||||||
const { createManifest, genres } = require('./lib/manifest');
|
import { createManifest, genres } from './lib/manifest.js';
|
||||||
const { getMetas } = require('./lib/metadata');
|
import { getMetas } from './lib/metadata.js';
|
||||||
const { cacheWrapCatalog, cacheWrapIds } = require('./lib/cache');
|
import { cacheWrapCatalog, cacheWrapIds } from './lib/cache.js';
|
||||||
const repository = require('./lib/repository');
|
import * as repository from './lib/repository.js';
|
||||||
|
|
||||||
const CACHE_MAX_AGE = parseInt(process.env.CACHE_MAX_AGE) || 4 * 60 * 60; // 4 hours in seconds
|
const CACHE_MAX_AGE = parseInt(process.env.CACHE_MAX_AGE) || 4 * 60 * 60; // 4 hours in seconds
|
||||||
const STALE_REVALIDATE_AGE = 4 * 60 * 60; // 4 hours
|
const STALE_REVALIDATE_AGE = 4 * 60 * 60; // 4 hours
|
||||||
@@ -96,4 +96,4 @@ function createCacheKey(catalogId, providers, genre, offset) {
|
|||||||
return [catalogId, providers.join(','), genre, dateKey, offset].filter(x => x !== undefined).join('|');
|
return [catalogId, providers.join(','), genre, dateKey, offset].filter(x => x !== undefined).join('|');
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = builder.getInterface();
|
export default builder.getInterface();
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
const express = require('express');
|
import express from 'express';
|
||||||
const serverless = require('./serverless');
|
import serverless from './serverless.js';
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
const cacheManager = require('cache-manager');
|
import cacheManager from 'cache-manager';
|
||||||
const mangodbStore = require('cache-manager-mongodb');
|
import mangodbStore from 'cache-manager-mongodb';
|
||||||
|
|
||||||
const CATALOG_TTL = process.env.STREAM_TTL || 24 * 60 * 60; // 24 hours
|
const CATALOG_TTL = process.env.STREAM_TTL || 24 * 60 * 60; // 24 hours
|
||||||
|
|
||||||
@@ -37,13 +37,10 @@ function cacheWrap(cache, key, method, options) {
|
|||||||
return cache.wrap(key, method, options);
|
return cache.wrap(key, method, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
function cacheWrapCatalog(key, method) {
|
export function cacheWrapCatalog(key, method) {
|
||||||
return cacheWrap(remoteCache, key, method, { ttl: CATALOG_TTL });
|
return cacheWrap(remoteCache, key, method, { ttl: CATALOG_TTL });
|
||||||
}
|
}
|
||||||
|
|
||||||
function cacheWrapIds(key, method) {
|
export function cacheWrapIds(key, method) {
|
||||||
return cacheWrap(remoteCache, `ids|${key}`, method, { ttl: CATALOG_TTL });
|
return cacheWrap(remoteCache, `ids|${key}`, method, { ttl: CATALOG_TTL });
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { cacheWrapCatalog, cacheWrapIds };
|
|
||||||
|
|
||||||
|
|||||||
@@ -180,9 +180,9 @@ button:active {
|
|||||||
box-shadow: 0 0.5vh 1vh rgba(0, 0, 0, 0.2);
|
box-shadow: 0 0.5vh 1vh rgba(0, 0, 0, 0.2);
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
const { Providers } = require('../../addon/lib/filter');
|
import { Providers } from '../../addon/lib/filter.js';
|
||||||
|
|
||||||
function landingTemplate(manifest, config = {}) {
|
export default function landingTemplate(manifest, config = {}) {
|
||||||
const providers = config.providers || [];
|
const providers = config.providers || [];
|
||||||
|
|
||||||
const background = manifest.background || 'https://dl.strem.io/addon-background.jpg';
|
const background = manifest.background || 'https://dl.strem.io/addon-background.jpg';
|
||||||
@@ -272,5 +272,3 @@ function landingTemplate(manifest, config = {}) {
|
|||||||
|
|
||||||
</html>`
|
</html>`
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = landingTemplate;
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
const { Type } = require('../../addon/lib/types');
|
import { Type } from '../../addon/lib/types.js';
|
||||||
|
|
||||||
const genres = [
|
export const genres = [
|
||||||
'Yesterday',
|
'Yesterday',
|
||||||
'This Week',
|
'This Week',
|
||||||
'Last Week',
|
'Last Week',
|
||||||
@@ -9,7 +9,7 @@ const genres = [
|
|||||||
'All Time'
|
'All Time'
|
||||||
]
|
]
|
||||||
|
|
||||||
function createManifest() {
|
export function createManifest() {
|
||||||
return {
|
return {
|
||||||
id: 'com.stremio.torrentio.catalog.addon',
|
id: 'com.stremio.torrentio.catalog.addon',
|
||||||
version: '1.0.2',
|
version: '1.0.2',
|
||||||
@@ -52,5 +52,3 @@ function createManifest() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { createManifest, genres };
|
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
const axios = require('axios');
|
import axios from 'axios';
|
||||||
const { Type } = require('../../addon/lib/types');
|
import { Type } from '../../addon/lib/types.js';
|
||||||
|
|
||||||
const CINEMETA_URL = 'https://v3-cinemeta.strem.io';
|
const CINEMETA_URL = 'https://v3-cinemeta.strem.io';
|
||||||
const KITSU_URL = 'https://anime-kitsu.strem.fun';
|
const KITSU_URL = 'https://anime-kitsu.strem.fun';
|
||||||
const TIMEOUT = 30000;
|
const TIMEOUT = 30000;
|
||||||
const MAX_SIZE = 40;
|
const MAX_SIZE = 40;
|
||||||
|
|
||||||
function getMetas(ids, type) {
|
export async function getMetas(ids, type) {
|
||||||
if (!ids.length || !type) {
|
if (!ids.length || !type) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
@@ -39,5 +39,3 @@ function _sanitizeMeta(meta) {
|
|||||||
delete meta.credits_crew;
|
delete meta.credits_crew;
|
||||||
return meta;
|
return meta;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { getMetas };
|
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
const { Sequelize, QueryTypes } = require('sequelize');
|
import { Sequelize, QueryTypes } from 'sequelize';
|
||||||
const { Type } = require('../../addon/lib/types');
|
import { Type } from '../../addon/lib/types.js';
|
||||||
|
|
||||||
const DATABASE_URI = process.env.DATABASE_URI;
|
const DATABASE_URI = process.env.DATABASE_URI;
|
||||||
|
|
||||||
const database = new Sequelize(DATABASE_URI, { logging: false });
|
const database = new Sequelize(DATABASE_URI, { logging: false });
|
||||||
|
|
||||||
async function getIds(providers, type, startDate, endDate) {
|
export async function getIds(providers, type, startDate, endDate) {
|
||||||
const idName = type === Type.ANIME ? 'kitsuId' : 'imdbId';
|
const idName = type === Type.ANIME ? 'kitsuId' : 'imdbId';
|
||||||
const episodeCondition = type === Type.SERIES
|
const episodeCondition = type === Type.SERIES
|
||||||
? 'AND files."imdbSeason" IS NOT NULL AND files."imdbEpisode" IS NOT NULL'
|
? 'AND files."imdbSeason" IS NOT NULL AND files."imdbEpisode" IS NOT NULL'
|
||||||
@@ -32,5 +32,3 @@ async function getIds(providers, type, startDate, endDate) {
|
|||||||
const results = await database.query(query, { type: QueryTypes.SELECT });
|
const results = await database.query(query, { type: QueryTypes.SELECT });
|
||||||
return results.map(result => `${result.imdbId || result.kitsuId}`);
|
return results.map(result => `${result.imdbId || result.kitsuId}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { getIds };
|
|
||||||
4
catalogs/package-lock.json
generated
4
catalogs/package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "stremio-torrentio-catalogs",
|
"name": "stremio-torrentio-catalogs",
|
||||||
"version": "1.0.2",
|
"version": "1.0.3",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "stremio-torrentio-catalogs",
|
"name": "stremio-torrentio-catalogs",
|
||||||
"version": "1.0.2",
|
"version": "1.0.3",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^0.27.2",
|
"axios": "^0.27.2",
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
{
|
{
|
||||||
"name": "stremio-torrentio-catalogs",
|
"name": "stremio-torrentio-catalogs",
|
||||||
"version": "1.0.2",
|
"version": "1.0.3",
|
||||||
"main": "index.js",
|
"exports": "./index.js",
|
||||||
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node index.js"
|
"start": "node index.js"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
const { getRouter } = require('stremio-addon-sdk');
|
import getRouter from 'stremio-addon-sdk/src/getRouter.js';
|
||||||
const addonInterface = require('./addon');
|
import addonInterface from './addon.js';
|
||||||
const qs = require('querystring')
|
import qs from 'querystring';
|
||||||
const { parseConfiguration } = require('../addon/lib/configuration');
|
import { parseConfiguration } from '../addon/lib/configuration.js';
|
||||||
const { createManifest } = require('./lib/manifest');
|
import { createManifest } from './lib/manifest.js';
|
||||||
|
|
||||||
const router = getRouter(addonInterface);
|
const router = getRouter(addonInterface);
|
||||||
|
|
||||||
@@ -60,7 +60,7 @@ router.get('/:configuration/:resource/:type/:id/:extra?.json', (req, res, next)
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = function (req, res) {
|
export default function (req, res) {
|
||||||
router(req, res, function () {
|
router(req, res, function () {
|
||||||
res.statusCode = 404;
|
res.statusCode = 404;
|
||||||
res.end();
|
res.end();
|
||||||
|
|||||||
Reference in New Issue
Block a user